pdf.combined.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.535';
  24. PDFJS.build = 'eff28ee';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. var globalScope = (typeof window === 'undefined') ? this : window;
  29. var isWorker = (typeof window === 'undefined');
  30. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  31. var TextRenderingMode = {
  32. FILL: 0,
  33. STROKE: 1,
  34. FILL_STROKE: 2,
  35. INVISIBLE: 3,
  36. FILL_ADD_TO_PATH: 4,
  37. STROKE_ADD_TO_PATH: 5,
  38. FILL_STROKE_ADD_TO_PATH: 6,
  39. ADD_TO_PATH: 7,
  40. FILL_STROKE_MASK: 3,
  41. ADD_TO_PATH_FLAG: 4
  42. };
  43. var ImageKind = {
  44. GRAYSCALE_1BPP: 1,
  45. RGB_24BPP: 2,
  46. RGBA_32BPP: 3
  47. };
  48. var AnnotationType = {
  49. WIDGET: 1,
  50. TEXT: 2,
  51. LINK: 3
  52. };
  53. var AnnotationBorderStyleType = {
  54. SOLID: 1,
  55. DASHED: 2,
  56. BEVELED: 3,
  57. INSET: 4,
  58. UNDERLINE: 5
  59. };
  60. var StreamType = {
  61. UNKNOWN: 0,
  62. FLATE: 1,
  63. LZW: 2,
  64. DCT: 3,
  65. JPX: 4,
  66. JBIG: 5,
  67. A85: 6,
  68. AHX: 7,
  69. CCF: 8,
  70. RL: 9
  71. };
  72. var FontType = {
  73. UNKNOWN: 0,
  74. TYPE1: 1,
  75. TYPE1C: 2,
  76. CIDFONTTYPE0: 3,
  77. CIDFONTTYPE0C: 4,
  78. TRUETYPE: 5,
  79. CIDFONTTYPE2: 6,
  80. TYPE3: 7,
  81. OPENTYPE: 8,
  82. TYPE0: 9,
  83. MMTYPE1: 10
  84. };
  85. // The global PDFJS object exposes the API
  86. // In production, it will be declared outside a global wrapper
  87. // In development, it will be declared here
  88. if (!globalScope.PDFJS) {
  89. globalScope.PDFJS = {};
  90. }
  91. globalScope.PDFJS.pdfBug = false;
  92. PDFJS.VERBOSITY_LEVELS = {
  93. errors: 0,
  94. warnings: 1,
  95. infos: 5
  96. };
  97. // All the possible operations for an operator list.
  98. var OPS = PDFJS.OPS = {
  99. // Intentionally start from 1 so it is easy to spot bad operators that will be
  100. // 0's.
  101. dependency: 1,
  102. setLineWidth: 2,
  103. setLineCap: 3,
  104. setLineJoin: 4,
  105. setMiterLimit: 5,
  106. setDash: 6,
  107. setRenderingIntent: 7,
  108. setFlatness: 8,
  109. setGState: 9,
  110. save: 10,
  111. restore: 11,
  112. transform: 12,
  113. moveTo: 13,
  114. lineTo: 14,
  115. curveTo: 15,
  116. curveTo2: 16,
  117. curveTo3: 17,
  118. closePath: 18,
  119. rectangle: 19,
  120. stroke: 20,
  121. closeStroke: 21,
  122. fill: 22,
  123. eoFill: 23,
  124. fillStroke: 24,
  125. eoFillStroke: 25,
  126. closeFillStroke: 26,
  127. closeEOFillStroke: 27,
  128. endPath: 28,
  129. clip: 29,
  130. eoClip: 30,
  131. beginText: 31,
  132. endText: 32,
  133. setCharSpacing: 33,
  134. setWordSpacing: 34,
  135. setHScale: 35,
  136. setLeading: 36,
  137. setFont: 37,
  138. setTextRenderingMode: 38,
  139. setTextRise: 39,
  140. moveText: 40,
  141. setLeadingMoveText: 41,
  142. setTextMatrix: 42,
  143. nextLine: 43,
  144. showText: 44,
  145. showSpacedText: 45,
  146. nextLineShowText: 46,
  147. nextLineSetSpacingShowText: 47,
  148. setCharWidth: 48,
  149. setCharWidthAndBounds: 49,
  150. setStrokeColorSpace: 50,
  151. setFillColorSpace: 51,
  152. setStrokeColor: 52,
  153. setStrokeColorN: 53,
  154. setFillColor: 54,
  155. setFillColorN: 55,
  156. setStrokeGray: 56,
  157. setFillGray: 57,
  158. setStrokeRGBColor: 58,
  159. setFillRGBColor: 59,
  160. setStrokeCMYKColor: 60,
  161. setFillCMYKColor: 61,
  162. shadingFill: 62,
  163. beginInlineImage: 63,
  164. beginImageData: 64,
  165. endInlineImage: 65,
  166. paintXObject: 66,
  167. markPoint: 67,
  168. markPointProps: 68,
  169. beginMarkedContent: 69,
  170. beginMarkedContentProps: 70,
  171. endMarkedContent: 71,
  172. beginCompat: 72,
  173. endCompat: 73,
  174. paintFormXObjectBegin: 74,
  175. paintFormXObjectEnd: 75,
  176. beginGroup: 76,
  177. endGroup: 77,
  178. beginAnnotations: 78,
  179. endAnnotations: 79,
  180. beginAnnotation: 80,
  181. endAnnotation: 81,
  182. paintJpegXObject: 82,
  183. paintImageMaskXObject: 83,
  184. paintImageMaskXObjectGroup: 84,
  185. paintImageXObject: 85,
  186. paintInlineImageXObject: 86,
  187. paintInlineImageXObjectGroup: 87,
  188. paintImageXObjectRepeat: 88,
  189. paintImageMaskXObjectRepeat: 89,
  190. paintSolidColorImageMask: 90,
  191. constructPath: 91
  192. };
  193. // A notice for devs. These are good for things that are helpful to devs, such
  194. // as warning that Workers were disabled, which is important to devs but not
  195. // end users.
  196. function info(msg) {
  197. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  198. console.log('Info: ' + msg);
  199. }
  200. }
  201. // Non-fatal warnings.
  202. function warn(msg) {
  203. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  204. console.log('Warning: ' + msg);
  205. }
  206. }
  207. // Fatal errors that should trigger the fallback UI and halt execution by
  208. // throwing an exception.
  209. function error(msg) {
  210. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  211. console.log('Error: ' + msg);
  212. console.log(backtrace());
  213. }
  214. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  215. throw new Error(msg);
  216. }
  217. function backtrace() {
  218. try {
  219. throw new Error();
  220. } catch (e) {
  221. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  222. }
  223. }
  224. function assert(cond, msg) {
  225. if (!cond) {
  226. error(msg);
  227. }
  228. }
  229. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  230. unknown: 'unknown',
  231. forms: 'forms',
  232. javaScript: 'javaScript',
  233. smask: 'smask',
  234. shadingPattern: 'shadingPattern',
  235. font: 'font'
  236. };
  237. var UnsupportedManager = PDFJS.UnsupportedManager =
  238. (function UnsupportedManagerClosure() {
  239. var listeners = [];
  240. return {
  241. listen: function (cb) {
  242. listeners.push(cb);
  243. },
  244. notify: function (featureId) {
  245. warn('Unsupported feature "' + featureId + '"');
  246. for (var i = 0, ii = listeners.length; i < ii; i++) {
  247. listeners[i](featureId);
  248. }
  249. }
  250. };
  251. })();
  252. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  253. // absolute URL, it will be returned as is.
  254. function combineUrl(baseUrl, url) {
  255. if (!url) {
  256. return baseUrl;
  257. }
  258. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  259. return url;
  260. }
  261. var i;
  262. if (url.charAt(0) === '/') {
  263. // absolute path
  264. i = baseUrl.indexOf('://');
  265. if (url.charAt(1) === '/') {
  266. ++i;
  267. } else {
  268. i = baseUrl.indexOf('/', i + 3);
  269. }
  270. return baseUrl.substring(0, i) + url;
  271. } else {
  272. // relative path
  273. var pathLength = baseUrl.length;
  274. i = baseUrl.lastIndexOf('#');
  275. pathLength = i >= 0 ? i : pathLength;
  276. i = baseUrl.lastIndexOf('?', pathLength);
  277. pathLength = i >= 0 ? i : pathLength;
  278. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  279. return baseUrl.substring(0, prefixLength + 1) + url;
  280. }
  281. }
  282. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  283. function isValidUrl(url, allowRelative) {
  284. if (!url) {
  285. return false;
  286. }
  287. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  288. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  289. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  290. if (!protocol) {
  291. return allowRelative;
  292. }
  293. protocol = protocol[0].toLowerCase();
  294. switch (protocol) {
  295. case 'http':
  296. case 'https':
  297. case 'ftp':
  298. case 'mailto':
  299. case 'tel':
  300. return true;
  301. default:
  302. return false;
  303. }
  304. }
  305. PDFJS.isValidUrl = isValidUrl;
  306. function shadow(obj, prop, value) {
  307. Object.defineProperty(obj, prop, { value: value,
  308. enumerable: true,
  309. configurable: true,
  310. writable: false });
  311. return value;
  312. }
  313. PDFJS.shadow = shadow;
  314. var LinkTarget = PDFJS.LinkTarget = {
  315. NONE: 0, // Default value.
  316. SELF: 1,
  317. BLANK: 2,
  318. PARENT: 3,
  319. TOP: 4,
  320. };
  321. var LinkTargetStringMap = [
  322. '',
  323. '_self',
  324. '_blank',
  325. '_parent',
  326. '_top'
  327. ];
  328. function isExternalLinkTargetSet() {
  329. switch (PDFJS.externalLinkTarget) {
  330. case LinkTarget.NONE:
  331. return false;
  332. case LinkTarget.SELF:
  333. case LinkTarget.BLANK:
  334. case LinkTarget.PARENT:
  335. case LinkTarget.TOP:
  336. return true;
  337. }
  338. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  339. // Reset the external link target, to suppress further warnings.
  340. PDFJS.externalLinkTarget = LinkTarget.NONE;
  341. return false;
  342. }
  343. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  344. var PasswordResponses = PDFJS.PasswordResponses = {
  345. NEED_PASSWORD: 1,
  346. INCORRECT_PASSWORD: 2
  347. };
  348. var PasswordException = (function PasswordExceptionClosure() {
  349. function PasswordException(msg, code) {
  350. this.name = 'PasswordException';
  351. this.message = msg;
  352. this.code = code;
  353. }
  354. PasswordException.prototype = new Error();
  355. PasswordException.constructor = PasswordException;
  356. return PasswordException;
  357. })();
  358. PDFJS.PasswordException = PasswordException;
  359. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  360. function UnknownErrorException(msg, details) {
  361. this.name = 'UnknownErrorException';
  362. this.message = msg;
  363. this.details = details;
  364. }
  365. UnknownErrorException.prototype = new Error();
  366. UnknownErrorException.constructor = UnknownErrorException;
  367. return UnknownErrorException;
  368. })();
  369. PDFJS.UnknownErrorException = UnknownErrorException;
  370. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  371. function InvalidPDFException(msg) {
  372. this.name = 'InvalidPDFException';
  373. this.message = msg;
  374. }
  375. InvalidPDFException.prototype = new Error();
  376. InvalidPDFException.constructor = InvalidPDFException;
  377. return InvalidPDFException;
  378. })();
  379. PDFJS.InvalidPDFException = InvalidPDFException;
  380. var MissingPDFException = (function MissingPDFExceptionClosure() {
  381. function MissingPDFException(msg) {
  382. this.name = 'MissingPDFException';
  383. this.message = msg;
  384. }
  385. MissingPDFException.prototype = new Error();
  386. MissingPDFException.constructor = MissingPDFException;
  387. return MissingPDFException;
  388. })();
  389. PDFJS.MissingPDFException = MissingPDFException;
  390. var UnexpectedResponseException =
  391. (function UnexpectedResponseExceptionClosure() {
  392. function UnexpectedResponseException(msg, status) {
  393. this.name = 'UnexpectedResponseException';
  394. this.message = msg;
  395. this.status = status;
  396. }
  397. UnexpectedResponseException.prototype = new Error();
  398. UnexpectedResponseException.constructor = UnexpectedResponseException;
  399. return UnexpectedResponseException;
  400. })();
  401. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  402. var NotImplementedException = (function NotImplementedExceptionClosure() {
  403. function NotImplementedException(msg) {
  404. this.message = msg;
  405. }
  406. NotImplementedException.prototype = new Error();
  407. NotImplementedException.prototype.name = 'NotImplementedException';
  408. NotImplementedException.constructor = NotImplementedException;
  409. return NotImplementedException;
  410. })();
  411. var MissingDataException = (function MissingDataExceptionClosure() {
  412. function MissingDataException(begin, end) {
  413. this.begin = begin;
  414. this.end = end;
  415. this.message = 'Missing data [' + begin + ', ' + end + ')';
  416. }
  417. MissingDataException.prototype = new Error();
  418. MissingDataException.prototype.name = 'MissingDataException';
  419. MissingDataException.constructor = MissingDataException;
  420. return MissingDataException;
  421. })();
  422. var XRefParseException = (function XRefParseExceptionClosure() {
  423. function XRefParseException(msg) {
  424. this.message = msg;
  425. }
  426. XRefParseException.prototype = new Error();
  427. XRefParseException.prototype.name = 'XRefParseException';
  428. XRefParseException.constructor = XRefParseException;
  429. return XRefParseException;
  430. })();
  431. function bytesToString(bytes) {
  432. assert(bytes !== null && typeof bytes === 'object' &&
  433. bytes.length !== undefined, 'Invalid argument for bytesToString');
  434. var length = bytes.length;
  435. var MAX_ARGUMENT_COUNT = 8192;
  436. if (length < MAX_ARGUMENT_COUNT) {
  437. return String.fromCharCode.apply(null, bytes);
  438. }
  439. var strBuf = [];
  440. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  441. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  442. var chunk = bytes.subarray(i, chunkEnd);
  443. strBuf.push(String.fromCharCode.apply(null, chunk));
  444. }
  445. return strBuf.join('');
  446. }
  447. function stringToBytes(str) {
  448. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  449. var length = str.length;
  450. var bytes = new Uint8Array(length);
  451. for (var i = 0; i < length; ++i) {
  452. bytes[i] = str.charCodeAt(i) & 0xFF;
  453. }
  454. return bytes;
  455. }
  456. function string32(value) {
  457. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  458. (value >> 8) & 0xff, value & 0xff);
  459. }
  460. function log2(x) {
  461. var n = 1, i = 0;
  462. while (x > n) {
  463. n <<= 1;
  464. i++;
  465. }
  466. return i;
  467. }
  468. function readInt8(data, start) {
  469. return (data[start] << 24) >> 24;
  470. }
  471. function readUint16(data, offset) {
  472. return (data[offset] << 8) | data[offset + 1];
  473. }
  474. function readUint32(data, offset) {
  475. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  476. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  477. }
  478. // Lazy test the endianness of the platform
  479. // NOTE: This will be 'true' for simulated TypedArrays
  480. function isLittleEndian() {
  481. var buffer8 = new Uint8Array(2);
  482. buffer8[0] = 1;
  483. var buffer16 = new Uint16Array(buffer8.buffer);
  484. return (buffer16[0] === 1);
  485. }
  486. Object.defineProperty(PDFJS, 'isLittleEndian', {
  487. configurable: true,
  488. get: function PDFJS_isLittleEndian() {
  489. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  490. }
  491. });
  492. // Lazy test if the userAgent support CanvasTypedArrays
  493. function hasCanvasTypedArrays() {
  494. var canvas = document.createElement('canvas');
  495. canvas.width = canvas.height = 1;
  496. var ctx = canvas.getContext('2d');
  497. var imageData = ctx.createImageData(1, 1);
  498. return (typeof imageData.data.buffer !== 'undefined');
  499. }
  500. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  501. configurable: true,
  502. get: function PDFJS_hasCanvasTypedArrays() {
  503. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  504. }
  505. });
  506. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  507. function Uint32ArrayView(buffer, length) {
  508. this.buffer = buffer;
  509. this.byteLength = buffer.length;
  510. this.length = length === undefined ? (this.byteLength >> 2) : length;
  511. ensureUint32ArrayViewProps(this.length);
  512. }
  513. Uint32ArrayView.prototype = Object.create(null);
  514. var uint32ArrayViewSetters = 0;
  515. function createUint32ArrayProp(index) {
  516. return {
  517. get: function () {
  518. var buffer = this.buffer, offset = index << 2;
  519. return (buffer[offset] | (buffer[offset + 1] << 8) |
  520. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  521. },
  522. set: function (value) {
  523. var buffer = this.buffer, offset = index << 2;
  524. buffer[offset] = value & 255;
  525. buffer[offset + 1] = (value >> 8) & 255;
  526. buffer[offset + 2] = (value >> 16) & 255;
  527. buffer[offset + 3] = (value >>> 24) & 255;
  528. }
  529. };
  530. }
  531. function ensureUint32ArrayViewProps(length) {
  532. while (uint32ArrayViewSetters < length) {
  533. Object.defineProperty(Uint32ArrayView.prototype,
  534. uint32ArrayViewSetters,
  535. createUint32ArrayProp(uint32ArrayViewSetters));
  536. uint32ArrayViewSetters++;
  537. }
  538. }
  539. return Uint32ArrayView;
  540. })();
  541. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  542. var Util = PDFJS.Util = (function UtilClosure() {
  543. function Util() {}
  544. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  545. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  546. // creating many intermediate strings.
  547. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  548. rgbBuf[1] = r;
  549. rgbBuf[3] = g;
  550. rgbBuf[5] = b;
  551. return rgbBuf.join('');
  552. };
  553. // Concatenates two transformation matrices together and returns the result.
  554. Util.transform = function Util_transform(m1, m2) {
  555. return [
  556. m1[0] * m2[0] + m1[2] * m2[1],
  557. m1[1] * m2[0] + m1[3] * m2[1],
  558. m1[0] * m2[2] + m1[2] * m2[3],
  559. m1[1] * m2[2] + m1[3] * m2[3],
  560. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  561. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  562. ];
  563. };
  564. // For 2d affine transforms
  565. Util.applyTransform = function Util_applyTransform(p, m) {
  566. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  567. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  568. return [xt, yt];
  569. };
  570. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  571. var d = m[0] * m[3] - m[1] * m[2];
  572. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  573. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  574. return [xt, yt];
  575. };
  576. // Applies the transform to the rectangle and finds the minimum axially
  577. // aligned bounding box.
  578. Util.getAxialAlignedBoundingBox =
  579. function Util_getAxialAlignedBoundingBox(r, m) {
  580. var p1 = Util.applyTransform(r, m);
  581. var p2 = Util.applyTransform(r.slice(2, 4), m);
  582. var p3 = Util.applyTransform([r[0], r[3]], m);
  583. var p4 = Util.applyTransform([r[2], r[1]], m);
  584. return [
  585. Math.min(p1[0], p2[0], p3[0], p4[0]),
  586. Math.min(p1[1], p2[1], p3[1], p4[1]),
  587. Math.max(p1[0], p2[0], p3[0], p4[0]),
  588. Math.max(p1[1], p2[1], p3[1], p4[1])
  589. ];
  590. };
  591. Util.inverseTransform = function Util_inverseTransform(m) {
  592. var d = m[0] * m[3] - m[1] * m[2];
  593. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  594. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  595. };
  596. // Apply a generic 3d matrix M on a 3-vector v:
  597. // | a b c | | X |
  598. // | d e f | x | Y |
  599. // | g h i | | Z |
  600. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  601. // with v as [X,Y,Z]
  602. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  603. return [
  604. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  605. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  606. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  607. ];
  608. };
  609. // This calculation uses Singular Value Decomposition.
  610. // The SVD can be represented with formula A = USV. We are interested in the
  611. // matrix S here because it represents the scale values.
  612. Util.singularValueDecompose2dScale =
  613. function Util_singularValueDecompose2dScale(m) {
  614. var transpose = [m[0], m[2], m[1], m[3]];
  615. // Multiply matrix m with its transpose.
  616. var a = m[0] * transpose[0] + m[1] * transpose[2];
  617. var b = m[0] * transpose[1] + m[1] * transpose[3];
  618. var c = m[2] * transpose[0] + m[3] * transpose[2];
  619. var d = m[2] * transpose[1] + m[3] * transpose[3];
  620. // Solve the second degree polynomial to get roots.
  621. var first = (a + d) / 2;
  622. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  623. var sx = first + second || 1;
  624. var sy = first - second || 1;
  625. // Scale values are the square roots of the eigenvalues.
  626. return [Math.sqrt(sx), Math.sqrt(sy)];
  627. };
  628. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  629. // For coordinate systems whose origin lies in the bottom-left, this
  630. // means normalization to (BL,TR) ordering. For systems with origin in the
  631. // top-left, this means (TL,BR) ordering.
  632. Util.normalizeRect = function Util_normalizeRect(rect) {
  633. var r = rect.slice(0); // clone rect
  634. if (rect[0] > rect[2]) {
  635. r[0] = rect[2];
  636. r[2] = rect[0];
  637. }
  638. if (rect[1] > rect[3]) {
  639. r[1] = rect[3];
  640. r[3] = rect[1];
  641. }
  642. return r;
  643. };
  644. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  645. // intersection of rect1 and rect2. If no intersection, returns 'false'
  646. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  647. Util.intersect = function Util_intersect(rect1, rect2) {
  648. function compare(a, b) {
  649. return a - b;
  650. }
  651. // Order points along the axes
  652. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  653. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  654. result = [];
  655. rect1 = Util.normalizeRect(rect1);
  656. rect2 = Util.normalizeRect(rect2);
  657. // X: first and second points belong to different rectangles?
  658. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  659. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  660. // Intersection must be between second and third points
  661. result[0] = orderedX[1];
  662. result[2] = orderedX[2];
  663. } else {
  664. return false;
  665. }
  666. // Y: first and second points belong to different rectangles?
  667. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  668. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  669. // Intersection must be between second and third points
  670. result[1] = orderedY[1];
  671. result[3] = orderedY[2];
  672. } else {
  673. return false;
  674. }
  675. return result;
  676. };
  677. Util.sign = function Util_sign(num) {
  678. return num < 0 ? -1 : 1;
  679. };
  680. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  681. Array.prototype.push.apply(arr1, arr2);
  682. };
  683. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  684. Array.prototype.unshift.apply(arr1, arr2);
  685. };
  686. Util.extendObj = function extendObj(obj1, obj2) {
  687. for (var key in obj2) {
  688. obj1[key] = obj2[key];
  689. }
  690. };
  691. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  692. name) {
  693. while (dict && !dict.has(name)) {
  694. dict = dict.get('Parent');
  695. }
  696. if (!dict) {
  697. return null;
  698. }
  699. return dict.get(name);
  700. };
  701. Util.inherit = function Util_inherit(sub, base, prototype) {
  702. sub.prototype = Object.create(base.prototype);
  703. sub.prototype.constructor = sub;
  704. for (var prop in prototype) {
  705. sub.prototype[prop] = prototype[prop];
  706. }
  707. };
  708. Util.loadScript = function Util_loadScript(src, callback) {
  709. var script = document.createElement('script');
  710. var loaded = false;
  711. script.setAttribute('src', src);
  712. if (callback) {
  713. script.onload = function() {
  714. if (!loaded) {
  715. callback();
  716. }
  717. loaded = true;
  718. };
  719. }
  720. document.getElementsByTagName('head')[0].appendChild(script);
  721. };
  722. return Util;
  723. })();
  724. /**
  725. * PDF page viewport created based on scale, rotation and offset.
  726. * @class
  727. * @alias PDFJS.PageViewport
  728. */
  729. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  730. /**
  731. * @constructor
  732. * @private
  733. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  734. * @param scale {number} scale of the viewport.
  735. * @param rotation {number} rotations of the viewport in degrees.
  736. * @param offsetX {number} offset X
  737. * @param offsetY {number} offset Y
  738. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  739. */
  740. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  741. this.viewBox = viewBox;
  742. this.scale = scale;
  743. this.rotation = rotation;
  744. this.offsetX = offsetX;
  745. this.offsetY = offsetY;
  746. // creating transform to convert pdf coordinate system to the normal
  747. // canvas like coordinates taking in account scale and rotation
  748. var centerX = (viewBox[2] + viewBox[0]) / 2;
  749. var centerY = (viewBox[3] + viewBox[1]) / 2;
  750. var rotateA, rotateB, rotateC, rotateD;
  751. rotation = rotation % 360;
  752. rotation = rotation < 0 ? rotation + 360 : rotation;
  753. switch (rotation) {
  754. case 180:
  755. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  756. break;
  757. case 90:
  758. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  759. break;
  760. case 270:
  761. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  762. break;
  763. //case 0:
  764. default:
  765. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  766. break;
  767. }
  768. if (dontFlip) {
  769. rotateC = -rotateC; rotateD = -rotateD;
  770. }
  771. var offsetCanvasX, offsetCanvasY;
  772. var width, height;
  773. if (rotateA === 0) {
  774. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  775. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  776. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  777. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  778. } else {
  779. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  780. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  781. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  782. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  783. }
  784. // creating transform for the following operations:
  785. // translate(-centerX, -centerY), rotate and flip vertically,
  786. // scale, and translate(offsetCanvasX, offsetCanvasY)
  787. this.transform = [
  788. rotateA * scale,
  789. rotateB * scale,
  790. rotateC * scale,
  791. rotateD * scale,
  792. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  793. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  794. ];
  795. this.width = width;
  796. this.height = height;
  797. this.fontScale = scale;
  798. }
  799. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  800. /**
  801. * Clones viewport with additional properties.
  802. * @param args {Object} (optional) If specified, may contain the 'scale' or
  803. * 'rotation' properties to override the corresponding properties in
  804. * the cloned viewport.
  805. * @returns {PDFJS.PageViewport} Cloned viewport.
  806. */
  807. clone: function PageViewPort_clone(args) {
  808. args = args || {};
  809. var scale = 'scale' in args ? args.scale : this.scale;
  810. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  811. return new PageViewport(this.viewBox.slice(), scale, rotation,
  812. this.offsetX, this.offsetY, args.dontFlip);
  813. },
  814. /**
  815. * Converts PDF point to the viewport coordinates. For examples, useful for
  816. * converting PDF location into canvas pixel coordinates.
  817. * @param x {number} X coordinate.
  818. * @param y {number} Y coordinate.
  819. * @returns {Object} Object that contains 'x' and 'y' properties of the
  820. * point in the viewport coordinate space.
  821. * @see {@link convertToPdfPoint}
  822. * @see {@link convertToViewportRectangle}
  823. */
  824. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  825. return Util.applyTransform([x, y], this.transform);
  826. },
  827. /**
  828. * Converts PDF rectangle to the viewport coordinates.
  829. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  830. * @returns {Array} Contains corresponding coordinates of the rectangle
  831. * in the viewport coordinate space.
  832. * @see {@link convertToViewportPoint}
  833. */
  834. convertToViewportRectangle:
  835. function PageViewport_convertToViewportRectangle(rect) {
  836. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  837. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  838. return [tl[0], tl[1], br[0], br[1]];
  839. },
  840. /**
  841. * Converts viewport coordinates to the PDF location. For examples, useful
  842. * for converting canvas pixel location into PDF one.
  843. * @param x {number} X coordinate.
  844. * @param y {number} Y coordinate.
  845. * @returns {Object} Object that contains 'x' and 'y' properties of the
  846. * point in the PDF coordinate space.
  847. * @see {@link convertToViewportPoint}
  848. */
  849. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  850. return Util.applyInverseTransform([x, y], this.transform);
  851. }
  852. };
  853. return PageViewport;
  854. })();
  855. var PDFStringTranslateTable = [
  856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  857. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  858. 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,
  859. 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,
  860. 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,
  861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  862. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  863. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  864. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  865. ];
  866. function stringToPDFString(str) {
  867. var i, n = str.length, strBuf = [];
  868. if (str[0] === '\xFE' && str[1] === '\xFF') {
  869. // UTF16BE BOM
  870. for (i = 2; i < n; i += 2) {
  871. strBuf.push(String.fromCharCode(
  872. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  873. }
  874. } else {
  875. for (i = 0; i < n; ++i) {
  876. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  877. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  878. }
  879. }
  880. return strBuf.join('');
  881. }
  882. function stringToUTF8String(str) {
  883. return decodeURIComponent(escape(str));
  884. }
  885. function utf8StringToString(str) {
  886. return unescape(encodeURIComponent(str));
  887. }
  888. function isEmptyObj(obj) {
  889. for (var key in obj) {
  890. return false;
  891. }
  892. return true;
  893. }
  894. function isBool(v) {
  895. return typeof v === 'boolean';
  896. }
  897. function isInt(v) {
  898. return typeof v === 'number' && ((v | 0) === v);
  899. }
  900. function isNum(v) {
  901. return typeof v === 'number';
  902. }
  903. function isString(v) {
  904. return typeof v === 'string';
  905. }
  906. function isName(v) {
  907. return v instanceof Name;
  908. }
  909. function isCmd(v, cmd) {
  910. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  911. }
  912. function isDict(v, type) {
  913. if (!(v instanceof Dict)) {
  914. return false;
  915. }
  916. if (!type) {
  917. return true;
  918. }
  919. var dictType = v.get('Type');
  920. return isName(dictType) && dictType.name === type;
  921. }
  922. function isArray(v) {
  923. return v instanceof Array;
  924. }
  925. function isStream(v) {
  926. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  927. }
  928. function isArrayBuffer(v) {
  929. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  930. }
  931. function isRef(v) {
  932. return v instanceof Ref;
  933. }
  934. /**
  935. * Promise Capability object.
  936. *
  937. * @typedef {Object} PromiseCapability
  938. * @property {Promise} promise - A promise object.
  939. * @property {function} resolve - Fullfills the promise.
  940. * @property {function} reject - Rejects the promise.
  941. */
  942. /**
  943. * Creates a promise capability object.
  944. * @alias PDFJS.createPromiseCapability
  945. *
  946. * @return {PromiseCapability} A capability object contains:
  947. * - a Promise, resolve and reject methods.
  948. */
  949. function createPromiseCapability() {
  950. var capability = {};
  951. capability.promise = new Promise(function (resolve, reject) {
  952. capability.resolve = resolve;
  953. capability.reject = reject;
  954. });
  955. return capability;
  956. }
  957. PDFJS.createPromiseCapability = createPromiseCapability;
  958. /**
  959. * Polyfill for Promises:
  960. * The following promise implementation tries to generally implement the
  961. * Promise/A+ spec. Some notable differences from other promise libaries are:
  962. * - There currently isn't a seperate deferred and promise object.
  963. * - Unhandled rejections eventually show an error if they aren't handled.
  964. *
  965. * Based off of the work in:
  966. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  967. */
  968. (function PromiseClosure() {
  969. if (globalScope.Promise) {
  970. // Promises existing in the DOM/Worker, checking presence of all/resolve
  971. if (typeof globalScope.Promise.all !== 'function') {
  972. globalScope.Promise.all = function (iterable) {
  973. var count = 0, results = [], resolve, reject;
  974. var promise = new globalScope.Promise(function (resolve_, reject_) {
  975. resolve = resolve_;
  976. reject = reject_;
  977. });
  978. iterable.forEach(function (p, i) {
  979. count++;
  980. p.then(function (result) {
  981. results[i] = result;
  982. count--;
  983. if (count === 0) {
  984. resolve(results);
  985. }
  986. }, reject);
  987. });
  988. if (count === 0) {
  989. resolve(results);
  990. }
  991. return promise;
  992. };
  993. }
  994. if (typeof globalScope.Promise.resolve !== 'function') {
  995. globalScope.Promise.resolve = function (value) {
  996. return new globalScope.Promise(function (resolve) { resolve(value); });
  997. };
  998. }
  999. if (typeof globalScope.Promise.reject !== 'function') {
  1000. globalScope.Promise.reject = function (reason) {
  1001. return new globalScope.Promise(function (resolve, reject) {
  1002. reject(reason);
  1003. });
  1004. };
  1005. }
  1006. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1007. globalScope.Promise.prototype.catch = function (onReject) {
  1008. return globalScope.Promise.prototype.then(undefined, onReject);
  1009. };
  1010. }
  1011. return;
  1012. }
  1013. var STATUS_PENDING = 0;
  1014. var STATUS_RESOLVED = 1;
  1015. var STATUS_REJECTED = 2;
  1016. // In an attempt to avoid silent exceptions, unhandled rejections are
  1017. // tracked and if they aren't handled in a certain amount of time an
  1018. // error is logged.
  1019. var REJECTION_TIMEOUT = 500;
  1020. var HandlerManager = {
  1021. handlers: [],
  1022. running: false,
  1023. unhandledRejections: [],
  1024. pendingRejectionCheck: false,
  1025. scheduleHandlers: function scheduleHandlers(promise) {
  1026. if (promise._status === STATUS_PENDING) {
  1027. return;
  1028. }
  1029. this.handlers = this.handlers.concat(promise._handlers);
  1030. promise._handlers = [];
  1031. if (this.running) {
  1032. return;
  1033. }
  1034. this.running = true;
  1035. setTimeout(this.runHandlers.bind(this), 0);
  1036. },
  1037. runHandlers: function runHandlers() {
  1038. var RUN_TIMEOUT = 1; // ms
  1039. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1040. while (this.handlers.length > 0) {
  1041. var handler = this.handlers.shift();
  1042. var nextStatus = handler.thisPromise._status;
  1043. var nextValue = handler.thisPromise._value;
  1044. try {
  1045. if (nextStatus === STATUS_RESOLVED) {
  1046. if (typeof handler.onResolve === 'function') {
  1047. nextValue = handler.onResolve(nextValue);
  1048. }
  1049. } else if (typeof handler.onReject === 'function') {
  1050. nextValue = handler.onReject(nextValue);
  1051. nextStatus = STATUS_RESOLVED;
  1052. if (handler.thisPromise._unhandledRejection) {
  1053. this.removeUnhandeledRejection(handler.thisPromise);
  1054. }
  1055. }
  1056. } catch (ex) {
  1057. nextStatus = STATUS_REJECTED;
  1058. nextValue = ex;
  1059. }
  1060. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1061. if (Date.now() >= timeoutAt) {
  1062. break;
  1063. }
  1064. }
  1065. if (this.handlers.length > 0) {
  1066. setTimeout(this.runHandlers.bind(this), 0);
  1067. return;
  1068. }
  1069. this.running = false;
  1070. },
  1071. addUnhandledRejection: function addUnhandledRejection(promise) {
  1072. this.unhandledRejections.push({
  1073. promise: promise,
  1074. time: Date.now()
  1075. });
  1076. this.scheduleRejectionCheck();
  1077. },
  1078. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1079. promise._unhandledRejection = false;
  1080. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1081. if (this.unhandledRejections[i].promise === promise) {
  1082. this.unhandledRejections.splice(i);
  1083. i--;
  1084. }
  1085. }
  1086. },
  1087. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1088. if (this.pendingRejectionCheck) {
  1089. return;
  1090. }
  1091. this.pendingRejectionCheck = true;
  1092. setTimeout(function rejectionCheck() {
  1093. this.pendingRejectionCheck = false;
  1094. var now = Date.now();
  1095. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1096. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1097. var unhandled = this.unhandledRejections[i].promise._value;
  1098. var msg = 'Unhandled rejection: ' + unhandled;
  1099. if (unhandled.stack) {
  1100. msg += '\n' + unhandled.stack;
  1101. }
  1102. warn(msg);
  1103. this.unhandledRejections.splice(i);
  1104. i--;
  1105. }
  1106. }
  1107. if (this.unhandledRejections.length) {
  1108. this.scheduleRejectionCheck();
  1109. }
  1110. }.bind(this), REJECTION_TIMEOUT);
  1111. }
  1112. };
  1113. function Promise(resolver) {
  1114. this._status = STATUS_PENDING;
  1115. this._handlers = [];
  1116. try {
  1117. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1118. } catch (e) {
  1119. this._reject(e);
  1120. }
  1121. }
  1122. /**
  1123. * Builds a promise that is resolved when all the passed in promises are
  1124. * resolved.
  1125. * @param {array} array of data and/or promises to wait for.
  1126. * @return {Promise} New dependant promise.
  1127. */
  1128. Promise.all = function Promise_all(promises) {
  1129. var resolveAll, rejectAll;
  1130. var deferred = new Promise(function (resolve, reject) {
  1131. resolveAll = resolve;
  1132. rejectAll = reject;
  1133. });
  1134. var unresolved = promises.length;
  1135. var results = [];
  1136. if (unresolved === 0) {
  1137. resolveAll(results);
  1138. return deferred;
  1139. }
  1140. function reject(reason) {
  1141. if (deferred._status === STATUS_REJECTED) {
  1142. return;
  1143. }
  1144. results = [];
  1145. rejectAll(reason);
  1146. }
  1147. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1148. var promise = promises[i];
  1149. var resolve = (function(i) {
  1150. return function(value) {
  1151. if (deferred._status === STATUS_REJECTED) {
  1152. return;
  1153. }
  1154. results[i] = value;
  1155. unresolved--;
  1156. if (unresolved === 0) {
  1157. resolveAll(results);
  1158. }
  1159. };
  1160. })(i);
  1161. if (Promise.isPromise(promise)) {
  1162. promise.then(resolve, reject);
  1163. } else {
  1164. resolve(promise);
  1165. }
  1166. }
  1167. return deferred;
  1168. };
  1169. /**
  1170. * Checks if the value is likely a promise (has a 'then' function).
  1171. * @return {boolean} true if value is thenable
  1172. */
  1173. Promise.isPromise = function Promise_isPromise(value) {
  1174. return value && typeof value.then === 'function';
  1175. };
  1176. /**
  1177. * Creates resolved promise
  1178. * @param value resolve value
  1179. * @returns {Promise}
  1180. */
  1181. Promise.resolve = function Promise_resolve(value) {
  1182. return new Promise(function (resolve) { resolve(value); });
  1183. };
  1184. /**
  1185. * Creates rejected promise
  1186. * @param reason rejection value
  1187. * @returns {Promise}
  1188. */
  1189. Promise.reject = function Promise_reject(reason) {
  1190. return new Promise(function (resolve, reject) { reject(reason); });
  1191. };
  1192. Promise.prototype = {
  1193. _status: null,
  1194. _value: null,
  1195. _handlers: null,
  1196. _unhandledRejection: null,
  1197. _updateStatus: function Promise__updateStatus(status, value) {
  1198. if (this._status === STATUS_RESOLVED ||
  1199. this._status === STATUS_REJECTED) {
  1200. return;
  1201. }
  1202. if (status === STATUS_RESOLVED &&
  1203. Promise.isPromise(value)) {
  1204. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1205. this._updateStatus.bind(this, STATUS_REJECTED));
  1206. return;
  1207. }
  1208. this._status = status;
  1209. this._value = value;
  1210. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1211. this._unhandledRejection = true;
  1212. HandlerManager.addUnhandledRejection(this);
  1213. }
  1214. HandlerManager.scheduleHandlers(this);
  1215. },
  1216. _resolve: function Promise_resolve(value) {
  1217. this._updateStatus(STATUS_RESOLVED, value);
  1218. },
  1219. _reject: function Promise_reject(reason) {
  1220. this._updateStatus(STATUS_REJECTED, reason);
  1221. },
  1222. then: function Promise_then(onResolve, onReject) {
  1223. var nextPromise = new Promise(function (resolve, reject) {
  1224. this.resolve = resolve;
  1225. this.reject = reject;
  1226. });
  1227. this._handlers.push({
  1228. thisPromise: this,
  1229. onResolve: onResolve,
  1230. onReject: onReject,
  1231. nextPromise: nextPromise
  1232. });
  1233. HandlerManager.scheduleHandlers(this);
  1234. return nextPromise;
  1235. },
  1236. catch: function Promise_catch(onReject) {
  1237. return this.then(undefined, onReject);
  1238. }
  1239. };
  1240. globalScope.Promise = Promise;
  1241. })();
  1242. var StatTimer = (function StatTimerClosure() {
  1243. function rpad(str, pad, length) {
  1244. while (str.length < length) {
  1245. str += pad;
  1246. }
  1247. return str;
  1248. }
  1249. function StatTimer() {
  1250. this.started = {};
  1251. this.times = [];
  1252. this.enabled = true;
  1253. }
  1254. StatTimer.prototype = {
  1255. time: function StatTimer_time(name) {
  1256. if (!this.enabled) {
  1257. return;
  1258. }
  1259. if (name in this.started) {
  1260. warn('Timer is already running for ' + name);
  1261. }
  1262. this.started[name] = Date.now();
  1263. },
  1264. timeEnd: function StatTimer_timeEnd(name) {
  1265. if (!this.enabled) {
  1266. return;
  1267. }
  1268. if (!(name in this.started)) {
  1269. warn('Timer has not been started for ' + name);
  1270. }
  1271. this.times.push({
  1272. 'name': name,
  1273. 'start': this.started[name],
  1274. 'end': Date.now()
  1275. });
  1276. // Remove timer from started so it can be called again.
  1277. delete this.started[name];
  1278. },
  1279. toString: function StatTimer_toString() {
  1280. var i, ii;
  1281. var times = this.times;
  1282. var out = '';
  1283. // Find the longest name for padding purposes.
  1284. var longest = 0;
  1285. for (i = 0, ii = times.length; i < ii; ++i) {
  1286. var name = times[i]['name'];
  1287. if (name.length > longest) {
  1288. longest = name.length;
  1289. }
  1290. }
  1291. for (i = 0, ii = times.length; i < ii; ++i) {
  1292. var span = times[i];
  1293. var duration = span.end - span.start;
  1294. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1295. }
  1296. return out;
  1297. }
  1298. };
  1299. return StatTimer;
  1300. })();
  1301. PDFJS.createBlob = function createBlob(data, contentType) {
  1302. if (typeof Blob !== 'undefined') {
  1303. return new Blob([data], { type: contentType });
  1304. }
  1305. // Blob builder is deprecated in FF14 and removed in FF18.
  1306. var bb = new MozBlobBuilder();
  1307. bb.append(data);
  1308. return bb.getBlob(contentType);
  1309. };
  1310. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1311. // Blob/createObjectURL is not available, falling back to data schema.
  1312. var digits =
  1313. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1314. return function createObjectURL(data, contentType) {
  1315. if (!PDFJS.disableCreateObjectURL &&
  1316. typeof URL !== 'undefined' && URL.createObjectURL) {
  1317. var blob = PDFJS.createBlob(data, contentType);
  1318. return URL.createObjectURL(blob);
  1319. }
  1320. var buffer = 'data:' + contentType + ';base64,';
  1321. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1322. var b1 = data[i] & 0xFF;
  1323. var b2 = data[i + 1] & 0xFF;
  1324. var b3 = data[i + 2] & 0xFF;
  1325. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1326. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1327. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1328. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1329. }
  1330. return buffer;
  1331. };
  1332. })();
  1333. function MessageHandler(name, comObj) {
  1334. this.name = name;
  1335. this.comObj = comObj;
  1336. this.callbackIndex = 1;
  1337. this.postMessageTransfers = true;
  1338. var callbacksCapabilities = this.callbacksCapabilities = {};
  1339. var ah = this.actionHandler = {};
  1340. ah['console_log'] = [function ahConsoleLog(data) {
  1341. console.log.apply(console, data);
  1342. }];
  1343. ah['console_error'] = [function ahConsoleError(data) {
  1344. console.error.apply(console, data);
  1345. }];
  1346. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1347. UnsupportedManager.notify(data);
  1348. }];
  1349. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1350. var data = event.data;
  1351. if (data.isReply) {
  1352. var callbackId = data.callbackId;
  1353. if (data.callbackId in callbacksCapabilities) {
  1354. var callback = callbacksCapabilities[callbackId];
  1355. delete callbacksCapabilities[callbackId];
  1356. if ('error' in data) {
  1357. callback.reject(data.error);
  1358. } else {
  1359. callback.resolve(data.data);
  1360. }
  1361. } else {
  1362. error('Cannot resolve callback ' + callbackId);
  1363. }
  1364. } else if (data.action in ah) {
  1365. var action = ah[data.action];
  1366. if (data.callbackId) {
  1367. Promise.resolve().then(function () {
  1368. return action[0].call(action[1], data.data);
  1369. }).then(function (result) {
  1370. comObj.postMessage({
  1371. isReply: true,
  1372. callbackId: data.callbackId,
  1373. data: result
  1374. });
  1375. }, function (reason) {
  1376. if (reason instanceof Error) {
  1377. // Serialize error to avoid "DataCloneError"
  1378. reason = reason + '';
  1379. }
  1380. comObj.postMessage({
  1381. isReply: true,
  1382. callbackId: data.callbackId,
  1383. error: reason
  1384. });
  1385. });
  1386. } else {
  1387. action[0].call(action[1], data.data);
  1388. }
  1389. } else {
  1390. error('Unknown action from worker: ' + data.action);
  1391. }
  1392. };
  1393. }
  1394. MessageHandler.prototype = {
  1395. on: function messageHandlerOn(actionName, handler, scope) {
  1396. var ah = this.actionHandler;
  1397. if (ah[actionName]) {
  1398. error('There is already an actionName called "' + actionName + '"');
  1399. }
  1400. ah[actionName] = [handler, scope];
  1401. },
  1402. /**
  1403. * Sends a message to the comObj to invoke the action with the supplied data.
  1404. * @param {String} actionName Action to call.
  1405. * @param {JSON} data JSON data to send.
  1406. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1407. */
  1408. send: function messageHandlerSend(actionName, data, transfers) {
  1409. var message = {
  1410. action: actionName,
  1411. data: data
  1412. };
  1413. this.postMessage(message, transfers);
  1414. },
  1415. /**
  1416. * Sends a message to the comObj to invoke the action with the supplied data.
  1417. * Expects that other side will callback with the response.
  1418. * @param {String} actionName Action to call.
  1419. * @param {JSON} data JSON data to send.
  1420. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1421. * @returns {Promise} Promise to be resolved with response data.
  1422. */
  1423. sendWithPromise:
  1424. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1425. var callbackId = this.callbackIndex++;
  1426. var message = {
  1427. action: actionName,
  1428. data: data,
  1429. callbackId: callbackId
  1430. };
  1431. var capability = createPromiseCapability();
  1432. this.callbacksCapabilities[callbackId] = capability;
  1433. try {
  1434. this.postMessage(message, transfers);
  1435. } catch (e) {
  1436. capability.reject(e);
  1437. }
  1438. return capability.promise;
  1439. },
  1440. /**
  1441. * Sends raw message to the comObj.
  1442. * @private
  1443. * @param message {Object} Raw message.
  1444. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1445. */
  1446. postMessage: function (message, transfers) {
  1447. if (transfers && this.postMessageTransfers) {
  1448. this.comObj.postMessage(message, transfers);
  1449. } else {
  1450. this.comObj.postMessage(message);
  1451. }
  1452. }
  1453. };
  1454. function loadJpegStream(id, imageUrl, objs) {
  1455. var img = new Image();
  1456. img.onload = (function loadJpegStream_onloadClosure() {
  1457. objs.resolve(id, img);
  1458. });
  1459. img.onerror = (function loadJpegStream_onerrorClosure() {
  1460. objs.resolve(id, null);
  1461. warn('Error during JPEG image loading');
  1462. });
  1463. img.src = imageUrl;
  1464. }
  1465. /**
  1466. * The maximum allowed image size in total pixels e.g. width * height. Images
  1467. * above this value will not be drawn. Use -1 for no limit.
  1468. * @var {number}
  1469. */
  1470. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1471. -1 : PDFJS.maxImageSize);
  1472. /**
  1473. * The url of where the predefined Adobe CMaps are located. Include trailing
  1474. * slash.
  1475. * @var {string}
  1476. */
  1477. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1478. /**
  1479. * Specifies if CMaps are binary packed.
  1480. * @var {boolean}
  1481. */
  1482. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1483. /**
  1484. * By default fonts are converted to OpenType fonts and loaded via font face
  1485. * rules. If disabled, the font will be rendered using a built in font renderer
  1486. * that constructs the glyphs with primitive path commands.
  1487. * @var {boolean}
  1488. */
  1489. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1490. false : PDFJS.disableFontFace);
  1491. /**
  1492. * Path for image resources, mainly for annotation icons. Include trailing
  1493. * slash.
  1494. * @var {string}
  1495. */
  1496. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1497. '' : PDFJS.imageResourcesPath);
  1498. /**
  1499. * Disable the web worker and run all code on the main thread. This will happen
  1500. * automatically if the browser doesn't support workers or sending typed arrays
  1501. * to workers.
  1502. * @var {boolean}
  1503. */
  1504. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1505. false : PDFJS.disableWorker);
  1506. /**
  1507. * Path and filename of the worker file. Required when the worker is enabled in
  1508. * development mode. If unspecified in the production build, the worker will be
  1509. * loaded based on the location of the pdf.js file.
  1510. * @var {string}
  1511. */
  1512. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1513. /**
  1514. * Disable range request loading of PDF files. When enabled and if the server
  1515. * supports partial content requests then the PDF will be fetched in chunks.
  1516. * Enabled (false) by default.
  1517. * @var {boolean}
  1518. */
  1519. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1520. false : PDFJS.disableRange);
  1521. /**
  1522. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1523. * in chunks. This default behavior can be disabled.
  1524. * @var {boolean}
  1525. */
  1526. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1527. false : PDFJS.disableStream);
  1528. /**
  1529. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1530. * will automatically keep fetching more data even if it isn't needed to display
  1531. * the current page. This default behavior can be disabled.
  1532. *
  1533. * NOTE: It is also necessary to disable streaming, see above,
  1534. * in order for disabling of pre-fetching to work correctly.
  1535. * @var {boolean}
  1536. */
  1537. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1538. false : PDFJS.disableAutoFetch);
  1539. /**
  1540. * Enables special hooks for debugging PDF.js.
  1541. * @var {boolean}
  1542. */
  1543. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1544. /**
  1545. * Enables transfer usage in postMessage for ArrayBuffers.
  1546. * @var {boolean}
  1547. */
  1548. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1549. true : PDFJS.postMessageTransfers);
  1550. /**
  1551. * Disables URL.createObjectURL usage.
  1552. * @var {boolean}
  1553. */
  1554. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1555. false : PDFJS.disableCreateObjectURL);
  1556. /**
  1557. * Disables WebGL usage.
  1558. * @var {boolean}
  1559. */
  1560. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1561. true : PDFJS.disableWebGL);
  1562. /**
  1563. * Disables fullscreen support, and by extension Presentation Mode,
  1564. * in browsers which support the fullscreen API.
  1565. * @var {boolean}
  1566. */
  1567. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1568. false : PDFJS.disableFullscreen);
  1569. /**
  1570. * Enables CSS only zooming.
  1571. * @var {boolean}
  1572. */
  1573. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1574. false : PDFJS.useOnlyCssZoom);
  1575. /**
  1576. * Controls the logging level.
  1577. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1578. * - errors
  1579. * - warnings [default]
  1580. * - infos
  1581. * @var {number}
  1582. */
  1583. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1584. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1585. /**
  1586. * The maximum supported canvas size in total pixels e.g. width * height.
  1587. * The default value is 4096 * 4096. Use -1 for no limit.
  1588. * @var {number}
  1589. */
  1590. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1591. 16777216 : PDFJS.maxCanvasPixels);
  1592. /**
  1593. * (Deprecated) Opens external links in a new window if enabled.
  1594. * The default behavior opens external links in the PDF.js window.
  1595. * @var {boolean}
  1596. */
  1597. PDFJS.openExternalLinksInNewWindow = (
  1598. PDFJS.openExternalLinksInNewWindow === undefined ?
  1599. false : PDFJS.openExternalLinksInNewWindow);
  1600. /**
  1601. * Specifies the |target| attribute for external links.
  1602. * The constants from PDFJS.LinkTarget should be used:
  1603. * - NONE [default]
  1604. * - SELF
  1605. * - BLANK
  1606. * - PARENT
  1607. * - TOP
  1608. * @var {number}
  1609. */
  1610. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  1611. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  1612. /**
  1613. * Determines if we can eval strings as JS. Primarily used to improve
  1614. * performance for font rendering.
  1615. * @var {boolean}
  1616. */
  1617. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  1618. true : PDFJS.isEvalSupported);
  1619. /**
  1620. * Document initialization / loading parameters object.
  1621. *
  1622. * @typedef {Object} DocumentInitParameters
  1623. * @property {string} url - The URL of the PDF.
  1624. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1625. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1626. * use atob() to convert it to a binary string first.
  1627. * @property {Object} httpHeaders - Basic authentication headers.
  1628. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1629. * Access-Control requests should be made using credentials such as cookies
  1630. * or authorization headers. The default is false.
  1631. * @property {string} password - For decrypting password-protected PDFs.
  1632. * @property {TypedArray} initialData - A typed array with the first portion or
  1633. * all of the pdf data. Used by the extension since some data is already
  1634. * loaded before the switch to range requests.
  1635. * @property {number} length - The PDF file length. It's used for progress
  1636. * reports and range requests operations.
  1637. * @property {PDFDataRangeTransport} range
  1638. */
  1639. /**
  1640. * @typedef {Object} PDFDocumentStats
  1641. * @property {Array} streamTypes - Used stream types in the document (an item
  1642. * is set to true if specific stream ID was used in the document).
  1643. * @property {Array} fontTypes - Used font type in the document (an item is set
  1644. * to true if specific font ID was used in the document).
  1645. */
  1646. /**
  1647. * This is the main entry point for loading a PDF and interacting with it.
  1648. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1649. * is used, which means it must follow the same origin rules that any XHR does
  1650. * e.g. No cross domain requests without CORS.
  1651. *
  1652. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1653. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1654. * already populated with data or parameter object.
  1655. *
  1656. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1657. * if you want to manually serve range requests for data in the PDF.
  1658. *
  1659. * @param {function} passwordCallback (deprecated) It is used to request a
  1660. * password if wrong or no password was provided. The callback receives two
  1661. * parameters: function that needs to be called with new password and reason
  1662. * (see {PasswordResponses}).
  1663. *
  1664. * @param {function} progressCallback (deprecated) It is used to be able to
  1665. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1666. * a loading bar). The callback receives an {Object} with the properties:
  1667. * {number} loaded and {number} total.
  1668. *
  1669. * @return {PDFDocumentLoadingTask}
  1670. */
  1671. PDFJS.getDocument = function getDocument(src,
  1672. pdfDataRangeTransport,
  1673. passwordCallback,
  1674. progressCallback) {
  1675. var task = new PDFDocumentLoadingTask();
  1676. // Support of the obsolete arguments (for compatibility with API v1.0)
  1677. if (pdfDataRangeTransport) {
  1678. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1679. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1680. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1681. pdfDataRangeTransport.length = src.length;
  1682. pdfDataRangeTransport.initialData = src.initialData;
  1683. }
  1684. src = Object.create(src);
  1685. src.range = pdfDataRangeTransport;
  1686. }
  1687. task.onPassword = passwordCallback || null;
  1688. task.onProgress = progressCallback || null;
  1689. var workerInitializedCapability, transport;
  1690. var source;
  1691. if (typeof src === 'string') {
  1692. source = { url: src };
  1693. } else if (isArrayBuffer(src)) {
  1694. source = { data: src };
  1695. } else if (src instanceof PDFDataRangeTransport) {
  1696. source = { range: src };
  1697. } else {
  1698. if (typeof src !== 'object') {
  1699. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1700. 'string or a parameter object');
  1701. }
  1702. if (!src.url && !src.data && !src.range) {
  1703. error('Invalid parameter object: need either .data, .range or .url');
  1704. }
  1705. source = src;
  1706. }
  1707. var params = {};
  1708. for (var key in source) {
  1709. if (key === 'url' && typeof window !== 'undefined') {
  1710. // The full path is required in the 'url' field.
  1711. params[key] = combineUrl(window.location.href, source[key]);
  1712. continue;
  1713. } else if (key === 'range') {
  1714. continue;
  1715. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1716. // Converting string or array-like data to Uint8Array.
  1717. var pdfBytes = source[key];
  1718. if (typeof pdfBytes === 'string') {
  1719. params[key] = stringToBytes(pdfBytes);
  1720. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1721. !isNaN(pdfBytes.length)) {
  1722. params[key] = new Uint8Array(pdfBytes);
  1723. } else if (isArrayBuffer(pdfBytes)) {
  1724. params[key] = new Uint8Array(pdfBytes);
  1725. } else {
  1726. error('Invalid PDF binary data: either typed array, string or ' +
  1727. 'array-like object is expected in the data property.');
  1728. }
  1729. continue;
  1730. }
  1731. params[key] = source[key];
  1732. }
  1733. workerInitializedCapability = createPromiseCapability();
  1734. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1735. workerInitializedCapability.promise.then(function transportInitialized() {
  1736. transport.fetchDocument(task, params);
  1737. });
  1738. return task;
  1739. };
  1740. /**
  1741. * PDF document loading operation.
  1742. * @class
  1743. */
  1744. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1745. /** @constructs PDFDocumentLoadingTask */
  1746. function PDFDocumentLoadingTask() {
  1747. this._capability = createPromiseCapability();
  1748. /**
  1749. * Callback to request a password if wrong or no password was provided.
  1750. * The callback receives two parameters: function that needs to be called
  1751. * with new password and reason (see {PasswordResponses}).
  1752. */
  1753. this.onPassword = null;
  1754. /**
  1755. * Callback to be able to monitor the loading progress of the PDF file
  1756. * (necessary to implement e.g. a loading bar). The callback receives
  1757. * an {Object} with the properties: {number} loaded and {number} total.
  1758. */
  1759. this.onProgress = null;
  1760. }
  1761. PDFDocumentLoadingTask.prototype =
  1762. /** @lends PDFDocumentLoadingTask.prototype */ {
  1763. /**
  1764. * @return {Promise}
  1765. */
  1766. get promise() {
  1767. return this._capability.promise;
  1768. },
  1769. // TODO add cancel or abort method
  1770. /**
  1771. * Registers callbacks to indicate the document loading completion.
  1772. *
  1773. * @param {function} onFulfilled The callback for the loading completion.
  1774. * @param {function} onRejected The callback for the loading failure.
  1775. * @return {Promise} A promise that is resolved after the onFulfilled or
  1776. * onRejected callback.
  1777. */
  1778. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1779. return this.promise.then.apply(this.promise, arguments);
  1780. }
  1781. };
  1782. return PDFDocumentLoadingTask;
  1783. })();
  1784. /**
  1785. * Abstract class to support range requests file loading.
  1786. * @class
  1787. */
  1788. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1789. /**
  1790. * @constructs PDFDataRangeTransport
  1791. * @param {number} length
  1792. * @param {Uint8Array} initialData
  1793. */
  1794. function PDFDataRangeTransport(length, initialData) {
  1795. this.length = length;
  1796. this.initialData = initialData;
  1797. this._rangeListeners = [];
  1798. this._progressListeners = [];
  1799. this._progressiveReadListeners = [];
  1800. this._readyCapability = createPromiseCapability();
  1801. }
  1802. PDFDataRangeTransport.prototype =
  1803. /** @lends PDFDataRangeTransport.prototype */ {
  1804. addRangeListener:
  1805. function PDFDataRangeTransport_addRangeListener(listener) {
  1806. this._rangeListeners.push(listener);
  1807. },
  1808. addProgressListener:
  1809. function PDFDataRangeTransport_addProgressListener(listener) {
  1810. this._progressListeners.push(listener);
  1811. },
  1812. addProgressiveReadListener:
  1813. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1814. this._progressiveReadListeners.push(listener);
  1815. },
  1816. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1817. var listeners = this._rangeListeners;
  1818. for (var i = 0, n = listeners.length; i < n; ++i) {
  1819. listeners[i](begin, chunk);
  1820. }
  1821. },
  1822. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1823. this._readyCapability.promise.then(function () {
  1824. var listeners = this._progressListeners;
  1825. for (var i = 0, n = listeners.length; i < n; ++i) {
  1826. listeners[i](loaded);
  1827. }
  1828. }.bind(this));
  1829. },
  1830. onDataProgressiveRead:
  1831. function PDFDataRangeTransport_onDataProgress(chunk) {
  1832. this._readyCapability.promise.then(function () {
  1833. var listeners = this._progressiveReadListeners;
  1834. for (var i = 0, n = listeners.length; i < n; ++i) {
  1835. listeners[i](chunk);
  1836. }
  1837. }.bind(this));
  1838. },
  1839. transportReady: function PDFDataRangeTransport_transportReady() {
  1840. this._readyCapability.resolve();
  1841. },
  1842. requestDataRange:
  1843. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1844. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1845. }
  1846. };
  1847. return PDFDataRangeTransport;
  1848. })();
  1849. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1850. /**
  1851. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1852. * properties that can be read synchronously.
  1853. * @class
  1854. */
  1855. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1856. function PDFDocumentProxy(pdfInfo, transport) {
  1857. this.pdfInfo = pdfInfo;
  1858. this.transport = transport;
  1859. }
  1860. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1861. /**
  1862. * @return {number} Total number of pages the PDF contains.
  1863. */
  1864. get numPages() {
  1865. return this.pdfInfo.numPages;
  1866. },
  1867. /**
  1868. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1869. * unique.
  1870. */
  1871. get fingerprint() {
  1872. return this.pdfInfo.fingerprint;
  1873. },
  1874. /**
  1875. * @param {number} pageNumber The page number to get. The first page is 1.
  1876. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1877. * object.
  1878. */
  1879. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1880. return this.transport.getPage(pageNumber);
  1881. },
  1882. /**
  1883. * @param {{num: number, gen: number}} ref The page reference. Must have
  1884. * the 'num' and 'gen' properties.
  1885. * @return {Promise} A promise that is resolved with the page index that is
  1886. * associated with the reference.
  1887. */
  1888. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1889. return this.transport.getPageIndex(ref);
  1890. },
  1891. /**
  1892. * @return {Promise} A promise that is resolved with a lookup table for
  1893. * mapping named destinations to reference numbers.
  1894. *
  1895. * This can be slow for large documents: use getDestination instead
  1896. */
  1897. getDestinations: function PDFDocumentProxy_getDestinations() {
  1898. return this.transport.getDestinations();
  1899. },
  1900. /**
  1901. * @param {string} id The named destination to get.
  1902. * @return {Promise} A promise that is resolved with all information
  1903. * of the given named destination.
  1904. */
  1905. getDestination: function PDFDocumentProxy_getDestination(id) {
  1906. return this.transport.getDestination(id);
  1907. },
  1908. /**
  1909. * @return {Promise} A promise that is resolved with a lookup table for
  1910. * mapping named attachments to their content.
  1911. */
  1912. getAttachments: function PDFDocumentProxy_getAttachments() {
  1913. return this.transport.getAttachments();
  1914. },
  1915. /**
  1916. * @return {Promise} A promise that is resolved with an array of all the
  1917. * JavaScript strings in the name tree.
  1918. */
  1919. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1920. return this.transport.getJavaScript();
  1921. },
  1922. /**
  1923. * @return {Promise} A promise that is resolved with an {Array} that is a
  1924. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1925. * [
  1926. * {
  1927. * title: string,
  1928. * bold: boolean,
  1929. * italic: boolean,
  1930. * color: rgb array,
  1931. * dest: dest obj,
  1932. * items: array of more items like this
  1933. * },
  1934. * ...
  1935. * ].
  1936. */
  1937. getOutline: function PDFDocumentProxy_getOutline() {
  1938. return this.transport.getOutline();
  1939. },
  1940. /**
  1941. * @return {Promise} A promise that is resolved with an {Object} that has
  1942. * info and metadata properties. Info is an {Object} filled with anything
  1943. * available in the information dictionary and similarly metadata is a
  1944. * {Metadata} object with information from the metadata section of the PDF.
  1945. */
  1946. getMetadata: function PDFDocumentProxy_getMetadata() {
  1947. return this.transport.getMetadata();
  1948. },
  1949. /**
  1950. * @return {Promise} A promise that is resolved with a TypedArray that has
  1951. * the raw data from the PDF.
  1952. */
  1953. getData: function PDFDocumentProxy_getData() {
  1954. return this.transport.getData();
  1955. },
  1956. /**
  1957. * @return {Promise} A promise that is resolved when the document's data
  1958. * is loaded. It is resolved with an {Object} that contains the length
  1959. * property that indicates size of the PDF data in bytes.
  1960. */
  1961. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1962. return this.transport.downloadInfoCapability.promise;
  1963. },
  1964. /**
  1965. * @return {Promise} A promise this is resolved with current stats about
  1966. * document structures (see {@link PDFDocumentStats}).
  1967. */
  1968. getStats: function PDFDocumentProxy_getStats() {
  1969. return this.transport.getStats();
  1970. },
  1971. /**
  1972. * Cleans up resources allocated by the document, e.g. created @font-face.
  1973. */
  1974. cleanup: function PDFDocumentProxy_cleanup() {
  1975. this.transport.startCleanup();
  1976. },
  1977. /**
  1978. * Destroys current document instance and terminates worker.
  1979. */
  1980. destroy: function PDFDocumentProxy_destroy() {
  1981. this.transport.destroy();
  1982. }
  1983. };
  1984. return PDFDocumentProxy;
  1985. })();
  1986. /**
  1987. * Page text content.
  1988. *
  1989. * @typedef {Object} TextContent
  1990. * @property {array} items - array of {@link TextItem}
  1991. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1992. * name.
  1993. */
  1994. /**
  1995. * Page text content part.
  1996. *
  1997. * @typedef {Object} TextItem
  1998. * @property {string} str - text content.
  1999. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  2000. * @property {array} transform - transformation matrix.
  2001. * @property {number} width - width in device space.
  2002. * @property {number} height - height in device space.
  2003. * @property {string} fontName - font name used by pdf.js for converted font.
  2004. */
  2005. /**
  2006. * Text style.
  2007. *
  2008. * @typedef {Object} TextStyle
  2009. * @property {number} ascent - font ascent.
  2010. * @property {number} descent - font descent.
  2011. * @property {boolean} vertical - text is in vertical mode.
  2012. * @property {string} fontFamily - possible font family
  2013. */
  2014. /**
  2015. * Page render parameters.
  2016. *
  2017. * @typedef {Object} RenderParameters
  2018. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  2019. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  2020. * calling of PDFPage.getViewport method.
  2021. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  2022. * (default value is 'display').
  2023. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  2024. * endLayout and appendImage functions.
  2025. * @property {function} continueCallback - (deprecated) A function that will be
  2026. * called each time the rendering is paused. To continue
  2027. * rendering call the function that is the first argument
  2028. * to the callback.
  2029. */
  2030. /**
  2031. * PDF page operator list.
  2032. *
  2033. * @typedef {Object} PDFOperatorList
  2034. * @property {Array} fnArray - Array containing the operator functions.
  2035. * @property {Array} argsArray - Array containing the arguments of the
  2036. * functions.
  2037. */
  2038. /**
  2039. * Proxy to a PDFPage in the worker thread.
  2040. * @class
  2041. */
  2042. var PDFPageProxy = (function PDFPageProxyClosure() {
  2043. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2044. this.pageIndex = pageIndex;
  2045. this.pageInfo = pageInfo;
  2046. this.transport = transport;
  2047. this.stats = new StatTimer();
  2048. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2049. this.commonObjs = transport.commonObjs;
  2050. this.objs = new PDFObjects();
  2051. this.cleanupAfterRender = false;
  2052. this.pendingDestroy = false;
  2053. this.intentStates = {};
  2054. }
  2055. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2056. /**
  2057. * @return {number} Page number of the page. First page is 1.
  2058. */
  2059. get pageNumber() {
  2060. return this.pageIndex + 1;
  2061. },
  2062. /**
  2063. * @return {number} The number of degrees the page is rotated clockwise.
  2064. */
  2065. get rotate() {
  2066. return this.pageInfo.rotate;
  2067. },
  2068. /**
  2069. * @return {Object} The reference that points to this page. It has 'num' and
  2070. * 'gen' properties.
  2071. */
  2072. get ref() {
  2073. return this.pageInfo.ref;
  2074. },
  2075. /**
  2076. * @return {Array} An array of the visible portion of the PDF page in the
  2077. * user space units - [x1, y1, x2, y2].
  2078. */
  2079. get view() {
  2080. return this.pageInfo.view;
  2081. },
  2082. /**
  2083. * @param {number} scale The desired scale of the viewport.
  2084. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2085. * defaults to the page rotation.
  2086. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2087. * along with transforms required for rendering.
  2088. */
  2089. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2090. if (arguments.length < 2) {
  2091. rotate = this.rotate;
  2092. }
  2093. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2094. },
  2095. /**
  2096. * @return {Promise} A promise that is resolved with an {Array} of the
  2097. * annotation objects.
  2098. */
  2099. getAnnotations: function PDFPageProxy_getAnnotations() {
  2100. if (!this.annotationsPromise) {
  2101. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex);
  2102. }
  2103. return this.annotationsPromise;
  2104. },
  2105. /**
  2106. * Begins the process of rendering a page to the desired context.
  2107. * @param {RenderParameters} params Page render parameters.
  2108. * @return {RenderTask} An object that contains the promise, which
  2109. * is resolved when the page finishes rendering.
  2110. */
  2111. render: function PDFPageProxy_render(params) {
  2112. var stats = this.stats;
  2113. stats.time('Overall');
  2114. // If there was a pending destroy cancel it so no cleanup happens during
  2115. // this call to render.
  2116. this.pendingDestroy = false;
  2117. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2118. if (!this.intentStates[renderingIntent]) {
  2119. this.intentStates[renderingIntent] = {};
  2120. }
  2121. var intentState = this.intentStates[renderingIntent];
  2122. // If there's no displayReadyCapability yet, then the operatorList
  2123. // was never requested before. Make the request and create the promise.
  2124. if (!intentState.displayReadyCapability) {
  2125. intentState.receivingOperatorList = true;
  2126. intentState.displayReadyCapability = createPromiseCapability();
  2127. intentState.operatorList = {
  2128. fnArray: [],
  2129. argsArray: [],
  2130. lastChunk: false
  2131. };
  2132. this.stats.time('Page Request');
  2133. this.transport.messageHandler.send('RenderPageRequest', {
  2134. pageIndex: this.pageNumber - 1,
  2135. intent: renderingIntent
  2136. });
  2137. }
  2138. var internalRenderTask = new InternalRenderTask(complete, params,
  2139. this.objs,
  2140. this.commonObjs,
  2141. intentState.operatorList,
  2142. this.pageNumber);
  2143. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  2144. if (!intentState.renderTasks) {
  2145. intentState.renderTasks = [];
  2146. }
  2147. intentState.renderTasks.push(internalRenderTask);
  2148. var renderTask = internalRenderTask.task;
  2149. // Obsolete parameter support
  2150. if (params.continueCallback) {
  2151. renderTask.onContinue = params.continueCallback;
  2152. }
  2153. var self = this;
  2154. intentState.displayReadyCapability.promise.then(
  2155. function pageDisplayReadyPromise(transparency) {
  2156. if (self.pendingDestroy) {
  2157. complete();
  2158. return;
  2159. }
  2160. stats.time('Rendering');
  2161. internalRenderTask.initalizeGraphics(transparency);
  2162. internalRenderTask.operatorListChanged();
  2163. },
  2164. function pageDisplayReadPromiseError(reason) {
  2165. complete(reason);
  2166. }
  2167. );
  2168. function complete(error) {
  2169. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2170. if (i >= 0) {
  2171. intentState.renderTasks.splice(i, 1);
  2172. }
  2173. if (self.cleanupAfterRender) {
  2174. self.pendingDestroy = true;
  2175. }
  2176. self._tryDestroy();
  2177. if (error) {
  2178. internalRenderTask.capability.reject(error);
  2179. } else {
  2180. internalRenderTask.capability.resolve();
  2181. }
  2182. stats.timeEnd('Rendering');
  2183. stats.timeEnd('Overall');
  2184. }
  2185. return renderTask;
  2186. },
  2187. /**
  2188. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2189. * object that represents page's operator list.
  2190. */
  2191. getOperatorList: function PDFPageProxy_getOperatorList() {
  2192. function operatorListChanged() {
  2193. if (intentState.operatorList.lastChunk) {
  2194. intentState.opListReadCapability.resolve(intentState.operatorList);
  2195. }
  2196. }
  2197. var renderingIntent = 'oplist';
  2198. if (!this.intentStates[renderingIntent]) {
  2199. this.intentStates[renderingIntent] = {};
  2200. }
  2201. var intentState = this.intentStates[renderingIntent];
  2202. if (!intentState.opListReadCapability) {
  2203. var opListTask = {};
  2204. opListTask.operatorListChanged = operatorListChanged;
  2205. intentState.receivingOperatorList = true;
  2206. intentState.opListReadCapability = createPromiseCapability();
  2207. intentState.renderTasks = [];
  2208. intentState.renderTasks.push(opListTask);
  2209. intentState.operatorList = {
  2210. fnArray: [],
  2211. argsArray: [],
  2212. lastChunk: false
  2213. };
  2214. this.transport.messageHandler.send('RenderPageRequest', {
  2215. pageIndex: this.pageIndex,
  2216. intent: renderingIntent
  2217. });
  2218. }
  2219. return intentState.opListReadCapability.promise;
  2220. },
  2221. /**
  2222. * @return {Promise} That is resolved a {@link TextContent}
  2223. * object that represent the page text content.
  2224. */
  2225. getTextContent: function PDFPageProxy_getTextContent() {
  2226. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2227. pageIndex: this.pageNumber - 1
  2228. });
  2229. },
  2230. /**
  2231. * Destroys resources allocated by the page.
  2232. */
  2233. destroy: function PDFPageProxy_destroy() {
  2234. this.pendingDestroy = true;
  2235. this._tryDestroy();
  2236. },
  2237. /**
  2238. * For internal use only. Attempts to clean up if rendering is in a state
  2239. * where that's possible.
  2240. * @ignore
  2241. */
  2242. _tryDestroy: function PDFPageProxy__destroy() {
  2243. if (!this.pendingDestroy ||
  2244. Object.keys(this.intentStates).some(function(intent) {
  2245. var intentState = this.intentStates[intent];
  2246. return (intentState.renderTasks.length !== 0 ||
  2247. intentState.receivingOperatorList);
  2248. }, this)) {
  2249. return;
  2250. }
  2251. Object.keys(this.intentStates).forEach(function(intent) {
  2252. delete this.intentStates[intent];
  2253. }, this);
  2254. this.objs.clear();
  2255. this.annotationsPromise = null;
  2256. this.pendingDestroy = false;
  2257. },
  2258. /**
  2259. * For internal use only.
  2260. * @ignore
  2261. */
  2262. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2263. intent) {
  2264. var intentState = this.intentStates[intent];
  2265. // TODO Refactor RenderPageRequest to separate rendering
  2266. // and operator list logic
  2267. if (intentState.displayReadyCapability) {
  2268. intentState.displayReadyCapability.resolve(transparency);
  2269. }
  2270. },
  2271. /**
  2272. * For internal use only.
  2273. * @ignore
  2274. */
  2275. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2276. intent) {
  2277. var intentState = this.intentStates[intent];
  2278. var i, ii;
  2279. // Add the new chunk to the current operator list.
  2280. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2281. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2282. intentState.operatorList.argsArray.push(
  2283. operatorListChunk.argsArray[i]);
  2284. }
  2285. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2286. // Notify all the rendering tasks there are more operators to be consumed.
  2287. for (i = 0; i < intentState.renderTasks.length; i++) {
  2288. intentState.renderTasks[i].operatorListChanged();
  2289. }
  2290. if (operatorListChunk.lastChunk) {
  2291. intentState.receivingOperatorList = false;
  2292. this._tryDestroy();
  2293. }
  2294. }
  2295. };
  2296. return PDFPageProxy;
  2297. })();
  2298. /**
  2299. * For internal use only.
  2300. * @ignore
  2301. */
  2302. var WorkerTransport = (function WorkerTransportClosure() {
  2303. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2304. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2305. this.workerInitializedCapability = workerInitializedCapability;
  2306. this.commonObjs = new PDFObjects();
  2307. this.loadingTask = null;
  2308. this.pageCache = [];
  2309. this.pagePromises = [];
  2310. this.downloadInfoCapability = createPromiseCapability();
  2311. // If worker support isn't disabled explicit and the browser has worker
  2312. // support, create a new web worker and test if it/the browser fullfills
  2313. // all requirements to run parts of pdf.js in a web worker.
  2314. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2315. // as it arrives on the worker. Chrome added this with version 15.
  2316. // Either workers are disabled, not supported or have thrown an exception.
  2317. // Thus, we fallback to a faked worker.
  2318. this.setupFakeWorker();
  2319. }
  2320. WorkerTransport.prototype = {
  2321. destroy: function WorkerTransport_destroy() {
  2322. this.pageCache = [];
  2323. this.pagePromises = [];
  2324. var self = this;
  2325. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2326. FontLoader.clear();
  2327. if (self.worker) {
  2328. self.worker.terminate();
  2329. }
  2330. });
  2331. },
  2332. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2333. globalScope.PDFJS.disableWorker = true;
  2334. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2335. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2336. // In the developer build load worker_loader which in turn loads all the
  2337. // other files and resolves the promise. In production only the
  2338. // pdf.worker.js file is needed.
  2339. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2340. }
  2341. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2342. warn('Setting up fake worker.');
  2343. // If we don't use a worker, just post/sendMessage to the main thread.
  2344. var fakeWorker = {
  2345. postMessage: function WorkerTransport_postMessage(obj) {
  2346. fakeWorker.onmessage({data: obj});
  2347. },
  2348. terminate: function WorkerTransport_terminate() {}
  2349. };
  2350. var messageHandler = new MessageHandler('main', fakeWorker);
  2351. this.setupMessageHandler(messageHandler);
  2352. // If the main thread is our worker, setup the handling for the messages
  2353. // the main thread sends to it self.
  2354. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2355. this.workerInitializedCapability.resolve();
  2356. }.bind(this));
  2357. },
  2358. setupMessageHandler:
  2359. function WorkerTransport_setupMessageHandler(messageHandler) {
  2360. this.messageHandler = messageHandler;
  2361. function updatePassword(password) {
  2362. messageHandler.send('UpdatePassword', password);
  2363. }
  2364. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2365. if (pdfDataRangeTransport) {
  2366. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2367. messageHandler.send('OnDataRange', {
  2368. begin: begin,
  2369. chunk: chunk
  2370. });
  2371. });
  2372. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2373. messageHandler.send('OnDataProgress', {
  2374. loaded: loaded
  2375. });
  2376. });
  2377. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2378. messageHandler.send('OnDataRange', {
  2379. chunk: chunk
  2380. });
  2381. });
  2382. messageHandler.on('RequestDataRange',
  2383. function transportDataRange(data) {
  2384. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2385. }, this);
  2386. }
  2387. messageHandler.on('GetDoc', function transportDoc(data) {
  2388. var pdfInfo = data.pdfInfo;
  2389. this.numPages = data.pdfInfo.numPages;
  2390. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2391. this.pdfDocument = pdfDocument;
  2392. this.loadingTask._capability.resolve(pdfDocument);
  2393. }, this);
  2394. messageHandler.on('NeedPassword',
  2395. function transportNeedPassword(exception) {
  2396. var loadingTask = this.loadingTask;
  2397. if (loadingTask.onPassword) {
  2398. return loadingTask.onPassword(updatePassword,
  2399. PasswordResponses.NEED_PASSWORD);
  2400. }
  2401. loadingTask._capability.reject(
  2402. new PasswordException(exception.message, exception.code));
  2403. }, this);
  2404. messageHandler.on('IncorrectPassword',
  2405. function transportIncorrectPassword(exception) {
  2406. var loadingTask = this.loadingTask;
  2407. if (loadingTask.onPassword) {
  2408. return loadingTask.onPassword(updatePassword,
  2409. PasswordResponses.INCORRECT_PASSWORD);
  2410. }
  2411. loadingTask._capability.reject(
  2412. new PasswordException(exception.message, exception.code));
  2413. }, this);
  2414. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2415. this.loadingTask._capability.reject(
  2416. new InvalidPDFException(exception.message));
  2417. }, this);
  2418. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2419. this.loadingTask._capability.reject(
  2420. new MissingPDFException(exception.message));
  2421. }, this);
  2422. messageHandler.on('UnexpectedResponse',
  2423. function transportUnexpectedResponse(exception) {
  2424. this.loadingTask._capability.reject(
  2425. new UnexpectedResponseException(exception.message, exception.status));
  2426. }, this);
  2427. messageHandler.on('UnknownError',
  2428. function transportUnknownError(exception) {
  2429. this.loadingTask._capability.reject(
  2430. new UnknownErrorException(exception.message, exception.details));
  2431. }, this);
  2432. messageHandler.on('DataLoaded', function transportPage(data) {
  2433. this.downloadInfoCapability.resolve(data);
  2434. }, this);
  2435. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2436. if (this.pdfDataRangeTransport) {
  2437. this.pdfDataRangeTransport.transportReady();
  2438. }
  2439. }, this);
  2440. messageHandler.on('StartRenderPage', function transportRender(data) {
  2441. var page = this.pageCache[data.pageIndex];
  2442. page.stats.timeEnd('Page Request');
  2443. page._startRenderPage(data.transparency, data.intent);
  2444. }, this);
  2445. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2446. var page = this.pageCache[data.pageIndex];
  2447. page._renderPageChunk(data.operatorList, data.intent);
  2448. }, this);
  2449. messageHandler.on('commonobj', function transportObj(data) {
  2450. var id = data[0];
  2451. var type = data[1];
  2452. if (this.commonObjs.hasData(id)) {
  2453. return;
  2454. }
  2455. switch (type) {
  2456. case 'Font':
  2457. var exportedData = data[2];
  2458. var font;
  2459. if ('error' in exportedData) {
  2460. var error = exportedData.error;
  2461. warn('Error during font loading: ' + error);
  2462. this.commonObjs.resolve(id, error);
  2463. break;
  2464. } else {
  2465. font = new FontFaceObject(exportedData);
  2466. }
  2467. FontLoader.bind(
  2468. [font],
  2469. function fontReady(fontObjs) {
  2470. this.commonObjs.resolve(id, font);
  2471. }.bind(this)
  2472. );
  2473. break;
  2474. case 'FontPath':
  2475. this.commonObjs.resolve(id, data[2]);
  2476. break;
  2477. default:
  2478. error('Got unknown common object type ' + type);
  2479. }
  2480. }, this);
  2481. messageHandler.on('obj', function transportObj(data) {
  2482. var id = data[0];
  2483. var pageIndex = data[1];
  2484. var type = data[2];
  2485. var pageProxy = this.pageCache[pageIndex];
  2486. var imageData;
  2487. if (pageProxy.objs.hasData(id)) {
  2488. return;
  2489. }
  2490. switch (type) {
  2491. case 'JpegStream':
  2492. imageData = data[3];
  2493. loadJpegStream(id, imageData, pageProxy.objs);
  2494. break;
  2495. case 'Image':
  2496. imageData = data[3];
  2497. pageProxy.objs.resolve(id, imageData);
  2498. // heuristics that will allow not to store large data
  2499. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2500. if (imageData && 'data' in imageData &&
  2501. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2502. pageProxy.cleanupAfterRender = true;
  2503. }
  2504. break;
  2505. default:
  2506. error('Got unknown object type ' + type);
  2507. }
  2508. }, this);
  2509. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2510. var loadingTask = this.loadingTask;
  2511. if (loadingTask.onProgress) {
  2512. loadingTask.onProgress({
  2513. loaded: data.loaded,
  2514. total: data.total
  2515. });
  2516. }
  2517. }, this);
  2518. messageHandler.on('PageError', function transportError(data) {
  2519. var page = this.pageCache[data.pageNum - 1];
  2520. var intentState = page.intentStates[data.intent];
  2521. if (intentState.displayReadyCapability) {
  2522. intentState.displayReadyCapability.reject(data.error);
  2523. } else {
  2524. error(data.error);
  2525. }
  2526. }, this);
  2527. messageHandler.on('JpegDecode', function(data) {
  2528. var imageUrl = data[0];
  2529. var components = data[1];
  2530. if (components !== 3 && components !== 1) {
  2531. return Promise.reject(
  2532. new Error('Only 3 components or 1 component can be returned'));
  2533. }
  2534. return new Promise(function (resolve, reject) {
  2535. var img = new Image();
  2536. img.onload = function () {
  2537. var width = img.width;
  2538. var height = img.height;
  2539. var size = width * height;
  2540. var rgbaLength = size * 4;
  2541. var buf = new Uint8Array(size * components);
  2542. var tmpCanvas = createScratchCanvas(width, height);
  2543. var tmpCtx = tmpCanvas.getContext('2d');
  2544. tmpCtx.drawImage(img, 0, 0);
  2545. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2546. var i, j;
  2547. if (components === 3) {
  2548. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2549. buf[j] = data[i];
  2550. buf[j + 1] = data[i + 1];
  2551. buf[j + 2] = data[i + 2];
  2552. }
  2553. } else if (components === 1) {
  2554. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2555. buf[j] = data[i];
  2556. }
  2557. }
  2558. resolve({ data: buf, width: width, height: height});
  2559. };
  2560. img.onerror = function () {
  2561. reject(new Error('JpegDecode failed to load image'));
  2562. };
  2563. img.src = imageUrl;
  2564. });
  2565. });
  2566. },
  2567. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2568. this.loadingTask = loadingTask;
  2569. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2570. source.disableStream = PDFJS.disableStream;
  2571. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2572. if (this.pdfDataRangeTransport) {
  2573. source.length = this.pdfDataRangeTransport.length;
  2574. source.initialData = this.pdfDataRangeTransport.initialData;
  2575. }
  2576. this.messageHandler.send('GetDocRequest', {
  2577. source: source,
  2578. disableRange: PDFJS.disableRange,
  2579. maxImageSize: PDFJS.maxImageSize,
  2580. cMapUrl: PDFJS.cMapUrl,
  2581. cMapPacked: PDFJS.cMapPacked,
  2582. disableFontFace: PDFJS.disableFontFace,
  2583. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2584. verbosity: PDFJS.verbosity
  2585. });
  2586. },
  2587. getData: function WorkerTransport_getData() {
  2588. return this.messageHandler.sendWithPromise('GetData', null);
  2589. },
  2590. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2591. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2592. (pageNumber|0) !== pageNumber) {
  2593. return Promise.reject(new Error('Invalid page request'));
  2594. }
  2595. var pageIndex = pageNumber - 1;
  2596. if (pageIndex in this.pagePromises) {
  2597. return this.pagePromises[pageIndex];
  2598. }
  2599. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2600. pageIndex: pageIndex
  2601. }).then(function (pageInfo) {
  2602. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2603. this.pageCache[pageIndex] = page;
  2604. return page;
  2605. }.bind(this));
  2606. this.pagePromises[pageIndex] = promise;
  2607. return promise;
  2608. },
  2609. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2610. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2611. },
  2612. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2613. return this.messageHandler.sendWithPromise('GetAnnotations',
  2614. { pageIndex: pageIndex });
  2615. },
  2616. getDestinations: function WorkerTransport_getDestinations() {
  2617. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2618. },
  2619. getDestination: function WorkerTransport_getDestination(id) {
  2620. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2621. },
  2622. getAttachments: function WorkerTransport_getAttachments() {
  2623. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2624. },
  2625. getJavaScript: function WorkerTransport_getJavaScript() {
  2626. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2627. },
  2628. getOutline: function WorkerTransport_getOutline() {
  2629. return this.messageHandler.sendWithPromise('GetOutline', null);
  2630. },
  2631. getMetadata: function WorkerTransport_getMetadata() {
  2632. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2633. then(function transportMetadata(results) {
  2634. return {
  2635. info: results[0],
  2636. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2637. };
  2638. });
  2639. },
  2640. getStats: function WorkerTransport_getStats() {
  2641. return this.messageHandler.sendWithPromise('GetStats', null);
  2642. },
  2643. startCleanup: function WorkerTransport_startCleanup() {
  2644. this.messageHandler.sendWithPromise('Cleanup', null).
  2645. then(function endCleanup() {
  2646. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2647. var page = this.pageCache[i];
  2648. if (page) {
  2649. page.destroy();
  2650. }
  2651. }
  2652. this.commonObjs.clear();
  2653. FontLoader.clear();
  2654. }.bind(this));
  2655. }
  2656. };
  2657. return WorkerTransport;
  2658. })();
  2659. /**
  2660. * A PDF document and page is built of many objects. E.g. there are objects
  2661. * for fonts, images, rendering code and such. These objects might get processed
  2662. * inside of a worker. The `PDFObjects` implements some basic functions to
  2663. * manage these objects.
  2664. * @ignore
  2665. */
  2666. var PDFObjects = (function PDFObjectsClosure() {
  2667. function PDFObjects() {
  2668. this.objs = {};
  2669. }
  2670. PDFObjects.prototype = {
  2671. /**
  2672. * Internal function.
  2673. * Ensures there is an object defined for `objId`.
  2674. */
  2675. ensureObj: function PDFObjects_ensureObj(objId) {
  2676. if (this.objs[objId]) {
  2677. return this.objs[objId];
  2678. }
  2679. var obj = {
  2680. capability: createPromiseCapability(),
  2681. data: null,
  2682. resolved: false
  2683. };
  2684. this.objs[objId] = obj;
  2685. return obj;
  2686. },
  2687. /**
  2688. * If called *without* callback, this returns the data of `objId` but the
  2689. * object needs to be resolved. If it isn't, this function throws.
  2690. *
  2691. * If called *with* a callback, the callback is called with the data of the
  2692. * object once the object is resolved. That means, if you call this
  2693. * function and the object is already resolved, the callback gets called
  2694. * right away.
  2695. */
  2696. get: function PDFObjects_get(objId, callback) {
  2697. // If there is a callback, then the get can be async and the object is
  2698. // not required to be resolved right now
  2699. if (callback) {
  2700. this.ensureObj(objId).capability.promise.then(callback);
  2701. return null;
  2702. }
  2703. // If there isn't a callback, the user expects to get the resolved data
  2704. // directly.
  2705. var obj = this.objs[objId];
  2706. // If there isn't an object yet or the object isn't resolved, then the
  2707. // data isn't ready yet!
  2708. if (!obj || !obj.resolved) {
  2709. error('Requesting object that isn\'t resolved yet ' + objId);
  2710. }
  2711. return obj.data;
  2712. },
  2713. /**
  2714. * Resolves the object `objId` with optional `data`.
  2715. */
  2716. resolve: function PDFObjects_resolve(objId, data) {
  2717. var obj = this.ensureObj(objId);
  2718. obj.resolved = true;
  2719. obj.data = data;
  2720. obj.capability.resolve(data);
  2721. },
  2722. isResolved: function PDFObjects_isResolved(objId) {
  2723. var objs = this.objs;
  2724. if (!objs[objId]) {
  2725. return false;
  2726. } else {
  2727. return objs[objId].resolved;
  2728. }
  2729. },
  2730. hasData: function PDFObjects_hasData(objId) {
  2731. return this.isResolved(objId);
  2732. },
  2733. /**
  2734. * Returns the data of `objId` if object exists, null otherwise.
  2735. */
  2736. getData: function PDFObjects_getData(objId) {
  2737. var objs = this.objs;
  2738. if (!objs[objId] || !objs[objId].resolved) {
  2739. return null;
  2740. } else {
  2741. return objs[objId].data;
  2742. }
  2743. },
  2744. clear: function PDFObjects_clear() {
  2745. this.objs = {};
  2746. }
  2747. };
  2748. return PDFObjects;
  2749. })();
  2750. /**
  2751. * Allows controlling of the rendering tasks.
  2752. * @class
  2753. */
  2754. var RenderTask = (function RenderTaskClosure() {
  2755. function RenderTask(internalRenderTask) {
  2756. this._internalRenderTask = internalRenderTask;
  2757. /**
  2758. * Callback for incremental rendering -- a function that will be called
  2759. * each time the rendering is paused. To continue rendering call the
  2760. * function that is the first argument to the callback.
  2761. * @type {function}
  2762. */
  2763. this.onContinue = null;
  2764. }
  2765. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2766. /**
  2767. * Promise for rendering task completion.
  2768. * @return {Promise}
  2769. */
  2770. get promise() {
  2771. return this._internalRenderTask.capability.promise;
  2772. },
  2773. /**
  2774. * Cancels the rendering task. If the task is currently rendering it will
  2775. * not be cancelled until graphics pauses with a timeout. The promise that
  2776. * this object extends will resolved when cancelled.
  2777. */
  2778. cancel: function RenderTask_cancel() {
  2779. this._internalRenderTask.cancel();
  2780. },
  2781. /**
  2782. * Registers callbacks to indicate the rendering task completion.
  2783. *
  2784. * @param {function} onFulfilled The callback for the rendering completion.
  2785. * @param {function} onRejected The callback for the rendering failure.
  2786. * @return {Promise} A promise that is resolved after the onFulfilled or
  2787. * onRejected callback.
  2788. */
  2789. then: function RenderTask_then(onFulfilled, onRejected) {
  2790. return this.promise.then.apply(this.promise, arguments);
  2791. }
  2792. };
  2793. return RenderTask;
  2794. })();
  2795. /**
  2796. * For internal use only.
  2797. * @ignore
  2798. */
  2799. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2800. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2801. pageNumber) {
  2802. this.callback = callback;
  2803. this.params = params;
  2804. this.objs = objs;
  2805. this.commonObjs = commonObjs;
  2806. this.operatorListIdx = null;
  2807. this.operatorList = operatorList;
  2808. this.pageNumber = pageNumber;
  2809. this.running = false;
  2810. this.graphicsReadyCallback = null;
  2811. this.graphicsReady = false;
  2812. this.useRequestAnimationFrame = false;
  2813. this.cancelled = false;
  2814. this.capability = createPromiseCapability();
  2815. this.task = new RenderTask(this);
  2816. // caching this-bound methods
  2817. this._continueBound = this._continue.bind(this);
  2818. this._scheduleNextBound = this._scheduleNext.bind(this);
  2819. this._nextBound = this._next.bind(this);
  2820. }
  2821. InternalRenderTask.prototype = {
  2822. initalizeGraphics:
  2823. function InternalRenderTask_initalizeGraphics(transparency) {
  2824. if (this.cancelled) {
  2825. return;
  2826. }
  2827. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2828. globalScope.StepperManager.enabled) {
  2829. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2830. this.stepper.init(this.operatorList);
  2831. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2832. }
  2833. var params = this.params;
  2834. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2835. this.objs, params.imageLayer);
  2836. this.gfx.beginDrawing(params.viewport, transparency);
  2837. this.operatorListIdx = 0;
  2838. this.graphicsReady = true;
  2839. if (this.graphicsReadyCallback) {
  2840. this.graphicsReadyCallback();
  2841. }
  2842. },
  2843. cancel: function InternalRenderTask_cancel() {
  2844. this.running = false;
  2845. this.cancelled = true;
  2846. this.callback('cancelled');
  2847. },
  2848. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2849. if (!this.graphicsReady) {
  2850. if (!this.graphicsReadyCallback) {
  2851. this.graphicsReadyCallback = this._continueBound;
  2852. }
  2853. return;
  2854. }
  2855. if (this.stepper) {
  2856. this.stepper.updateOperatorList(this.operatorList);
  2857. }
  2858. if (this.running) {
  2859. return;
  2860. }
  2861. this._continue();
  2862. },
  2863. _continue: function InternalRenderTask__continue() {
  2864. this.running = true;
  2865. if (this.cancelled) {
  2866. return;
  2867. }
  2868. if (this.task.onContinue) {
  2869. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2870. } else {
  2871. this._scheduleNext();
  2872. }
  2873. },
  2874. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2875. if (this.useRequestAnimationFrame) {
  2876. window.requestAnimationFrame(this._nextBound);
  2877. } else {
  2878. Promise.resolve(undefined).then(this._nextBound);
  2879. }
  2880. },
  2881. _next: function InternalRenderTask__next() {
  2882. if (this.cancelled) {
  2883. return;
  2884. }
  2885. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2886. this.operatorListIdx,
  2887. this._continueBound,
  2888. this.stepper);
  2889. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2890. this.running = false;
  2891. if (this.operatorList.lastChunk) {
  2892. this.gfx.endDrawing();
  2893. this.callback();
  2894. }
  2895. }
  2896. }
  2897. };
  2898. return InternalRenderTask;
  2899. })();
  2900. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2901. function fixMetadata(meta) {
  2902. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2903. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2904. function(code, d1, d2, d3) {
  2905. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2906. });
  2907. var chars = '';
  2908. for (var i = 0; i < bytes.length; i += 2) {
  2909. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2910. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2911. code !== 38 && false ? String.fromCharCode(code) :
  2912. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2913. }
  2914. return '>' + chars;
  2915. });
  2916. }
  2917. function Metadata(meta) {
  2918. if (typeof meta === 'string') {
  2919. // Ghostscript produces invalid metadata
  2920. meta = fixMetadata(meta);
  2921. var parser = new DOMParser();
  2922. meta = parser.parseFromString(meta, 'application/xml');
  2923. } else if (!(meta instanceof Document)) {
  2924. error('Metadata: Invalid metadata object');
  2925. }
  2926. this.metaDocument = meta;
  2927. this.metadata = {};
  2928. this.parse();
  2929. }
  2930. Metadata.prototype = {
  2931. parse: function Metadata_parse() {
  2932. var doc = this.metaDocument;
  2933. var rdf = doc.documentElement;
  2934. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2935. rdf = rdf.firstChild;
  2936. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2937. rdf = rdf.nextSibling;
  2938. }
  2939. }
  2940. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2941. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2942. return;
  2943. }
  2944. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2945. for (i = 0, length = children.length; i < length; i++) {
  2946. desc = children[i];
  2947. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2948. continue;
  2949. }
  2950. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2951. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2952. entry = desc.childNodes[ii];
  2953. name = entry.nodeName.toLowerCase();
  2954. this.metadata[name] = entry.textContent.trim();
  2955. }
  2956. }
  2957. }
  2958. },
  2959. get: function Metadata_get(name) {
  2960. return this.metadata[name] || null;
  2961. },
  2962. has: function Metadata_has(name) {
  2963. return typeof this.metadata[name] !== 'undefined';
  2964. }
  2965. };
  2966. return Metadata;
  2967. })();
  2968. // <canvas> contexts store most of the state we need natively.
  2969. // However, PDF needs a bit more state, which we store here.
  2970. // Minimal font size that would be used during canvas fillText operations.
  2971. var MIN_FONT_SIZE = 16;
  2972. // Maximum font size that would be used during canvas fillText operations.
  2973. var MAX_FONT_SIZE = 100;
  2974. var MAX_GROUP_SIZE = 4096;
  2975. // Heuristic value used when enforcing minimum line widths.
  2976. var MIN_WIDTH_FACTOR = 0.65;
  2977. var COMPILE_TYPE3_GLYPHS = true;
  2978. var MAX_SIZE_TO_COMPILE = 1000;
  2979. var FULL_CHUNK_HEIGHT = 16;
  2980. function createScratchCanvas(width, height) {
  2981. var canvas = document.createElement('canvas');
  2982. canvas.width = width;
  2983. canvas.height = height;
  2984. return canvas;
  2985. }
  2986. function addContextCurrentTransform(ctx) {
  2987. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  2988. if (!ctx.mozCurrentTransform) {
  2989. ctx._originalSave = ctx.save;
  2990. ctx._originalRestore = ctx.restore;
  2991. ctx._originalRotate = ctx.rotate;
  2992. ctx._originalScale = ctx.scale;
  2993. ctx._originalTranslate = ctx.translate;
  2994. ctx._originalTransform = ctx.transform;
  2995. ctx._originalSetTransform = ctx.setTransform;
  2996. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  2997. ctx._transformStack = [];
  2998. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2999. get: function getCurrentTransform() {
  3000. return this._transformMatrix;
  3001. }
  3002. });
  3003. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  3004. get: function getCurrentTransformInverse() {
  3005. // Calculation done using WolframAlpha:
  3006. // http://www.wolframalpha.com/input/?
  3007. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  3008. var m = this._transformMatrix;
  3009. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  3010. var ad_bc = a * d - b * c;
  3011. var bc_ad = b * c - a * d;
  3012. return [
  3013. d / ad_bc,
  3014. b / bc_ad,
  3015. c / bc_ad,
  3016. a / ad_bc,
  3017. (d * e - c * f) / bc_ad,
  3018. (b * e - a * f) / ad_bc
  3019. ];
  3020. }
  3021. });
  3022. ctx.save = function ctxSave() {
  3023. var old = this._transformMatrix;
  3024. this._transformStack.push(old);
  3025. this._transformMatrix = old.slice(0, 6);
  3026. this._originalSave();
  3027. };
  3028. ctx.restore = function ctxRestore() {
  3029. var prev = this._transformStack.pop();
  3030. if (prev) {
  3031. this._transformMatrix = prev;
  3032. this._originalRestore();
  3033. }
  3034. };
  3035. ctx.translate = function ctxTranslate(x, y) {
  3036. var m = this._transformMatrix;
  3037. m[4] = m[0] * x + m[2] * y + m[4];
  3038. m[5] = m[1] * x + m[3] * y + m[5];
  3039. this._originalTranslate(x, y);
  3040. };
  3041. ctx.scale = function ctxScale(x, y) {
  3042. var m = this._transformMatrix;
  3043. m[0] = m[0] * x;
  3044. m[1] = m[1] * x;
  3045. m[2] = m[2] * y;
  3046. m[3] = m[3] * y;
  3047. this._originalScale(x, y);
  3048. };
  3049. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3050. var m = this._transformMatrix;
  3051. this._transformMatrix = [
  3052. m[0] * a + m[2] * b,
  3053. m[1] * a + m[3] * b,
  3054. m[0] * c + m[2] * d,
  3055. m[1] * c + m[3] * d,
  3056. m[0] * e + m[2] * f + m[4],
  3057. m[1] * e + m[3] * f + m[5]
  3058. ];
  3059. ctx._originalTransform(a, b, c, d, e, f);
  3060. };
  3061. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3062. this._transformMatrix = [a, b, c, d, e, f];
  3063. ctx._originalSetTransform(a, b, c, d, e, f);
  3064. };
  3065. ctx.rotate = function ctxRotate(angle) {
  3066. var cosValue = Math.cos(angle);
  3067. var sinValue = Math.sin(angle);
  3068. var m = this._transformMatrix;
  3069. this._transformMatrix = [
  3070. m[0] * cosValue + m[2] * sinValue,
  3071. m[1] * cosValue + m[3] * sinValue,
  3072. m[0] * (-sinValue) + m[2] * cosValue,
  3073. m[1] * (-sinValue) + m[3] * cosValue,
  3074. m[4],
  3075. m[5]
  3076. ];
  3077. this._originalRotate(angle);
  3078. };
  3079. }
  3080. }
  3081. var CachedCanvases = (function CachedCanvasesClosure() {
  3082. var cache = {};
  3083. return {
  3084. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3085. trackTransform) {
  3086. var canvasEntry;
  3087. if (cache[id] !== undefined) {
  3088. canvasEntry = cache[id];
  3089. canvasEntry.canvas.width = width;
  3090. canvasEntry.canvas.height = height;
  3091. // reset canvas transform for emulated mozCurrentTransform, if needed
  3092. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3093. } else {
  3094. var canvas = createScratchCanvas(width, height);
  3095. var ctx = canvas.getContext('2d');
  3096. if (trackTransform) {
  3097. addContextCurrentTransform(ctx);
  3098. }
  3099. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3100. }
  3101. return canvasEntry;
  3102. },
  3103. clear: function () {
  3104. for (var id in cache) {
  3105. var canvasEntry = cache[id];
  3106. // Zeroing the width and height causes Firefox to release graphics
  3107. // resources immediately, which can greatly reduce memory consumption.
  3108. canvasEntry.canvas.width = 0;
  3109. canvasEntry.canvas.height = 0;
  3110. delete cache[id];
  3111. }
  3112. }
  3113. };
  3114. })();
  3115. function compileType3Glyph(imgData) {
  3116. var POINT_TO_PROCESS_LIMIT = 1000;
  3117. var width = imgData.width, height = imgData.height;
  3118. var i, j, j0, width1 = width + 1;
  3119. var points = new Uint8Array(width1 * (height + 1));
  3120. var POINT_TYPES =
  3121. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3122. // decodes bit-packed mask data
  3123. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3124. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3125. for (i = 0, ii = data0.length; i < ii; i++) {
  3126. var mask = 128, elem = data0[i];
  3127. while (mask > 0) {
  3128. data[pos++] = (elem & mask) ? 0 : 255;
  3129. mask >>= 1;
  3130. }
  3131. }
  3132. // finding iteresting points: every point is located between mask pixels,
  3133. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3134. // will have flags assigned based on neighboring mask pixels:
  3135. // 4 | 8
  3136. // --P--
  3137. // 2 | 1
  3138. // We are interested only in points with the flags:
  3139. // - outside corners: 1, 2, 4, 8;
  3140. // - inside corners: 7, 11, 13, 14;
  3141. // - and, intersections: 5, 10.
  3142. var count = 0;
  3143. pos = 0;
  3144. if (data[pos] !== 0) {
  3145. points[0] = 1;
  3146. ++count;
  3147. }
  3148. for (j = 1; j < width; j++) {
  3149. if (data[pos] !== data[pos + 1]) {
  3150. points[j] = data[pos] ? 2 : 1;
  3151. ++count;
  3152. }
  3153. pos++;
  3154. }
  3155. if (data[pos] !== 0) {
  3156. points[j] = 2;
  3157. ++count;
  3158. }
  3159. for (i = 1; i < height; i++) {
  3160. pos = i * lineSize;
  3161. j0 = i * width1;
  3162. if (data[pos - lineSize] !== data[pos]) {
  3163. points[j0] = data[pos] ? 1 : 8;
  3164. ++count;
  3165. }
  3166. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3167. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3168. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3169. for (j = 1; j < width; j++) {
  3170. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3171. (data[pos - lineSize + 1] ? 8 : 0);
  3172. if (POINT_TYPES[sum]) {
  3173. points[j0 + j] = POINT_TYPES[sum];
  3174. ++count;
  3175. }
  3176. pos++;
  3177. }
  3178. if (data[pos - lineSize] !== data[pos]) {
  3179. points[j0 + j] = data[pos] ? 2 : 4;
  3180. ++count;
  3181. }
  3182. if (count > POINT_TO_PROCESS_LIMIT) {
  3183. return null;
  3184. }
  3185. }
  3186. pos = lineSize * (height - 1);
  3187. j0 = i * width1;
  3188. if (data[pos] !== 0) {
  3189. points[j0] = 8;
  3190. ++count;
  3191. }
  3192. for (j = 1; j < width; j++) {
  3193. if (data[pos] !== data[pos + 1]) {
  3194. points[j0 + j] = data[pos] ? 4 : 8;
  3195. ++count;
  3196. }
  3197. pos++;
  3198. }
  3199. if (data[pos] !== 0) {
  3200. points[j0 + j] = 4;
  3201. ++count;
  3202. }
  3203. if (count > POINT_TO_PROCESS_LIMIT) {
  3204. return null;
  3205. }
  3206. // building outlines
  3207. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3208. var outlines = [];
  3209. for (i = 0; count && i <= height; i++) {
  3210. var p = i * width1;
  3211. var end = p + width;
  3212. while (p < end && !points[p]) {
  3213. p++;
  3214. }
  3215. if (p === end) {
  3216. continue;
  3217. }
  3218. var coords = [p % width1, i];
  3219. var type = points[p], p0 = p, pp;
  3220. do {
  3221. var step = steps[type];
  3222. do {
  3223. p += step;
  3224. } while (!points[p]);
  3225. pp = points[p];
  3226. if (pp !== 5 && pp !== 10) {
  3227. // set new direction
  3228. type = pp;
  3229. // delete mark
  3230. points[p] = 0;
  3231. } else { // type is 5 or 10, ie, a crossing
  3232. // set new direction
  3233. type = pp & ((0x33 * type) >> 4);
  3234. // set new type for "future hit"
  3235. points[p] &= (type >> 2 | type << 2);
  3236. }
  3237. coords.push(p % width1);
  3238. coords.push((p / width1) | 0);
  3239. --count;
  3240. } while (p0 !== p);
  3241. outlines.push(coords);
  3242. --i;
  3243. }
  3244. var drawOutline = function(c) {
  3245. c.save();
  3246. // the path shall be painted in [0..1]x[0..1] space
  3247. c.scale(1 / width, -1 / height);
  3248. c.translate(0, -height);
  3249. c.beginPath();
  3250. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3251. var o = outlines[i];
  3252. c.moveTo(o[0], o[1]);
  3253. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3254. c.lineTo(o[j], o[j+1]);
  3255. }
  3256. }
  3257. c.fill();
  3258. c.beginPath();
  3259. c.restore();
  3260. };
  3261. return drawOutline;
  3262. }
  3263. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3264. function CanvasExtraState(old) {
  3265. // Are soft masks and alpha values shapes or opacities?
  3266. this.alphaIsShape = false;
  3267. this.fontSize = 0;
  3268. this.fontSizeScale = 1;
  3269. this.textMatrix = IDENTITY_MATRIX;
  3270. this.textMatrixScale = 1;
  3271. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3272. this.leading = 0;
  3273. // Current point (in user coordinates)
  3274. this.x = 0;
  3275. this.y = 0;
  3276. // Start of text line (in text coordinates)
  3277. this.lineX = 0;
  3278. this.lineY = 0;
  3279. // Character and word spacing
  3280. this.charSpacing = 0;
  3281. this.wordSpacing = 0;
  3282. this.textHScale = 1;
  3283. this.textRenderingMode = TextRenderingMode.FILL;
  3284. this.textRise = 0;
  3285. // Default fore and background colors
  3286. this.fillColor = '#000000';
  3287. this.strokeColor = '#000000';
  3288. this.patternFill = false;
  3289. // Note: fill alpha applies to all non-stroking operations
  3290. this.fillAlpha = 1;
  3291. this.strokeAlpha = 1;
  3292. this.lineWidth = 1;
  3293. this.activeSMask = null; // nonclonable field (see the save method below)
  3294. this.old = old;
  3295. }
  3296. CanvasExtraState.prototype = {
  3297. clone: function CanvasExtraState_clone() {
  3298. return Object.create(this);
  3299. },
  3300. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3301. this.x = x;
  3302. this.y = y;
  3303. }
  3304. };
  3305. return CanvasExtraState;
  3306. })();
  3307. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3308. // Defines the time the executeOperatorList is going to be executing
  3309. // before it stops and shedules a continue of execution.
  3310. var EXECUTION_TIME = 15;
  3311. // Defines the number of steps before checking the execution time
  3312. var EXECUTION_STEPS = 10;
  3313. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3314. this.ctx = canvasCtx;
  3315. this.current = new CanvasExtraState();
  3316. this.stateStack = [];
  3317. this.pendingClip = null;
  3318. this.pendingEOFill = false;
  3319. this.res = null;
  3320. this.xobjs = null;
  3321. this.commonObjs = commonObjs;
  3322. this.objs = objs;
  3323. this.imageLayer = imageLayer;
  3324. this.groupStack = [];
  3325. this.processingType3 = null;
  3326. // Patterns are painted relative to the initial page/form transform, see pdf
  3327. // spec 8.7.2 NOTE 1.
  3328. this.baseTransform = null;
  3329. this.baseTransformStack = [];
  3330. this.groupLevel = 0;
  3331. this.smaskStack = [];
  3332. this.smaskCounter = 0;
  3333. this.tempSMask = null;
  3334. if (canvasCtx) {
  3335. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3336. // the transformation must already be set in canvasCtx._transformMatrix.
  3337. addContextCurrentTransform(canvasCtx);
  3338. }
  3339. this.cachedGetSinglePixelWidth = null;
  3340. }
  3341. function putBinaryImageData(ctx, imgData) {
  3342. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3343. ctx.putImageData(imgData, 0, 0);
  3344. return;
  3345. }
  3346. // Put the image data to the canvas in chunks, rather than putting the
  3347. // whole image at once. This saves JS memory, because the ImageData object
  3348. // is smaller. It also possibly saves C++ memory within the implementation
  3349. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3350. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3351. // because too many putImageData() calls will slow things down.
  3352. //
  3353. // Note: as written, if the last chunk is partial, the putImageData() call
  3354. // will (conceptually) put pixels past the bounds of the canvas. But
  3355. // that's ok; any such pixels are ignored.
  3356. var height = imgData.height, width = imgData.width;
  3357. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3358. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3359. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3360. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3361. var srcPos = 0, destPos;
  3362. var src = imgData.data;
  3363. var dest = chunkImgData.data;
  3364. var i, j, thisChunkHeight, elemsInThisChunk;
  3365. // There are multiple forms in which the pixel data can be passed, and
  3366. // imgData.kind tells us which one this is.
  3367. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3368. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3369. var srcLength = src.byteLength;
  3370. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3371. new Uint32ArrayView(dest);
  3372. var dest32DataLength = dest32.length;
  3373. var fullSrcDiff = (width + 7) >> 3;
  3374. var white = 0xFFFFFFFF;
  3375. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3376. 0xFF000000 : 0x000000FF;
  3377. for (i = 0; i < totalChunks; i++) {
  3378. thisChunkHeight =
  3379. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3380. destPos = 0;
  3381. for (j = 0; j < thisChunkHeight; j++) {
  3382. var srcDiff = srcLength - srcPos;
  3383. var k = 0;
  3384. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3385. var kEndUnrolled = kEnd & ~7;
  3386. var mask = 0;
  3387. var srcByte = 0;
  3388. for (; k < kEndUnrolled; k += 8) {
  3389. srcByte = src[srcPos++];
  3390. dest32[destPos++] = (srcByte & 128) ? white : black;
  3391. dest32[destPos++] = (srcByte & 64) ? white : black;
  3392. dest32[destPos++] = (srcByte & 32) ? white : black;
  3393. dest32[destPos++] = (srcByte & 16) ? white : black;
  3394. dest32[destPos++] = (srcByte & 8) ? white : black;
  3395. dest32[destPos++] = (srcByte & 4) ? white : black;
  3396. dest32[destPos++] = (srcByte & 2) ? white : black;
  3397. dest32[destPos++] = (srcByte & 1) ? white : black;
  3398. }
  3399. for (; k < kEnd; k++) {
  3400. if (mask === 0) {
  3401. srcByte = src[srcPos++];
  3402. mask = 128;
  3403. }
  3404. dest32[destPos++] = (srcByte & mask) ? white : black;
  3405. mask >>= 1;
  3406. }
  3407. }
  3408. // We ran out of input. Make all remaining pixels transparent.
  3409. while (destPos < dest32DataLength) {
  3410. dest32[destPos++] = 0;
  3411. }
  3412. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3413. }
  3414. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3415. // RGBA, 32-bits per pixel.
  3416. j = 0;
  3417. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3418. for (i = 0; i < fullChunks; i++) {
  3419. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3420. srcPos += elemsInThisChunk;
  3421. ctx.putImageData(chunkImgData, 0, j);
  3422. j += FULL_CHUNK_HEIGHT;
  3423. }
  3424. if (i < totalChunks) {
  3425. elemsInThisChunk = width * partialChunkHeight * 4;
  3426. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3427. ctx.putImageData(chunkImgData, 0, j);
  3428. }
  3429. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3430. // RGB, 24-bits per pixel.
  3431. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3432. elemsInThisChunk = width * thisChunkHeight;
  3433. for (i = 0; i < totalChunks; i++) {
  3434. if (i >= fullChunks) {
  3435. thisChunkHeight = partialChunkHeight;
  3436. elemsInThisChunk = width * thisChunkHeight;
  3437. }
  3438. destPos = 0;
  3439. for (j = elemsInThisChunk; j--;) {
  3440. dest[destPos++] = src[srcPos++];
  3441. dest[destPos++] = src[srcPos++];
  3442. dest[destPos++] = src[srcPos++];
  3443. dest[destPos++] = 255;
  3444. }
  3445. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3446. }
  3447. } else {
  3448. error('bad image kind: ' + imgData.kind);
  3449. }
  3450. }
  3451. function putBinaryImageMask(ctx, imgData) {
  3452. var height = imgData.height, width = imgData.width;
  3453. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3454. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3455. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3456. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3457. var srcPos = 0;
  3458. var src = imgData.data;
  3459. var dest = chunkImgData.data;
  3460. for (var i = 0; i < totalChunks; i++) {
  3461. var thisChunkHeight =
  3462. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3463. // Expand the mask so it can be used by the canvas. Any required
  3464. // inversion has already been handled.
  3465. var destPos = 3; // alpha component offset
  3466. for (var j = 0; j < thisChunkHeight; j++) {
  3467. var mask = 0;
  3468. for (var k = 0; k < width; k++) {
  3469. if (!mask) {
  3470. var elem = src[srcPos++];
  3471. mask = 128;
  3472. }
  3473. dest[destPos] = (elem & mask) ? 0 : 255;
  3474. destPos += 4;
  3475. mask >>= 1;
  3476. }
  3477. }
  3478. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3479. }
  3480. }
  3481. function copyCtxState(sourceCtx, destCtx) {
  3482. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3483. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3484. 'globalCompositeOperation', 'font'];
  3485. for (var i = 0, ii = properties.length; i < ii; i++) {
  3486. var property = properties[i];
  3487. if (sourceCtx[property] !== undefined) {
  3488. destCtx[property] = sourceCtx[property];
  3489. }
  3490. }
  3491. if (sourceCtx.setLineDash !== undefined) {
  3492. destCtx.setLineDash(sourceCtx.getLineDash());
  3493. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3494. } else if (sourceCtx.mozDashOffset !== undefined) {
  3495. destCtx.mozDash = sourceCtx.mozDash;
  3496. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3497. }
  3498. }
  3499. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3500. var length = bytes.length;
  3501. for (var i = 3; i < length; i += 4) {
  3502. var alpha = bytes[i];
  3503. if (alpha === 0) {
  3504. bytes[i - 3] = r0;
  3505. bytes[i - 2] = g0;
  3506. bytes[i - 1] = b0;
  3507. } else if (alpha < 255) {
  3508. var alpha_ = 255 - alpha;
  3509. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3510. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3511. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3512. }
  3513. }
  3514. }
  3515. function composeSMaskAlpha(maskData, layerData) {
  3516. var length = maskData.length;
  3517. var scale = 1 / 255;
  3518. for (var i = 3; i < length; i += 4) {
  3519. var alpha = maskData[i];
  3520. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3521. }
  3522. }
  3523. function composeSMaskLuminosity(maskData, layerData) {
  3524. var length = maskData.length;
  3525. for (var i = 3; i < length; i += 4) {
  3526. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3527. (maskData[i - 2] * 152) + // * 0.59 ....
  3528. (maskData[i - 1] * 28); // * 0.11 ....
  3529. layerData[i] = (layerData[i] * y) >> 16;
  3530. }
  3531. }
  3532. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3533. subtype, backdrop) {
  3534. var hasBackdrop = !!backdrop;
  3535. var r0 = hasBackdrop ? backdrop[0] : 0;
  3536. var g0 = hasBackdrop ? backdrop[1] : 0;
  3537. var b0 = hasBackdrop ? backdrop[2] : 0;
  3538. var composeFn;
  3539. if (subtype === 'Luminosity') {
  3540. composeFn = composeSMaskLuminosity;
  3541. } else {
  3542. composeFn = composeSMaskAlpha;
  3543. }
  3544. // processing image in chunks to save memory
  3545. var PIXELS_TO_PROCESS = 1048576;
  3546. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3547. for (var row = 0; row < height; row += chunkSize) {
  3548. var chunkHeight = Math.min(chunkSize, height - row);
  3549. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3550. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3551. if (hasBackdrop) {
  3552. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3553. }
  3554. composeFn(maskData.data, layerData.data);
  3555. maskCtx.putImageData(layerData, 0, row);
  3556. }
  3557. }
  3558. function composeSMask(ctx, smask, layerCtx) {
  3559. var mask = smask.canvas;
  3560. var maskCtx = smask.context;
  3561. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3562. smask.offsetX, smask.offsetY);
  3563. var backdrop = smask.backdrop || null;
  3564. if (WebGLUtils.isEnabled) {
  3565. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3566. {subtype: smask.subtype, backdrop: backdrop});
  3567. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3568. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3569. return;
  3570. }
  3571. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3572. smask.subtype, backdrop);
  3573. ctx.drawImage(mask, 0, 0);
  3574. }
  3575. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3576. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3577. var NORMAL_CLIP = {};
  3578. var EO_CLIP = {};
  3579. CanvasGraphics.prototype = {
  3580. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3581. // For pdfs that use blend modes we have to clear the canvas else certain
  3582. // blend modes can look wrong since we'd be blending with a white
  3583. // backdrop. The problem with a transparent backdrop though is we then
  3584. // don't get sub pixel anti aliasing on text, so we fill with white if
  3585. // we can.
  3586. var width = this.ctx.canvas.width;
  3587. var height = this.ctx.canvas.height;
  3588. if (transparency) {
  3589. this.ctx.clearRect(0, 0, width, height);
  3590. } else {
  3591. this.ctx.mozOpaque = true;
  3592. this.ctx.save();
  3593. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3594. this.ctx.fillRect(0, 0, width, height);
  3595. this.ctx.restore();
  3596. }
  3597. var transform = viewport.transform;
  3598. this.ctx.save();
  3599. this.ctx.transform.apply(this.ctx, transform);
  3600. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3601. if (this.imageLayer) {
  3602. this.imageLayer.beginLayout();
  3603. }
  3604. },
  3605. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3606. operatorList,
  3607. executionStartIdx, continueCallback,
  3608. stepper) {
  3609. var argsArray = operatorList.argsArray;
  3610. var fnArray = operatorList.fnArray;
  3611. var i = executionStartIdx || 0;
  3612. var argsArrayLen = argsArray.length;
  3613. // Sometimes the OperatorList to execute is empty.
  3614. if (argsArrayLen === i) {
  3615. return i;
  3616. }
  3617. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3618. typeof continueCallback === 'function');
  3619. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3620. var steps = 0;
  3621. var commonObjs = this.commonObjs;
  3622. var objs = this.objs;
  3623. var fnId;
  3624. while (true) {
  3625. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3626. stepper.breakIt(i, continueCallback);
  3627. return i;
  3628. }
  3629. fnId = fnArray[i];
  3630. if (fnId !== OPS.dependency) {
  3631. this[fnId].apply(this, argsArray[i]);
  3632. } else {
  3633. var deps = argsArray[i];
  3634. for (var n = 0, nn = deps.length; n < nn; n++) {
  3635. var depObjId = deps[n];
  3636. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3637. var objsPool = common ? commonObjs : objs;
  3638. // If the promise isn't resolved yet, add the continueCallback
  3639. // to the promise and bail out.
  3640. if (!objsPool.isResolved(depObjId)) {
  3641. objsPool.get(depObjId, continueCallback);
  3642. return i;
  3643. }
  3644. }
  3645. }
  3646. i++;
  3647. // If the entire operatorList was executed, stop as were done.
  3648. if (i === argsArrayLen) {
  3649. return i;
  3650. }
  3651. // If the execution took longer then a certain amount of time and
  3652. // `continueCallback` is specified, interrupt the execution.
  3653. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3654. if (Date.now() > endTime) {
  3655. continueCallback();
  3656. return i;
  3657. }
  3658. steps = 0;
  3659. }
  3660. // If the operatorList isn't executed completely yet OR the execution
  3661. // time was short enough, do another execution round.
  3662. }
  3663. },
  3664. endDrawing: function CanvasGraphics_endDrawing() {
  3665. this.ctx.restore();
  3666. CachedCanvases.clear();
  3667. WebGLUtils.clear();
  3668. if (this.imageLayer) {
  3669. this.imageLayer.endLayout();
  3670. }
  3671. },
  3672. // Graphics state
  3673. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3674. this.current.lineWidth = width;
  3675. this.ctx.lineWidth = width;
  3676. },
  3677. setLineCap: function CanvasGraphics_setLineCap(style) {
  3678. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3679. },
  3680. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3681. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3682. },
  3683. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3684. this.ctx.miterLimit = limit;
  3685. },
  3686. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3687. var ctx = this.ctx;
  3688. if (ctx.setLineDash !== undefined) {
  3689. ctx.setLineDash(dashArray);
  3690. ctx.lineDashOffset = dashPhase;
  3691. } else {
  3692. ctx.mozDash = dashArray;
  3693. ctx.mozDashOffset = dashPhase;
  3694. }
  3695. },
  3696. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3697. // Maybe if we one day fully support color spaces this will be important
  3698. // for now we can ignore.
  3699. // TODO set rendering intent?
  3700. },
  3701. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3702. // There's no way to control this with canvas, but we can safely ignore.
  3703. // TODO set flatness?
  3704. },
  3705. setGState: function CanvasGraphics_setGState(states) {
  3706. for (var i = 0, ii = states.length; i < ii; i++) {
  3707. var state = states[i];
  3708. var key = state[0];
  3709. var value = state[1];
  3710. switch (key) {
  3711. case 'LW':
  3712. this.setLineWidth(value);
  3713. break;
  3714. case 'LC':
  3715. this.setLineCap(value);
  3716. break;
  3717. case 'LJ':
  3718. this.setLineJoin(value);
  3719. break;
  3720. case 'ML':
  3721. this.setMiterLimit(value);
  3722. break;
  3723. case 'D':
  3724. this.setDash(value[0], value[1]);
  3725. break;
  3726. case 'RI':
  3727. this.setRenderingIntent(value);
  3728. break;
  3729. case 'FL':
  3730. this.setFlatness(value);
  3731. break;
  3732. case 'Font':
  3733. this.setFont(value[0], value[1]);
  3734. break;
  3735. case 'CA':
  3736. this.current.strokeAlpha = state[1];
  3737. break;
  3738. case 'ca':
  3739. this.current.fillAlpha = state[1];
  3740. this.ctx.globalAlpha = state[1];
  3741. break;
  3742. case 'BM':
  3743. if (value && value.name && (value.name !== 'Normal')) {
  3744. var mode = value.name.replace(/([A-Z])/g,
  3745. function(c) {
  3746. return '-' + c.toLowerCase();
  3747. }
  3748. ).substring(1);
  3749. this.ctx.globalCompositeOperation = mode;
  3750. if (this.ctx.globalCompositeOperation !== mode) {
  3751. warn('globalCompositeOperation "' + mode +
  3752. '" is not supported');
  3753. }
  3754. } else {
  3755. this.ctx.globalCompositeOperation = 'source-over';
  3756. }
  3757. break;
  3758. case 'SMask':
  3759. if (this.current.activeSMask) {
  3760. this.endSMaskGroup();
  3761. }
  3762. this.current.activeSMask = value ? this.tempSMask : null;
  3763. if (this.current.activeSMask) {
  3764. this.beginSMaskGroup();
  3765. }
  3766. this.tempSMask = null;
  3767. break;
  3768. }
  3769. }
  3770. },
  3771. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3772. var activeSMask = this.current.activeSMask;
  3773. var drawnWidth = activeSMask.canvas.width;
  3774. var drawnHeight = activeSMask.canvas.height;
  3775. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3776. var scratchCanvas = CachedCanvases.getCanvas(
  3777. cacheId, drawnWidth, drawnHeight, true);
  3778. var currentCtx = this.ctx;
  3779. var currentTransform = currentCtx.mozCurrentTransform;
  3780. this.ctx.save();
  3781. var groupCtx = scratchCanvas.context;
  3782. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3783. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3784. groupCtx.transform.apply(groupCtx, currentTransform);
  3785. copyCtxState(currentCtx, groupCtx);
  3786. this.ctx = groupCtx;
  3787. this.setGState([
  3788. ['BM', 'Normal'],
  3789. ['ca', 1],
  3790. ['CA', 1]
  3791. ]);
  3792. this.groupStack.push(currentCtx);
  3793. this.groupLevel++;
  3794. },
  3795. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3796. var groupCtx = this.ctx;
  3797. this.groupLevel--;
  3798. this.ctx = this.groupStack.pop();
  3799. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3800. this.ctx.restore();
  3801. },
  3802. save: function CanvasGraphics_save() {
  3803. this.ctx.save();
  3804. var old = this.current;
  3805. this.stateStack.push(old);
  3806. this.current = old.clone();
  3807. this.current.activeSMask = null;
  3808. },
  3809. restore: function CanvasGraphics_restore() {
  3810. if (this.stateStack.length !== 0) {
  3811. if (this.current.activeSMask !== null) {
  3812. this.endSMaskGroup();
  3813. }
  3814. this.current = this.stateStack.pop();
  3815. this.ctx.restore();
  3816. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  3817. this.pendingClip = null;
  3818. this.cachedGetSinglePixelWidth = null;
  3819. }
  3820. },
  3821. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3822. this.ctx.transform(a, b, c, d, e, f);
  3823. this.cachedGetSinglePixelWidth = null;
  3824. },
  3825. // Path
  3826. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3827. var ctx = this.ctx;
  3828. var current = this.current;
  3829. var x = current.x, y = current.y;
  3830. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3831. switch (ops[i] | 0) {
  3832. case OPS.rectangle:
  3833. x = args[j++];
  3834. y = args[j++];
  3835. var width = args[j++];
  3836. var height = args[j++];
  3837. if (width === 0) {
  3838. width = this.getSinglePixelWidth();
  3839. }
  3840. if (height === 0) {
  3841. height = this.getSinglePixelWidth();
  3842. }
  3843. var xw = x + width;
  3844. var yh = y + height;
  3845. this.ctx.moveTo(x, y);
  3846. this.ctx.lineTo(xw, y);
  3847. this.ctx.lineTo(xw, yh);
  3848. this.ctx.lineTo(x, yh);
  3849. this.ctx.lineTo(x, y);
  3850. this.ctx.closePath();
  3851. break;
  3852. case OPS.moveTo:
  3853. x = args[j++];
  3854. y = args[j++];
  3855. ctx.moveTo(x, y);
  3856. break;
  3857. case OPS.lineTo:
  3858. x = args[j++];
  3859. y = args[j++];
  3860. ctx.lineTo(x, y);
  3861. break;
  3862. case OPS.curveTo:
  3863. x = args[j + 4];
  3864. y = args[j + 5];
  3865. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3866. x, y);
  3867. j += 6;
  3868. break;
  3869. case OPS.curveTo2:
  3870. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3871. args[j + 2], args[j + 3]);
  3872. x = args[j + 2];
  3873. y = args[j + 3];
  3874. j += 4;
  3875. break;
  3876. case OPS.curveTo3:
  3877. x = args[j + 2];
  3878. y = args[j + 3];
  3879. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3880. j += 4;
  3881. break;
  3882. case OPS.closePath:
  3883. ctx.closePath();
  3884. break;
  3885. }
  3886. }
  3887. current.setCurrentPoint(x, y);
  3888. },
  3889. closePath: function CanvasGraphics_closePath() {
  3890. this.ctx.closePath();
  3891. },
  3892. stroke: function CanvasGraphics_stroke(consumePath) {
  3893. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3894. var ctx = this.ctx;
  3895. var strokeColor = this.current.strokeColor;
  3896. // Prevent drawing too thin lines by enforcing a minimum line width.
  3897. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3898. this.current.lineWidth);
  3899. // For stroke we want to temporarily change the global alpha to the
  3900. // stroking alpha.
  3901. ctx.globalAlpha = this.current.strokeAlpha;
  3902. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3903. strokeColor.type === 'Pattern') {
  3904. // for patterns, we transform to pattern space, calculate
  3905. // the pattern, call stroke, and restore to user space
  3906. ctx.save();
  3907. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3908. ctx.stroke();
  3909. ctx.restore();
  3910. } else {
  3911. ctx.stroke();
  3912. }
  3913. if (consumePath) {
  3914. this.consumePath();
  3915. }
  3916. // Restore the global alpha to the fill alpha
  3917. ctx.globalAlpha = this.current.fillAlpha;
  3918. },
  3919. closeStroke: function CanvasGraphics_closeStroke() {
  3920. this.closePath();
  3921. this.stroke();
  3922. },
  3923. fill: function CanvasGraphics_fill(consumePath) {
  3924. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3925. var ctx = this.ctx;
  3926. var fillColor = this.current.fillColor;
  3927. var isPatternFill = this.current.patternFill;
  3928. var needRestore = false;
  3929. if (isPatternFill) {
  3930. ctx.save();
  3931. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3932. needRestore = true;
  3933. }
  3934. if (this.pendingEOFill) {
  3935. if (ctx.mozFillRule !== undefined) {
  3936. ctx.mozFillRule = 'evenodd';
  3937. ctx.fill();
  3938. ctx.mozFillRule = 'nonzero';
  3939. } else {
  3940. ctx.fill('evenodd');
  3941. }
  3942. this.pendingEOFill = false;
  3943. } else {
  3944. ctx.fill();
  3945. }
  3946. if (needRestore) {
  3947. ctx.restore();
  3948. }
  3949. if (consumePath) {
  3950. this.consumePath();
  3951. }
  3952. },
  3953. eoFill: function CanvasGraphics_eoFill() {
  3954. this.pendingEOFill = true;
  3955. this.fill();
  3956. },
  3957. fillStroke: function CanvasGraphics_fillStroke() {
  3958. this.fill(false);
  3959. this.stroke(false);
  3960. this.consumePath();
  3961. },
  3962. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3963. this.pendingEOFill = true;
  3964. this.fillStroke();
  3965. },
  3966. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3967. this.closePath();
  3968. this.fillStroke();
  3969. },
  3970. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3971. this.pendingEOFill = true;
  3972. this.closePath();
  3973. this.fillStroke();
  3974. },
  3975. endPath: function CanvasGraphics_endPath() {
  3976. this.consumePath();
  3977. },
  3978. // Clipping
  3979. clip: function CanvasGraphics_clip() {
  3980. this.pendingClip = NORMAL_CLIP;
  3981. },
  3982. eoClip: function CanvasGraphics_eoClip() {
  3983. this.pendingClip = EO_CLIP;
  3984. },
  3985. // Text
  3986. beginText: function CanvasGraphics_beginText() {
  3987. this.current.textMatrix = IDENTITY_MATRIX;
  3988. this.current.textMatrixScale = 1;
  3989. this.current.x = this.current.lineX = 0;
  3990. this.current.y = this.current.lineY = 0;
  3991. },
  3992. endText: function CanvasGraphics_endText() {
  3993. var paths = this.pendingTextPaths;
  3994. var ctx = this.ctx;
  3995. if (paths === undefined) {
  3996. ctx.beginPath();
  3997. return;
  3998. }
  3999. ctx.save();
  4000. ctx.beginPath();
  4001. for (var i = 0; i < paths.length; i++) {
  4002. var path = paths[i];
  4003. ctx.setTransform.apply(ctx, path.transform);
  4004. ctx.translate(path.x, path.y);
  4005. path.addToPath(ctx, path.fontSize);
  4006. }
  4007. ctx.restore();
  4008. ctx.clip();
  4009. ctx.beginPath();
  4010. delete this.pendingTextPaths;
  4011. },
  4012. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4013. this.current.charSpacing = spacing;
  4014. },
  4015. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4016. this.current.wordSpacing = spacing;
  4017. },
  4018. setHScale: function CanvasGraphics_setHScale(scale) {
  4019. this.current.textHScale = scale / 100;
  4020. },
  4021. setLeading: function CanvasGraphics_setLeading(leading) {
  4022. this.current.leading = -leading;
  4023. },
  4024. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4025. var fontObj = this.commonObjs.get(fontRefName);
  4026. var current = this.current;
  4027. if (!fontObj) {
  4028. error('Can\'t find font for ' + fontRefName);
  4029. }
  4030. current.fontMatrix = (fontObj.fontMatrix ?
  4031. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  4032. // A valid matrix needs all main diagonal elements to be non-zero
  4033. // This also ensures we bypass FF bugzilla bug #719844.
  4034. if (current.fontMatrix[0] === 0 ||
  4035. current.fontMatrix[3] === 0) {
  4036. warn('Invalid font matrix for font ' + fontRefName);
  4037. }
  4038. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4039. // and in some docs this can be negative (inverted x-y axes).
  4040. if (size < 0) {
  4041. size = -size;
  4042. current.fontDirection = -1;
  4043. } else {
  4044. current.fontDirection = 1;
  4045. }
  4046. this.current.font = fontObj;
  4047. this.current.fontSize = size;
  4048. if (fontObj.isType3Font) {
  4049. return; // we don't need ctx.font for Type3 fonts
  4050. }
  4051. var name = fontObj.loadedName || 'sans-serif';
  4052. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  4053. (fontObj.bold ? 'bold' : 'normal');
  4054. var italic = fontObj.italic ? 'italic' : 'normal';
  4055. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4056. // Some font backends cannot handle fonts below certain size.
  4057. // Keeping the font at minimal size and using the fontSizeScale to change
  4058. // the current transformation matrix before the fillText/strokeText.
  4059. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4060. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4061. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4062. this.current.fontSizeScale = size / browserFontSize;
  4063. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4064. this.ctx.font = rule;
  4065. },
  4066. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4067. this.current.textRenderingMode = mode;
  4068. },
  4069. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4070. this.current.textRise = rise;
  4071. },
  4072. moveText: function CanvasGraphics_moveText(x, y) {
  4073. this.current.x = this.current.lineX += x;
  4074. this.current.y = this.current.lineY += y;
  4075. },
  4076. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4077. this.setLeading(-y);
  4078. this.moveText(x, y);
  4079. },
  4080. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4081. this.current.textMatrix = [a, b, c, d, e, f];
  4082. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4083. this.current.x = this.current.lineX = 0;
  4084. this.current.y = this.current.lineY = 0;
  4085. },
  4086. nextLine: function CanvasGraphics_nextLine() {
  4087. this.moveText(0, this.current.leading);
  4088. },
  4089. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4090. var ctx = this.ctx;
  4091. var current = this.current;
  4092. var font = current.font;
  4093. var textRenderingMode = current.textRenderingMode;
  4094. var fontSize = current.fontSize / current.fontSizeScale;
  4095. var fillStrokeMode = textRenderingMode &
  4096. TextRenderingMode.FILL_STROKE_MASK;
  4097. var isAddToPathSet = !!(textRenderingMode &
  4098. TextRenderingMode.ADD_TO_PATH_FLAG);
  4099. var addToPath;
  4100. if (font.disableFontFace || isAddToPathSet) {
  4101. addToPath = font.getPathGenerator(this.commonObjs, character);
  4102. }
  4103. if (font.disableFontFace) {
  4104. ctx.save();
  4105. ctx.translate(x, y);
  4106. ctx.beginPath();
  4107. addToPath(ctx, fontSize);
  4108. if (fillStrokeMode === TextRenderingMode.FILL ||
  4109. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4110. ctx.fill();
  4111. }
  4112. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4113. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4114. ctx.stroke();
  4115. }
  4116. ctx.restore();
  4117. } else {
  4118. if (fillStrokeMode === TextRenderingMode.FILL ||
  4119. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4120. ctx.fillText(character, x, y);
  4121. }
  4122. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4123. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4124. ctx.strokeText(character, x, y);
  4125. }
  4126. }
  4127. if (isAddToPathSet) {
  4128. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4129. paths.push({
  4130. transform: ctx.mozCurrentTransform,
  4131. x: x,
  4132. y: y,
  4133. fontSize: fontSize,
  4134. addToPath: addToPath
  4135. });
  4136. }
  4137. },
  4138. get isFontSubpixelAAEnabled() {
  4139. // Checks if anti-aliasing is enabled when scaled text is painted.
  4140. // On Windows GDI scaled fonts looks bad.
  4141. var ctx = document.createElement('canvas').getContext('2d');
  4142. ctx.scale(1.5, 1);
  4143. ctx.fillText('I', 0, 10);
  4144. var data = ctx.getImageData(0, 0, 10, 10).data;
  4145. var enabled = false;
  4146. for (var i = 3; i < data.length; i += 4) {
  4147. if (data[i] > 0 && data[i] < 255) {
  4148. enabled = true;
  4149. break;
  4150. }
  4151. }
  4152. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4153. },
  4154. showText: function CanvasGraphics_showText(glyphs) {
  4155. var current = this.current;
  4156. var font = current.font;
  4157. if (font.isType3Font) {
  4158. return this.showType3Text(glyphs);
  4159. }
  4160. var fontSize = current.fontSize;
  4161. if (fontSize === 0) {
  4162. return;
  4163. }
  4164. var ctx = this.ctx;
  4165. var fontSizeScale = current.fontSizeScale;
  4166. var charSpacing = current.charSpacing;
  4167. var wordSpacing = current.wordSpacing;
  4168. var fontDirection = current.fontDirection;
  4169. var textHScale = current.textHScale * fontDirection;
  4170. var glyphsLength = glyphs.length;
  4171. var vertical = font.vertical;
  4172. var spacingDir = vertical ? 1 : -1;
  4173. var defaultVMetrics = font.defaultVMetrics;
  4174. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4175. var simpleFillText =
  4176. current.textRenderingMode === TextRenderingMode.FILL &&
  4177. !font.disableFontFace;
  4178. ctx.save();
  4179. ctx.transform.apply(ctx, current.textMatrix);
  4180. ctx.translate(current.x, current.y + current.textRise);
  4181. if (fontDirection > 0) {
  4182. ctx.scale(textHScale, -1);
  4183. } else {
  4184. ctx.scale(textHScale, 1);
  4185. }
  4186. var lineWidth = current.lineWidth;
  4187. var scale = current.textMatrixScale;
  4188. if (scale === 0 || lineWidth === 0) {
  4189. var fillStrokeMode = current.textRenderingMode &
  4190. TextRenderingMode.FILL_STROKE_MASK;
  4191. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4192. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4193. this.cachedGetSinglePixelWidth = null;
  4194. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4195. }
  4196. } else {
  4197. lineWidth /= scale;
  4198. }
  4199. if (fontSizeScale !== 1.0) {
  4200. ctx.scale(fontSizeScale, fontSizeScale);
  4201. lineWidth /= fontSizeScale;
  4202. }
  4203. ctx.lineWidth = lineWidth;
  4204. var x = 0, i;
  4205. for (i = 0; i < glyphsLength; ++i) {
  4206. var glyph = glyphs[i];
  4207. if (glyph === null) {
  4208. // word break
  4209. x += fontDirection * wordSpacing;
  4210. continue;
  4211. } else if (isNum(glyph)) {
  4212. x += spacingDir * glyph * fontSize / 1000;
  4213. continue;
  4214. }
  4215. var restoreNeeded = false;
  4216. var character = glyph.fontChar;
  4217. var accent = glyph.accent;
  4218. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4219. var width = glyph.width;
  4220. if (vertical) {
  4221. var vmetric, vx, vy;
  4222. vmetric = glyph.vmetric || defaultVMetrics;
  4223. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4224. vx = -vx * widthAdvanceScale;
  4225. vy = vmetric[2] * widthAdvanceScale;
  4226. width = vmetric ? -vmetric[0] : width;
  4227. scaledX = vx / fontSizeScale;
  4228. scaledY = (x + vy) / fontSizeScale;
  4229. } else {
  4230. scaledX = x / fontSizeScale;
  4231. scaledY = 0;
  4232. }
  4233. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4234. // some standard fonts may not have the exact width, trying to
  4235. // rescale per character
  4236. var measuredWidth = ctx.measureText(character).width * 1000 /
  4237. fontSize * fontSizeScale;
  4238. var characterScaleX = width / measuredWidth;
  4239. restoreNeeded = true;
  4240. ctx.save();
  4241. ctx.scale(characterScaleX, 1);
  4242. scaledX /= characterScaleX;
  4243. }
  4244. if (simpleFillText && !accent) {
  4245. // common case
  4246. ctx.fillText(character, scaledX, scaledY);
  4247. } else {
  4248. this.paintChar(character, scaledX, scaledY);
  4249. if (accent) {
  4250. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4251. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4252. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4253. }
  4254. }
  4255. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4256. x += charWidth;
  4257. if (restoreNeeded) {
  4258. ctx.restore();
  4259. }
  4260. }
  4261. if (vertical) {
  4262. current.y -= x * textHScale;
  4263. } else {
  4264. current.x += x * textHScale;
  4265. }
  4266. ctx.restore();
  4267. },
  4268. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4269. // Type3 fonts - each glyph is a "mini-PDF"
  4270. var ctx = this.ctx;
  4271. var current = this.current;
  4272. var font = current.font;
  4273. var fontSize = current.fontSize;
  4274. var fontDirection = current.fontDirection;
  4275. var spacingDir = font.vertical ? 1 : -1;
  4276. var charSpacing = current.charSpacing;
  4277. var wordSpacing = current.wordSpacing;
  4278. var textHScale = current.textHScale * fontDirection;
  4279. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4280. var glyphsLength = glyphs.length;
  4281. var isTextInvisible =
  4282. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4283. var i, glyph, width, spacingLength;
  4284. if (isTextInvisible || fontSize === 0) {
  4285. return;
  4286. }
  4287. this.cachedGetSinglePixelWidth = null;
  4288. ctx.save();
  4289. ctx.transform.apply(ctx, current.textMatrix);
  4290. ctx.translate(current.x, current.y);
  4291. ctx.scale(textHScale, fontDirection);
  4292. for (i = 0; i < glyphsLength; ++i) {
  4293. glyph = glyphs[i];
  4294. if (glyph === null) {
  4295. // word break
  4296. this.ctx.translate(wordSpacing, 0);
  4297. current.x += wordSpacing * textHScale;
  4298. continue;
  4299. } else if (isNum(glyph)) {
  4300. spacingLength = spacingDir * glyph * fontSize / 1000;
  4301. this.ctx.translate(spacingLength, 0);
  4302. current.x += spacingLength * textHScale;
  4303. continue;
  4304. }
  4305. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4306. if (!operatorList) {
  4307. warn('Type3 character \"' + glyph.operatorListId +
  4308. '\" is not available');
  4309. continue;
  4310. }
  4311. this.processingType3 = glyph;
  4312. this.save();
  4313. ctx.scale(fontSize, fontSize);
  4314. ctx.transform.apply(ctx, fontMatrix);
  4315. this.executeOperatorList(operatorList);
  4316. this.restore();
  4317. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4318. width = transformed[0] * fontSize + charSpacing;
  4319. ctx.translate(width, 0);
  4320. current.x += width * textHScale;
  4321. }
  4322. ctx.restore();
  4323. this.processingType3 = null;
  4324. },
  4325. // Type3 fonts
  4326. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4327. // We can safely ignore this since the width should be the same
  4328. // as the width in the Widths array.
  4329. },
  4330. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4331. yWidth,
  4332. llx,
  4333. lly,
  4334. urx,
  4335. ury) {
  4336. // TODO According to the spec we're also suppose to ignore any operators
  4337. // that set color or include images while processing this type3 font.
  4338. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4339. this.clip();
  4340. this.endPath();
  4341. },
  4342. // Color
  4343. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4344. var pattern;
  4345. if (IR[0] === 'TilingPattern') {
  4346. var color = IR[1];
  4347. var baseTransform = this.baseTransform ||
  4348. this.ctx.mozCurrentTransform.slice();
  4349. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4350. this.commonObjs, baseTransform);
  4351. } else {
  4352. pattern = getShadingPatternFromIR(IR);
  4353. }
  4354. return pattern;
  4355. },
  4356. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4357. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4358. },
  4359. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4360. this.current.fillColor = this.getColorN_Pattern(arguments);
  4361. this.current.patternFill = true;
  4362. },
  4363. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4364. var color = Util.makeCssRgb(r, g, b);
  4365. this.ctx.strokeStyle = color;
  4366. this.current.strokeColor = color;
  4367. },
  4368. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4369. var color = Util.makeCssRgb(r, g, b);
  4370. this.ctx.fillStyle = color;
  4371. this.current.fillColor = color;
  4372. this.current.patternFill = false;
  4373. },
  4374. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4375. var ctx = this.ctx;
  4376. this.save();
  4377. var pattern = getShadingPatternFromIR(patternIR);
  4378. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4379. var inv = ctx.mozCurrentTransformInverse;
  4380. if (inv) {
  4381. var canvas = ctx.canvas;
  4382. var width = canvas.width;
  4383. var height = canvas.height;
  4384. var bl = Util.applyTransform([0, 0], inv);
  4385. var br = Util.applyTransform([0, height], inv);
  4386. var ul = Util.applyTransform([width, 0], inv);
  4387. var ur = Util.applyTransform([width, height], inv);
  4388. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4389. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4390. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4391. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4392. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4393. } else {
  4394. // HACK to draw the gradient onto an infinite rectangle.
  4395. // PDF gradients are drawn across the entire image while
  4396. // Canvas only allows gradients to be drawn in a rectangle
  4397. // The following bug should allow us to remove this.
  4398. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4399. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4400. }
  4401. this.restore();
  4402. },
  4403. // Images
  4404. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4405. error('Should not call beginInlineImage');
  4406. },
  4407. beginImageData: function CanvasGraphics_beginImageData() {
  4408. error('Should not call beginImageData');
  4409. },
  4410. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4411. bbox) {
  4412. this.save();
  4413. this.baseTransformStack.push(this.baseTransform);
  4414. if (isArray(matrix) && 6 === matrix.length) {
  4415. this.transform.apply(this, matrix);
  4416. }
  4417. this.baseTransform = this.ctx.mozCurrentTransform;
  4418. if (isArray(bbox) && 4 === bbox.length) {
  4419. var width = bbox[2] - bbox[0];
  4420. var height = bbox[3] - bbox[1];
  4421. this.ctx.rect(bbox[0], bbox[1], width, height);
  4422. this.clip();
  4423. this.endPath();
  4424. }
  4425. },
  4426. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4427. this.restore();
  4428. this.baseTransform = this.baseTransformStack.pop();
  4429. },
  4430. beginGroup: function CanvasGraphics_beginGroup(group) {
  4431. this.save();
  4432. var currentCtx = this.ctx;
  4433. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4434. // group results aren't usually that different and they even have tools
  4435. // that ignore this setting. Notes from Rik on implmenting:
  4436. // - When you encounter an transparency group, create a new canvas with
  4437. // the dimensions of the bbox
  4438. // - copy the content from the previous canvas to the new canvas
  4439. // - draw as usual
  4440. // - remove the backdrop alpha:
  4441. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4442. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4443. // backdrop
  4444. // - remove background color:
  4445. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4446. if (!group.isolated) {
  4447. info('TODO: Support non-isolated groups.');
  4448. }
  4449. // TODO knockout - supposedly possible with the clever use of compositing
  4450. // modes.
  4451. if (group.knockout) {
  4452. warn('Knockout groups not supported.');
  4453. }
  4454. var currentTransform = currentCtx.mozCurrentTransform;
  4455. if (group.matrix) {
  4456. currentCtx.transform.apply(currentCtx, group.matrix);
  4457. }
  4458. assert(group.bbox, 'Bounding box is required.');
  4459. // Based on the current transform figure out how big the bounding box
  4460. // will actually be.
  4461. var bounds = Util.getAxialAlignedBoundingBox(
  4462. group.bbox,
  4463. currentCtx.mozCurrentTransform);
  4464. // Clip the bounding box to the current canvas.
  4465. var canvasBounds = [0,
  4466. 0,
  4467. currentCtx.canvas.width,
  4468. currentCtx.canvas.height];
  4469. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4470. // Use ceil in case we're between sizes so we don't create canvas that is
  4471. // too small and make the canvas at least 1x1 pixels.
  4472. var offsetX = Math.floor(bounds[0]);
  4473. var offsetY = Math.floor(bounds[1]);
  4474. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4475. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4476. var scaleX = 1, scaleY = 1;
  4477. if (drawnWidth > MAX_GROUP_SIZE) {
  4478. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4479. drawnWidth = MAX_GROUP_SIZE;
  4480. }
  4481. if (drawnHeight > MAX_GROUP_SIZE) {
  4482. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4483. drawnHeight = MAX_GROUP_SIZE;
  4484. }
  4485. var cacheId = 'groupAt' + this.groupLevel;
  4486. if (group.smask) {
  4487. // Using two cache entries is case if masks are used one after another.
  4488. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4489. }
  4490. var scratchCanvas = CachedCanvases.getCanvas(
  4491. cacheId, drawnWidth, drawnHeight, true);
  4492. var groupCtx = scratchCanvas.context;
  4493. // Since we created a new canvas that is just the size of the bounding box
  4494. // we have to translate the group ctx.
  4495. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4496. groupCtx.translate(-offsetX, -offsetY);
  4497. groupCtx.transform.apply(groupCtx, currentTransform);
  4498. if (group.smask) {
  4499. // Saving state and cached mask to be used in setGState.
  4500. this.smaskStack.push({
  4501. canvas: scratchCanvas.canvas,
  4502. context: groupCtx,
  4503. offsetX: offsetX,
  4504. offsetY: offsetY,
  4505. scaleX: scaleX,
  4506. scaleY: scaleY,
  4507. subtype: group.smask.subtype,
  4508. backdrop: group.smask.backdrop
  4509. });
  4510. } else {
  4511. // Setup the current ctx so when the group is popped we draw it at the
  4512. // right location.
  4513. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4514. currentCtx.translate(offsetX, offsetY);
  4515. currentCtx.scale(scaleX, scaleY);
  4516. }
  4517. // The transparency group inherits all off the current graphics state
  4518. // except the blend mode, soft mask, and alpha constants.
  4519. copyCtxState(currentCtx, groupCtx);
  4520. this.ctx = groupCtx;
  4521. this.setGState([
  4522. ['BM', 'Normal'],
  4523. ['ca', 1],
  4524. ['CA', 1]
  4525. ]);
  4526. this.groupStack.push(currentCtx);
  4527. this.groupLevel++;
  4528. },
  4529. endGroup: function CanvasGraphics_endGroup(group) {
  4530. this.groupLevel--;
  4531. var groupCtx = this.ctx;
  4532. this.ctx = this.groupStack.pop();
  4533. // Turn off image smoothing to avoid sub pixel interpolation which can
  4534. // look kind of blurry for some pdfs.
  4535. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4536. this.ctx.imageSmoothingEnabled = false;
  4537. } else {
  4538. this.ctx.mozImageSmoothingEnabled = false;
  4539. }
  4540. if (group.smask) {
  4541. this.tempSMask = this.smaskStack.pop();
  4542. } else {
  4543. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4544. }
  4545. this.restore();
  4546. },
  4547. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4548. this.save();
  4549. this.current = new CanvasExtraState();
  4550. },
  4551. endAnnotations: function CanvasGraphics_endAnnotations() {
  4552. this.restore();
  4553. },
  4554. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4555. matrix) {
  4556. this.save();
  4557. if (isArray(rect) && 4 === rect.length) {
  4558. var width = rect[2] - rect[0];
  4559. var height = rect[3] - rect[1];
  4560. this.ctx.rect(rect[0], rect[1], width, height);
  4561. this.clip();
  4562. this.endPath();
  4563. }
  4564. this.transform.apply(this, transform);
  4565. this.transform.apply(this, matrix);
  4566. },
  4567. endAnnotation: function CanvasGraphics_endAnnotation() {
  4568. this.restore();
  4569. },
  4570. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4571. var domImage = this.objs.get(objId);
  4572. if (!domImage) {
  4573. warn('Dependent image isn\'t ready yet');
  4574. return;
  4575. }
  4576. this.save();
  4577. var ctx = this.ctx;
  4578. // scale the image to the unit square
  4579. ctx.scale(1 / w, -1 / h);
  4580. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4581. 0, -h, w, h);
  4582. if (this.imageLayer) {
  4583. var currentTransform = ctx.mozCurrentTransformInverse;
  4584. var position = this.getCanvasPosition(0, 0);
  4585. this.imageLayer.appendImage({
  4586. objId: objId,
  4587. left: position[0],
  4588. top: position[1],
  4589. width: w / currentTransform[0],
  4590. height: h / currentTransform[3]
  4591. });
  4592. }
  4593. this.restore();
  4594. },
  4595. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4596. var ctx = this.ctx;
  4597. var width = img.width, height = img.height;
  4598. var fillColor = this.current.fillColor;
  4599. var isPatternFill = this.current.patternFill;
  4600. var glyph = this.processingType3;
  4601. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4602. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4603. glyph.compiled =
  4604. compileType3Glyph({data: img.data, width: width, height: height});
  4605. } else {
  4606. glyph.compiled = null;
  4607. }
  4608. }
  4609. if (glyph && glyph.compiled) {
  4610. glyph.compiled(ctx);
  4611. return;
  4612. }
  4613. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4614. var maskCtx = maskCanvas.context;
  4615. maskCtx.save();
  4616. putBinaryImageMask(maskCtx, img);
  4617. maskCtx.globalCompositeOperation = 'source-in';
  4618. maskCtx.fillStyle = isPatternFill ?
  4619. fillColor.getPattern(maskCtx, this) : fillColor;
  4620. maskCtx.fillRect(0, 0, width, height);
  4621. maskCtx.restore();
  4622. this.paintInlineImageXObject(maskCanvas.canvas);
  4623. },
  4624. paintImageMaskXObjectRepeat:
  4625. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4626. scaleY, positions) {
  4627. var width = imgData.width;
  4628. var height = imgData.height;
  4629. var fillColor = this.current.fillColor;
  4630. var isPatternFill = this.current.patternFill;
  4631. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4632. var maskCtx = maskCanvas.context;
  4633. maskCtx.save();
  4634. putBinaryImageMask(maskCtx, imgData);
  4635. maskCtx.globalCompositeOperation = 'source-in';
  4636. maskCtx.fillStyle = isPatternFill ?
  4637. fillColor.getPattern(maskCtx, this) : fillColor;
  4638. maskCtx.fillRect(0, 0, width, height);
  4639. maskCtx.restore();
  4640. var ctx = this.ctx;
  4641. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4642. ctx.save();
  4643. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4644. ctx.scale(1, -1);
  4645. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4646. 0, -1, 1, 1);
  4647. ctx.restore();
  4648. }
  4649. },
  4650. paintImageMaskXObjectGroup:
  4651. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4652. var ctx = this.ctx;
  4653. var fillColor = this.current.fillColor;
  4654. var isPatternFill = this.current.patternFill;
  4655. for (var i = 0, ii = images.length; i < ii; i++) {
  4656. var image = images[i];
  4657. var width = image.width, height = image.height;
  4658. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4659. var maskCtx = maskCanvas.context;
  4660. maskCtx.save();
  4661. putBinaryImageMask(maskCtx, image);
  4662. maskCtx.globalCompositeOperation = 'source-in';
  4663. maskCtx.fillStyle = isPatternFill ?
  4664. fillColor.getPattern(maskCtx, this) : fillColor;
  4665. maskCtx.fillRect(0, 0, width, height);
  4666. maskCtx.restore();
  4667. ctx.save();
  4668. ctx.transform.apply(ctx, image.transform);
  4669. ctx.scale(1, -1);
  4670. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4671. 0, -1, 1, 1);
  4672. ctx.restore();
  4673. }
  4674. },
  4675. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4676. var imgData = this.objs.get(objId);
  4677. if (!imgData) {
  4678. warn('Dependent image isn\'t ready yet');
  4679. return;
  4680. }
  4681. this.paintInlineImageXObject(imgData);
  4682. },
  4683. paintImageXObjectRepeat:
  4684. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4685. positions) {
  4686. var imgData = this.objs.get(objId);
  4687. if (!imgData) {
  4688. warn('Dependent image isn\'t ready yet');
  4689. return;
  4690. }
  4691. var width = imgData.width;
  4692. var height = imgData.height;
  4693. var map = [];
  4694. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4695. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4696. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4697. }
  4698. this.paintInlineImageXObjectGroup(imgData, map);
  4699. },
  4700. paintInlineImageXObject:
  4701. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4702. var width = imgData.width;
  4703. var height = imgData.height;
  4704. var ctx = this.ctx;
  4705. this.save();
  4706. // scale the image to the unit square
  4707. ctx.scale(1 / width, -1 / height);
  4708. var currentTransform = ctx.mozCurrentTransformInverse;
  4709. var a = currentTransform[0], b = currentTransform[1];
  4710. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4711. var c = currentTransform[2], d = currentTransform[3];
  4712. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4713. var imgToPaint, tmpCanvas;
  4714. // instanceof HTMLElement does not work in jsdom node.js module
  4715. if (imgData instanceof HTMLElement || !imgData.data) {
  4716. imgToPaint = imgData;
  4717. } else {
  4718. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4719. var tmpCtx = tmpCanvas.context;
  4720. putBinaryImageData(tmpCtx, imgData);
  4721. imgToPaint = tmpCanvas.canvas;
  4722. }
  4723. var paintWidth = width, paintHeight = height;
  4724. var tmpCanvasId = 'prescale1';
  4725. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4726. // pixels during drawImage operation, painting on the temporary canvas(es)
  4727. // that are twice smaller in size
  4728. while ((widthScale > 2 && paintWidth > 1) ||
  4729. (heightScale > 2 && paintHeight > 1)) {
  4730. var newWidth = paintWidth, newHeight = paintHeight;
  4731. if (widthScale > 2 && paintWidth > 1) {
  4732. newWidth = Math.ceil(paintWidth / 2);
  4733. widthScale /= paintWidth / newWidth;
  4734. }
  4735. if (heightScale > 2 && paintHeight > 1) {
  4736. newHeight = Math.ceil(paintHeight / 2);
  4737. heightScale /= paintHeight / newHeight;
  4738. }
  4739. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4740. tmpCtx = tmpCanvas.context;
  4741. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4742. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4743. 0, 0, newWidth, newHeight);
  4744. imgToPaint = tmpCanvas.canvas;
  4745. paintWidth = newWidth;
  4746. paintHeight = newHeight;
  4747. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4748. }
  4749. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4750. 0, -height, width, height);
  4751. if (this.imageLayer) {
  4752. var position = this.getCanvasPosition(0, -height);
  4753. this.imageLayer.appendImage({
  4754. imgData: imgData,
  4755. left: position[0],
  4756. top: position[1],
  4757. width: width / currentTransform[0],
  4758. height: height / currentTransform[3]
  4759. });
  4760. }
  4761. this.restore();
  4762. },
  4763. paintInlineImageXObjectGroup:
  4764. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4765. var ctx = this.ctx;
  4766. var w = imgData.width;
  4767. var h = imgData.height;
  4768. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4769. var tmpCtx = tmpCanvas.context;
  4770. putBinaryImageData(tmpCtx, imgData);
  4771. for (var i = 0, ii = map.length; i < ii; i++) {
  4772. var entry = map[i];
  4773. ctx.save();
  4774. ctx.transform.apply(ctx, entry.transform);
  4775. ctx.scale(1, -1);
  4776. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4777. 0, -1, 1, 1);
  4778. if (this.imageLayer) {
  4779. var position = this.getCanvasPosition(entry.x, entry.y);
  4780. this.imageLayer.appendImage({
  4781. imgData: imgData,
  4782. left: position[0],
  4783. top: position[1],
  4784. width: w,
  4785. height: h
  4786. });
  4787. }
  4788. ctx.restore();
  4789. }
  4790. },
  4791. paintSolidColorImageMask:
  4792. function CanvasGraphics_paintSolidColorImageMask() {
  4793. this.ctx.fillRect(0, 0, 1, 1);
  4794. },
  4795. // Marked content
  4796. markPoint: function CanvasGraphics_markPoint(tag) {
  4797. // TODO Marked content.
  4798. },
  4799. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4800. // TODO Marked content.
  4801. },
  4802. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4803. // TODO Marked content.
  4804. },
  4805. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4806. tag, properties) {
  4807. // TODO Marked content.
  4808. },
  4809. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4810. // TODO Marked content.
  4811. },
  4812. // Compatibility
  4813. beginCompat: function CanvasGraphics_beginCompat() {
  4814. // TODO ignore undefined operators (should we do that anyway?)
  4815. },
  4816. endCompat: function CanvasGraphics_endCompat() {
  4817. // TODO stop ignoring undefined operators
  4818. },
  4819. // Helper functions
  4820. consumePath: function CanvasGraphics_consumePath() {
  4821. var ctx = this.ctx;
  4822. if (this.pendingClip) {
  4823. if (this.pendingClip === EO_CLIP) {
  4824. if (ctx.mozFillRule !== undefined) {
  4825. ctx.mozFillRule = 'evenodd';
  4826. ctx.clip();
  4827. ctx.mozFillRule = 'nonzero';
  4828. } else {
  4829. ctx.clip('evenodd');
  4830. }
  4831. } else {
  4832. ctx.clip();
  4833. }
  4834. this.pendingClip = null;
  4835. }
  4836. ctx.beginPath();
  4837. },
  4838. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4839. if (this.cachedGetSinglePixelWidth === null) {
  4840. var inverse = this.ctx.mozCurrentTransformInverse;
  4841. // max of the current horizontal and vertical scale
  4842. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4843. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4844. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4845. }
  4846. return this.cachedGetSinglePixelWidth;
  4847. },
  4848. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4849. var transform = this.ctx.mozCurrentTransform;
  4850. return [
  4851. transform[0] * x + transform[2] * y + transform[4],
  4852. transform[1] * x + transform[3] * y + transform[5]
  4853. ];
  4854. }
  4855. };
  4856. for (var op in OPS) {
  4857. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4858. }
  4859. return CanvasGraphics;
  4860. })();
  4861. var WebGLUtils = (function WebGLUtilsClosure() {
  4862. function loadShader(gl, code, shaderType) {
  4863. var shader = gl.createShader(shaderType);
  4864. gl.shaderSource(shader, code);
  4865. gl.compileShader(shader);
  4866. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4867. if (!compiled) {
  4868. var errorMsg = gl.getShaderInfoLog(shader);
  4869. throw new Error('Error during shader compilation: ' + errorMsg);
  4870. }
  4871. return shader;
  4872. }
  4873. function createVertexShader(gl, code) {
  4874. return loadShader(gl, code, gl.VERTEX_SHADER);
  4875. }
  4876. function createFragmentShader(gl, code) {
  4877. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4878. }
  4879. function createProgram(gl, shaders) {
  4880. var program = gl.createProgram();
  4881. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4882. gl.attachShader(program, shaders[i]);
  4883. }
  4884. gl.linkProgram(program);
  4885. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4886. if (!linked) {
  4887. var errorMsg = gl.getProgramInfoLog(program);
  4888. throw new Error('Error during program linking: ' + errorMsg);
  4889. }
  4890. return program;
  4891. }
  4892. function createTexture(gl, image, textureId) {
  4893. gl.activeTexture(textureId);
  4894. var texture = gl.createTexture();
  4895. gl.bindTexture(gl.TEXTURE_2D, texture);
  4896. // Set the parameters so we can render any size image.
  4897. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4898. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4899. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4900. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4901. // Upload the image into the texture.
  4902. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4903. return texture;
  4904. }
  4905. var currentGL, currentCanvas;
  4906. function generateGL() {
  4907. if (currentGL) {
  4908. return;
  4909. }
  4910. currentCanvas = document.createElement('canvas');
  4911. currentGL = currentCanvas.getContext('webgl',
  4912. { premultipliedalpha: false });
  4913. }
  4914. var smaskVertexShaderCode = '\
  4915. attribute vec2 a_position; \
  4916. attribute vec2 a_texCoord; \
  4917. \
  4918. uniform vec2 u_resolution; \
  4919. \
  4920. varying vec2 v_texCoord; \
  4921. \
  4922. void main() { \
  4923. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4924. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4925. \
  4926. v_texCoord = a_texCoord; \
  4927. } ';
  4928. var smaskFragmentShaderCode = '\
  4929. precision mediump float; \
  4930. \
  4931. uniform vec4 u_backdrop; \
  4932. uniform int u_subtype; \
  4933. uniform sampler2D u_image; \
  4934. uniform sampler2D u_mask; \
  4935. \
  4936. varying vec2 v_texCoord; \
  4937. \
  4938. void main() { \
  4939. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4940. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4941. if (u_backdrop.a > 0.0) { \
  4942. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4943. u_backdrop.rgb * (1.0 - maskColor.a); \
  4944. } \
  4945. float lum; \
  4946. if (u_subtype == 0) { \
  4947. lum = maskColor.a; \
  4948. } else { \
  4949. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4950. maskColor.b * 0.11; \
  4951. } \
  4952. imageColor.a *= lum; \
  4953. imageColor.rgb *= imageColor.a; \
  4954. gl_FragColor = imageColor; \
  4955. } ';
  4956. var smaskCache = null;
  4957. function initSmaskGL() {
  4958. var canvas, gl;
  4959. generateGL();
  4960. canvas = currentCanvas;
  4961. currentCanvas = null;
  4962. gl = currentGL;
  4963. currentGL = null;
  4964. // setup a GLSL program
  4965. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4966. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4967. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4968. gl.useProgram(program);
  4969. var cache = {};
  4970. cache.gl = gl;
  4971. cache.canvas = canvas;
  4972. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4973. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4974. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4975. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4976. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4977. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4978. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4979. // provide texture coordinates for the rectangle.
  4980. var texCoordBuffer = gl.createBuffer();
  4981. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4982. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4983. 0.0, 0.0,
  4984. 1.0, 0.0,
  4985. 0.0, 1.0,
  4986. 0.0, 1.0,
  4987. 1.0, 0.0,
  4988. 1.0, 1.0]), gl.STATIC_DRAW);
  4989. gl.enableVertexAttribArray(texCoordLocation);
  4990. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4991. gl.uniform1i(texLayerLocation, 0);
  4992. gl.uniform1i(texMaskLocation, 1);
  4993. smaskCache = cache;
  4994. }
  4995. function composeSMask(layer, mask, properties) {
  4996. var width = layer.width, height = layer.height;
  4997. if (!smaskCache) {
  4998. initSmaskGL();
  4999. }
  5000. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  5001. canvas.width = width;
  5002. canvas.height = height;
  5003. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5004. gl.uniform2f(cache.resolutionLocation, width, height);
  5005. if (properties.backdrop) {
  5006. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  5007. properties.backdrop[1], properties.backdrop[2], 1);
  5008. } else {
  5009. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  5010. }
  5011. gl.uniform1i(cache.subtypeLocation,
  5012. properties.subtype === 'Luminosity' ? 1 : 0);
  5013. // Create a textures
  5014. var texture = createTexture(gl, layer, gl.TEXTURE0);
  5015. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  5016. // Create a buffer and put a single clipspace rectangle in
  5017. // it (2 triangles)
  5018. var buffer = gl.createBuffer();
  5019. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  5020. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  5021. 0, 0,
  5022. width, 0,
  5023. 0, height,
  5024. 0, height,
  5025. width, 0,
  5026. width, height]), gl.STATIC_DRAW);
  5027. gl.enableVertexAttribArray(cache.positionLocation);
  5028. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5029. // draw
  5030. gl.clearColor(0, 0, 0, 0);
  5031. gl.enable(gl.BLEND);
  5032. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  5033. gl.clear(gl.COLOR_BUFFER_BIT);
  5034. gl.drawArrays(gl.TRIANGLES, 0, 6);
  5035. gl.flush();
  5036. gl.deleteTexture(texture);
  5037. gl.deleteTexture(maskTexture);
  5038. gl.deleteBuffer(buffer);
  5039. return canvas;
  5040. }
  5041. var figuresVertexShaderCode = '\
  5042. attribute vec2 a_position; \
  5043. attribute vec3 a_color; \
  5044. \
  5045. uniform vec2 u_resolution; \
  5046. uniform vec2 u_scale; \
  5047. uniform vec2 u_offset; \
  5048. \
  5049. varying vec4 v_color; \
  5050. \
  5051. void main() { \
  5052. vec2 position = (a_position + u_offset) * u_scale; \
  5053. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5054. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5055. \
  5056. v_color = vec4(a_color / 255.0, 1.0); \
  5057. } ';
  5058. var figuresFragmentShaderCode = '\
  5059. precision mediump float; \
  5060. \
  5061. varying vec4 v_color; \
  5062. \
  5063. void main() { \
  5064. gl_FragColor = v_color; \
  5065. } ';
  5066. var figuresCache = null;
  5067. function initFiguresGL() {
  5068. var canvas, gl;
  5069. generateGL();
  5070. canvas = currentCanvas;
  5071. currentCanvas = null;
  5072. gl = currentGL;
  5073. currentGL = null;
  5074. // setup a GLSL program
  5075. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5076. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5077. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5078. gl.useProgram(program);
  5079. var cache = {};
  5080. cache.gl = gl;
  5081. cache.canvas = canvas;
  5082. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5083. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5084. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5085. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5086. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5087. figuresCache = cache;
  5088. }
  5089. function drawFigures(width, height, backgroundColor, figures, context) {
  5090. if (!figuresCache) {
  5091. initFiguresGL();
  5092. }
  5093. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5094. canvas.width = width;
  5095. canvas.height = height;
  5096. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5097. gl.uniform2f(cache.resolutionLocation, width, height);
  5098. // count triangle points
  5099. var count = 0;
  5100. var i, ii, rows;
  5101. for (i = 0, ii = figures.length; i < ii; i++) {
  5102. switch (figures[i].type) {
  5103. case 'lattice':
  5104. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5105. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5106. break;
  5107. case 'triangles':
  5108. count += figures[i].coords.length;
  5109. break;
  5110. }
  5111. }
  5112. // transfer data
  5113. var coords = new Float32Array(count * 2);
  5114. var colors = new Uint8Array(count * 3);
  5115. var coordsMap = context.coords, colorsMap = context.colors;
  5116. var pIndex = 0, cIndex = 0;
  5117. for (i = 0, ii = figures.length; i < ii; i++) {
  5118. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5119. switch (figure.type) {
  5120. case 'lattice':
  5121. var cols = figure.verticesPerRow;
  5122. rows = (ps.length / cols) | 0;
  5123. for (var row = 1; row < rows; row++) {
  5124. var offset = row * cols + 1;
  5125. for (var col = 1; col < cols; col++, offset++) {
  5126. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5127. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5128. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5129. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5130. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5131. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5132. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5133. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5134. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5135. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5136. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5137. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5138. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5139. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5140. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5141. coords[pIndex + 6] = coords[pIndex + 2];
  5142. coords[pIndex + 7] = coords[pIndex + 3];
  5143. coords[pIndex + 8] = coords[pIndex + 4];
  5144. coords[pIndex + 9] = coords[pIndex + 5];
  5145. coords[pIndex + 10] = coordsMap[ps[offset]];
  5146. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5147. colors[cIndex + 9] = colors[cIndex + 3];
  5148. colors[cIndex + 10] = colors[cIndex + 4];
  5149. colors[cIndex + 11] = colors[cIndex + 5];
  5150. colors[cIndex + 12] = colors[cIndex + 6];
  5151. colors[cIndex + 13] = colors[cIndex + 7];
  5152. colors[cIndex + 14] = colors[cIndex + 8];
  5153. colors[cIndex + 15] = colorsMap[cs[offset]];
  5154. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5155. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5156. pIndex += 12;
  5157. cIndex += 18;
  5158. }
  5159. }
  5160. break;
  5161. case 'triangles':
  5162. for (var j = 0, jj = ps.length; j < jj; j++) {
  5163. coords[pIndex] = coordsMap[ps[j]];
  5164. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5165. colors[cIndex] = colorsMap[cs[j]];
  5166. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5167. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5168. pIndex += 2;
  5169. cIndex += 3;
  5170. }
  5171. break;
  5172. }
  5173. }
  5174. // draw
  5175. if (backgroundColor) {
  5176. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5177. backgroundColor[2] / 255, 1.0);
  5178. } else {
  5179. gl.clearColor(0, 0, 0, 0);
  5180. }
  5181. gl.clear(gl.COLOR_BUFFER_BIT);
  5182. var coordsBuffer = gl.createBuffer();
  5183. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5184. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5185. gl.enableVertexAttribArray(cache.positionLocation);
  5186. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5187. var colorsBuffer = gl.createBuffer();
  5188. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5189. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5190. gl.enableVertexAttribArray(cache.colorLocation);
  5191. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5192. 0, 0);
  5193. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5194. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5195. gl.drawArrays(gl.TRIANGLES, 0, count);
  5196. gl.flush();
  5197. gl.deleteBuffer(coordsBuffer);
  5198. gl.deleteBuffer(colorsBuffer);
  5199. return canvas;
  5200. }
  5201. function cleanup() {
  5202. if (smaskCache && smaskCache.canvas) {
  5203. smaskCache.canvas.width = 0;
  5204. smaskCache.canvas.height = 0;
  5205. }
  5206. if (figuresCache && figuresCache.canvas) {
  5207. figuresCache.canvas.width = 0;
  5208. figuresCache.canvas.height = 0;
  5209. }
  5210. smaskCache = null;
  5211. figuresCache = null;
  5212. }
  5213. return {
  5214. get isEnabled() {
  5215. if (PDFJS.disableWebGL) {
  5216. return false;
  5217. }
  5218. var enabled = false;
  5219. try {
  5220. generateGL();
  5221. enabled = !!currentGL;
  5222. } catch (e) { }
  5223. return shadow(this, 'isEnabled', enabled);
  5224. },
  5225. composeSMask: composeSMask,
  5226. drawFigures: drawFigures,
  5227. clear: cleanup
  5228. };
  5229. })();
  5230. var ShadingIRs = {};
  5231. ShadingIRs.RadialAxial = {
  5232. fromIR: function RadialAxial_fromIR(raw) {
  5233. var type = raw[1];
  5234. var colorStops = raw[2];
  5235. var p0 = raw[3];
  5236. var p1 = raw[4];
  5237. var r0 = raw[5];
  5238. var r1 = raw[6];
  5239. return {
  5240. type: 'Pattern',
  5241. getPattern: function RadialAxial_getPattern(ctx) {
  5242. var grad;
  5243. if (type === 'axial') {
  5244. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5245. } else if (type === 'radial') {
  5246. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5247. }
  5248. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5249. var c = colorStops[i];
  5250. grad.addColorStop(c[0], c[1]);
  5251. }
  5252. return grad;
  5253. }
  5254. };
  5255. }
  5256. };
  5257. var createMeshCanvas = (function createMeshCanvasClosure() {
  5258. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5259. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5260. var coords = context.coords, colors = context.colors;
  5261. var bytes = data.data, rowSize = data.width * 4;
  5262. var tmp;
  5263. if (coords[p1 + 1] > coords[p2 + 1]) {
  5264. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5265. }
  5266. if (coords[p2 + 1] > coords[p3 + 1]) {
  5267. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5268. }
  5269. if (coords[p1 + 1] > coords[p2 + 1]) {
  5270. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5271. }
  5272. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5273. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5274. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5275. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5276. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5277. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5278. if (y1 >= y3) {
  5279. return;
  5280. }
  5281. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5282. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5283. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5284. var minY = Math.round(y1), maxY = Math.round(y3);
  5285. var xa, car, cag, cab;
  5286. var xb, cbr, cbg, cbb;
  5287. var k;
  5288. for (var y = minY; y <= maxY; y++) {
  5289. if (y < y2) {
  5290. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5291. xa = x1 - (x1 - x2) * k;
  5292. car = c1r - (c1r - c2r) * k;
  5293. cag = c1g - (c1g - c2g) * k;
  5294. cab = c1b - (c1b - c2b) * k;
  5295. } else {
  5296. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5297. xa = x2 - (x2 - x3) * k;
  5298. car = c2r - (c2r - c3r) * k;
  5299. cag = c2g - (c2g - c3g) * k;
  5300. cab = c2b - (c2b - c3b) * k;
  5301. }
  5302. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5303. xb = x1 - (x1 - x3) * k;
  5304. cbr = c1r - (c1r - c3r) * k;
  5305. cbg = c1g - (c1g - c3g) * k;
  5306. cbb = c1b - (c1b - c3b) * k;
  5307. var x1_ = Math.round(Math.min(xa, xb));
  5308. var x2_ = Math.round(Math.max(xa, xb));
  5309. var j = rowSize * y + x1_ * 4;
  5310. for (var x = x1_; x <= x2_; x++) {
  5311. k = (xa - x) / (xa - xb);
  5312. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5313. bytes[j++] = (car - (car - cbr) * k) | 0;
  5314. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5315. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5316. bytes[j++] = 255;
  5317. }
  5318. }
  5319. }
  5320. function drawFigure(data, figure, context) {
  5321. var ps = figure.coords;
  5322. var cs = figure.colors;
  5323. var i, ii;
  5324. switch (figure.type) {
  5325. case 'lattice':
  5326. var verticesPerRow = figure.verticesPerRow;
  5327. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5328. var cols = verticesPerRow - 1;
  5329. for (i = 0; i < rows; i++) {
  5330. var q = i * verticesPerRow;
  5331. for (var j = 0; j < cols; j++, q++) {
  5332. drawTriangle(data, context,
  5333. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5334. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5335. drawTriangle(data, context,
  5336. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5337. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5338. }
  5339. }
  5340. break;
  5341. case 'triangles':
  5342. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5343. drawTriangle(data, context,
  5344. ps[i], ps[i + 1], ps[i + 2],
  5345. cs[i], cs[i + 1], cs[i + 2]);
  5346. }
  5347. break;
  5348. default:
  5349. error('illigal figure');
  5350. break;
  5351. }
  5352. }
  5353. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5354. backgroundColor) {
  5355. // we will increase scale on some weird factor to let antialiasing take
  5356. // care of "rough" edges
  5357. var EXPECTED_SCALE = 1.1;
  5358. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5359. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5360. var offsetX = Math.floor(bounds[0]);
  5361. var offsetY = Math.floor(bounds[1]);
  5362. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5363. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5364. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5365. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5366. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5367. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5368. var scaleX = boundsWidth / width;
  5369. var scaleY = boundsHeight / height;
  5370. var context = {
  5371. coords: coords,
  5372. colors: colors,
  5373. offsetX: -offsetX,
  5374. offsetY: -offsetY,
  5375. scaleX: 1 / scaleX,
  5376. scaleY: 1 / scaleY
  5377. };
  5378. var canvas, tmpCanvas, i, ii;
  5379. if (WebGLUtils.isEnabled) {
  5380. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5381. figures, context);
  5382. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5383. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5384. tmpCanvas.context.drawImage(canvas, 0, 0);
  5385. canvas = tmpCanvas.canvas;
  5386. } else {
  5387. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5388. var tmpCtx = tmpCanvas.context;
  5389. var data = tmpCtx.createImageData(width, height);
  5390. if (backgroundColor) {
  5391. var bytes = data.data;
  5392. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5393. bytes[i] = backgroundColor[0];
  5394. bytes[i + 1] = backgroundColor[1];
  5395. bytes[i + 2] = backgroundColor[2];
  5396. bytes[i + 3] = 255;
  5397. }
  5398. }
  5399. for (i = 0; i < figures.length; i++) {
  5400. drawFigure(data, figures[i], context);
  5401. }
  5402. tmpCtx.putImageData(data, 0, 0);
  5403. canvas = tmpCanvas.canvas;
  5404. }
  5405. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5406. scaleX: scaleX, scaleY: scaleY};
  5407. }
  5408. return createMeshCanvas;
  5409. })();
  5410. ShadingIRs.Mesh = {
  5411. fromIR: function Mesh_fromIR(raw) {
  5412. //var type = raw[1];
  5413. var coords = raw[2];
  5414. var colors = raw[3];
  5415. var figures = raw[4];
  5416. var bounds = raw[5];
  5417. var matrix = raw[6];
  5418. //var bbox = raw[7];
  5419. var background = raw[8];
  5420. return {
  5421. type: 'Pattern',
  5422. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5423. var scale;
  5424. if (shadingFill) {
  5425. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5426. } else {
  5427. // Obtain scale from matrix and current transformation matrix.
  5428. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5429. if (matrix) {
  5430. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5431. scale = [scale[0] * matrixScale[0],
  5432. scale[1] * matrixScale[1]];
  5433. }
  5434. }
  5435. // Rasterizing on the main thread since sending/queue large canvases
  5436. // might cause OOM.
  5437. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5438. colors, figures, shadingFill ? null : background);
  5439. if (!shadingFill) {
  5440. ctx.setTransform.apply(ctx, owner.baseTransform);
  5441. if (matrix) {
  5442. ctx.transform.apply(ctx, matrix);
  5443. }
  5444. }
  5445. ctx.translate(temporaryPatternCanvas.offsetX,
  5446. temporaryPatternCanvas.offsetY);
  5447. ctx.scale(temporaryPatternCanvas.scaleX,
  5448. temporaryPatternCanvas.scaleY);
  5449. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5450. }
  5451. };
  5452. }
  5453. };
  5454. ShadingIRs.Dummy = {
  5455. fromIR: function Dummy_fromIR() {
  5456. return {
  5457. type: 'Pattern',
  5458. getPattern: function Dummy_fromIR_getPattern() {
  5459. return 'hotpink';
  5460. }
  5461. };
  5462. }
  5463. };
  5464. function getShadingPatternFromIR(raw) {
  5465. var shadingIR = ShadingIRs[raw[0]];
  5466. if (!shadingIR) {
  5467. error('Unknown IR type: ' + raw[0]);
  5468. }
  5469. return shadingIR.fromIR(raw);
  5470. }
  5471. var TilingPattern = (function TilingPatternClosure() {
  5472. var PaintType = {
  5473. COLORED: 1,
  5474. UNCOLORED: 2
  5475. };
  5476. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5477. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5478. this.operatorList = IR[2];
  5479. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5480. this.bbox = IR[4];
  5481. this.xstep = IR[5];
  5482. this.ystep = IR[6];
  5483. this.paintType = IR[7];
  5484. this.tilingType = IR[8];
  5485. this.color = color;
  5486. this.objs = objs;
  5487. this.commonObjs = commonObjs;
  5488. this.baseTransform = baseTransform;
  5489. this.type = 'Pattern';
  5490. this.ctx = ctx;
  5491. }
  5492. TilingPattern.prototype = {
  5493. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5494. var operatorList = this.operatorList;
  5495. var bbox = this.bbox;
  5496. var xstep = this.xstep;
  5497. var ystep = this.ystep;
  5498. var paintType = this.paintType;
  5499. var tilingType = this.tilingType;
  5500. var color = this.color;
  5501. var objs = this.objs;
  5502. var commonObjs = this.commonObjs;
  5503. info('TilingType: ' + tilingType);
  5504. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5505. var topLeft = [x0, y0];
  5506. // we want the canvas to be as large as the step size
  5507. var botRight = [x0 + xstep, y0 + ystep];
  5508. var width = botRight[0] - topLeft[0];
  5509. var height = botRight[1] - topLeft[1];
  5510. // Obtain scale from matrix and current transformation matrix.
  5511. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5512. var curMatrixScale = Util.singularValueDecompose2dScale(
  5513. this.baseTransform);
  5514. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5515. matrixScale[1] * curMatrixScale[1]];
  5516. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5517. // Use width and height values that are as close as possible to the end
  5518. // result when the pattern is used. Too low value makes the pattern look
  5519. // blurry. Too large value makes it look too crispy.
  5520. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5521. MAX_PATTERN_SIZE);
  5522. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5523. MAX_PATTERN_SIZE);
  5524. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5525. var tmpCtx = tmpCanvas.context;
  5526. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5527. graphics.groupLevel = owner.groupLevel;
  5528. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5529. this.setScale(width, height, xstep, ystep);
  5530. this.transformToScale(graphics);
  5531. // transform coordinates to pattern space
  5532. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5533. graphics.transform.apply(graphics, tmpTranslate);
  5534. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5535. graphics.executeOperatorList(operatorList);
  5536. return tmpCanvas.canvas;
  5537. },
  5538. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5539. this.scale = [width / xstep, height / ystep];
  5540. },
  5541. transformToScale: function TilingPattern_transformToScale(graphics) {
  5542. var scale = this.scale;
  5543. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5544. graphics.transform.apply(graphics, tmpScale);
  5545. },
  5546. scaleToContext: function TilingPattern_scaleToContext() {
  5547. var scale = this.scale;
  5548. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5549. },
  5550. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5551. if (bbox && isArray(bbox) && bbox.length === 4) {
  5552. var bboxWidth = x1 - x0;
  5553. var bboxHeight = y1 - y0;
  5554. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5555. graphics.clip();
  5556. graphics.endPath();
  5557. }
  5558. },
  5559. setFillAndStrokeStyleToContext:
  5560. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5561. switch (paintType) {
  5562. case PaintType.COLORED:
  5563. var ctx = this.ctx;
  5564. context.fillStyle = ctx.fillStyle;
  5565. context.strokeStyle = ctx.strokeStyle;
  5566. break;
  5567. case PaintType.UNCOLORED:
  5568. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5569. context.fillStyle = cssColor;
  5570. context.strokeStyle = cssColor;
  5571. break;
  5572. default:
  5573. error('Unsupported paint type: ' + paintType);
  5574. }
  5575. },
  5576. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5577. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5578. ctx = this.ctx;
  5579. ctx.setTransform.apply(ctx, this.baseTransform);
  5580. ctx.transform.apply(ctx, this.matrix);
  5581. this.scaleToContext();
  5582. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5583. }
  5584. };
  5585. return TilingPattern;
  5586. })();
  5587. PDFJS.disableFontFace = false;
  5588. var FontLoader = {
  5589. insertRule: function fontLoaderInsertRule(rule) {
  5590. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5591. if (!styleElement) {
  5592. styleElement = document.createElement('style');
  5593. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5594. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5595. styleElement);
  5596. }
  5597. var styleSheet = styleElement.sheet;
  5598. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5599. },
  5600. clear: function fontLoaderClear() {
  5601. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5602. if (styleElement) {
  5603. styleElement.parentNode.removeChild(styleElement);
  5604. }
  5605. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5606. document.fonts.delete(nativeFontFace);
  5607. });
  5608. this.nativeFontFaces.length = 0;
  5609. },
  5610. get loadTestFont() {
  5611. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5612. // height.
  5613. return shadow(this, 'loadTestFont', atob(
  5614. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5615. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5616. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5617. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5618. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5619. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5620. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5621. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5622. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5623. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5624. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5625. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5626. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5627. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5628. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5629. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5630. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5631. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5632. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5633. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5634. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5635. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5636. ));
  5637. },
  5638. get isEvalSupported() {
  5639. var evalSupport = false;
  5640. if (PDFJS.isEvalSupported) {
  5641. try {
  5642. /* jshint evil: true */
  5643. new Function('');
  5644. evalSupport = true;
  5645. } catch (e) {}
  5646. }
  5647. return shadow(this, 'isEvalSupported', evalSupport);
  5648. },
  5649. loadTestFontId: 0,
  5650. loadingContext: {
  5651. requests: [],
  5652. nextRequestId: 0
  5653. },
  5654. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5655. if (isWorker) {
  5656. return false;
  5657. }
  5658. // User agent string sniffing is bad, but there is no reliable way to tell
  5659. // if font is fully loaded and ready to be used with canvas.
  5660. var userAgent = window.navigator.userAgent;
  5661. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5662. if (m && m[1] >= 14) {
  5663. return true;
  5664. }
  5665. // TODO other browsers
  5666. if (userAgent === 'node') {
  5667. return true;
  5668. }
  5669. return false;
  5670. })(),
  5671. nativeFontFaces: [],
  5672. isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
  5673. !!document.fonts),
  5674. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5675. this.nativeFontFaces.push(nativeFontFace);
  5676. document.fonts.add(nativeFontFace);
  5677. },
  5678. bind: function fontLoaderBind(fonts, callback) {
  5679. assert(!isWorker, 'bind() shall be called from main thread');
  5680. var rules = [];
  5681. var fontsToLoad = [];
  5682. var fontLoadPromises = [];
  5683. var getNativeFontPromise = function(nativeFontFace) {
  5684. // Return a promise that is always fulfilled, even when the font fails to
  5685. // load.
  5686. return nativeFontFace.loaded.catch(function(e) {
  5687. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  5688. });
  5689. };
  5690. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5691. var font = fonts[i];
  5692. // Add the font to the DOM only once or skip if the font
  5693. // is already loaded.
  5694. if (font.attached || font.loading === false) {
  5695. continue;
  5696. }
  5697. font.attached = true;
  5698. if (this.isFontLoadingAPISupported) {
  5699. var nativeFontFace = font.createNativeFontFace();
  5700. if (nativeFontFace) {
  5701. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  5702. }
  5703. } else {
  5704. var rule = font.bindDOM();
  5705. if (rule) {
  5706. rules.push(rule);
  5707. fontsToLoad.push(font);
  5708. }
  5709. }
  5710. }
  5711. var request = FontLoader.queueLoadingCallback(callback);
  5712. if (this.isFontLoadingAPISupported) {
  5713. Promise.all(fontLoadPromises).then(function() {
  5714. request.complete();
  5715. });
  5716. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5717. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5718. } else {
  5719. request.complete();
  5720. }
  5721. },
  5722. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5723. function LoadLoader_completeRequest() {
  5724. assert(!request.end, 'completeRequest() cannot be called twice');
  5725. request.end = Date.now();
  5726. // sending all completed requests in order how they were queued
  5727. while (context.requests.length > 0 && context.requests[0].end) {
  5728. var otherRequest = context.requests.shift();
  5729. setTimeout(otherRequest.callback, 0);
  5730. }
  5731. }
  5732. var context = FontLoader.loadingContext;
  5733. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5734. var request = {
  5735. id: requestId,
  5736. complete: LoadLoader_completeRequest,
  5737. callback: callback,
  5738. started: Date.now()
  5739. };
  5740. context.requests.push(request);
  5741. return request;
  5742. },
  5743. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5744. fonts,
  5745. request) {
  5746. /** Hack begin */
  5747. // There's currently no event when a font has finished downloading so the
  5748. // following code is a dirty hack to 'guess' when a font is
  5749. // ready. It's assumed fonts are loaded in order, so add a known test
  5750. // font after the desired fonts and then test for the loading of that
  5751. // test font.
  5752. function int32(data, offset) {
  5753. return (data.charCodeAt(offset) << 24) |
  5754. (data.charCodeAt(offset + 1) << 16) |
  5755. (data.charCodeAt(offset + 2) << 8) |
  5756. (data.charCodeAt(offset + 3) & 0xff);
  5757. }
  5758. function spliceString(s, offset, remove, insert) {
  5759. var chunk1 = s.substr(0, offset);
  5760. var chunk2 = s.substr(offset + remove);
  5761. return chunk1 + insert + chunk2;
  5762. }
  5763. var i, ii;
  5764. var canvas = document.createElement('canvas');
  5765. canvas.width = 1;
  5766. canvas.height = 1;
  5767. var ctx = canvas.getContext('2d');
  5768. var called = 0;
  5769. function isFontReady(name, callback) {
  5770. called++;
  5771. // With setTimeout clamping this gives the font ~100ms to load.
  5772. if(called > 30) {
  5773. warn('Load test font never loaded.');
  5774. callback();
  5775. return;
  5776. }
  5777. ctx.font = '30px ' + name;
  5778. ctx.fillText('.', 0, 20);
  5779. var imageData = ctx.getImageData(0, 0, 1, 1);
  5780. if (imageData.data[3] > 0) {
  5781. callback();
  5782. return;
  5783. }
  5784. setTimeout(isFontReady.bind(null, name, callback));
  5785. }
  5786. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5787. // Chromium seems to cache fonts based on a hash of the actual font data,
  5788. // so the font must be modified for each load test else it will appear to
  5789. // be loaded already.
  5790. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5791. // font by splitting it in chunks before hand and padding the font id.
  5792. var data = this.loadTestFont;
  5793. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5794. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5795. loadTestFontId);
  5796. // CFF checksum is important for IE, adjusting it
  5797. var CFF_CHECKSUM_OFFSET = 16;
  5798. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5799. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5800. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5801. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5802. }
  5803. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5804. checksum = (checksum - XXXX_VALUE +
  5805. int32(loadTestFontId + 'XXX', i)) | 0;
  5806. }
  5807. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5808. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5809. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5810. url + '}';
  5811. FontLoader.insertRule(rule);
  5812. var names = [];
  5813. for (i = 0, ii = fonts.length; i < ii; i++) {
  5814. names.push(fonts[i].loadedName);
  5815. }
  5816. names.push(loadTestFontId);
  5817. var div = document.createElement('div');
  5818. div.setAttribute('style',
  5819. 'visibility: hidden;' +
  5820. 'width: 10px; height: 10px;' +
  5821. 'position: absolute; top: 0px; left: 0px;');
  5822. for (i = 0, ii = names.length; i < ii; ++i) {
  5823. var span = document.createElement('span');
  5824. span.textContent = 'Hi';
  5825. span.style.fontFamily = names[i];
  5826. div.appendChild(span);
  5827. }
  5828. document.body.appendChild(div);
  5829. isFontReady(loadTestFontId, function() {
  5830. document.body.removeChild(div);
  5831. request.complete();
  5832. });
  5833. /** Hack end */
  5834. }
  5835. };
  5836. var FontFaceObject = (function FontFaceObjectClosure() {
  5837. function FontFaceObject(name, file, properties) {
  5838. this.compiledGlyphs = {};
  5839. if (arguments.length === 1) {
  5840. // importing translated data
  5841. var data = arguments[0];
  5842. for (var i in data) {
  5843. this[i] = data[i];
  5844. }
  5845. return;
  5846. }
  5847. }
  5848. FontFaceObject.prototype = {
  5849. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5850. if (!this.data) {
  5851. return null;
  5852. }
  5853. if (PDFJS.disableFontFace) {
  5854. this.disableFontFace = true;
  5855. return null;
  5856. }
  5857. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5858. FontLoader.addNativeFontFace(nativeFontFace);
  5859. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5860. globalScope['FontInspector'].enabled) {
  5861. globalScope['FontInspector'].fontAdded(this);
  5862. }
  5863. return nativeFontFace;
  5864. },
  5865. bindDOM: function FontFaceObject_bindDOM() {
  5866. if (!this.data) {
  5867. return null;
  5868. }
  5869. if (PDFJS.disableFontFace) {
  5870. this.disableFontFace = true;
  5871. return null;
  5872. }
  5873. var data = bytesToString(new Uint8Array(this.data));
  5874. var fontName = this.loadedName;
  5875. // Add the font-face rule to the document
  5876. var url = ('url(data:' + this.mimetype + ';base64,' +
  5877. window.btoa(data) + ');');
  5878. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5879. FontLoader.insertRule(rule);
  5880. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5881. globalScope['FontInspector'].enabled) {
  5882. globalScope['FontInspector'].fontAdded(this, url);
  5883. }
  5884. return rule;
  5885. },
  5886. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5887. if (!(character in this.compiledGlyphs)) {
  5888. var cmds = objs.get(this.loadedName + '_path_' + character);
  5889. var current, i, len;
  5890. // If we can, compile cmds into JS for MAXIMUM SPEED
  5891. if (FontLoader.isEvalSupported) {
  5892. var args, js = '';
  5893. for (i = 0, len = cmds.length; i < len; i++) {
  5894. current = cmds[i];
  5895. if (current.args !== undefined) {
  5896. args = current.args.join(',');
  5897. } else {
  5898. args = '';
  5899. }
  5900. js += 'c.' + current.cmd + '(' + args + ');\n';
  5901. }
  5902. /* jshint -W054 */
  5903. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5904. } else {
  5905. // But fall back on using Function.prototype.apply() if we're
  5906. // blocked from using eval() for whatever reason (like CSP policies)
  5907. this.compiledGlyphs[character] = function(c, size) {
  5908. for (i = 0, len = cmds.length; i < len; i++) {
  5909. current = cmds[i];
  5910. if (current.cmd === 'scale') {
  5911. current.args = [size, -size];
  5912. }
  5913. c[current.cmd].apply(c, current.args);
  5914. }
  5915. };
  5916. }
  5917. }
  5918. return this.compiledGlyphs[character];
  5919. }
  5920. };
  5921. return FontFaceObject;
  5922. })();
  5923. var ANNOT_MIN_SIZE = 10; // px
  5924. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5925. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5926. function setTextStyles(element, item, fontObj) {
  5927. var style = element.style;
  5928. style.fontSize = item.fontSize + 'px';
  5929. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5930. if (!fontObj) {
  5931. return;
  5932. }
  5933. style.fontWeight = fontObj.black ?
  5934. (fontObj.bold ? 'bolder' : 'bold') :
  5935. (fontObj.bold ? 'bold' : 'normal');
  5936. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5937. var fontName = fontObj.loadedName;
  5938. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5939. // Use a reasonable default font if the font doesn't specify a fallback
  5940. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5941. style.fontFamily = fontFamily + fallbackName;
  5942. }
  5943. function initContainer(item) {
  5944. var container = document.createElement('section');
  5945. var cstyle = container.style;
  5946. var width = item.rect[2] - item.rect[0];
  5947. var height = item.rect[3] - item.rect[1];
  5948. // Border
  5949. if (item.borderStyle.width > 0) {
  5950. // Border width
  5951. container.style.borderWidth = item.borderStyle.width + 'px';
  5952. if (item.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  5953. // Underline styles only have a bottom border, so we do not need
  5954. // to adjust for all borders. This yields a similar result as
  5955. // Adobe Acrobat/Reader.
  5956. width = width - 2 * item.borderStyle.width;
  5957. height = height - 2 * item.borderStyle.width;
  5958. }
  5959. // Horizontal and vertical border radius
  5960. var horizontalRadius = item.borderStyle.horizontalCornerRadius;
  5961. var verticalRadius = item.borderStyle.verticalCornerRadius;
  5962. if (horizontalRadius > 0 || verticalRadius > 0) {
  5963. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  5964. CustomStyle.setProp('borderRadius', container, radius);
  5965. }
  5966. // Border style
  5967. switch (item.borderStyle.style) {
  5968. case AnnotationBorderStyleType.SOLID:
  5969. container.style.borderStyle = 'solid';
  5970. break;
  5971. case AnnotationBorderStyleType.DASHED:
  5972. container.style.borderStyle = 'dashed';
  5973. break;
  5974. case AnnotationBorderStyleType.BEVELED:
  5975. warn('Unimplemented border style: beveled');
  5976. break;
  5977. case AnnotationBorderStyleType.INSET:
  5978. warn('Unimplemented border style: inset');
  5979. break;
  5980. case AnnotationBorderStyleType.UNDERLINE:
  5981. container.style.borderBottomStyle = 'solid';
  5982. break;
  5983. default:
  5984. break;
  5985. }
  5986. // Border color
  5987. if (item.color) {
  5988. container.style.borderColor =
  5989. Util.makeCssRgb(item.color[0] | 0,
  5990. item.color[1] | 0,
  5991. item.color[2] | 0);
  5992. } else {
  5993. // Transparent (invisible) border, so do not draw it at all.
  5994. container.style.borderWidth = 0;
  5995. }
  5996. }
  5997. cstyle.width = width + 'px';
  5998. cstyle.height = height + 'px';
  5999. return container;
  6000. }
  6001. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  6002. var element = document.createElement('div');
  6003. var width = item.rect[2] - item.rect[0];
  6004. var height = item.rect[3] - item.rect[1];
  6005. element.style.width = width + 'px';
  6006. element.style.height = height + 'px';
  6007. element.style.display = 'table';
  6008. var content = document.createElement('div');
  6009. content.textContent = item.fieldValue;
  6010. var textAlignment = item.textAlignment;
  6011. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  6012. content.style.verticalAlign = 'middle';
  6013. content.style.display = 'table-cell';
  6014. var fontObj = item.fontRefName ?
  6015. commonObjs.getData(item.fontRefName) : null;
  6016. setTextStyles(content, item, fontObj);
  6017. element.appendChild(content);
  6018. return element;
  6019. }
  6020. function getHtmlElementForTextAnnotation(item) {
  6021. var rect = item.rect;
  6022. // sanity check because of OOo-generated PDFs
  6023. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  6024. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  6025. }
  6026. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  6027. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  6028. }
  6029. var container = initContainer(item);
  6030. container.className = 'annotText';
  6031. var image = document.createElement('img');
  6032. image.style.height = container.style.height;
  6033. image.style.width = container.style.width;
  6034. var iconName = item.name;
  6035. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  6036. iconName.toLowerCase() + '.svg';
  6037. image.alt = '[{{type}} Annotation]';
  6038. image.dataset.l10nId = 'text_annotation_type';
  6039. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  6040. var contentWrapper = document.createElement('div');
  6041. contentWrapper.className = 'annotTextContentWrapper';
  6042. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  6043. contentWrapper.style.top = '-10px';
  6044. var content = document.createElement('div');
  6045. content.className = 'annotTextContent';
  6046. content.setAttribute('hidden', true);
  6047. var i, ii;
  6048. if (item.hasBgColor && item.color) {
  6049. var color = item.color;
  6050. // Enlighten the color (70%)
  6051. var BACKGROUND_ENLIGHT = 0.7;
  6052. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  6053. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  6054. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  6055. content.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  6056. }
  6057. var title = document.createElement('h1');
  6058. var text = document.createElement('p');
  6059. title.textContent = item.title;
  6060. if (!item.content && !item.title) {
  6061. content.setAttribute('hidden', true);
  6062. } else {
  6063. var e = document.createElement('span');
  6064. var lines = item.content.split(/(?:\r\n?|\n)/);
  6065. for (i = 0, ii = lines.length; i < ii; ++i) {
  6066. var line = lines[i];
  6067. e.appendChild(document.createTextNode(line));
  6068. if (i < (ii - 1)) {
  6069. e.appendChild(document.createElement('br'));
  6070. }
  6071. }
  6072. text.appendChild(e);
  6073. var pinned = false;
  6074. var showAnnotation = function showAnnotation(pin) {
  6075. if (pin) {
  6076. pinned = true;
  6077. }
  6078. if (content.hasAttribute('hidden')) {
  6079. container.style.zIndex += 1;
  6080. content.removeAttribute('hidden');
  6081. }
  6082. };
  6083. var hideAnnotation = function hideAnnotation(unpin) {
  6084. if (unpin) {
  6085. pinned = false;
  6086. }
  6087. if (!content.hasAttribute('hidden') && !pinned) {
  6088. container.style.zIndex -= 1;
  6089. content.setAttribute('hidden', true);
  6090. }
  6091. };
  6092. var toggleAnnotation = function toggleAnnotation() {
  6093. if (pinned) {
  6094. hideAnnotation(true);
  6095. } else {
  6096. showAnnotation(true);
  6097. }
  6098. };
  6099. image.addEventListener('click', function image_clickHandler() {
  6100. toggleAnnotation();
  6101. }, false);
  6102. image.addEventListener('mouseover', function image_mouseOverHandler() {
  6103. showAnnotation();
  6104. }, false);
  6105. image.addEventListener('mouseout', function image_mouseOutHandler() {
  6106. hideAnnotation();
  6107. }, false);
  6108. content.addEventListener('click', function content_clickHandler() {
  6109. hideAnnotation(true);
  6110. }, false);
  6111. }
  6112. content.appendChild(title);
  6113. content.appendChild(text);
  6114. contentWrapper.appendChild(content);
  6115. container.appendChild(image);
  6116. container.appendChild(contentWrapper);
  6117. return container;
  6118. }
  6119. function getHtmlElementForLinkAnnotation(item) {
  6120. var container = initContainer(item);
  6121. container.className = 'annotLink';
  6122. var link = document.createElement('a');
  6123. link.href = link.title = item.url || '';
  6124. if (item.url && isExternalLinkTargetSet()) {
  6125. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  6126. }
  6127. container.appendChild(link);
  6128. return container;
  6129. }
  6130. function getHtmlElement(data, objs) {
  6131. switch (data.annotationType) {
  6132. case AnnotationType.WIDGET:
  6133. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6134. case AnnotationType.TEXT:
  6135. return getHtmlElementForTextAnnotation(data);
  6136. case AnnotationType.LINK:
  6137. return getHtmlElementForLinkAnnotation(data);
  6138. default:
  6139. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6140. }
  6141. }
  6142. return {
  6143. getHtmlElement: getHtmlElement
  6144. };
  6145. })();
  6146. PDFJS.AnnotationUtils = AnnotationUtils;
  6147. var SVG_DEFAULTS = {
  6148. fontStyle: 'normal',
  6149. fontWeight: 'normal',
  6150. fillColor: '#000000'
  6151. };
  6152. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6153. var PNG_HEADER =
  6154. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6155. var CHUNK_WRAPPER_SIZE = 12;
  6156. var crcTable = new Int32Array(256);
  6157. for (var i = 0; i < 256; i++) {
  6158. var c = i;
  6159. for (var h = 0; h < 8; h++) {
  6160. if (c & 1) {
  6161. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6162. } else {
  6163. c = (c >> 1) & 0x7fffffff;
  6164. }
  6165. }
  6166. crcTable[i] = c;
  6167. }
  6168. function crc32(data, start, end) {
  6169. var crc = -1;
  6170. for (var i = start; i < end; i++) {
  6171. var a = (crc ^ data[i]) & 0xff;
  6172. var b = crcTable[a];
  6173. crc = (crc >>> 8) ^ b;
  6174. }
  6175. return crc ^ -1;
  6176. }
  6177. function writePngChunk(type, body, data, offset) {
  6178. var p = offset;
  6179. var len = body.length;
  6180. data[p] = len >> 24 & 0xff;
  6181. data[p + 1] = len >> 16 & 0xff;
  6182. data[p + 2] = len >> 8 & 0xff;
  6183. data[p + 3] = len & 0xff;
  6184. p += 4;
  6185. data[p] = type.charCodeAt(0) & 0xff;
  6186. data[p + 1] = type.charCodeAt(1) & 0xff;
  6187. data[p + 2] = type.charCodeAt(2) & 0xff;
  6188. data[p + 3] = type.charCodeAt(3) & 0xff;
  6189. p += 4;
  6190. data.set(body, p);
  6191. p += body.length;
  6192. var crc = crc32(data, offset + 4, p);
  6193. data[p] = crc >> 24 & 0xff;
  6194. data[p + 1] = crc >> 16 & 0xff;
  6195. data[p + 2] = crc >> 8 & 0xff;
  6196. data[p + 3] = crc & 0xff;
  6197. }
  6198. function adler32(data, start, end) {
  6199. var a = 1;
  6200. var b = 0;
  6201. for (var i = start; i < end; ++i) {
  6202. a = (a + (data[i] & 0xff)) % 65521;
  6203. b = (b + a) % 65521;
  6204. }
  6205. return (b << 16) | a;
  6206. }
  6207. function encode(imgData, kind) {
  6208. var width = imgData.width;
  6209. var height = imgData.height;
  6210. var bitDepth, colorType, lineSize;
  6211. var bytes = imgData.data;
  6212. switch (kind) {
  6213. case ImageKind.GRAYSCALE_1BPP:
  6214. colorType = 0;
  6215. bitDepth = 1;
  6216. lineSize = (width + 7) >> 3;
  6217. break;
  6218. case ImageKind.RGB_24BPP:
  6219. colorType = 2;
  6220. bitDepth = 8;
  6221. lineSize = width * 3;
  6222. break;
  6223. case ImageKind.RGBA_32BPP:
  6224. colorType = 6;
  6225. bitDepth = 8;
  6226. lineSize = width * 4;
  6227. break;
  6228. default:
  6229. throw new Error('invalid format');
  6230. }
  6231. // prefix every row with predictor 0
  6232. var literals = new Uint8Array((1 + lineSize) * height);
  6233. var offsetLiterals = 0, offsetBytes = 0;
  6234. var y, i;
  6235. for (y = 0; y < height; ++y) {
  6236. literals[offsetLiterals++] = 0; // no prediction
  6237. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6238. offsetLiterals);
  6239. offsetBytes += lineSize;
  6240. offsetLiterals += lineSize;
  6241. }
  6242. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6243. // inverting for B/W
  6244. offsetLiterals = 0;
  6245. for (y = 0; y < height; y++) {
  6246. offsetLiterals++; // skipping predictor
  6247. for (i = 0; i < lineSize; i++) {
  6248. literals[offsetLiterals++] ^= 0xFF;
  6249. }
  6250. }
  6251. }
  6252. var ihdr = new Uint8Array([
  6253. width >> 24 & 0xff,
  6254. width >> 16 & 0xff,
  6255. width >> 8 & 0xff,
  6256. width & 0xff,
  6257. height >> 24 & 0xff,
  6258. height >> 16 & 0xff,
  6259. height >> 8 & 0xff,
  6260. height & 0xff,
  6261. bitDepth, // bit depth
  6262. colorType, // color type
  6263. 0x00, // compression method
  6264. 0x00, // filter method
  6265. 0x00 // interlace method
  6266. ]);
  6267. var len = literals.length;
  6268. var maxBlockLength = 0xFFFF;
  6269. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6270. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6271. var pi = 0;
  6272. idat[pi++] = 0x78; // compression method and flags
  6273. idat[pi++] = 0x9c; // flags
  6274. var pos = 0;
  6275. while (len > maxBlockLength) {
  6276. // writing non-final DEFLATE blocks type 0 and length of 65535
  6277. idat[pi++] = 0x00;
  6278. idat[pi++] = 0xff;
  6279. idat[pi++] = 0xff;
  6280. idat[pi++] = 0x00;
  6281. idat[pi++] = 0x00;
  6282. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6283. pi += maxBlockLength;
  6284. pos += maxBlockLength;
  6285. len -= maxBlockLength;
  6286. }
  6287. // writing non-final DEFLATE blocks type 0
  6288. idat[pi++] = 0x01;
  6289. idat[pi++] = len & 0xff;
  6290. idat[pi++] = len >> 8 & 0xff;
  6291. idat[pi++] = (~len & 0xffff) & 0xff;
  6292. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6293. idat.set(literals.subarray(pos), pi);
  6294. pi += literals.length - pos;
  6295. var adler = adler32(literals, 0, literals.length); // checksum
  6296. idat[pi++] = adler >> 24 & 0xff;
  6297. idat[pi++] = adler >> 16 & 0xff;
  6298. idat[pi++] = adler >> 8 & 0xff;
  6299. idat[pi++] = adler & 0xff;
  6300. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6301. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6302. ihdr.length + idat.length;
  6303. var data = new Uint8Array(pngLength);
  6304. var offset = 0;
  6305. data.set(PNG_HEADER, offset);
  6306. offset += PNG_HEADER.length;
  6307. writePngChunk('IHDR', ihdr, data, offset);
  6308. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6309. writePngChunk('IDATA', idat, data, offset);
  6310. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6311. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6312. return PDFJS.createObjectURL(data, 'image/png');
  6313. }
  6314. return function convertImgDataToPng(imgData) {
  6315. var kind = (imgData.kind === undefined ?
  6316. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6317. return encode(imgData, kind);
  6318. };
  6319. })();
  6320. var SVGExtraState = (function SVGExtraStateClosure() {
  6321. function SVGExtraState() {
  6322. this.fontSizeScale = 1;
  6323. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6324. this.fontSize = 0;
  6325. this.textMatrix = IDENTITY_MATRIX;
  6326. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6327. this.leading = 0;
  6328. // Current point (in user coordinates)
  6329. this.x = 0;
  6330. this.y = 0;
  6331. // Start of text line (in text coordinates)
  6332. this.lineX = 0;
  6333. this.lineY = 0;
  6334. // Character and word spacing
  6335. this.charSpacing = 0;
  6336. this.wordSpacing = 0;
  6337. this.textHScale = 1;
  6338. this.textRise = 0;
  6339. // Default foreground and background colors
  6340. this.fillColor = SVG_DEFAULTS.fillColor;
  6341. this.strokeColor = '#000000';
  6342. this.fillAlpha = 1;
  6343. this.strokeAlpha = 1;
  6344. this.lineWidth = 1;
  6345. this.lineJoin = '';
  6346. this.lineCap = '';
  6347. this.miterLimit = 0;
  6348. this.dashArray = [];
  6349. this.dashPhase = 0;
  6350. this.dependencies = [];
  6351. // Clipping
  6352. this.clipId = '';
  6353. this.pendingClip = false;
  6354. this.maskId = '';
  6355. }
  6356. SVGExtraState.prototype = {
  6357. clone: function SVGExtraState_clone() {
  6358. return Object.create(this);
  6359. },
  6360. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6361. this.x = x;
  6362. this.y = y;
  6363. }
  6364. };
  6365. return SVGExtraState;
  6366. })();
  6367. var SVGGraphics = (function SVGGraphicsClosure() {
  6368. function createScratchSVG(width, height) {
  6369. var NS = 'http://www.w3.org/2000/svg';
  6370. var svg = document.createElementNS(NS, 'svg:svg');
  6371. svg.setAttributeNS(null, 'version', '1.1');
  6372. svg.setAttributeNS(null, 'width', width + 'px');
  6373. svg.setAttributeNS(null, 'height', height + 'px');
  6374. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6375. return svg;
  6376. }
  6377. function opListToTree(opList) {
  6378. var opTree = [];
  6379. var tmp = [];
  6380. var opListLen = opList.length;
  6381. for (var x = 0; x < opListLen; x++) {
  6382. if (opList[x].fn === 'save') {
  6383. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6384. tmp.push(opTree);
  6385. opTree = opTree[opTree.length - 1].items;
  6386. continue;
  6387. }
  6388. if(opList[x].fn === 'restore') {
  6389. opTree = tmp.pop();
  6390. } else {
  6391. opTree.push(opList[x]);
  6392. }
  6393. }
  6394. return opTree;
  6395. }
  6396. /**
  6397. * Formats float number.
  6398. * @param value {number} number to format.
  6399. * @returns {string}
  6400. */
  6401. function pf(value) {
  6402. if (value === (value | 0)) { // integer number
  6403. return value.toString();
  6404. }
  6405. var s = value.toFixed(10);
  6406. var i = s.length - 1;
  6407. if (s[i] !== '0') {
  6408. return s;
  6409. }
  6410. // removing trailing zeros
  6411. do {
  6412. i--;
  6413. } while (s[i] === '0');
  6414. return s.substr(0, s[i] === '.' ? i : i + 1);
  6415. }
  6416. /**
  6417. * Formats transform matrix. The standard rotation, scale and translate
  6418. * matrices are replaced by their shorter forms, and for identity matrix
  6419. * returns empty string to save the memory.
  6420. * @param m {Array} matrix to format.
  6421. * @returns {string}
  6422. */
  6423. function pm(m) {
  6424. if (m[4] === 0 && m[5] === 0) {
  6425. if (m[1] === 0 && m[2] === 0) {
  6426. if (m[0] === 1 && m[3] === 1) {
  6427. return '';
  6428. }
  6429. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6430. }
  6431. if (m[0] === m[3] && m[1] === -m[2]) {
  6432. var a = Math.acos(m[0]) * 180 / Math.PI;
  6433. return 'rotate(' + pf(a) + ')';
  6434. }
  6435. } else {
  6436. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6437. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6438. }
  6439. }
  6440. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6441. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6442. }
  6443. function SVGGraphics(commonObjs, objs) {
  6444. this.current = new SVGExtraState();
  6445. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6446. this.transformStack = [];
  6447. this.extraStack = [];
  6448. this.commonObjs = commonObjs;
  6449. this.objs = objs;
  6450. this.pendingEOFill = false;
  6451. this.embedFonts = false;
  6452. this.embeddedFonts = {};
  6453. this.cssStyle = null;
  6454. }
  6455. var NS = 'http://www.w3.org/2000/svg';
  6456. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6457. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6458. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6459. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6460. var clipCount = 0;
  6461. var maskCount = 0;
  6462. SVGGraphics.prototype = {
  6463. save: function SVGGraphics_save() {
  6464. this.transformStack.push(this.transformMatrix);
  6465. var old = this.current;
  6466. this.extraStack.push(old);
  6467. this.current = old.clone();
  6468. },
  6469. restore: function SVGGraphics_restore() {
  6470. this.transformMatrix = this.transformStack.pop();
  6471. this.current = this.extraStack.pop();
  6472. this.tgrp = document.createElementNS(NS, 'svg:g');
  6473. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6474. this.pgrp.appendChild(this.tgrp);
  6475. },
  6476. group: function SVGGraphics_group(items) {
  6477. this.save();
  6478. this.executeOpTree(items);
  6479. this.restore();
  6480. },
  6481. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6482. var fnArray = operatorList.fnArray;
  6483. var fnArrayLen = fnArray.length;
  6484. var argsArray = operatorList.argsArray;
  6485. var self = this;
  6486. for (var i = 0; i < fnArrayLen; i++) {
  6487. if (OPS.dependency === fnArray[i]) {
  6488. var deps = argsArray[i];
  6489. for (var n = 0, nn = deps.length; n < nn; n++) {
  6490. var obj = deps[n];
  6491. var common = obj.substring(0, 2) === 'g_';
  6492. var promise;
  6493. if (common) {
  6494. promise = new Promise(function(resolve) {
  6495. self.commonObjs.get(obj, resolve);
  6496. });
  6497. } else {
  6498. promise = new Promise(function(resolve) {
  6499. self.objs.get(obj, resolve);
  6500. });
  6501. }
  6502. this.current.dependencies.push(promise);
  6503. }
  6504. }
  6505. }
  6506. return Promise.all(this.current.dependencies);
  6507. },
  6508. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6509. var transformMatrix = [a, b, c, d, e, f];
  6510. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6511. transformMatrix);
  6512. this.tgrp = document.createElementNS(NS, 'svg:g');
  6513. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6514. },
  6515. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6516. this.svg = createScratchSVG(viewport.width, viewport.height);
  6517. this.viewport = viewport;
  6518. return this.loadDependencies(operatorList).then(function () {
  6519. this.transformMatrix = IDENTITY_MATRIX;
  6520. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6521. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6522. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6523. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6524. this.defs = document.createElementNS(NS, 'svg:defs');
  6525. this.pgrp.appendChild(this.defs);
  6526. this.pgrp.appendChild(this.tgrp);
  6527. this.svg.appendChild(this.pgrp);
  6528. var opTree = this.convertOpList(operatorList);
  6529. this.executeOpTree(opTree);
  6530. return this.svg;
  6531. }.bind(this));
  6532. },
  6533. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6534. var argsArray = operatorList.argsArray;
  6535. var fnArray = operatorList.fnArray;
  6536. var fnArrayLen = fnArray.length;
  6537. var REVOPS = [];
  6538. var opList = [];
  6539. for (var op in OPS) {
  6540. REVOPS[OPS[op]] = op;
  6541. }
  6542. for (var x = 0; x < fnArrayLen; x++) {
  6543. var fnId = fnArray[x];
  6544. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6545. }
  6546. return opListToTree(opList);
  6547. },
  6548. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6549. var opTreeLen = opTree.length;
  6550. for(var x = 0; x < opTreeLen; x++) {
  6551. var fn = opTree[x].fn;
  6552. var fnId = opTree[x].fnId;
  6553. var args = opTree[x].args;
  6554. switch (fnId | 0) {
  6555. case OPS.beginText:
  6556. this.beginText();
  6557. break;
  6558. case OPS.setLeading:
  6559. this.setLeading(args);
  6560. break;
  6561. case OPS.setLeadingMoveText:
  6562. this.setLeadingMoveText(args[0], args[1]);
  6563. break;
  6564. case OPS.setFont:
  6565. this.setFont(args);
  6566. break;
  6567. case OPS.showText:
  6568. this.showText(args[0]);
  6569. break;
  6570. case OPS.showSpacedText:
  6571. this.showText(args[0]);
  6572. break;
  6573. case OPS.endText:
  6574. this.endText();
  6575. break;
  6576. case OPS.moveText:
  6577. this.moveText(args[0], args[1]);
  6578. break;
  6579. case OPS.setCharSpacing:
  6580. this.setCharSpacing(args[0]);
  6581. break;
  6582. case OPS.setWordSpacing:
  6583. this.setWordSpacing(args[0]);
  6584. break;
  6585. case OPS.setHScale:
  6586. this.setHScale(args[0]);
  6587. break;
  6588. case OPS.setTextMatrix:
  6589. this.setTextMatrix(args[0], args[1], args[2],
  6590. args[3], args[4], args[5]);
  6591. break;
  6592. case OPS.setLineWidth:
  6593. this.setLineWidth(args[0]);
  6594. break;
  6595. case OPS.setLineJoin:
  6596. this.setLineJoin(args[0]);
  6597. break;
  6598. case OPS.setLineCap:
  6599. this.setLineCap(args[0]);
  6600. break;
  6601. case OPS.setMiterLimit:
  6602. this.setMiterLimit(args[0]);
  6603. break;
  6604. case OPS.setFillRGBColor:
  6605. this.setFillRGBColor(args[0], args[1], args[2]);
  6606. break;
  6607. case OPS.setStrokeRGBColor:
  6608. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6609. break;
  6610. case OPS.setDash:
  6611. this.setDash(args[0], args[1]);
  6612. break;
  6613. case OPS.setGState:
  6614. this.setGState(args[0]);
  6615. break;
  6616. case OPS.fill:
  6617. this.fill();
  6618. break;
  6619. case OPS.eoFill:
  6620. this.eoFill();
  6621. break;
  6622. case OPS.stroke:
  6623. this.stroke();
  6624. break;
  6625. case OPS.fillStroke:
  6626. this.fillStroke();
  6627. break;
  6628. case OPS.eoFillStroke:
  6629. this.eoFillStroke();
  6630. break;
  6631. case OPS.clip:
  6632. this.clip('nonzero');
  6633. break;
  6634. case OPS.eoClip:
  6635. this.clip('evenodd');
  6636. break;
  6637. case OPS.paintSolidColorImageMask:
  6638. this.paintSolidColorImageMask();
  6639. break;
  6640. case OPS.paintJpegXObject:
  6641. this.paintJpegXObject(args[0], args[1], args[2]);
  6642. break;
  6643. case OPS.paintImageXObject:
  6644. this.paintImageXObject(args[0]);
  6645. break;
  6646. case OPS.paintInlineImageXObject:
  6647. this.paintInlineImageXObject(args[0]);
  6648. break;
  6649. case OPS.paintImageMaskXObject:
  6650. this.paintImageMaskXObject(args[0]);
  6651. break;
  6652. case OPS.paintFormXObjectBegin:
  6653. this.paintFormXObjectBegin(args[0], args[1]);
  6654. break;
  6655. case OPS.paintFormXObjectEnd:
  6656. this.paintFormXObjectEnd();
  6657. break;
  6658. case OPS.closePath:
  6659. this.closePath();
  6660. break;
  6661. case OPS.closeStroke:
  6662. this.closeStroke();
  6663. break;
  6664. case OPS.closeFillStroke:
  6665. this.closeFillStroke();
  6666. break;
  6667. case OPS.nextLine:
  6668. this.nextLine();
  6669. break;
  6670. case OPS.transform:
  6671. this.transform(args[0], args[1], args[2], args[3],
  6672. args[4], args[5]);
  6673. break;
  6674. case OPS.constructPath:
  6675. this.constructPath(args[0], args[1]);
  6676. break;
  6677. case OPS.endPath:
  6678. this.endPath();
  6679. break;
  6680. case 92:
  6681. this.group(opTree[x].items);
  6682. break;
  6683. default:
  6684. warn('Unimplemented method '+ fn);
  6685. break;
  6686. }
  6687. }
  6688. },
  6689. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6690. this.current.wordSpacing = wordSpacing;
  6691. },
  6692. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6693. this.current.charSpacing = charSpacing;
  6694. },
  6695. nextLine: function SVGGraphics_nextLine() {
  6696. this.moveText(0, this.current.leading);
  6697. },
  6698. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6699. var current = this.current;
  6700. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6701. this.current.x = this.current.lineX = 0;
  6702. this.current.y = this.current.lineY = 0;
  6703. current.xcoords = [];
  6704. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6705. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6706. current.tspan.setAttributeNS(null, 'font-size',
  6707. pf(current.fontSize) + 'px');
  6708. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6709. current.txtElement = document.createElementNS(NS, 'svg:text');
  6710. current.txtElement.appendChild(current.tspan);
  6711. },
  6712. beginText: function SVGGraphics_beginText() {
  6713. this.current.x = this.current.lineX = 0;
  6714. this.current.y = this.current.lineY = 0;
  6715. this.current.textMatrix = IDENTITY_MATRIX;
  6716. this.current.lineMatrix = IDENTITY_MATRIX;
  6717. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6718. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6719. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6720. this.current.xcoords = [];
  6721. },
  6722. moveText: function SVGGraphics_moveText(x, y) {
  6723. var current = this.current;
  6724. this.current.x = this.current.lineX += x;
  6725. this.current.y = this.current.lineY += y;
  6726. current.xcoords = [];
  6727. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6728. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6729. current.tspan.setAttributeNS(null, 'font-size',
  6730. pf(current.fontSize) + 'px');
  6731. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6732. },
  6733. showText: function SVGGraphics_showText(glyphs) {
  6734. var current = this.current;
  6735. var font = current.font;
  6736. var fontSize = current.fontSize;
  6737. if (fontSize === 0) {
  6738. return;
  6739. }
  6740. var charSpacing = current.charSpacing;
  6741. var wordSpacing = current.wordSpacing;
  6742. var fontDirection = current.fontDirection;
  6743. var textHScale = current.textHScale * fontDirection;
  6744. var glyphsLength = glyphs.length;
  6745. var vertical = font.vertical;
  6746. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6747. var x = 0, i;
  6748. for (i = 0; i < glyphsLength; ++i) {
  6749. var glyph = glyphs[i];
  6750. if (glyph === null) {
  6751. // word break
  6752. x += fontDirection * wordSpacing;
  6753. continue;
  6754. } else if (isNum(glyph)) {
  6755. x += -glyph * fontSize * 0.001;
  6756. continue;
  6757. }
  6758. current.xcoords.push(current.x + x * textHScale);
  6759. var width = glyph.width;
  6760. var character = glyph.fontChar;
  6761. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6762. x += charWidth;
  6763. current.tspan.textContent += character;
  6764. }
  6765. if (vertical) {
  6766. current.y -= x * textHScale;
  6767. } else {
  6768. current.x += x * textHScale;
  6769. }
  6770. current.tspan.setAttributeNS(null, 'x',
  6771. current.xcoords.map(pf).join(' '));
  6772. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6773. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6774. current.tspan.setAttributeNS(null, 'font-size',
  6775. pf(current.fontSize) + 'px');
  6776. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6777. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6778. }
  6779. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6780. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6781. }
  6782. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6783. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6784. }
  6785. current.txtElement.setAttributeNS(null, 'transform',
  6786. pm(current.textMatrix) +
  6787. ' scale(1, -1)' );
  6788. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6789. current.txtElement.appendChild(current.tspan);
  6790. current.txtgrp.appendChild(current.txtElement);
  6791. this.tgrp.appendChild(current.txtElement);
  6792. },
  6793. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6794. this.setLeading(-y);
  6795. this.moveText(x, y);
  6796. },
  6797. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6798. if (!this.cssStyle) {
  6799. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6800. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6801. this.defs.appendChild(this.cssStyle);
  6802. }
  6803. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6804. this.cssStyle.textContent +=
  6805. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6806. ' src: url(' + url + '); }\n';
  6807. },
  6808. setFont: function SVGGraphics_setFont(details) {
  6809. var current = this.current;
  6810. var fontObj = this.commonObjs.get(details[0]);
  6811. var size = details[1];
  6812. this.current.font = fontObj;
  6813. if (this.embedFonts && fontObj.data &&
  6814. !this.embeddedFonts[fontObj.loadedName]) {
  6815. this.addFontStyle(fontObj);
  6816. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6817. }
  6818. current.fontMatrix = (fontObj.fontMatrix ?
  6819. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6820. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6821. (fontObj.bold ? 'bold' : 'normal');
  6822. var italic = fontObj.italic ? 'italic' : 'normal';
  6823. if (size < 0) {
  6824. size = -size;
  6825. current.fontDirection = -1;
  6826. } else {
  6827. current.fontDirection = 1;
  6828. }
  6829. current.fontSize = size;
  6830. current.fontFamily = fontObj.loadedName;
  6831. current.fontWeight = bold;
  6832. current.fontStyle = italic;
  6833. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6834. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6835. current.xcoords = [];
  6836. },
  6837. endText: function SVGGraphics_endText() {
  6838. if (this.current.pendingClip) {
  6839. this.cgrp.appendChild(this.tgrp);
  6840. this.pgrp.appendChild(this.cgrp);
  6841. } else {
  6842. this.pgrp.appendChild(this.tgrp);
  6843. }
  6844. this.tgrp = document.createElementNS(NS, 'svg:g');
  6845. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6846. },
  6847. // Path properties
  6848. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6849. this.current.lineWidth = width;
  6850. },
  6851. setLineCap: function SVGGraphics_setLineCap(style) {
  6852. this.current.lineCap = LINE_CAP_STYLES[style];
  6853. },
  6854. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6855. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6856. },
  6857. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6858. this.current.miterLimit = limit;
  6859. },
  6860. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6861. var color = Util.makeCssRgb(r, g, b);
  6862. this.current.strokeColor = color;
  6863. },
  6864. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6865. var color = Util.makeCssRgb(r, g, b);
  6866. this.current.fillColor = color;
  6867. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6868. this.current.xcoords = [];
  6869. },
  6870. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6871. this.current.dashArray = dashArray;
  6872. this.current.dashPhase = dashPhase;
  6873. },
  6874. constructPath: function SVGGraphics_constructPath(ops, args) {
  6875. var current = this.current;
  6876. var x = current.x, y = current.y;
  6877. current.path = document.createElementNS(NS, 'svg:path');
  6878. var d = [];
  6879. var opLength = ops.length;
  6880. for (var i = 0, j = 0; i < opLength; i++) {
  6881. switch (ops[i] | 0) {
  6882. case OPS.rectangle:
  6883. x = args[j++];
  6884. y = args[j++];
  6885. var width = args[j++];
  6886. var height = args[j++];
  6887. var xw = x + width;
  6888. var yh = y + height;
  6889. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6890. 'L', pf(x), pf(yh), 'Z');
  6891. break;
  6892. case OPS.moveTo:
  6893. x = args[j++];
  6894. y = args[j++];
  6895. d.push('M', pf(x), pf(y));
  6896. break;
  6897. case OPS.lineTo:
  6898. x = args[j++];
  6899. y = args[j++];
  6900. d.push('L', pf(x) , pf(y));
  6901. break;
  6902. case OPS.curveTo:
  6903. x = args[j + 4];
  6904. y = args[j + 5];
  6905. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6906. pf(args[j + 3]), pf(x), pf(y));
  6907. j += 6;
  6908. break;
  6909. case OPS.curveTo2:
  6910. x = args[j + 2];
  6911. y = args[j + 3];
  6912. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6913. pf(args[j + 2]), pf(args[j + 3]));
  6914. j += 4;
  6915. break;
  6916. case OPS.curveTo3:
  6917. x = args[j + 2];
  6918. y = args[j + 3];
  6919. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6920. pf(x), pf(y));
  6921. j += 4;
  6922. break;
  6923. case OPS.closePath:
  6924. d.push('Z');
  6925. break;
  6926. }
  6927. }
  6928. current.path.setAttributeNS(null, 'd', d.join(' '));
  6929. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6930. pf(current.miterLimit));
  6931. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6932. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6933. current.path.setAttributeNS(null, 'stroke-width',
  6934. pf(current.lineWidth) + 'px');
  6935. current.path.setAttributeNS(null, 'stroke-dasharray',
  6936. current.dashArray.map(pf).join(' '));
  6937. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6938. pf(current.dashPhase) + 'px');
  6939. current.path.setAttributeNS(null, 'fill', 'none');
  6940. this.tgrp.appendChild(current.path);
  6941. if (current.pendingClip) {
  6942. this.cgrp.appendChild(this.tgrp);
  6943. this.pgrp.appendChild(this.cgrp);
  6944. } else {
  6945. this.pgrp.appendChild(this.tgrp);
  6946. }
  6947. // Saving a reference in current.element so that it can be addressed
  6948. // in 'fill' and 'stroke'
  6949. current.element = current.path;
  6950. current.setCurrentPoint(x, y);
  6951. },
  6952. endPath: function SVGGraphics_endPath() {
  6953. var current = this.current;
  6954. if (current.pendingClip) {
  6955. this.cgrp.appendChild(this.tgrp);
  6956. this.pgrp.appendChild(this.cgrp);
  6957. } else {
  6958. this.pgrp.appendChild(this.tgrp);
  6959. }
  6960. this.tgrp = document.createElementNS(NS, 'svg:g');
  6961. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6962. },
  6963. clip: function SVGGraphics_clip(type) {
  6964. var current = this.current;
  6965. // Add current path to clipping path
  6966. current.clipId = 'clippath' + clipCount;
  6967. clipCount++;
  6968. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6969. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6970. var clipElement = current.element.cloneNode();
  6971. if (type === 'evenodd') {
  6972. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6973. } else {
  6974. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6975. }
  6976. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6977. this.clippath.appendChild(clipElement);
  6978. this.defs.appendChild(this.clippath);
  6979. // Create a new group with that attribute
  6980. current.pendingClip = true;
  6981. this.cgrp = document.createElementNS(NS, 'svg:g');
  6982. this.cgrp.setAttributeNS(null, 'clip-path',
  6983. 'url(#' + current.clipId + ')');
  6984. this.pgrp.appendChild(this.cgrp);
  6985. },
  6986. closePath: function SVGGraphics_closePath() {
  6987. var current = this.current;
  6988. var d = current.path.getAttributeNS(null, 'd');
  6989. d += 'Z';
  6990. current.path.setAttributeNS(null, 'd', d);
  6991. },
  6992. setLeading: function SVGGraphics_setLeading(leading) {
  6993. this.current.leading = -leading;
  6994. },
  6995. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6996. this.current.textRise = textRise;
  6997. },
  6998. setHScale: function SVGGraphics_setHScale(scale) {
  6999. this.current.textHScale = scale / 100;
  7000. },
  7001. setGState: function SVGGraphics_setGState(states) {
  7002. for (var i = 0, ii = states.length; i < ii; i++) {
  7003. var state = states[i];
  7004. var key = state[0];
  7005. var value = state[1];
  7006. switch (key) {
  7007. case 'LW':
  7008. this.setLineWidth(value);
  7009. break;
  7010. case 'LC':
  7011. this.setLineCap(value);
  7012. break;
  7013. case 'LJ':
  7014. this.setLineJoin(value);
  7015. break;
  7016. case 'ML':
  7017. this.setMiterLimit(value);
  7018. break;
  7019. case 'D':
  7020. this.setDash(value[0], value[1]);
  7021. break;
  7022. case 'RI':
  7023. break;
  7024. case 'FL':
  7025. break;
  7026. case 'Font':
  7027. this.setFont(value);
  7028. break;
  7029. case 'CA':
  7030. break;
  7031. case 'ca':
  7032. break;
  7033. case 'BM':
  7034. break;
  7035. case 'SMask':
  7036. break;
  7037. }
  7038. }
  7039. },
  7040. fill: function SVGGraphics_fill() {
  7041. var current = this.current;
  7042. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7043. },
  7044. stroke: function SVGGraphics_stroke() {
  7045. var current = this.current;
  7046. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  7047. current.element.setAttributeNS(null, 'fill', 'none');
  7048. },
  7049. eoFill: function SVGGraphics_eoFill() {
  7050. var current = this.current;
  7051. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7052. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7053. },
  7054. fillStroke: function SVGGraphics_fillStroke() {
  7055. // Order is important since stroke wants fill to be none.
  7056. // First stroke, then if fill needed, it will be overwritten.
  7057. this.stroke();
  7058. this.fill();
  7059. },
  7060. eoFillStroke: function SVGGraphics_eoFillStroke() {
  7061. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7062. this.fillStroke();
  7063. },
  7064. closeStroke: function SVGGraphics_closeStroke() {
  7065. this.closePath();
  7066. this.stroke();
  7067. },
  7068. closeFillStroke: function SVGGraphics_closeFillStroke() {
  7069. this.closePath();
  7070. this.fillStroke();
  7071. },
  7072. paintSolidColorImageMask:
  7073. function SVGGraphics_paintSolidColorImageMask() {
  7074. var current = this.current;
  7075. var rect = document.createElementNS(NS, 'svg:rect');
  7076. rect.setAttributeNS(null, 'x', '0');
  7077. rect.setAttributeNS(null, 'y', '0');
  7078. rect.setAttributeNS(null, 'width', '1px');
  7079. rect.setAttributeNS(null, 'height', '1px');
  7080. rect.setAttributeNS(null, 'fill', current.fillColor);
  7081. this.tgrp.appendChild(rect);
  7082. },
  7083. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  7084. var current = this.current;
  7085. var imgObj = this.objs.get(objId);
  7086. var imgEl = document.createElementNS(NS, 'svg:image');
  7087. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  7088. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  7089. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  7090. imgEl.setAttributeNS(null, 'x', '0');
  7091. imgEl.setAttributeNS(null, 'y', pf(-h));
  7092. imgEl.setAttributeNS(null, 'transform',
  7093. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  7094. this.tgrp.appendChild(imgEl);
  7095. if (current.pendingClip) {
  7096. this.cgrp.appendChild(this.tgrp);
  7097. this.pgrp.appendChild(this.cgrp);
  7098. } else {
  7099. this.pgrp.appendChild(this.tgrp);
  7100. }
  7101. },
  7102. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  7103. var imgData = this.objs.get(objId);
  7104. if (!imgData) {
  7105. warn('Dependent image isn\'t ready yet');
  7106. return;
  7107. }
  7108. this.paintInlineImageXObject(imgData);
  7109. },
  7110. paintInlineImageXObject:
  7111. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  7112. var current = this.current;
  7113. var width = imgData.width;
  7114. var height = imgData.height;
  7115. var imgSrc = convertImgDataToPng(imgData);
  7116. var cliprect = document.createElementNS(NS, 'svg:rect');
  7117. cliprect.setAttributeNS(null, 'x', '0');
  7118. cliprect.setAttributeNS(null, 'y', '0');
  7119. cliprect.setAttributeNS(null, 'width', pf(width));
  7120. cliprect.setAttributeNS(null, 'height', pf(height));
  7121. current.element = cliprect;
  7122. this.clip('nonzero');
  7123. var imgEl = document.createElementNS(NS, 'svg:image');
  7124. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7125. imgEl.setAttributeNS(null, 'x', '0');
  7126. imgEl.setAttributeNS(null, 'y', pf(-height));
  7127. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7128. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7129. imgEl.setAttributeNS(null, 'transform',
  7130. 'scale(' + pf(1 / width) + ' ' +
  7131. pf(-1 / height) + ')');
  7132. if (mask) {
  7133. mask.appendChild(imgEl);
  7134. } else {
  7135. this.tgrp.appendChild(imgEl);
  7136. }
  7137. if (current.pendingClip) {
  7138. this.cgrp.appendChild(this.tgrp);
  7139. this.pgrp.appendChild(this.cgrp);
  7140. } else {
  7141. this.pgrp.appendChild(this.tgrp);
  7142. }
  7143. },
  7144. paintImageMaskXObject:
  7145. function SVGGraphics_paintImageMaskXObject(imgData) {
  7146. var current = this.current;
  7147. var width = imgData.width;
  7148. var height = imgData.height;
  7149. var fillColor = current.fillColor;
  7150. current.maskId = 'mask' + maskCount++;
  7151. var mask = document.createElementNS(NS, 'svg:mask');
  7152. mask.setAttributeNS(null, 'id', current.maskId);
  7153. var rect = document.createElementNS(NS, 'svg:rect');
  7154. rect.setAttributeNS(null, 'x', '0');
  7155. rect.setAttributeNS(null, 'y', '0');
  7156. rect.setAttributeNS(null, 'width', pf(width));
  7157. rect.setAttributeNS(null, 'height', pf(height));
  7158. rect.setAttributeNS(null, 'fill', fillColor);
  7159. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7160. this.defs.appendChild(mask);
  7161. this.tgrp.appendChild(rect);
  7162. this.paintInlineImageXObject(imgData, mask);
  7163. },
  7164. paintFormXObjectBegin:
  7165. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7166. this.save();
  7167. if (isArray(matrix) && matrix.length === 6) {
  7168. this.transform(matrix[0], matrix[1], matrix[2],
  7169. matrix[3], matrix[4], matrix[5]);
  7170. }
  7171. if (isArray(bbox) && bbox.length === 4) {
  7172. var width = bbox[2] - bbox[0];
  7173. var height = bbox[3] - bbox[1];
  7174. var cliprect = document.createElementNS(NS, 'svg:rect');
  7175. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7176. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7177. cliprect.setAttributeNS(null, 'width', pf(width));
  7178. cliprect.setAttributeNS(null, 'height', pf(height));
  7179. this.current.element = cliprect;
  7180. this.clip('nonzero');
  7181. this.endPath();
  7182. }
  7183. },
  7184. paintFormXObjectEnd:
  7185. function SVGGraphics_paintFormXObjectEnd() {
  7186. this.restore();
  7187. }
  7188. };
  7189. return SVGGraphics;
  7190. })();
  7191. PDFJS.SVGGraphics = SVGGraphics;
  7192. var NetworkManager = (function NetworkManagerClosure() {
  7193. var OK_RESPONSE = 200;
  7194. var PARTIAL_CONTENT_RESPONSE = 206;
  7195. function NetworkManager(url, args) {
  7196. this.url = url;
  7197. args = args || {};
  7198. this.isHttp = /^https?:/i.test(url);
  7199. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7200. this.withCredentials = args.withCredentials || false;
  7201. this.getXhr = args.getXhr ||
  7202. function NetworkManager_getXhr() {
  7203. return new XMLHttpRequest();
  7204. };
  7205. this.currXhrId = 0;
  7206. this.pendingRequests = {};
  7207. this.loadedRequests = {};
  7208. }
  7209. function getArrayBuffer(xhr) {
  7210. var data = xhr.response;
  7211. if (typeof data !== 'string') {
  7212. return data;
  7213. }
  7214. var length = data.length;
  7215. var array = new Uint8Array(length);
  7216. for (var i = 0; i < length; i++) {
  7217. array[i] = data.charCodeAt(i) & 0xFF;
  7218. }
  7219. return array.buffer;
  7220. }
  7221. var supportsMozChunked = (function supportsMozChunkedClosure() {
  7222. try {
  7223. var x = new XMLHttpRequest();
  7224. // Firefox 37- required .open() to be called before setting responseType.
  7225. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  7226. // Even though the URL is not visited, .open() could fail if the URL is
  7227. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  7228. // When this error occurs, this feature detection method will mistakenly
  7229. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  7230. x.open('GET', 'https://example.com');
  7231. x.responseType = 'moz-chunked-arraybuffer';
  7232. return x.responseType === 'moz-chunked-arraybuffer';
  7233. } catch (e) {
  7234. return false;
  7235. }
  7236. })();
  7237. NetworkManager.prototype = {
  7238. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7239. var args = {
  7240. begin: begin,
  7241. end: end
  7242. };
  7243. for (var prop in listeners) {
  7244. args[prop] = listeners[prop];
  7245. }
  7246. return this.request(args);
  7247. },
  7248. requestFull: function NetworkManager_requestFull(listeners) {
  7249. return this.request(listeners);
  7250. },
  7251. request: function NetworkManager_request(args) {
  7252. var xhr = this.getXhr();
  7253. var xhrId = this.currXhrId++;
  7254. var pendingRequest = this.pendingRequests[xhrId] = {
  7255. xhr: xhr
  7256. };
  7257. xhr.open('GET', this.url);
  7258. xhr.withCredentials = this.withCredentials;
  7259. for (var property in this.httpHeaders) {
  7260. var value = this.httpHeaders[property];
  7261. if (typeof value === 'undefined') {
  7262. continue;
  7263. }
  7264. xhr.setRequestHeader(property, value);
  7265. }
  7266. if (this.isHttp && 'begin' in args && 'end' in args) {
  7267. var rangeStr = args.begin + '-' + (args.end - 1);
  7268. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7269. pendingRequest.expectedStatus = 206;
  7270. } else {
  7271. pendingRequest.expectedStatus = 200;
  7272. }
  7273. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  7274. if (useMozChunkedLoading) {
  7275. xhr.responseType = 'moz-chunked-arraybuffer';
  7276. pendingRequest.onProgressiveData = args.onProgressiveData;
  7277. pendingRequest.mozChunked = true;
  7278. } else {
  7279. xhr.responseType = 'arraybuffer';
  7280. }
  7281. if (args.onError) {
  7282. xhr.onerror = function(evt) {
  7283. args.onError(xhr.status);
  7284. };
  7285. }
  7286. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7287. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7288. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7289. pendingRequest.onDone = args.onDone;
  7290. pendingRequest.onError = args.onError;
  7291. pendingRequest.onProgress = args.onProgress;
  7292. xhr.send(null);
  7293. return xhrId;
  7294. },
  7295. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7296. var pendingRequest = this.pendingRequests[xhrId];
  7297. if (!pendingRequest) {
  7298. // Maybe abortRequest was called...
  7299. return;
  7300. }
  7301. if (pendingRequest.mozChunked) {
  7302. var chunk = getArrayBuffer(pendingRequest.xhr);
  7303. pendingRequest.onProgressiveData(chunk);
  7304. }
  7305. var onProgress = pendingRequest.onProgress;
  7306. if (onProgress) {
  7307. onProgress(evt);
  7308. }
  7309. },
  7310. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7311. var pendingRequest = this.pendingRequests[xhrId];
  7312. if (!pendingRequest) {
  7313. // Maybe abortRequest was called...
  7314. return;
  7315. }
  7316. var xhr = pendingRequest.xhr;
  7317. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7318. pendingRequest.onHeadersReceived();
  7319. delete pendingRequest.onHeadersReceived;
  7320. }
  7321. if (xhr.readyState !== 4) {
  7322. return;
  7323. }
  7324. if (!(xhrId in this.pendingRequests)) {
  7325. // The XHR request might have been aborted in onHeadersReceived()
  7326. // callback, in which case we should abort request
  7327. return;
  7328. }
  7329. delete this.pendingRequests[xhrId];
  7330. // success status == 0 can be on ftp, file and other protocols
  7331. if (xhr.status === 0 && this.isHttp) {
  7332. if (pendingRequest.onError) {
  7333. pendingRequest.onError(xhr.status);
  7334. }
  7335. return;
  7336. }
  7337. var xhrStatus = xhr.status || OK_RESPONSE;
  7338. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7339. // "A server MAY ignore the Range header". This means it's possible to
  7340. // get a 200 rather than a 206 response from a range request.
  7341. var ok_response_on_range_request =
  7342. xhrStatus === OK_RESPONSE &&
  7343. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7344. if (!ok_response_on_range_request &&
  7345. xhrStatus !== pendingRequest.expectedStatus) {
  7346. if (pendingRequest.onError) {
  7347. pendingRequest.onError(xhr.status);
  7348. }
  7349. return;
  7350. }
  7351. this.loadedRequests[xhrId] = true;
  7352. var chunk = getArrayBuffer(xhr);
  7353. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7354. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7355. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7356. var begin = parseInt(matches[1], 10);
  7357. pendingRequest.onDone({
  7358. begin: begin,
  7359. chunk: chunk
  7360. });
  7361. } else if (pendingRequest.onProgressiveData) {
  7362. pendingRequest.onDone(null);
  7363. } else {
  7364. pendingRequest.onDone({
  7365. begin: 0,
  7366. chunk: chunk
  7367. });
  7368. }
  7369. },
  7370. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7371. for (var xhrId in this.pendingRequests) {
  7372. return true;
  7373. }
  7374. return false;
  7375. },
  7376. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7377. return this.pendingRequests[xhrId].xhr;
  7378. },
  7379. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7380. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7381. },
  7382. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7383. return xhrId in this.pendingRequests;
  7384. },
  7385. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7386. return xhrId in this.loadedRequests;
  7387. },
  7388. abortAllRequests: function NetworkManager_abortAllRequests() {
  7389. for (var xhrId in this.pendingRequests) {
  7390. this.abortRequest(xhrId | 0);
  7391. }
  7392. },
  7393. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7394. var xhr = this.pendingRequests[xhrId].xhr;
  7395. delete this.pendingRequests[xhrId];
  7396. xhr.abort();
  7397. }
  7398. };
  7399. return NetworkManager;
  7400. })();
  7401. var ChunkedStream = (function ChunkedStreamClosure() {
  7402. function ChunkedStream(length, chunkSize, manager) {
  7403. this.bytes = new Uint8Array(length);
  7404. this.start = 0;
  7405. this.pos = 0;
  7406. this.end = length;
  7407. this.chunkSize = chunkSize;
  7408. this.loadedChunks = [];
  7409. this.numChunksLoaded = 0;
  7410. this.numChunks = Math.ceil(length / chunkSize);
  7411. this.manager = manager;
  7412. this.progressiveDataLength = 0;
  7413. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7414. }
  7415. // required methods for a stream. if a particular stream does not
  7416. // implement these, an error should be thrown
  7417. ChunkedStream.prototype = {
  7418. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7419. var chunks = [];
  7420. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7421. if (!this.loadedChunks[chunk]) {
  7422. chunks.push(chunk);
  7423. }
  7424. }
  7425. return chunks;
  7426. },
  7427. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7428. return [this];
  7429. },
  7430. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7431. return this.numChunksLoaded === this.numChunks;
  7432. },
  7433. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7434. var end = begin + chunk.byteLength;
  7435. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7436. // Using this.length is inaccurate here since this.start can be moved
  7437. // See ChunkedStream.moveStart()
  7438. var length = this.bytes.length;
  7439. assert(end % this.chunkSize === 0 || end === length,
  7440. 'Bad end offset: ' + end);
  7441. this.bytes.set(new Uint8Array(chunk), begin);
  7442. var chunkSize = this.chunkSize;
  7443. var beginChunk = Math.floor(begin / chunkSize);
  7444. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7445. var curChunk;
  7446. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7447. if (!this.loadedChunks[curChunk]) {
  7448. this.loadedChunks[curChunk] = true;
  7449. ++this.numChunksLoaded;
  7450. }
  7451. }
  7452. },
  7453. onReceiveProgressiveData:
  7454. function ChunkedStream_onReceiveProgressiveData(data) {
  7455. var position = this.progressiveDataLength;
  7456. var beginChunk = Math.floor(position / this.chunkSize);
  7457. this.bytes.set(new Uint8Array(data), position);
  7458. position += data.byteLength;
  7459. this.progressiveDataLength = position;
  7460. var endChunk = position >= this.end ? this.numChunks :
  7461. Math.floor(position / this.chunkSize);
  7462. var curChunk;
  7463. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7464. if (!this.loadedChunks[curChunk]) {
  7465. this.loadedChunks[curChunk] = true;
  7466. ++this.numChunksLoaded;
  7467. }
  7468. }
  7469. },
  7470. ensureByte: function ChunkedStream_ensureByte(pos) {
  7471. var chunk = Math.floor(pos / this.chunkSize);
  7472. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7473. return;
  7474. }
  7475. if (!this.loadedChunks[chunk]) {
  7476. throw new MissingDataException(pos, pos + 1);
  7477. }
  7478. this.lastSuccessfulEnsureByteChunk = chunk;
  7479. },
  7480. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7481. if (begin >= end) {
  7482. return;
  7483. }
  7484. if (end <= this.progressiveDataLength) {
  7485. return;
  7486. }
  7487. var chunkSize = this.chunkSize;
  7488. var beginChunk = Math.floor(begin / chunkSize);
  7489. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7490. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7491. if (!this.loadedChunks[chunk]) {
  7492. throw new MissingDataException(begin, end);
  7493. }
  7494. }
  7495. },
  7496. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7497. var chunk, numChunks = this.numChunks;
  7498. for (var i = 0; i < numChunks; ++i) {
  7499. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  7500. if (!this.loadedChunks[chunk]) {
  7501. return chunk;
  7502. }
  7503. }
  7504. return null;
  7505. },
  7506. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7507. return !!this.loadedChunks[chunk];
  7508. },
  7509. get length() {
  7510. return this.end - this.start;
  7511. },
  7512. get isEmpty() {
  7513. return this.length === 0;
  7514. },
  7515. getByte: function ChunkedStream_getByte() {
  7516. var pos = this.pos;
  7517. if (pos >= this.end) {
  7518. return -1;
  7519. }
  7520. this.ensureByte(pos);
  7521. return this.bytes[this.pos++];
  7522. },
  7523. getUint16: function ChunkedStream_getUint16() {
  7524. var b0 = this.getByte();
  7525. var b1 = this.getByte();
  7526. if (b0 === -1 || b1 === -1) {
  7527. return -1;
  7528. }
  7529. return (b0 << 8) + b1;
  7530. },
  7531. getInt32: function ChunkedStream_getInt32() {
  7532. var b0 = this.getByte();
  7533. var b1 = this.getByte();
  7534. var b2 = this.getByte();
  7535. var b3 = this.getByte();
  7536. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7537. },
  7538. // returns subarray of original buffer
  7539. // should only be read
  7540. getBytes: function ChunkedStream_getBytes(length) {
  7541. var bytes = this.bytes;
  7542. var pos = this.pos;
  7543. var strEnd = this.end;
  7544. if (!length) {
  7545. this.ensureRange(pos, strEnd);
  7546. return bytes.subarray(pos, strEnd);
  7547. }
  7548. var end = pos + length;
  7549. if (end > strEnd) {
  7550. end = strEnd;
  7551. }
  7552. this.ensureRange(pos, end);
  7553. this.pos = end;
  7554. return bytes.subarray(pos, end);
  7555. },
  7556. peekByte: function ChunkedStream_peekByte() {
  7557. var peekedByte = this.getByte();
  7558. this.pos--;
  7559. return peekedByte;
  7560. },
  7561. peekBytes: function ChunkedStream_peekBytes(length) {
  7562. var bytes = this.getBytes(length);
  7563. this.pos -= bytes.length;
  7564. return bytes;
  7565. },
  7566. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7567. this.ensureRange(begin, end);
  7568. return this.bytes.subarray(begin, end);
  7569. },
  7570. skip: function ChunkedStream_skip(n) {
  7571. if (!n) {
  7572. n = 1;
  7573. }
  7574. this.pos += n;
  7575. },
  7576. reset: function ChunkedStream_reset() {
  7577. this.pos = this.start;
  7578. },
  7579. moveStart: function ChunkedStream_moveStart() {
  7580. this.start = this.pos;
  7581. },
  7582. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7583. this.ensureRange(start, start + length);
  7584. function ChunkedStreamSubstream() {}
  7585. ChunkedStreamSubstream.prototype = Object.create(this);
  7586. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7587. var chunkSize = this.chunkSize;
  7588. var beginChunk = Math.floor(this.start / chunkSize);
  7589. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7590. var missingChunks = [];
  7591. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7592. if (!this.loadedChunks[chunk]) {
  7593. missingChunks.push(chunk);
  7594. }
  7595. }
  7596. return missingChunks;
  7597. };
  7598. var subStream = new ChunkedStreamSubstream();
  7599. subStream.pos = subStream.start = start;
  7600. subStream.end = start + length || this.end;
  7601. subStream.dict = dict;
  7602. return subStream;
  7603. },
  7604. isStream: true
  7605. };
  7606. return ChunkedStream;
  7607. })();
  7608. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7609. function ChunkedStreamManager(length, chunkSize, url, args) {
  7610. this.stream = new ChunkedStream(length, chunkSize, this);
  7611. this.length = length;
  7612. this.chunkSize = chunkSize;
  7613. this.url = url;
  7614. this.disableAutoFetch = args.disableAutoFetch;
  7615. var msgHandler = this.msgHandler = args.msgHandler;
  7616. if (args.chunkedViewerLoading) {
  7617. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7618. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7619. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7620. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7621. };
  7622. } else {
  7623. var getXhr = function getXhr() {
  7624. return new XMLHttpRequest();
  7625. };
  7626. this.networkManager = new NetworkManager(this.url, {
  7627. getXhr: getXhr,
  7628. httpHeaders: args.httpHeaders,
  7629. withCredentials: args.withCredentials
  7630. });
  7631. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7632. this.networkManager.requestRange(begin, end, {
  7633. onDone: this.onReceiveData.bind(this),
  7634. onProgress: this.onProgress.bind(this)
  7635. });
  7636. };
  7637. }
  7638. this.currRequestId = 0;
  7639. this.chunksNeededByRequest = {};
  7640. this.requestsByChunk = {};
  7641. this.callbacksByRequest = {};
  7642. this.progressiveDataLength = 0;
  7643. this._loadedStreamCapability = createPromiseCapability();
  7644. if (args.initialData) {
  7645. this.onReceiveData({chunk: args.initialData});
  7646. }
  7647. }
  7648. ChunkedStreamManager.prototype = {
  7649. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7650. return this._loadedStreamCapability.promise;
  7651. },
  7652. // Get all the chunks that are not yet loaded and groups them into
  7653. // contiguous ranges to load in as few requests as possible
  7654. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7655. var missingChunks = this.stream.getMissingChunks();
  7656. this.requestChunks(missingChunks);
  7657. return this._loadedStreamCapability.promise;
  7658. },
  7659. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7660. callback) {
  7661. var requestId = this.currRequestId++;
  7662. var chunksNeeded;
  7663. var i, ii;
  7664. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7665. for (i = 0, ii = chunks.length; i < ii; i++) {
  7666. if (!this.stream.hasChunk(chunks[i])) {
  7667. chunksNeeded[chunks[i]] = true;
  7668. }
  7669. }
  7670. if (isEmptyObj(chunksNeeded)) {
  7671. if (callback) {
  7672. callback();
  7673. }
  7674. return;
  7675. }
  7676. this.callbacksByRequest[requestId] = callback;
  7677. var chunksToRequest = [];
  7678. for (var chunk in chunksNeeded) {
  7679. chunk = chunk | 0;
  7680. if (!(chunk in this.requestsByChunk)) {
  7681. this.requestsByChunk[chunk] = [];
  7682. chunksToRequest.push(chunk);
  7683. }
  7684. this.requestsByChunk[chunk].push(requestId);
  7685. }
  7686. if (!chunksToRequest.length) {
  7687. return;
  7688. }
  7689. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7690. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7691. var groupedChunk = groupedChunksToRequest[i];
  7692. var begin = groupedChunk.beginChunk * this.chunkSize;
  7693. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7694. this.sendRequest(begin, end);
  7695. }
  7696. },
  7697. getStream: function ChunkedStreamManager_getStream() {
  7698. return this.stream;
  7699. },
  7700. // Loads any chunks in the requested range that are not yet loaded
  7701. requestRange: function ChunkedStreamManager_requestRange(
  7702. begin, end, callback) {
  7703. end = Math.min(end, this.length);
  7704. var beginChunk = this.getBeginChunk(begin);
  7705. var endChunk = this.getEndChunk(end);
  7706. var chunks = [];
  7707. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7708. chunks.push(chunk);
  7709. }
  7710. this.requestChunks(chunks, callback);
  7711. },
  7712. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7713. callback) {
  7714. ranges = ranges || [];
  7715. var chunksToRequest = [];
  7716. for (var i = 0; i < ranges.length; i++) {
  7717. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7718. var endChunk = this.getEndChunk(ranges[i].end);
  7719. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7720. if (chunksToRequest.indexOf(chunk) < 0) {
  7721. chunksToRequest.push(chunk);
  7722. }
  7723. }
  7724. }
  7725. chunksToRequest.sort(function(a, b) { return a - b; });
  7726. this.requestChunks(chunksToRequest, callback);
  7727. },
  7728. // Groups a sorted array of chunks into as few contiguous larger
  7729. // chunks as possible
  7730. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7731. var groupedChunks = [];
  7732. var beginChunk = -1;
  7733. var prevChunk = -1;
  7734. for (var i = 0; i < chunks.length; ++i) {
  7735. var chunk = chunks[i];
  7736. if (beginChunk < 0) {
  7737. beginChunk = chunk;
  7738. }
  7739. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7740. groupedChunks.push({ beginChunk: beginChunk,
  7741. endChunk: prevChunk + 1 });
  7742. beginChunk = chunk;
  7743. }
  7744. if (i + 1 === chunks.length) {
  7745. groupedChunks.push({ beginChunk: beginChunk,
  7746. endChunk: chunk + 1 });
  7747. }
  7748. prevChunk = chunk;
  7749. }
  7750. return groupedChunks;
  7751. },
  7752. onProgress: function ChunkedStreamManager_onProgress(args) {
  7753. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7754. args.loaded);
  7755. this.msgHandler.send('DocProgress', {
  7756. loaded: bytesLoaded,
  7757. total: this.length
  7758. });
  7759. },
  7760. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7761. var chunk = args.chunk;
  7762. var isProgressive = args.begin === undefined;
  7763. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7764. var end = begin + chunk.byteLength;
  7765. var beginChunk = Math.floor(begin / this.chunkSize);
  7766. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7767. Math.ceil(end / this.chunkSize);
  7768. if (isProgressive) {
  7769. this.stream.onReceiveProgressiveData(chunk);
  7770. this.progressiveDataLength = end;
  7771. } else {
  7772. this.stream.onReceiveData(begin, chunk);
  7773. }
  7774. if (this.stream.allChunksLoaded()) {
  7775. this._loadedStreamCapability.resolve(this.stream);
  7776. }
  7777. var loadedRequests = [];
  7778. var i, requestId;
  7779. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7780. // The server might return more chunks than requested
  7781. var requestIds = this.requestsByChunk[chunk] || [];
  7782. delete this.requestsByChunk[chunk];
  7783. for (i = 0; i < requestIds.length; ++i) {
  7784. requestId = requestIds[i];
  7785. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7786. if (chunk in chunksNeeded) {
  7787. delete chunksNeeded[chunk];
  7788. }
  7789. if (!isEmptyObj(chunksNeeded)) {
  7790. continue;
  7791. }
  7792. loadedRequests.push(requestId);
  7793. }
  7794. }
  7795. // If there are no pending requests, automatically fetch the next
  7796. // unfetched chunk of the PDF
  7797. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7798. var nextEmptyChunk;
  7799. if (this.stream.numChunksLoaded === 1) {
  7800. // This is a special optimization so that after fetching the first
  7801. // chunk, rather than fetching the second chunk, we fetch the last
  7802. // chunk.
  7803. var lastChunk = this.stream.numChunks - 1;
  7804. if (!this.stream.hasChunk(lastChunk)) {
  7805. nextEmptyChunk = lastChunk;
  7806. }
  7807. } else {
  7808. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7809. }
  7810. if (isInt(nextEmptyChunk)) {
  7811. this.requestChunks([nextEmptyChunk]);
  7812. }
  7813. }
  7814. for (i = 0; i < loadedRequests.length; ++i) {
  7815. requestId = loadedRequests[i];
  7816. var callback = this.callbacksByRequest[requestId];
  7817. delete this.callbacksByRequest[requestId];
  7818. if (callback) {
  7819. callback();
  7820. }
  7821. }
  7822. this.msgHandler.send('DocProgress', {
  7823. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7824. total: this.length
  7825. });
  7826. },
  7827. onError: function ChunkedStreamManager_onError(err) {
  7828. this._loadedStreamCapability.reject(err);
  7829. },
  7830. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7831. var chunk = Math.floor(begin / this.chunkSize);
  7832. return chunk;
  7833. },
  7834. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7835. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7836. return chunk;
  7837. }
  7838. };
  7839. return ChunkedStreamManager;
  7840. })();
  7841. // The maximum number of bytes fetched per range request
  7842. var RANGE_CHUNK_SIZE = 65536;
  7843. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7844. var BasePdfManager = (function BasePdfManagerClosure() {
  7845. function BasePdfManager() {
  7846. throw new Error('Cannot initialize BaseManagerManager');
  7847. }
  7848. BasePdfManager.prototype = {
  7849. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7850. throw new NotImplementedException();
  7851. },
  7852. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7853. return this.ensure(this.pdfDocument, prop, args);
  7854. },
  7855. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7856. return this.ensure(this.pdfDocument.xref, prop, args);
  7857. },
  7858. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7859. return this.ensure(this.pdfDocument.catalog, prop, args);
  7860. },
  7861. getPage: function BasePdfManager_pagePage(pageIndex) {
  7862. return this.pdfDocument.getPage(pageIndex);
  7863. },
  7864. cleanup: function BasePdfManager_cleanup() {
  7865. return this.pdfDocument.cleanup();
  7866. },
  7867. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7868. return new NotImplementedException();
  7869. },
  7870. requestRange: function BasePdfManager_ensure(begin, end) {
  7871. return new NotImplementedException();
  7872. },
  7873. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7874. return new NotImplementedException();
  7875. },
  7876. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7877. return new NotImplementedException();
  7878. },
  7879. updatePassword: function BasePdfManager_updatePassword(password) {
  7880. this.pdfDocument.xref.password = this.password = password;
  7881. if (this._passwordChangedCapability) {
  7882. this._passwordChangedCapability.resolve();
  7883. }
  7884. },
  7885. passwordChanged: function BasePdfManager_passwordChanged() {
  7886. this._passwordChangedCapability = createPromiseCapability();
  7887. return this._passwordChangedCapability.promise;
  7888. },
  7889. terminate: function BasePdfManager_terminate() {
  7890. return new NotImplementedException();
  7891. }
  7892. };
  7893. return BasePdfManager;
  7894. })();
  7895. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7896. function LocalPdfManager(data, password) {
  7897. var stream = new Stream(data);
  7898. this.pdfDocument = new PDFDocument(this, stream, password);
  7899. this._loadedStreamCapability = createPromiseCapability();
  7900. this._loadedStreamCapability.resolve(stream);
  7901. }
  7902. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7903. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7904. LocalPdfManager.prototype.ensure =
  7905. function LocalPdfManager_ensure(obj, prop, args) {
  7906. return new Promise(function (resolve, reject) {
  7907. try {
  7908. var value = obj[prop];
  7909. var result;
  7910. if (typeof value === 'function') {
  7911. result = value.apply(obj, args);
  7912. } else {
  7913. result = value;
  7914. }
  7915. resolve(result);
  7916. } catch (e) {
  7917. reject(e);
  7918. }
  7919. });
  7920. };
  7921. LocalPdfManager.prototype.requestRange =
  7922. function LocalPdfManager_requestRange(begin, end) {
  7923. return Promise.resolve();
  7924. };
  7925. LocalPdfManager.prototype.requestLoadedStream =
  7926. function LocalPdfManager_requestLoadedStream() {
  7927. };
  7928. LocalPdfManager.prototype.onLoadedStream =
  7929. function LocalPdfManager_getLoadedStream() {
  7930. return this._loadedStreamCapability.promise;
  7931. };
  7932. LocalPdfManager.prototype.terminate =
  7933. function LocalPdfManager_terminate() {
  7934. return;
  7935. };
  7936. return LocalPdfManager;
  7937. })();
  7938. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7939. function NetworkPdfManager(args, msgHandler) {
  7940. this.msgHandler = msgHandler;
  7941. var params = {
  7942. msgHandler: msgHandler,
  7943. httpHeaders: args.httpHeaders,
  7944. withCredentials: args.withCredentials,
  7945. chunkedViewerLoading: args.chunkedViewerLoading,
  7946. disableAutoFetch: args.disableAutoFetch,
  7947. initialData: args.initialData
  7948. };
  7949. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7950. args.url, params);
  7951. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7952. args.password);
  7953. }
  7954. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7955. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7956. NetworkPdfManager.prototype.ensure =
  7957. function NetworkPdfManager_ensure(obj, prop, args) {
  7958. var pdfManager = this;
  7959. return new Promise(function (resolve, reject) {
  7960. function ensureHelper() {
  7961. try {
  7962. var result;
  7963. var value = obj[prop];
  7964. if (typeof value === 'function') {
  7965. result = value.apply(obj, args);
  7966. } else {
  7967. result = value;
  7968. }
  7969. resolve(result);
  7970. } catch(e) {
  7971. if (!(e instanceof MissingDataException)) {
  7972. reject(e);
  7973. return;
  7974. }
  7975. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7976. }
  7977. }
  7978. ensureHelper();
  7979. });
  7980. };
  7981. NetworkPdfManager.prototype.requestRange =
  7982. function NetworkPdfManager_requestRange(begin, end) {
  7983. return new Promise(function (resolve) {
  7984. this.streamManager.requestRange(begin, end, function() {
  7985. resolve();
  7986. });
  7987. }.bind(this));
  7988. };
  7989. NetworkPdfManager.prototype.requestLoadedStream =
  7990. function NetworkPdfManager_requestLoadedStream() {
  7991. this.streamManager.requestAllChunks();
  7992. };
  7993. NetworkPdfManager.prototype.sendProgressiveData =
  7994. function NetworkPdfManager_sendProgressiveData(chunk) {
  7995. this.streamManager.onReceiveData({ chunk: chunk });
  7996. };
  7997. NetworkPdfManager.prototype.onLoadedStream =
  7998. function NetworkPdfManager_getLoadedStream() {
  7999. return this.streamManager.onLoadedStream();
  8000. };
  8001. NetworkPdfManager.prototype.terminate =
  8002. function NetworkPdfManager_terminate() {
  8003. this.streamManager.networkManager.abortAllRequests();
  8004. };
  8005. return NetworkPdfManager;
  8006. })();
  8007. var Page = (function PageClosure() {
  8008. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  8009. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  8010. this.pdfManager = pdfManager;
  8011. this.pageIndex = pageIndex;
  8012. this.pageDict = pageDict;
  8013. this.xref = xref;
  8014. this.ref = ref;
  8015. this.fontCache = fontCache;
  8016. this.idCounters = {
  8017. obj: 0
  8018. };
  8019. this.resourcesPromise = null;
  8020. }
  8021. Page.prototype = {
  8022. getPageProp: function Page_getPageProp(key) {
  8023. return this.pageDict.get(key);
  8024. },
  8025. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  8026. var dict = this.pageDict, valueArray = null, loopCount = 0;
  8027. var MAX_LOOP_COUNT = 100;
  8028. // Always walk up the entire parent chain, to be able to find
  8029. // e.g. \Resources placed on multiple levels of the tree.
  8030. while (dict) {
  8031. var value = dict.get(key);
  8032. if (value) {
  8033. if (!valueArray) {
  8034. valueArray = [];
  8035. }
  8036. valueArray.push(value);
  8037. }
  8038. if (++loopCount > MAX_LOOP_COUNT) {
  8039. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  8040. break;
  8041. }
  8042. dict = dict.get('Parent');
  8043. }
  8044. if (!valueArray) {
  8045. return Dict.empty;
  8046. }
  8047. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  8048. loopCount > MAX_LOOP_COUNT) {
  8049. return valueArray[0];
  8050. }
  8051. return Dict.merge(this.xref, valueArray);
  8052. },
  8053. get content() {
  8054. return this.getPageProp('Contents');
  8055. },
  8056. get resources() {
  8057. // For robustness: The spec states that a \Resources entry has to be
  8058. // present, but can be empty. Some document omit it still, in this case
  8059. // we return an empty dictionary.
  8060. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  8061. },
  8062. get mediaBox() {
  8063. var obj = this.getInheritedPageProp('MediaBox');
  8064. // Reset invalid media box to letter size.
  8065. if (!isArray(obj) || obj.length !== 4) {
  8066. obj = LETTER_SIZE_MEDIABOX;
  8067. }
  8068. return shadow(this, 'mediaBox', obj);
  8069. },
  8070. get view() {
  8071. var mediaBox = this.mediaBox;
  8072. var cropBox = this.getInheritedPageProp('CropBox');
  8073. if (!isArray(cropBox) || cropBox.length !== 4) {
  8074. return shadow(this, 'view', mediaBox);
  8075. }
  8076. // From the spec, 6th ed., p.963:
  8077. // "The crop, bleed, trim, and art boxes should not ordinarily
  8078. // extend beyond the boundaries of the media box. If they do, they are
  8079. // effectively reduced to their intersection with the media box."
  8080. cropBox = Util.intersect(cropBox, mediaBox);
  8081. if (!cropBox) {
  8082. return shadow(this, 'view', mediaBox);
  8083. }
  8084. return shadow(this, 'view', cropBox);
  8085. },
  8086. get rotate() {
  8087. var rotate = this.getInheritedPageProp('Rotate') || 0;
  8088. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  8089. if (rotate % 90 !== 0) {
  8090. rotate = 0;
  8091. } else if (rotate >= 360) {
  8092. rotate = rotate % 360;
  8093. } else if (rotate < 0) {
  8094. // The spec doesn't cover negatives, assume its counterclockwise
  8095. // rotation. The following is the other implementation of modulo.
  8096. rotate = ((rotate % 360) + 360) % 360;
  8097. }
  8098. return shadow(this, 'rotate', rotate);
  8099. },
  8100. getContentStream: function Page_getContentStream() {
  8101. var content = this.content;
  8102. var stream;
  8103. if (isArray(content)) {
  8104. // fetching items
  8105. var xref = this.xref;
  8106. var i, n = content.length;
  8107. var streams = [];
  8108. for (i = 0; i < n; ++i) {
  8109. streams.push(xref.fetchIfRef(content[i]));
  8110. }
  8111. stream = new StreamsSequenceStream(streams);
  8112. } else if (isStream(content)) {
  8113. stream = content;
  8114. } else {
  8115. // replacing non-existent page content with empty one
  8116. stream = new NullStream();
  8117. }
  8118. return stream;
  8119. },
  8120. loadResources: function Page_loadResources(keys) {
  8121. if (!this.resourcesPromise) {
  8122. // TODO: add async getInheritedPageProp and remove this.
  8123. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  8124. }
  8125. return this.resourcesPromise.then(function resourceSuccess() {
  8126. var objectLoader = new ObjectLoader(this.resources.map,
  8127. keys,
  8128. this.xref);
  8129. return objectLoader.load();
  8130. }.bind(this));
  8131. },
  8132. getOperatorList: function Page_getOperatorList(handler, intent) {
  8133. var self = this;
  8134. var pdfManager = this.pdfManager;
  8135. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8136. []);
  8137. var resourcesPromise = this.loadResources([
  8138. 'ExtGState',
  8139. 'ColorSpace',
  8140. 'Pattern',
  8141. 'Shading',
  8142. 'XObject',
  8143. 'Font'
  8144. // ProcSet
  8145. // Properties
  8146. ]);
  8147. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8148. handler, this.pageIndex,
  8149. 'p' + this.pageIndex + '_',
  8150. this.idCounters,
  8151. this.fontCache);
  8152. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8153. var pageListPromise = dataPromises.then(function(data) {
  8154. var contentStream = data[0];
  8155. var opList = new OperatorList(intent, handler, self.pageIndex);
  8156. handler.send('StartRenderPage', {
  8157. transparency: partialEvaluator.hasBlendModes(self.resources),
  8158. pageIndex: self.pageIndex,
  8159. intent: intent
  8160. });
  8161. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8162. opList).then(function () {
  8163. return opList;
  8164. });
  8165. });
  8166. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8167. return Promise.all([pageListPromise, annotationsPromise]).then(
  8168. function(datas) {
  8169. var pageOpList = datas[0];
  8170. var annotations = datas[1];
  8171. if (annotations.length === 0) {
  8172. pageOpList.flush(true);
  8173. return pageOpList;
  8174. }
  8175. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8176. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8177. return annotationsReadyPromise.then(function () {
  8178. pageOpList.flush(true);
  8179. return pageOpList;
  8180. });
  8181. });
  8182. },
  8183. extractTextContent: function Page_extractTextContent() {
  8184. var handler = {
  8185. on: function nullHandlerOn() {},
  8186. send: function nullHandlerSend() {}
  8187. };
  8188. var self = this;
  8189. var pdfManager = this.pdfManager;
  8190. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8191. []);
  8192. var resourcesPromise = this.loadResources([
  8193. 'ExtGState',
  8194. 'XObject',
  8195. 'Font'
  8196. ]);
  8197. var dataPromises = Promise.all([contentStreamPromise,
  8198. resourcesPromise]);
  8199. return dataPromises.then(function(data) {
  8200. var contentStream = data[0];
  8201. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8202. handler, self.pageIndex,
  8203. 'p' + self.pageIndex + '_',
  8204. self.idCounters,
  8205. self.fontCache);
  8206. return partialEvaluator.getTextContent(contentStream,
  8207. self.resources);
  8208. });
  8209. },
  8210. getAnnotationsData: function Page_getAnnotationsData() {
  8211. var annotations = this.annotations;
  8212. var annotationsData = [];
  8213. for (var i = 0, n = annotations.length; i < n; ++i) {
  8214. annotationsData.push(annotations[i].data);
  8215. }
  8216. return annotationsData;
  8217. },
  8218. get annotations() {
  8219. var annotations = [];
  8220. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  8221. var annotationFactory = new AnnotationFactory();
  8222. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8223. var annotationRef = annotationRefs[i];
  8224. var annotation = annotationFactory.create(this.xref, annotationRef);
  8225. if (annotation &&
  8226. (annotation.isViewable() || annotation.isPrintable())) {
  8227. annotations.push(annotation);
  8228. }
  8229. }
  8230. return shadow(this, 'annotations', annotations);
  8231. }
  8232. };
  8233. return Page;
  8234. })();
  8235. /**
  8236. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8237. * `PDFDoc`, this one doesn't have any job management code.
  8238. * Right now there exists one PDFDocument on the main thread + one object
  8239. * for each worker. If there is no worker support enabled, there are two
  8240. * `PDFDocument` objects on the main thread created.
  8241. */
  8242. var PDFDocument = (function PDFDocumentClosure() {
  8243. var FINGERPRINT_FIRST_BYTES = 1024;
  8244. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8245. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8246. function PDFDocument(pdfManager, arg, password) {
  8247. if (isStream(arg)) {
  8248. init.call(this, pdfManager, arg, password);
  8249. } else if (isArrayBuffer(arg)) {
  8250. init.call(this, pdfManager, new Stream(arg), password);
  8251. } else {
  8252. error('PDFDocument: Unknown argument type');
  8253. }
  8254. }
  8255. function init(pdfManager, stream, password) {
  8256. assert(stream.length > 0, 'stream must have data');
  8257. this.pdfManager = pdfManager;
  8258. this.stream = stream;
  8259. var xref = new XRef(this.stream, password, pdfManager);
  8260. this.xref = xref;
  8261. }
  8262. function find(stream, needle, limit, backwards) {
  8263. var pos = stream.pos;
  8264. var end = stream.end;
  8265. var strBuf = [];
  8266. if (pos + limit > end) {
  8267. limit = end - pos;
  8268. }
  8269. for (var n = 0; n < limit; ++n) {
  8270. strBuf.push(String.fromCharCode(stream.getByte()));
  8271. }
  8272. var str = strBuf.join('');
  8273. stream.pos = pos;
  8274. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8275. if (index === -1) {
  8276. return false; /* not found */
  8277. }
  8278. stream.pos += index;
  8279. return true; /* found */
  8280. }
  8281. var DocumentInfoValidators = {
  8282. get entries() {
  8283. // Lazily build this since all the validation functions below are not
  8284. // defined until after this file loads.
  8285. return shadow(this, 'entries', {
  8286. Title: isString,
  8287. Author: isString,
  8288. Subject: isString,
  8289. Keywords: isString,
  8290. Creator: isString,
  8291. Producer: isString,
  8292. CreationDate: isString,
  8293. ModDate: isString,
  8294. Trapped: isName
  8295. });
  8296. }
  8297. };
  8298. PDFDocument.prototype = {
  8299. parse: function PDFDocument_parse(recoveryMode) {
  8300. this.setup(recoveryMode);
  8301. var version = this.catalog.catDict.get('Version');
  8302. if (isName(version)) {
  8303. this.pdfFormatVersion = version.name;
  8304. }
  8305. try {
  8306. // checking if AcroForm is present
  8307. this.acroForm = this.catalog.catDict.get('AcroForm');
  8308. if (this.acroForm) {
  8309. this.xfa = this.acroForm.get('XFA');
  8310. var fields = this.acroForm.get('Fields');
  8311. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8312. !this.xfa) {
  8313. // no fields and no XFA -- not a form (?)
  8314. this.acroForm = null;
  8315. }
  8316. }
  8317. } catch (ex) {
  8318. info('Something wrong with AcroForm entry');
  8319. this.acroForm = null;
  8320. }
  8321. },
  8322. get linearization() {
  8323. var linearization = null;
  8324. if (this.stream.length) {
  8325. try {
  8326. linearization = Linearization.create(this.stream);
  8327. } catch (err) {
  8328. if (err instanceof MissingDataException) {
  8329. throw err;
  8330. }
  8331. info(err);
  8332. }
  8333. }
  8334. // shadow the prototype getter with a data property
  8335. return shadow(this, 'linearization', linearization);
  8336. },
  8337. get startXRef() {
  8338. var stream = this.stream;
  8339. var startXRef = 0;
  8340. var linearization = this.linearization;
  8341. if (linearization) {
  8342. // Find end of first obj.
  8343. stream.reset();
  8344. if (find(stream, 'endobj', 1024)) {
  8345. startXRef = stream.pos + 6;
  8346. }
  8347. } else {
  8348. // Find startxref by jumping backward from the end of the file.
  8349. var step = 1024;
  8350. var found = false, pos = stream.end;
  8351. while (!found && pos > 0) {
  8352. pos -= step - 'startxref'.length;
  8353. if (pos < 0) {
  8354. pos = 0;
  8355. }
  8356. stream.pos = pos;
  8357. found = find(stream, 'startxref', step, true);
  8358. }
  8359. if (found) {
  8360. stream.skip(9);
  8361. var ch;
  8362. do {
  8363. ch = stream.getByte();
  8364. } while (Lexer.isSpace(ch));
  8365. var str = '';
  8366. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8367. str += String.fromCharCode(ch);
  8368. ch = stream.getByte();
  8369. }
  8370. startXRef = parseInt(str, 10);
  8371. if (isNaN(startXRef)) {
  8372. startXRef = 0;
  8373. }
  8374. }
  8375. }
  8376. // shadow the prototype getter with a data property
  8377. return shadow(this, 'startXRef', startXRef);
  8378. },
  8379. get mainXRefEntriesOffset() {
  8380. var mainXRefEntriesOffset = 0;
  8381. var linearization = this.linearization;
  8382. if (linearization) {
  8383. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8384. }
  8385. // shadow the prototype getter with a data property
  8386. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8387. },
  8388. // Find the header, remove leading garbage and setup the stream
  8389. // starting from the header.
  8390. checkHeader: function PDFDocument_checkHeader() {
  8391. var stream = this.stream;
  8392. stream.reset();
  8393. if (find(stream, '%PDF-', 1024)) {
  8394. // Found the header, trim off any garbage before it.
  8395. stream.moveStart();
  8396. // Reading file format version
  8397. var MAX_VERSION_LENGTH = 12;
  8398. var version = '', ch;
  8399. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8400. if (version.length >= MAX_VERSION_LENGTH) {
  8401. break;
  8402. }
  8403. version += String.fromCharCode(ch);
  8404. }
  8405. if (!this.pdfFormatVersion) {
  8406. // removing "%PDF-"-prefix
  8407. this.pdfFormatVersion = version.substring(5);
  8408. }
  8409. return;
  8410. }
  8411. // May not be a PDF file, continue anyway.
  8412. },
  8413. parseStartXRef: function PDFDocument_parseStartXRef() {
  8414. var startXRef = this.startXRef;
  8415. this.xref.setStartXRef(startXRef);
  8416. },
  8417. setup: function PDFDocument_setup(recoveryMode) {
  8418. this.xref.parse(recoveryMode);
  8419. this.catalog = new Catalog(this.pdfManager, this.xref);
  8420. },
  8421. get numPages() {
  8422. var linearization = this.linearization;
  8423. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8424. // shadow the prototype getter
  8425. return shadow(this, 'numPages', num);
  8426. },
  8427. get documentInfo() {
  8428. var docInfo = {
  8429. PDFFormatVersion: this.pdfFormatVersion,
  8430. IsAcroFormPresent: !!this.acroForm,
  8431. IsXFAPresent: !!this.xfa
  8432. };
  8433. var infoDict;
  8434. try {
  8435. infoDict = this.xref.trailer.get('Info');
  8436. } catch (err) {
  8437. info('The document information dictionary is invalid.');
  8438. }
  8439. if (infoDict) {
  8440. var validEntries = DocumentInfoValidators.entries;
  8441. // Only fill the document info with valid entries from the spec.
  8442. for (var key in validEntries) {
  8443. if (infoDict.has(key)) {
  8444. var value = infoDict.get(key);
  8445. // Make sure the value conforms to the spec.
  8446. if (validEntries[key](value)) {
  8447. docInfo[key] = (typeof value !== 'string' ?
  8448. value : stringToPDFString(value));
  8449. } else {
  8450. info('Bad value in document info for "' + key + '"');
  8451. }
  8452. }
  8453. }
  8454. }
  8455. return shadow(this, 'documentInfo', docInfo);
  8456. },
  8457. get fingerprint() {
  8458. var xref = this.xref, hash, fileID = '';
  8459. var idArray = xref.trailer.get('ID');
  8460. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  8461. idArray[0] !== EMPTY_FINGERPRINT) {
  8462. hash = stringToBytes(idArray[0]);
  8463. } else {
  8464. if (this.stream.ensureRange) {
  8465. this.stream.ensureRange(0,
  8466. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8467. }
  8468. hash = calculateMD5(this.stream.bytes.subarray(0,
  8469. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8470. }
  8471. for (var i = 0, n = hash.length; i < n; i++) {
  8472. var hex = hash[i].toString(16);
  8473. fileID += hex.length === 1 ? '0' + hex : hex;
  8474. }
  8475. return shadow(this, 'fingerprint', fileID);
  8476. },
  8477. getPage: function PDFDocument_getPage(pageIndex) {
  8478. return this.catalog.getPage(pageIndex);
  8479. },
  8480. cleanup: function PDFDocument_cleanup() {
  8481. return this.catalog.cleanup();
  8482. }
  8483. };
  8484. return PDFDocument;
  8485. })();
  8486. var Name = (function NameClosure() {
  8487. function Name(name) {
  8488. this.name = name;
  8489. }
  8490. Name.prototype = {};
  8491. var nameCache = {};
  8492. Name.get = function Name_get(name) {
  8493. var nameValue = nameCache[name];
  8494. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8495. };
  8496. return Name;
  8497. })();
  8498. var Cmd = (function CmdClosure() {
  8499. function Cmd(cmd) {
  8500. this.cmd = cmd;
  8501. }
  8502. Cmd.prototype = {};
  8503. var cmdCache = {};
  8504. Cmd.get = function Cmd_get(cmd) {
  8505. var cmdValue = cmdCache[cmd];
  8506. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8507. };
  8508. return Cmd;
  8509. })();
  8510. var Dict = (function DictClosure() {
  8511. var nonSerializable = function nonSerializableClosure() {
  8512. return nonSerializable; // creating closure on some variable
  8513. };
  8514. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8515. 'Background': true,
  8516. 'ExtGState': true,
  8517. 'Halftone': true,
  8518. 'Layout': true,
  8519. 'Mask': true,
  8520. 'Pagination': true,
  8521. 'Printing': true
  8522. };
  8523. function isRecursionAllowedFor(dict) {
  8524. if (!isName(dict.Type)) {
  8525. return true;
  8526. }
  8527. var dictType = dict.Type.name;
  8528. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8529. }
  8530. // xref is optional
  8531. function Dict(xref) {
  8532. // Map should only be used internally, use functions below to access.
  8533. this.map = Object.create(null);
  8534. this.xref = xref;
  8535. this.objId = null;
  8536. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8537. }
  8538. Dict.prototype = {
  8539. assignXref: function Dict_assignXref(newXref) {
  8540. this.xref = newXref;
  8541. },
  8542. // automatically dereferences Ref objects
  8543. get: function Dict_get(key1, key2, key3) {
  8544. var value;
  8545. var xref = this.xref;
  8546. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8547. typeof key2 === 'undefined') {
  8548. return xref ? xref.fetchIfRef(value) : value;
  8549. }
  8550. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8551. typeof key3 === 'undefined') {
  8552. return xref ? xref.fetchIfRef(value) : value;
  8553. }
  8554. value = this.map[key3] || null;
  8555. return xref ? xref.fetchIfRef(value) : value;
  8556. },
  8557. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8558. getAsync: function Dict_getAsync(key1, key2, key3) {
  8559. var value;
  8560. var xref = this.xref;
  8561. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8562. typeof key2 === 'undefined') {
  8563. if (xref) {
  8564. return xref.fetchIfRefAsync(value);
  8565. }
  8566. return Promise.resolve(value);
  8567. }
  8568. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8569. typeof key3 === 'undefined') {
  8570. if (xref) {
  8571. return xref.fetchIfRefAsync(value);
  8572. }
  8573. return Promise.resolve(value);
  8574. }
  8575. value = this.map[key3] || null;
  8576. if (xref) {
  8577. return xref.fetchIfRefAsync(value);
  8578. }
  8579. return Promise.resolve(value);
  8580. },
  8581. // Same as get(), but dereferences all elements if the result is an Array.
  8582. getArray: function Dict_getArray(key1, key2, key3) {
  8583. var value = this.get(key1, key2, key3);
  8584. var xref = this.xref;
  8585. if (!isArray(value) || !xref) {
  8586. return value;
  8587. }
  8588. value = value.slice(); // Ensure that we don't modify the Dict data.
  8589. for (var i = 0, ii = value.length; i < ii; i++) {
  8590. if (!isRef(value[i])) {
  8591. continue;
  8592. }
  8593. value[i] = xref.fetch(value[i]);
  8594. }
  8595. return value;
  8596. },
  8597. // no dereferencing
  8598. getRaw: function Dict_getRaw(key) {
  8599. return this.map[key];
  8600. },
  8601. // creates new map and dereferences all Refs
  8602. getAll: function Dict_getAll() {
  8603. var all = Object.create(null);
  8604. var queue = null;
  8605. var key, obj;
  8606. for (key in this.map) {
  8607. obj = this.get(key);
  8608. if (obj instanceof Dict) {
  8609. if (isRecursionAllowedFor(obj)) {
  8610. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8611. } else {
  8612. all[key] = this.getRaw(key);
  8613. }
  8614. } else {
  8615. all[key] = obj;
  8616. }
  8617. }
  8618. if (!queue) {
  8619. return all;
  8620. }
  8621. // trying to take cyclic references into the account
  8622. var processed = Object.create(null);
  8623. while (queue.length > 0) {
  8624. var item = queue.shift();
  8625. var itemObj = item.obj;
  8626. var objId = itemObj.objId;
  8627. if (objId && objId in processed) {
  8628. item.target[item.key] = processed[objId];
  8629. continue;
  8630. }
  8631. var dereferenced = Object.create(null);
  8632. for (key in itemObj.map) {
  8633. obj = itemObj.get(key);
  8634. if (obj instanceof Dict) {
  8635. if (isRecursionAllowedFor(obj)) {
  8636. queue.push({target: dereferenced, key: key, obj: obj});
  8637. } else {
  8638. dereferenced[key] = itemObj.getRaw(key);
  8639. }
  8640. } else {
  8641. dereferenced[key] = obj;
  8642. }
  8643. }
  8644. if (objId) {
  8645. processed[objId] = dereferenced;
  8646. }
  8647. item.target[item.key] = dereferenced;
  8648. }
  8649. return all;
  8650. },
  8651. getKeys: function Dict_getKeys() {
  8652. return Object.keys(this.map);
  8653. },
  8654. set: function Dict_set(key, value) {
  8655. this.map[key] = value;
  8656. },
  8657. has: function Dict_has(key) {
  8658. return key in this.map;
  8659. },
  8660. forEach: function Dict_forEach(callback) {
  8661. for (var key in this.map) {
  8662. callback(key, this.get(key));
  8663. }
  8664. }
  8665. };
  8666. Dict.empty = new Dict(null);
  8667. Dict.merge = function Dict_merge(xref, dictArray) {
  8668. var mergedDict = new Dict(xref);
  8669. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  8670. var dict = dictArray[i];
  8671. if (!isDict(dict)) {
  8672. continue;
  8673. }
  8674. for (var keyName in dict.map) {
  8675. if (mergedDict.map[keyName]) {
  8676. continue;
  8677. }
  8678. mergedDict.map[keyName] = dict.map[keyName];
  8679. }
  8680. }
  8681. return mergedDict;
  8682. };
  8683. return Dict;
  8684. })();
  8685. var Ref = (function RefClosure() {
  8686. function Ref(num, gen) {
  8687. this.num = num;
  8688. this.gen = gen;
  8689. }
  8690. Ref.prototype = {
  8691. toString: function Ref_toString() {
  8692. // This function is hot, so we make the string as compact as possible.
  8693. // |this.gen| is almost always zero, so we treat that case specially.
  8694. var str = this.num + 'R';
  8695. if (this.gen !== 0) {
  8696. str += this.gen;
  8697. }
  8698. return str;
  8699. }
  8700. };
  8701. return Ref;
  8702. })();
  8703. // The reference is identified by number and generation.
  8704. // This structure stores only one instance of the reference.
  8705. var RefSet = (function RefSetClosure() {
  8706. function RefSet() {
  8707. this.dict = {};
  8708. }
  8709. RefSet.prototype = {
  8710. has: function RefSet_has(ref) {
  8711. return ref.toString() in this.dict;
  8712. },
  8713. put: function RefSet_put(ref) {
  8714. this.dict[ref.toString()] = true;
  8715. },
  8716. remove: function RefSet_remove(ref) {
  8717. delete this.dict[ref.toString()];
  8718. }
  8719. };
  8720. return RefSet;
  8721. })();
  8722. var RefSetCache = (function RefSetCacheClosure() {
  8723. function RefSetCache() {
  8724. this.dict = Object.create(null);
  8725. }
  8726. RefSetCache.prototype = {
  8727. get: function RefSetCache_get(ref) {
  8728. return this.dict[ref.toString()];
  8729. },
  8730. has: function RefSetCache_has(ref) {
  8731. return ref.toString() in this.dict;
  8732. },
  8733. put: function RefSetCache_put(ref, obj) {
  8734. this.dict[ref.toString()] = obj;
  8735. },
  8736. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8737. this.dict[ref.toString()] = this.get(aliasRef);
  8738. },
  8739. forEach: function RefSetCache_forEach(fn, thisArg) {
  8740. for (var i in this.dict) {
  8741. fn.call(thisArg, this.dict[i]);
  8742. }
  8743. },
  8744. clear: function RefSetCache_clear() {
  8745. this.dict = Object.create(null);
  8746. }
  8747. };
  8748. return RefSetCache;
  8749. })();
  8750. var Catalog = (function CatalogClosure() {
  8751. function Catalog(pdfManager, xref) {
  8752. this.pdfManager = pdfManager;
  8753. this.xref = xref;
  8754. this.catDict = xref.getCatalogObj();
  8755. this.fontCache = new RefSetCache();
  8756. assert(isDict(this.catDict),
  8757. 'catalog object is not a dictionary');
  8758. this.pagePromises = [];
  8759. }
  8760. Catalog.prototype = {
  8761. get metadata() {
  8762. var streamRef = this.catDict.getRaw('Metadata');
  8763. if (!isRef(streamRef)) {
  8764. return shadow(this, 'metadata', null);
  8765. }
  8766. var encryptMetadata = (!this.xref.encrypt ? false :
  8767. this.xref.encrypt.encryptMetadata);
  8768. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8769. var metadata;
  8770. if (stream && isDict(stream.dict)) {
  8771. var type = stream.dict.get('Type');
  8772. var subtype = stream.dict.get('Subtype');
  8773. if (isName(type) && isName(subtype) &&
  8774. type.name === 'Metadata' && subtype.name === 'XML') {
  8775. // XXX: This should examine the charset the XML document defines,
  8776. // however since there are currently no real means to decode
  8777. // arbitrary charsets, let's just hope that the author of the PDF
  8778. // was reasonable enough to stick with the XML default charset,
  8779. // which is UTF-8.
  8780. try {
  8781. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8782. } catch (e) {
  8783. info('Skipping invalid metadata.');
  8784. }
  8785. }
  8786. }
  8787. return shadow(this, 'metadata', metadata);
  8788. },
  8789. get toplevelPagesDict() {
  8790. var pagesObj = this.catDict.get('Pages');
  8791. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8792. // shadow the prototype getter
  8793. return shadow(this, 'toplevelPagesDict', pagesObj);
  8794. },
  8795. get documentOutline() {
  8796. var obj = null;
  8797. try {
  8798. obj = this.readDocumentOutline();
  8799. } catch (ex) {
  8800. if (ex instanceof MissingDataException) {
  8801. throw ex;
  8802. }
  8803. warn('Unable to read document outline');
  8804. }
  8805. return shadow(this, 'documentOutline', obj);
  8806. },
  8807. readDocumentOutline: function Catalog_readDocumentOutline() {
  8808. var xref = this.xref;
  8809. var obj = this.catDict.get('Outlines');
  8810. var root = { items: [] };
  8811. if (isDict(obj)) {
  8812. obj = obj.getRaw('First');
  8813. var processed = new RefSet();
  8814. if (isRef(obj)) {
  8815. var queue = [{obj: obj, parent: root}];
  8816. // to avoid recursion keeping track of the items
  8817. // in the processed dictionary
  8818. processed.put(obj);
  8819. while (queue.length > 0) {
  8820. var i = queue.shift();
  8821. var outlineDict = xref.fetchIfRef(i.obj);
  8822. if (outlineDict === null) {
  8823. continue;
  8824. }
  8825. if (!outlineDict.has('Title')) {
  8826. error('Invalid outline item');
  8827. }
  8828. var dest = outlineDict.get('A');
  8829. if (dest) {
  8830. dest = dest.get('D');
  8831. } else if (outlineDict.has('Dest')) {
  8832. dest = outlineDict.getRaw('Dest');
  8833. if (isName(dest)) {
  8834. dest = dest.name;
  8835. }
  8836. }
  8837. var title = outlineDict.get('Title');
  8838. var outlineItem = {
  8839. dest: dest,
  8840. title: stringToPDFString(title),
  8841. color: outlineDict.get('C') || [0, 0, 0],
  8842. count: outlineDict.get('Count'),
  8843. bold: !!(outlineDict.get('F') & 2),
  8844. italic: !!(outlineDict.get('F') & 1),
  8845. items: []
  8846. };
  8847. i.parent.items.push(outlineItem);
  8848. obj = outlineDict.getRaw('First');
  8849. if (isRef(obj) && !processed.has(obj)) {
  8850. queue.push({obj: obj, parent: outlineItem});
  8851. processed.put(obj);
  8852. }
  8853. obj = outlineDict.getRaw('Next');
  8854. if (isRef(obj) && !processed.has(obj)) {
  8855. queue.push({obj: obj, parent: i.parent});
  8856. processed.put(obj);
  8857. }
  8858. }
  8859. }
  8860. }
  8861. return (root.items.length > 0 ? root.items : null);
  8862. },
  8863. get numPages() {
  8864. var obj = this.toplevelPagesDict.get('Count');
  8865. assert(
  8866. isInt(obj),
  8867. 'page count in top level pages object is not an integer'
  8868. );
  8869. // shadow the prototype getter
  8870. return shadow(this, 'num', obj);
  8871. },
  8872. get destinations() {
  8873. function fetchDestination(dest) {
  8874. return isDict(dest) ? dest.get('D') : dest;
  8875. }
  8876. var xref = this.xref;
  8877. var dests = {}, nameTreeRef, nameDictionaryRef;
  8878. var obj = this.catDict.get('Names');
  8879. if (obj && obj.has('Dests')) {
  8880. nameTreeRef = obj.getRaw('Dests');
  8881. } else if (this.catDict.has('Dests')) {
  8882. nameDictionaryRef = this.catDict.get('Dests');
  8883. }
  8884. if (nameDictionaryRef) {
  8885. // reading simple destination dictionary
  8886. obj = nameDictionaryRef;
  8887. obj.forEach(function catalogForEach(key, value) {
  8888. if (!value) {
  8889. return;
  8890. }
  8891. dests[key] = fetchDestination(value);
  8892. });
  8893. }
  8894. if (nameTreeRef) {
  8895. var nameTree = new NameTree(nameTreeRef, xref);
  8896. var names = nameTree.getAll();
  8897. for (var name in names) {
  8898. if (!names.hasOwnProperty(name)) {
  8899. continue;
  8900. }
  8901. dests[name] = fetchDestination(names[name]);
  8902. }
  8903. }
  8904. return shadow(this, 'destinations', dests);
  8905. },
  8906. getDestination: function Catalog_getDestination(destinationId) {
  8907. function fetchDestination(dest) {
  8908. return isDict(dest) ? dest.get('D') : dest;
  8909. }
  8910. var xref = this.xref;
  8911. var dest = null, nameTreeRef, nameDictionaryRef;
  8912. var obj = this.catDict.get('Names');
  8913. if (obj && obj.has('Dests')) {
  8914. nameTreeRef = obj.getRaw('Dests');
  8915. } else if (this.catDict.has('Dests')) {
  8916. nameDictionaryRef = this.catDict.get('Dests');
  8917. }
  8918. if (nameDictionaryRef) { // Simple destination dictionary.
  8919. var value = nameDictionaryRef.get(destinationId);
  8920. if (value) {
  8921. dest = fetchDestination(value);
  8922. }
  8923. }
  8924. if (nameTreeRef) {
  8925. var nameTree = new NameTree(nameTreeRef, xref);
  8926. dest = fetchDestination(nameTree.get(destinationId));
  8927. }
  8928. return dest;
  8929. },
  8930. get attachments() {
  8931. var xref = this.xref;
  8932. var attachments = null, nameTreeRef;
  8933. var obj = this.catDict.get('Names');
  8934. if (obj) {
  8935. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8936. }
  8937. if (nameTreeRef) {
  8938. var nameTree = new NameTree(nameTreeRef, xref);
  8939. var names = nameTree.getAll();
  8940. for (var name in names) {
  8941. if (!names.hasOwnProperty(name)) {
  8942. continue;
  8943. }
  8944. var fs = new FileSpec(names[name], xref);
  8945. if (!attachments) {
  8946. attachments = {};
  8947. }
  8948. attachments[stringToPDFString(name)] = fs.serializable;
  8949. }
  8950. }
  8951. return shadow(this, 'attachments', attachments);
  8952. },
  8953. get javaScript() {
  8954. var xref = this.xref;
  8955. var obj = this.catDict.get('Names');
  8956. var javaScript = [];
  8957. function appendIfJavaScriptDict(jsDict) {
  8958. var type = jsDict.get('S');
  8959. if (!isName(type) || type.name !== 'JavaScript') {
  8960. return;
  8961. }
  8962. var js = jsDict.get('JS');
  8963. if (isStream(js)) {
  8964. js = bytesToString(js.getBytes());
  8965. } else if (!isString(js)) {
  8966. return;
  8967. }
  8968. javaScript.push(stringToPDFString(js));
  8969. }
  8970. if (obj && obj.has('JavaScript')) {
  8971. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8972. var names = nameTree.getAll();
  8973. for (var name in names) {
  8974. if (!names.hasOwnProperty(name)) {
  8975. continue;
  8976. }
  8977. // We don't really use the JavaScript right now. This code is
  8978. // defensive so we don't cause errors on document load.
  8979. var jsDict = names[name];
  8980. if (isDict(jsDict)) {
  8981. appendIfJavaScriptDict(jsDict);
  8982. }
  8983. }
  8984. }
  8985. // Append OpenAction actions to javaScript array
  8986. var openactionDict = this.catDict.get('OpenAction');
  8987. if (isDict(openactionDict, 'Action')) {
  8988. var actionType = openactionDict.get('S');
  8989. if (isName(actionType) && actionType.name === 'Named') {
  8990. // The named Print action is not a part of the PDF 1.7 specification,
  8991. // but is supported by many PDF readers/writers (including Adobe's).
  8992. var action = openactionDict.get('N');
  8993. if (isName(action) && action.name === 'Print') {
  8994. javaScript.push('print({});');
  8995. }
  8996. } else {
  8997. appendIfJavaScriptDict(openactionDict);
  8998. }
  8999. }
  9000. return shadow(this, 'javaScript', javaScript);
  9001. },
  9002. cleanup: function Catalog_cleanup() {
  9003. var promises = [];
  9004. this.fontCache.forEach(function (promise) {
  9005. promises.push(promise);
  9006. });
  9007. return Promise.all(promises).then(function (translatedFonts) {
  9008. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  9009. var font = translatedFonts[i].dict;
  9010. delete font.translated;
  9011. }
  9012. this.fontCache.clear();
  9013. }.bind(this));
  9014. },
  9015. getPage: function Catalog_getPage(pageIndex) {
  9016. if (!(pageIndex in this.pagePromises)) {
  9017. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  9018. function (a) {
  9019. var dict = a[0];
  9020. var ref = a[1];
  9021. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  9022. this.fontCache);
  9023. }.bind(this)
  9024. );
  9025. }
  9026. return this.pagePromises[pageIndex];
  9027. },
  9028. getPageDict: function Catalog_getPageDict(pageIndex) {
  9029. var capability = createPromiseCapability();
  9030. var nodesToVisit = [this.catDict.getRaw('Pages')];
  9031. var currentPageIndex = 0;
  9032. var xref = this.xref;
  9033. var checkAllKids = false;
  9034. function next() {
  9035. while (nodesToVisit.length) {
  9036. var currentNode = nodesToVisit.pop();
  9037. if (isRef(currentNode)) {
  9038. xref.fetchAsync(currentNode).then(function (obj) {
  9039. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  9040. if (pageIndex === currentPageIndex) {
  9041. capability.resolve([obj, currentNode]);
  9042. } else {
  9043. currentPageIndex++;
  9044. next();
  9045. }
  9046. return;
  9047. }
  9048. nodesToVisit.push(obj);
  9049. next();
  9050. }, capability.reject);
  9051. return;
  9052. }
  9053. // Must be a child page dictionary.
  9054. assert(
  9055. isDict(currentNode),
  9056. 'page dictionary kid reference points to wrong type of object'
  9057. );
  9058. var count = currentNode.get('Count');
  9059. // If the current node doesn't have any children, avoid getting stuck
  9060. // in an empty node further down in the tree (see issue5644.pdf).
  9061. if (count === 0) {
  9062. checkAllKids = true;
  9063. }
  9064. // Skip nodes where the page can't be.
  9065. if (currentPageIndex + count <= pageIndex) {
  9066. currentPageIndex += count;
  9067. continue;
  9068. }
  9069. var kids = currentNode.get('Kids');
  9070. assert(isArray(kids), 'page dictionary kids object is not an array');
  9071. if (!checkAllKids && count === kids.length) {
  9072. // Nodes that don't have the page have been skipped and this is the
  9073. // bottom of the tree which means the page requested must be a
  9074. // descendant of this pages node. Ideally we would just resolve the
  9075. // promise with the page ref here, but there is the case where more
  9076. // pages nodes could link to single a page (see issue 3666 pdf). To
  9077. // handle this push it back on the queue so if it is a pages node it
  9078. // will be descended into.
  9079. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  9080. currentPageIndex = pageIndex;
  9081. continue;
  9082. } else {
  9083. for (var last = kids.length - 1; last >= 0; last--) {
  9084. nodesToVisit.push(kids[last]);
  9085. }
  9086. }
  9087. }
  9088. capability.reject('Page index ' + pageIndex + ' not found.');
  9089. }
  9090. next();
  9091. return capability.promise;
  9092. },
  9093. getPageIndex: function Catalog_getPageIndex(ref) {
  9094. // The page tree nodes have the count of all the leaves below them. To get
  9095. // how many pages are before we just have to walk up the tree and keep
  9096. // adding the count of siblings to the left of the node.
  9097. var xref = this.xref;
  9098. function pagesBeforeRef(kidRef) {
  9099. var total = 0;
  9100. var parentRef;
  9101. return xref.fetchAsync(kidRef).then(function (node) {
  9102. if (!node) {
  9103. return null;
  9104. }
  9105. parentRef = node.getRaw('Parent');
  9106. return node.getAsync('Parent');
  9107. }).then(function (parent) {
  9108. if (!parent) {
  9109. return null;
  9110. }
  9111. return parent.getAsync('Kids');
  9112. }).then(function (kids) {
  9113. if (!kids) {
  9114. return null;
  9115. }
  9116. var kidPromises = [];
  9117. var found = false;
  9118. for (var i = 0; i < kids.length; i++) {
  9119. var kid = kids[i];
  9120. assert(isRef(kid), 'kids must be a ref');
  9121. if (kid.num === kidRef.num) {
  9122. found = true;
  9123. break;
  9124. }
  9125. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  9126. if (kid.has('Count')) {
  9127. var count = kid.get('Count');
  9128. total += count;
  9129. } else { // page leaf node
  9130. total++;
  9131. }
  9132. }));
  9133. }
  9134. if (!found) {
  9135. error('kid ref not found in parents kids');
  9136. }
  9137. return Promise.all(kidPromises).then(function () {
  9138. return [total, parentRef];
  9139. });
  9140. });
  9141. }
  9142. var total = 0;
  9143. function next(ref) {
  9144. return pagesBeforeRef(ref).then(function (args) {
  9145. if (!args) {
  9146. return total;
  9147. }
  9148. var count = args[0];
  9149. var parentRef = args[1];
  9150. total += count;
  9151. return next(parentRef);
  9152. });
  9153. }
  9154. return next(ref);
  9155. }
  9156. };
  9157. return Catalog;
  9158. })();
  9159. var XRef = (function XRefClosure() {
  9160. function XRef(stream, password) {
  9161. this.stream = stream;
  9162. this.entries = [];
  9163. this.xrefstms = {};
  9164. // prepare the XRef cache
  9165. this.cache = [];
  9166. this.password = password;
  9167. this.stats = {
  9168. streamTypes: [],
  9169. fontTypes: []
  9170. };
  9171. }
  9172. XRef.prototype = {
  9173. setStartXRef: function XRef_setStartXRef(startXRef) {
  9174. // Store the starting positions of xref tables as we process them
  9175. // so we can recover from missing data errors
  9176. this.startXRefQueue = [startXRef];
  9177. },
  9178. parse: function XRef_parse(recoveryMode) {
  9179. var trailerDict;
  9180. if (!recoveryMode) {
  9181. trailerDict = this.readXRef();
  9182. } else {
  9183. warn('Indexing all PDF objects');
  9184. trailerDict = this.indexObjects();
  9185. }
  9186. trailerDict.assignXref(this);
  9187. this.trailer = trailerDict;
  9188. var encrypt = trailerDict.get('Encrypt');
  9189. if (encrypt) {
  9190. var ids = trailerDict.get('ID');
  9191. var fileId = (ids && ids.length) ? ids[0] : '';
  9192. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9193. this.password);
  9194. }
  9195. // get the root dictionary (catalog) object
  9196. if (!(this.root = trailerDict.get('Root'))) {
  9197. error('Invalid root reference');
  9198. }
  9199. },
  9200. processXRefTable: function XRef_processXRefTable(parser) {
  9201. if (!('tableState' in this)) {
  9202. // Stores state of the table as we process it so we can resume
  9203. // from middle of table in case of missing data error
  9204. this.tableState = {
  9205. entryNum: 0,
  9206. streamPos: parser.lexer.stream.pos,
  9207. parserBuf1: parser.buf1,
  9208. parserBuf2: parser.buf2
  9209. };
  9210. }
  9211. var obj = this.readXRefTable(parser);
  9212. // Sanity check
  9213. if (!isCmd(obj, 'trailer')) {
  9214. error('Invalid XRef table: could not find trailer dictionary');
  9215. }
  9216. // Read trailer dictionary, e.g.
  9217. // trailer
  9218. // << /Size 22
  9219. // /Root 20R
  9220. // /Info 10R
  9221. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9222. // >>
  9223. // The parser goes through the entire stream << ... >> and provides
  9224. // a getter interface for the key-value table
  9225. var dict = parser.getObj();
  9226. // The pdflib PDF generator can generate a nested trailer dictionary
  9227. if (!isDict(dict) && dict.dict) {
  9228. dict = dict.dict;
  9229. }
  9230. if (!isDict(dict)) {
  9231. error('Invalid XRef table: could not parse trailer dictionary');
  9232. }
  9233. delete this.tableState;
  9234. return dict;
  9235. },
  9236. readXRefTable: function XRef_readXRefTable(parser) {
  9237. // Example of cross-reference table:
  9238. // xref
  9239. // 0 1 <-- subsection header (first obj #, obj count)
  9240. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9241. // 23 2 <-- subsection header ... and so on ...
  9242. // 0000025518 00002 n
  9243. // 0000025635 00000 n
  9244. // trailer
  9245. // ...
  9246. var stream = parser.lexer.stream;
  9247. var tableState = this.tableState;
  9248. stream.pos = tableState.streamPos;
  9249. parser.buf1 = tableState.parserBuf1;
  9250. parser.buf2 = tableState.parserBuf2;
  9251. // Outer loop is over subsection headers
  9252. var obj;
  9253. while (true) {
  9254. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9255. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9256. break;
  9257. }
  9258. tableState.firstEntryNum = obj;
  9259. tableState.entryCount = parser.getObj();
  9260. }
  9261. var first = tableState.firstEntryNum;
  9262. var count = tableState.entryCount;
  9263. if (!isInt(first) || !isInt(count)) {
  9264. error('Invalid XRef table: wrong types in subsection header');
  9265. }
  9266. // Inner loop is over objects themselves
  9267. for (var i = tableState.entryNum; i < count; i++) {
  9268. tableState.streamPos = stream.pos;
  9269. tableState.entryNum = i;
  9270. tableState.parserBuf1 = parser.buf1;
  9271. tableState.parserBuf2 = parser.buf2;
  9272. var entry = {};
  9273. entry.offset = parser.getObj();
  9274. entry.gen = parser.getObj();
  9275. var type = parser.getObj();
  9276. if (isCmd(type, 'f')) {
  9277. entry.free = true;
  9278. } else if (isCmd(type, 'n')) {
  9279. entry.uncompressed = true;
  9280. }
  9281. // Validate entry obj
  9282. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9283. !(entry.free || entry.uncompressed)) {
  9284. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9285. }
  9286. if (!this.entries[i + first]) {
  9287. this.entries[i + first] = entry;
  9288. }
  9289. }
  9290. tableState.entryNum = 0;
  9291. tableState.streamPos = stream.pos;
  9292. tableState.parserBuf1 = parser.buf1;
  9293. tableState.parserBuf2 = parser.buf2;
  9294. delete tableState.firstEntryNum;
  9295. delete tableState.entryCount;
  9296. }
  9297. // Per issue 3248: hp scanners generate bad XRef
  9298. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9299. // shifting the entries
  9300. this.entries.shift();
  9301. }
  9302. // Sanity check: as per spec, first object must be free
  9303. if (this.entries[0] && !this.entries[0].free) {
  9304. error('Invalid XRef table: unexpected first object');
  9305. }
  9306. return obj;
  9307. },
  9308. processXRefStream: function XRef_processXRefStream(stream) {
  9309. if (!('streamState' in this)) {
  9310. // Stores state of the stream as we process it so we can resume
  9311. // from middle of stream in case of missing data error
  9312. var streamParameters = stream.dict;
  9313. var byteWidths = streamParameters.get('W');
  9314. var range = streamParameters.get('Index');
  9315. if (!range) {
  9316. range = [0, streamParameters.get('Size')];
  9317. }
  9318. this.streamState = {
  9319. entryRanges: range,
  9320. byteWidths: byteWidths,
  9321. entryNum: 0,
  9322. streamPos: stream.pos
  9323. };
  9324. }
  9325. this.readXRefStream(stream);
  9326. delete this.streamState;
  9327. return stream.dict;
  9328. },
  9329. readXRefStream: function XRef_readXRefStream(stream) {
  9330. var i, j;
  9331. var streamState = this.streamState;
  9332. stream.pos = streamState.streamPos;
  9333. var byteWidths = streamState.byteWidths;
  9334. var typeFieldWidth = byteWidths[0];
  9335. var offsetFieldWidth = byteWidths[1];
  9336. var generationFieldWidth = byteWidths[2];
  9337. var entryRanges = streamState.entryRanges;
  9338. while (entryRanges.length > 0) {
  9339. var first = entryRanges[0];
  9340. var n = entryRanges[1];
  9341. if (!isInt(first) || !isInt(n)) {
  9342. error('Invalid XRef range fields: ' + first + ', ' + n);
  9343. }
  9344. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9345. !isInt(generationFieldWidth)) {
  9346. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9347. }
  9348. for (i = streamState.entryNum; i < n; ++i) {
  9349. streamState.entryNum = i;
  9350. streamState.streamPos = stream.pos;
  9351. var type = 0, offset = 0, generation = 0;
  9352. for (j = 0; j < typeFieldWidth; ++j) {
  9353. type = (type << 8) | stream.getByte();
  9354. }
  9355. // if type field is absent, its default value is 1
  9356. if (typeFieldWidth === 0) {
  9357. type = 1;
  9358. }
  9359. for (j = 0; j < offsetFieldWidth; ++j) {
  9360. offset = (offset << 8) | stream.getByte();
  9361. }
  9362. for (j = 0; j < generationFieldWidth; ++j) {
  9363. generation = (generation << 8) | stream.getByte();
  9364. }
  9365. var entry = {};
  9366. entry.offset = offset;
  9367. entry.gen = generation;
  9368. switch (type) {
  9369. case 0:
  9370. entry.free = true;
  9371. break;
  9372. case 1:
  9373. entry.uncompressed = true;
  9374. break;
  9375. case 2:
  9376. break;
  9377. default:
  9378. error('Invalid XRef entry type: ' + type);
  9379. }
  9380. if (!this.entries[first + i]) {
  9381. this.entries[first + i] = entry;
  9382. }
  9383. }
  9384. streamState.entryNum = 0;
  9385. streamState.streamPos = stream.pos;
  9386. entryRanges.splice(0, 2);
  9387. }
  9388. },
  9389. indexObjects: function XRef_indexObjects() {
  9390. // Simple scan through the PDF content to find objects,
  9391. // trailers and XRef streams.
  9392. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  9393. var PERCENT = 0x25, LT = 0x3C;
  9394. function readToken(data, offset) {
  9395. var token = '', ch = data[offset];
  9396. while (ch !== LF && ch !== CR && ch !== LT) {
  9397. if (++offset >= data.length) {
  9398. break;
  9399. }
  9400. token += String.fromCharCode(ch);
  9401. ch = data[offset];
  9402. }
  9403. return token;
  9404. }
  9405. function skipUntil(data, offset, what) {
  9406. var length = what.length, dataLength = data.length;
  9407. var skipped = 0;
  9408. // finding byte sequence
  9409. while (offset < dataLength) {
  9410. var i = 0;
  9411. while (i < length && data[offset + i] === what[i]) {
  9412. ++i;
  9413. }
  9414. if (i >= length) {
  9415. break; // sequence found
  9416. }
  9417. offset++;
  9418. skipped++;
  9419. }
  9420. return skipped;
  9421. }
  9422. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  9423. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9424. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9425. 101, 102]);
  9426. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9427. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9428. // Clear out any existing entries, since they may be bogus.
  9429. this.entries.length = 0;
  9430. var stream = this.stream;
  9431. stream.pos = 0;
  9432. var buffer = stream.getBytes();
  9433. var position = stream.start, length = buffer.length;
  9434. var trailers = [], xrefStms = [];
  9435. while (position < length) {
  9436. var ch = buffer[position];
  9437. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  9438. ++position;
  9439. continue;
  9440. }
  9441. if (ch === PERCENT) { // %-comment
  9442. do {
  9443. ++position;
  9444. if (position >= length) {
  9445. break;
  9446. }
  9447. ch = buffer[position];
  9448. } while (ch !== LF && ch !== CR);
  9449. continue;
  9450. }
  9451. var token = readToken(buffer, position);
  9452. var m;
  9453. if (token.indexOf('xref') === 0 &&
  9454. (token.length === 4 || /\s/.test(token[4]))) {
  9455. position += skipUntil(buffer, position, trailerBytes);
  9456. trailers.push(position);
  9457. position += skipUntil(buffer, position, startxrefBytes);
  9458. } else if ((m = objRegExp.exec(token))) {
  9459. if (typeof this.entries[m[1]] === 'undefined') {
  9460. this.entries[m[1]] = {
  9461. offset: position - stream.start,
  9462. gen: m[2] | 0,
  9463. uncompressed: true
  9464. };
  9465. }
  9466. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9467. var content = buffer.subarray(position, position + contentLength);
  9468. // checking XRef stream suspect
  9469. // (it shall have '/XRef' and next char is not a letter)
  9470. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9471. if (xrefTagOffset < contentLength &&
  9472. content[xrefTagOffset + 5] < 64) {
  9473. xrefStms.push(position - stream.start);
  9474. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  9475. }
  9476. position += contentLength;
  9477. } else if (token.indexOf('trailer') === 0 &&
  9478. (token.length === 7 || /\s/.test(token[7]))) {
  9479. trailers.push(position);
  9480. position += skipUntil(buffer, position, startxrefBytes);
  9481. } else {
  9482. position += token.length + 1;
  9483. }
  9484. }
  9485. // reading XRef streams
  9486. var i, ii;
  9487. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9488. this.startXRefQueue.push(xrefStms[i]);
  9489. this.readXRef(/* recoveryMode */ true);
  9490. }
  9491. // finding main trailer
  9492. var dict;
  9493. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9494. stream.pos = trailers[i];
  9495. var parser = new Parser(new Lexer(stream), true, this);
  9496. var obj = parser.getObj();
  9497. if (!isCmd(obj, 'trailer')) {
  9498. continue;
  9499. }
  9500. // read the trailer dictionary
  9501. if (!isDict(dict = parser.getObj())) {
  9502. continue;
  9503. }
  9504. // taking the first one with 'ID'
  9505. if (dict.has('ID')) {
  9506. return dict;
  9507. }
  9508. }
  9509. // no tailer with 'ID', taking last one (if exists)
  9510. if (dict) {
  9511. return dict;
  9512. }
  9513. // nothing helps
  9514. // calling error() would reject worker with an UnknownErrorException.
  9515. throw new InvalidPDFException('Invalid PDF structure');
  9516. },
  9517. readXRef: function XRef_readXRef(recoveryMode) {
  9518. var stream = this.stream;
  9519. try {
  9520. while (this.startXRefQueue.length) {
  9521. var startXRef = this.startXRefQueue[0];
  9522. stream.pos = startXRef + stream.start;
  9523. var parser = new Parser(new Lexer(stream), true, this);
  9524. var obj = parser.getObj();
  9525. var dict;
  9526. // Get dictionary
  9527. if (isCmd(obj, 'xref')) {
  9528. // Parse end-of-file XRef
  9529. dict = this.processXRefTable(parser);
  9530. if (!this.topDict) {
  9531. this.topDict = dict;
  9532. }
  9533. // Recursively get other XRefs 'XRefStm', if any
  9534. obj = dict.get('XRefStm');
  9535. if (isInt(obj)) {
  9536. var pos = obj;
  9537. // ignore previously loaded xref streams
  9538. // (possible infinite recursion)
  9539. if (!(pos in this.xrefstms)) {
  9540. this.xrefstms[pos] = 1;
  9541. this.startXRefQueue.push(pos);
  9542. }
  9543. }
  9544. } else if (isInt(obj)) {
  9545. // Parse in-stream XRef
  9546. if (!isInt(parser.getObj()) ||
  9547. !isCmd(parser.getObj(), 'obj') ||
  9548. !isStream(obj = parser.getObj())) {
  9549. error('Invalid XRef stream');
  9550. }
  9551. dict = this.processXRefStream(obj);
  9552. if (!this.topDict) {
  9553. this.topDict = dict;
  9554. }
  9555. if (!dict) {
  9556. error('Failed to read XRef stream');
  9557. }
  9558. } else {
  9559. error('Invalid XRef stream header');
  9560. }
  9561. // Recursively get previous dictionary, if any
  9562. obj = dict.get('Prev');
  9563. if (isInt(obj)) {
  9564. this.startXRefQueue.push(obj);
  9565. } else if (isRef(obj)) {
  9566. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9567. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9568. this.startXRefQueue.push(obj.num);
  9569. }
  9570. this.startXRefQueue.shift();
  9571. }
  9572. return this.topDict;
  9573. } catch (e) {
  9574. if (e instanceof MissingDataException) {
  9575. throw e;
  9576. }
  9577. info('(while reading XRef): ' + e);
  9578. }
  9579. if (recoveryMode) {
  9580. return;
  9581. }
  9582. throw new XRefParseException();
  9583. },
  9584. getEntry: function XRef_getEntry(i) {
  9585. var xrefEntry = this.entries[i];
  9586. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9587. return xrefEntry;
  9588. }
  9589. return null;
  9590. },
  9591. fetchIfRef: function XRef_fetchIfRef(obj) {
  9592. if (!isRef(obj)) {
  9593. return obj;
  9594. }
  9595. return this.fetch(obj);
  9596. },
  9597. fetch: function XRef_fetch(ref, suppressEncryption) {
  9598. assert(isRef(ref), 'ref object is not a reference');
  9599. var num = ref.num;
  9600. if (num in this.cache) {
  9601. var cacheEntry = this.cache[num];
  9602. return cacheEntry;
  9603. }
  9604. var xrefEntry = this.getEntry(num);
  9605. // the referenced entry can be free
  9606. if (xrefEntry === null) {
  9607. return (this.cache[num] = null);
  9608. }
  9609. if (xrefEntry.uncompressed) {
  9610. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9611. } else {
  9612. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9613. }
  9614. if (isDict(xrefEntry)){
  9615. xrefEntry.objId = ref.toString();
  9616. } else if (isStream(xrefEntry)) {
  9617. xrefEntry.dict.objId = ref.toString();
  9618. }
  9619. return xrefEntry;
  9620. },
  9621. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9622. suppressEncryption) {
  9623. var gen = ref.gen;
  9624. var num = ref.num;
  9625. if (xrefEntry.gen !== gen) {
  9626. error('inconsistent generation in XRef');
  9627. }
  9628. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9629. this.stream.start);
  9630. var parser = new Parser(new Lexer(stream), true, this);
  9631. var obj1 = parser.getObj();
  9632. var obj2 = parser.getObj();
  9633. var obj3 = parser.getObj();
  9634. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9635. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9636. !isCmd(obj3)) {
  9637. error('bad XRef entry');
  9638. }
  9639. if (!isCmd(obj3, 'obj')) {
  9640. // some bad PDFs use "obj1234" and really mean 1234
  9641. if (obj3.cmd.indexOf('obj') === 0) {
  9642. num = parseInt(obj3.cmd.substring(3), 10);
  9643. if (!isNaN(num)) {
  9644. return num;
  9645. }
  9646. }
  9647. error('bad XRef entry');
  9648. }
  9649. if (this.encrypt && !suppressEncryption) {
  9650. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9651. } else {
  9652. xrefEntry = parser.getObj();
  9653. }
  9654. if (!isStream(xrefEntry)) {
  9655. this.cache[num] = xrefEntry;
  9656. }
  9657. return xrefEntry;
  9658. },
  9659. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9660. suppressEncryption) {
  9661. var tableOffset = xrefEntry.offset;
  9662. var stream = this.fetch(new Ref(tableOffset, 0));
  9663. if (!isStream(stream)) {
  9664. error('bad ObjStm stream');
  9665. }
  9666. var first = stream.dict.get('First');
  9667. var n = stream.dict.get('N');
  9668. if (!isInt(first) || !isInt(n)) {
  9669. error('invalid first and n parameters for ObjStm stream');
  9670. }
  9671. var parser = new Parser(new Lexer(stream), false, this);
  9672. parser.allowStreams = true;
  9673. var i, entries = [], num, nums = [];
  9674. // read the object numbers to populate cache
  9675. for (i = 0; i < n; ++i) {
  9676. num = parser.getObj();
  9677. if (!isInt(num)) {
  9678. error('invalid object number in the ObjStm stream: ' + num);
  9679. }
  9680. nums.push(num);
  9681. var offset = parser.getObj();
  9682. if (!isInt(offset)) {
  9683. error('invalid object offset in the ObjStm stream: ' + offset);
  9684. }
  9685. }
  9686. // read stream objects for cache
  9687. for (i = 0; i < n; ++i) {
  9688. entries.push(parser.getObj());
  9689. num = nums[i];
  9690. var entry = this.entries[num];
  9691. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9692. this.cache[num] = entries[i];
  9693. }
  9694. }
  9695. xrefEntry = entries[xrefEntry.gen];
  9696. if (xrefEntry === undefined) {
  9697. error('bad XRef entry for compressed object');
  9698. }
  9699. return xrefEntry;
  9700. },
  9701. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9702. if (!isRef(obj)) {
  9703. return Promise.resolve(obj);
  9704. }
  9705. return this.fetchAsync(obj);
  9706. },
  9707. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9708. var streamManager = this.stream.manager;
  9709. var xref = this;
  9710. return new Promise(function tryFetch(resolve, reject) {
  9711. try {
  9712. resolve(xref.fetch(ref, suppressEncryption));
  9713. } catch (e) {
  9714. if (e instanceof MissingDataException) {
  9715. streamManager.requestRange(e.begin, e.end, function () {
  9716. tryFetch(resolve, reject);
  9717. });
  9718. return;
  9719. }
  9720. reject(e);
  9721. }
  9722. });
  9723. },
  9724. getCatalogObj: function XRef_getCatalogObj() {
  9725. return this.root;
  9726. }
  9727. };
  9728. return XRef;
  9729. })();
  9730. /**
  9731. * A NameTree is like a Dict but has some advantageous properties, see the
  9732. * spec (7.9.6) for more details.
  9733. * TODO: implement all the Dict functions and make this more efficent.
  9734. */
  9735. var NameTree = (function NameTreeClosure() {
  9736. function NameTree(root, xref) {
  9737. this.root = root;
  9738. this.xref = xref;
  9739. }
  9740. NameTree.prototype = {
  9741. getAll: function NameTree_getAll() {
  9742. var dict = {};
  9743. if (!this.root) {
  9744. return dict;
  9745. }
  9746. var xref = this.xref;
  9747. // reading name tree
  9748. var processed = new RefSet();
  9749. processed.put(this.root);
  9750. var queue = [this.root];
  9751. while (queue.length > 0) {
  9752. var i, n;
  9753. var obj = xref.fetchIfRef(queue.shift());
  9754. if (!isDict(obj)) {
  9755. continue;
  9756. }
  9757. if (obj.has('Kids')) {
  9758. var kids = obj.get('Kids');
  9759. for (i = 0, n = kids.length; i < n; i++) {
  9760. var kid = kids[i];
  9761. if (processed.has(kid)) {
  9762. error('invalid destinations');
  9763. }
  9764. queue.push(kid);
  9765. processed.put(kid);
  9766. }
  9767. continue;
  9768. }
  9769. var names = obj.get('Names');
  9770. if (names) {
  9771. for (i = 0, n = names.length; i < n; i += 2) {
  9772. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  9773. }
  9774. }
  9775. }
  9776. return dict;
  9777. },
  9778. get: function NameTree_get(destinationId) {
  9779. if (!this.root) {
  9780. return null;
  9781. }
  9782. var xref = this.xref;
  9783. var kidsOrNames = xref.fetchIfRef(this.root);
  9784. var loopCount = 0;
  9785. var MAX_NAMES_LEVELS = 10;
  9786. var l, r, m;
  9787. // Perform a binary search to quickly find the entry that
  9788. // contains the named destination we are looking for.
  9789. while (kidsOrNames.has('Kids')) {
  9790. loopCount++;
  9791. if (loopCount > MAX_NAMES_LEVELS) {
  9792. warn('Search depth limit for named destionations has been reached.');
  9793. return null;
  9794. }
  9795. var kids = kidsOrNames.get('Kids');
  9796. if (!isArray(kids)) {
  9797. return null;
  9798. }
  9799. l = 0;
  9800. r = kids.length - 1;
  9801. while (l <= r) {
  9802. m = (l + r) >> 1;
  9803. var kid = xref.fetchIfRef(kids[m]);
  9804. var limits = kid.get('Limits');
  9805. if (destinationId < xref.fetchIfRef(limits[0])) {
  9806. r = m - 1;
  9807. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  9808. l = m + 1;
  9809. } else {
  9810. kidsOrNames = xref.fetchIfRef(kids[m]);
  9811. break;
  9812. }
  9813. }
  9814. if (l > r) {
  9815. return null;
  9816. }
  9817. }
  9818. // If we get here, then we have found the right entry. Now
  9819. // go through the named destinations in the Named dictionary
  9820. // until we find the exact destination we're looking for.
  9821. var names = kidsOrNames.get('Names');
  9822. if (isArray(names)) {
  9823. // Perform a binary search to reduce the lookup time.
  9824. l = 0;
  9825. r = names.length - 2;
  9826. while (l <= r) {
  9827. // Check only even indices (0, 2, 4, ...) because the
  9828. // odd indices contain the actual D array.
  9829. m = (l + r) & ~1;
  9830. if (destinationId < xref.fetchIfRef(names[m])) {
  9831. r = m - 2;
  9832. } else if (destinationId > xref.fetchIfRef(names[m])) {
  9833. l = m + 2;
  9834. } else {
  9835. return xref.fetchIfRef(names[m + 1]);
  9836. }
  9837. }
  9838. }
  9839. return null;
  9840. }
  9841. };
  9842. return NameTree;
  9843. })();
  9844. /**
  9845. * "A PDF file can refer to the contents of another file by using a File
  9846. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9847. * NOTE: Only embedded files are supported (as part of the attachments support)
  9848. * TODO: support the 'URL' file system (with caching if !/V), portable
  9849. * collections attributes and related files (/RF)
  9850. */
  9851. var FileSpec = (function FileSpecClosure() {
  9852. function FileSpec(root, xref) {
  9853. if (!root || !isDict(root)) {
  9854. return;
  9855. }
  9856. this.xref = xref;
  9857. this.root = root;
  9858. if (root.has('FS')) {
  9859. this.fs = root.get('FS');
  9860. }
  9861. this.description = root.has('Desc') ?
  9862. stringToPDFString(root.get('Desc')) :
  9863. '';
  9864. if (root.has('RF')) {
  9865. warn('Related file specifications are not supported');
  9866. }
  9867. this.contentAvailable = true;
  9868. if (!root.has('EF')) {
  9869. this.contentAvailable = false;
  9870. warn('Non-embedded file specifications are not supported');
  9871. }
  9872. }
  9873. function pickPlatformItem(dict) {
  9874. // Look for the filename in this order:
  9875. // UF, F, Unix, Mac, DOS
  9876. if (dict.has('UF')) {
  9877. return dict.get('UF');
  9878. } else if (dict.has('F')) {
  9879. return dict.get('F');
  9880. } else if (dict.has('Unix')) {
  9881. return dict.get('Unix');
  9882. } else if (dict.has('Mac')) {
  9883. return dict.get('Mac');
  9884. } else if (dict.has('DOS')) {
  9885. return dict.get('DOS');
  9886. } else {
  9887. return null;
  9888. }
  9889. }
  9890. FileSpec.prototype = {
  9891. get filename() {
  9892. if (!this._filename && this.root) {
  9893. var filename = pickPlatformItem(this.root) || 'unnamed';
  9894. this._filename = stringToPDFString(filename).
  9895. replace(/\\\\/g, '\\').
  9896. replace(/\\\//g, '/').
  9897. replace(/\\/g, '/');
  9898. }
  9899. return this._filename;
  9900. },
  9901. get content() {
  9902. if (!this.contentAvailable) {
  9903. return null;
  9904. }
  9905. if (!this.contentRef && this.root) {
  9906. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9907. }
  9908. var content = null;
  9909. if (this.contentRef) {
  9910. var xref = this.xref;
  9911. var fileObj = xref.fetchIfRef(this.contentRef);
  9912. if (fileObj && isStream(fileObj)) {
  9913. content = fileObj.getBytes();
  9914. } else {
  9915. warn('Embedded file specification points to non-existing/invalid ' +
  9916. 'content');
  9917. }
  9918. } else {
  9919. warn('Embedded file specification does not have a content');
  9920. }
  9921. return content;
  9922. },
  9923. get serializable() {
  9924. return {
  9925. filename: this.filename,
  9926. content: this.content
  9927. };
  9928. }
  9929. };
  9930. return FileSpec;
  9931. })();
  9932. /**
  9933. * A helper for loading missing data in object graphs. It traverses the graph
  9934. * depth first and queues up any objects that have missing data. Once it has
  9935. * has traversed as many objects that are available it attempts to bundle the
  9936. * missing data requests and then resume from the nodes that weren't ready.
  9937. *
  9938. * NOTE: It provides protection from circular references by keeping track of
  9939. * of loaded references. However, you must be careful not to load any graphs
  9940. * that have references to the catalog or other pages since that will cause the
  9941. * entire PDF document object graph to be traversed.
  9942. */
  9943. var ObjectLoader = (function() {
  9944. function mayHaveChildren(value) {
  9945. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9946. }
  9947. function addChildren(node, nodesToVisit) {
  9948. var value;
  9949. if (isDict(node) || isStream(node)) {
  9950. var map;
  9951. if (isDict(node)) {
  9952. map = node.map;
  9953. } else {
  9954. map = node.dict.map;
  9955. }
  9956. for (var key in map) {
  9957. value = map[key];
  9958. if (mayHaveChildren(value)) {
  9959. nodesToVisit.push(value);
  9960. }
  9961. }
  9962. } else if (isArray(node)) {
  9963. for (var i = 0, ii = node.length; i < ii; i++) {
  9964. value = node[i];
  9965. if (mayHaveChildren(value)) {
  9966. nodesToVisit.push(value);
  9967. }
  9968. }
  9969. }
  9970. }
  9971. function ObjectLoader(obj, keys, xref) {
  9972. this.obj = obj;
  9973. this.keys = keys;
  9974. this.xref = xref;
  9975. this.refSet = null;
  9976. }
  9977. ObjectLoader.prototype = {
  9978. load: function ObjectLoader_load() {
  9979. var keys = this.keys;
  9980. this.capability = createPromiseCapability();
  9981. // Don't walk the graph if all the data is already loaded.
  9982. if (!(this.xref.stream instanceof ChunkedStream) ||
  9983. this.xref.stream.getMissingChunks().length === 0) {
  9984. this.capability.resolve();
  9985. return this.capability.promise;
  9986. }
  9987. this.refSet = new RefSet();
  9988. // Setup the initial nodes to visit.
  9989. var nodesToVisit = [];
  9990. for (var i = 0; i < keys.length; i++) {
  9991. nodesToVisit.push(this.obj[keys[i]]);
  9992. }
  9993. this.walk(nodesToVisit);
  9994. return this.capability.promise;
  9995. },
  9996. walk: function ObjectLoader_walk(nodesToVisit) {
  9997. var nodesToRevisit = [];
  9998. var pendingRequests = [];
  9999. // DFS walk of the object graph.
  10000. while (nodesToVisit.length) {
  10001. var currentNode = nodesToVisit.pop();
  10002. // Only references or chunked streams can cause missing data exceptions.
  10003. if (isRef(currentNode)) {
  10004. // Skip nodes that have already been visited.
  10005. if (this.refSet.has(currentNode)) {
  10006. continue;
  10007. }
  10008. try {
  10009. var ref = currentNode;
  10010. this.refSet.put(ref);
  10011. currentNode = this.xref.fetch(currentNode);
  10012. } catch (e) {
  10013. if (!(e instanceof MissingDataException)) {
  10014. throw e;
  10015. }
  10016. nodesToRevisit.push(currentNode);
  10017. pendingRequests.push({ begin: e.begin, end: e.end });
  10018. }
  10019. }
  10020. if (currentNode && currentNode.getBaseStreams) {
  10021. var baseStreams = currentNode.getBaseStreams();
  10022. var foundMissingData = false;
  10023. for (var i = 0; i < baseStreams.length; i++) {
  10024. var stream = baseStreams[i];
  10025. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  10026. foundMissingData = true;
  10027. pendingRequests.push({
  10028. begin: stream.start,
  10029. end: stream.end
  10030. });
  10031. }
  10032. }
  10033. if (foundMissingData) {
  10034. nodesToRevisit.push(currentNode);
  10035. }
  10036. }
  10037. addChildren(currentNode, nodesToVisit);
  10038. }
  10039. if (pendingRequests.length) {
  10040. this.xref.stream.manager.requestRanges(pendingRequests,
  10041. function pendingRequestCallback() {
  10042. nodesToVisit = nodesToRevisit;
  10043. for (var i = 0; i < nodesToRevisit.length; i++) {
  10044. var node = nodesToRevisit[i];
  10045. // Remove any reference nodes from the currrent refset so they
  10046. // aren't skipped when we revist them.
  10047. if (isRef(node)) {
  10048. this.refSet.remove(node);
  10049. }
  10050. }
  10051. this.walk(nodesToVisit);
  10052. }.bind(this));
  10053. return;
  10054. }
  10055. // Everything is loaded.
  10056. this.refSet = null;
  10057. this.capability.resolve();
  10058. }
  10059. };
  10060. return ObjectLoader;
  10061. })();
  10062. var ISOAdobeCharset = [
  10063. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  10064. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  10065. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  10066. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  10067. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  10068. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  10069. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  10070. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  10071. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  10072. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  10073. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  10074. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  10075. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  10076. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  10077. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  10078. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  10079. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  10080. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  10081. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  10082. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  10083. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  10084. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  10085. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  10086. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  10087. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  10088. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  10089. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  10090. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  10091. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  10092. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  10093. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  10094. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  10095. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  10096. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  10097. ];
  10098. var ExpertCharset = [
  10099. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  10100. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  10101. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  10102. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  10103. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  10104. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  10105. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  10106. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  10107. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  10108. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  10109. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  10110. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  10111. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  10112. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  10113. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  10114. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  10115. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  10116. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  10117. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  10118. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  10119. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  10120. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  10121. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  10122. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  10123. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  10124. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  10125. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  10126. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  10127. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  10128. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  10129. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  10130. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  10131. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  10132. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  10133. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  10134. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  10135. 'Ydieresissmall'
  10136. ];
  10137. var ExpertSubsetCharset = [
  10138. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  10139. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  10140. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  10141. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  10142. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  10143. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  10144. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  10145. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  10146. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  10147. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  10148. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  10149. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  10150. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  10151. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  10152. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  10153. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  10154. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  10155. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  10156. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  10157. 'periodinferior', 'commainferior'
  10158. ];
  10159. var DEFAULT_ICON_SIZE = 22; // px
  10160. /**
  10161. * @constructor
  10162. */
  10163. function AnnotationFactory() {}
  10164. AnnotationFactory.prototype = {
  10165. /**
  10166. * @param {XRef} xref
  10167. * @param {Object} ref
  10168. * @returns {Annotation}
  10169. */
  10170. create: function AnnotationFactory_create(xref, ref) {
  10171. var dict = xref.fetchIfRef(ref);
  10172. if (!isDict(dict)) {
  10173. return;
  10174. }
  10175. // Determine the annotation's subtype.
  10176. var subtype = dict.get('Subtype');
  10177. subtype = isName(subtype) ? subtype.name : '';
  10178. // Return the right annotation object based on the subtype and field type.
  10179. var parameters = {
  10180. dict: dict,
  10181. ref: ref
  10182. };
  10183. switch (subtype) {
  10184. case 'Link':
  10185. return new LinkAnnotation(parameters);
  10186. case 'Text':
  10187. return new TextAnnotation(parameters);
  10188. case 'Widget':
  10189. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10190. if (isName(fieldType) && fieldType.name === 'Tx') {
  10191. return new TextWidgetAnnotation(parameters);
  10192. }
  10193. return new WidgetAnnotation(parameters);
  10194. default:
  10195. warn('Unimplemented annotation type "' + subtype + '", ' +
  10196. 'falling back to base annotation');
  10197. return new Annotation(parameters);
  10198. }
  10199. }
  10200. };
  10201. var Annotation = (function AnnotationClosure() {
  10202. // 12.5.5: Algorithm: Appearance streams
  10203. function getTransformMatrix(rect, bbox, matrix) {
  10204. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  10205. var minX = bounds[0];
  10206. var minY = bounds[1];
  10207. var maxX = bounds[2];
  10208. var maxY = bounds[3];
  10209. if (minX === maxX || minY === maxY) {
  10210. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  10211. // just apply the transform for rect
  10212. return [1, 0, 0, 1, rect[0], rect[1]];
  10213. }
  10214. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  10215. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  10216. return [
  10217. xRatio,
  10218. 0,
  10219. 0,
  10220. yRatio,
  10221. rect[0] - minX * xRatio,
  10222. rect[1] - minY * yRatio
  10223. ];
  10224. }
  10225. function getDefaultAppearance(dict) {
  10226. var appearanceState = dict.get('AP');
  10227. if (!isDict(appearanceState)) {
  10228. return;
  10229. }
  10230. var appearance;
  10231. var appearances = appearanceState.get('N');
  10232. if (isDict(appearances)) {
  10233. var as = dict.get('AS');
  10234. if (as && appearances.has(as.name)) {
  10235. appearance = appearances.get(as.name);
  10236. }
  10237. } else {
  10238. appearance = appearances;
  10239. }
  10240. return appearance;
  10241. }
  10242. function Annotation(params) {
  10243. var dict = params.dict;
  10244. var data = this.data = {};
  10245. data.subtype = dict.get('Subtype').name;
  10246. data.annotationFlags = dict.get('F');
  10247. this.setRectangle(dict.get('Rect'));
  10248. data.rect = this.rectangle;
  10249. this.setColor(dict.get('C'));
  10250. data.color = this.color;
  10251. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  10252. this.setBorderStyle(dict);
  10253. this.appearance = getDefaultAppearance(dict);
  10254. data.hasAppearance = !!this.appearance;
  10255. data.id = params.ref.num;
  10256. }
  10257. Annotation.prototype = {
  10258. /**
  10259. * Set the rectangle.
  10260. *
  10261. * @public
  10262. * @memberof Annotation
  10263. * @param {Array} rectangle - The rectangle array with exactly four entries
  10264. */
  10265. setRectangle: function Annotation_setRectangle(rectangle) {
  10266. if (isArray(rectangle) && rectangle.length === 4) {
  10267. this.rectangle = Util.normalizeRect(rectangle);
  10268. } else {
  10269. this.rectangle = [0, 0, 0, 0];
  10270. }
  10271. },
  10272. /**
  10273. * Set the color and take care of color space conversion.
  10274. *
  10275. * @public
  10276. * @memberof Annotation
  10277. * @param {Array} color - The color array containing either 0
  10278. * (transparent), 1 (grayscale), 3 (RGB) or
  10279. * 4 (CMYK) elements
  10280. */
  10281. setColor: function Annotation_setColor(color) {
  10282. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  10283. if (!isArray(color)) {
  10284. this.color = rgbColor;
  10285. return;
  10286. }
  10287. switch (color.length) {
  10288. case 0: // Transparent, which we indicate with a null value
  10289. this.color = null;
  10290. break;
  10291. case 1: // Convert grayscale to RGB
  10292. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  10293. this.color = rgbColor;
  10294. break;
  10295. case 3: // Convert RGB percentages to RGB
  10296. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  10297. this.color = rgbColor;
  10298. break;
  10299. case 4: // Convert CMYK to RGB
  10300. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  10301. this.color = rgbColor;
  10302. break;
  10303. default:
  10304. this.color = rgbColor;
  10305. break;
  10306. }
  10307. },
  10308. /**
  10309. * Set the border style (as AnnotationBorderStyle object).
  10310. *
  10311. * @public
  10312. * @memberof Annotation
  10313. * @param {Dict} borderStyle - The border style dictionary
  10314. */
  10315. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  10316. if (!isDict(borderStyle)) {
  10317. return;
  10318. }
  10319. if (borderStyle.has('BS')) {
  10320. var dict = borderStyle.get('BS');
  10321. var dictType;
  10322. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  10323. dictType.name === 'Border')) {
  10324. this.borderStyle.setWidth(dict.get('W'));
  10325. this.borderStyle.setStyle(dict.get('S'));
  10326. this.borderStyle.setDashArray(dict.get('D'));
  10327. }
  10328. } else if (borderStyle.has('Border')) {
  10329. var array = borderStyle.get('Border');
  10330. if (isArray(array) && array.length >= 3) {
  10331. this.borderStyle.setHorizontalCornerRadius(array[0]);
  10332. this.borderStyle.setVerticalCornerRadius(array[1]);
  10333. this.borderStyle.setWidth(array[2]);
  10334. if (array.length === 4) { // Dash array available
  10335. this.borderStyle.setDashArray(array[3]);
  10336. }
  10337. }
  10338. } else {
  10339. // There are no border entries in the dictionary. According to the
  10340. // specification, we should draw a solid border of width 1 in that
  10341. // case, but Adobe Reader did not implement that part of the
  10342. // specification and instead draws no border at all, so we do the same.
  10343. // See also https://github.com/mozilla/pdf.js/issues/6179.
  10344. this.borderStyle.setWidth(0);
  10345. }
  10346. },
  10347. isInvisible: function Annotation_isInvisible() {
  10348. var data = this.data;
  10349. return !!(data &&
  10350. data.annotationFlags && // Default: not invisible
  10351. data.annotationFlags & 0x1); // Invisible
  10352. },
  10353. isViewable: function Annotation_isViewable() {
  10354. var data = this.data;
  10355. return !!(!this.isInvisible() &&
  10356. data &&
  10357. (!data.annotationFlags ||
  10358. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10359. data.rect); // rectangle is necessary
  10360. },
  10361. isPrintable: function Annotation_isPrintable() {
  10362. var data = this.data;
  10363. return !!(!this.isInvisible() &&
  10364. data &&
  10365. data.annotationFlags && // Default: not printable
  10366. data.annotationFlags & 0x4 && // Print
  10367. !(data.annotationFlags & 0x2) && // Hidden
  10368. data.rect); // rectangle is necessary
  10369. },
  10370. loadResources: function Annotation_loadResources(keys) {
  10371. return new Promise(function (resolve, reject) {
  10372. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10373. if (!resources) {
  10374. resolve();
  10375. return;
  10376. }
  10377. var objectLoader = new ObjectLoader(resources.map,
  10378. keys,
  10379. resources.xref);
  10380. objectLoader.load().then(function() {
  10381. resolve(resources);
  10382. }, reject);
  10383. }, reject);
  10384. }.bind(this));
  10385. },
  10386. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10387. if (!this.appearance) {
  10388. return Promise.resolve(new OperatorList());
  10389. }
  10390. var data = this.data;
  10391. var appearanceDict = this.appearance.dict;
  10392. var resourcesPromise = this.loadResources([
  10393. 'ExtGState',
  10394. 'ColorSpace',
  10395. 'Pattern',
  10396. 'Shading',
  10397. 'XObject',
  10398. 'Font'
  10399. // ProcSet
  10400. // Properties
  10401. ]);
  10402. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10403. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10404. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10405. var self = this;
  10406. return resourcesPromise.then(function(resources) {
  10407. var opList = new OperatorList();
  10408. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10409. return evaluator.getOperatorList(self.appearance, resources, opList).
  10410. then(function () {
  10411. opList.addOp(OPS.endAnnotation, []);
  10412. self.appearance.reset();
  10413. return opList;
  10414. });
  10415. });
  10416. }
  10417. };
  10418. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10419. annotations, opList, pdfManager, partialEvaluator, intent) {
  10420. function reject(e) {
  10421. annotationsReadyCapability.reject(e);
  10422. }
  10423. var annotationsReadyCapability = createPromiseCapability();
  10424. var annotationPromises = [];
  10425. for (var i = 0, n = annotations.length; i < n; ++i) {
  10426. if (intent === 'display' && annotations[i].isViewable() ||
  10427. intent === 'print' && annotations[i].isPrintable()) {
  10428. annotationPromises.push(
  10429. annotations[i].getOperatorList(partialEvaluator));
  10430. }
  10431. }
  10432. Promise.all(annotationPromises).then(function(datas) {
  10433. opList.addOp(OPS.beginAnnotations, []);
  10434. for (var i = 0, n = datas.length; i < n; ++i) {
  10435. var annotOpList = datas[i];
  10436. opList.addOpList(annotOpList);
  10437. }
  10438. opList.addOp(OPS.endAnnotations, []);
  10439. annotationsReadyCapability.resolve();
  10440. }, reject);
  10441. return annotationsReadyCapability.promise;
  10442. };
  10443. return Annotation;
  10444. })();
  10445. /**
  10446. * Contains all data regarding an annotation's border style.
  10447. *
  10448. * @class
  10449. */
  10450. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  10451. /**
  10452. * @constructor
  10453. * @private
  10454. */
  10455. function AnnotationBorderStyle() {
  10456. this.width = 1;
  10457. this.style = AnnotationBorderStyleType.SOLID;
  10458. this.dashArray = [3];
  10459. this.horizontalCornerRadius = 0;
  10460. this.verticalCornerRadius = 0;
  10461. }
  10462. AnnotationBorderStyle.prototype = {
  10463. /**
  10464. * Set the width.
  10465. *
  10466. * @public
  10467. * @memberof AnnotationBorderStyle
  10468. * @param {integer} width - The width
  10469. */
  10470. setWidth: function AnnotationBorderStyle_setWidth(width) {
  10471. if (width === (width | 0)) {
  10472. this.width = width;
  10473. }
  10474. },
  10475. /**
  10476. * Set the style.
  10477. *
  10478. * @public
  10479. * @memberof AnnotationBorderStyle
  10480. * @param {Object} style - The style object
  10481. * @see {@link shared/util.js}
  10482. */
  10483. setStyle: function AnnotationBorderStyle_setStyle(style) {
  10484. if (!style) {
  10485. return;
  10486. }
  10487. switch (style.name) {
  10488. case 'S':
  10489. this.style = AnnotationBorderStyleType.SOLID;
  10490. break;
  10491. case 'D':
  10492. this.style = AnnotationBorderStyleType.DASHED;
  10493. break;
  10494. case 'B':
  10495. this.style = AnnotationBorderStyleType.BEVELED;
  10496. break;
  10497. case 'I':
  10498. this.style = AnnotationBorderStyleType.INSET;
  10499. break;
  10500. case 'U':
  10501. this.style = AnnotationBorderStyleType.UNDERLINE;
  10502. break;
  10503. default:
  10504. break;
  10505. }
  10506. },
  10507. /**
  10508. * Set the dash array.
  10509. *
  10510. * @public
  10511. * @memberof AnnotationBorderStyle
  10512. * @param {Array} dashArray - The dash array with at least one element
  10513. */
  10514. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  10515. // We validate the dash array, but we do not use it because CSS does not
  10516. // allow us to change spacing of dashes. For more information, visit
  10517. // http://www.w3.org/TR/css3-background/#the-border-style.
  10518. if (isArray(dashArray) && dashArray.length > 0) {
  10519. // According to the PDF specification: the elements in a dashArray
  10520. // shall be numbers that are nonnegative and not all equal to zero.
  10521. var isValid = true;
  10522. var allZeros = true;
  10523. for (var i = 0, len = dashArray.length; i < len; i++) {
  10524. var element = dashArray[i];
  10525. var validNumber = (+element >= 0);
  10526. if (!validNumber) {
  10527. isValid = false;
  10528. break;
  10529. } else if (element > 0) {
  10530. allZeros = false;
  10531. }
  10532. }
  10533. if (isValid && !allZeros) {
  10534. this.dashArray = dashArray;
  10535. } else {
  10536. this.width = 0; // Adobe behavior when the array is invalid.
  10537. }
  10538. } else if (dashArray) {
  10539. this.width = 0; // Adobe behavior when the array is invalid.
  10540. }
  10541. },
  10542. /**
  10543. * Set the horizontal corner radius (from a Border dictionary).
  10544. *
  10545. * @public
  10546. * @memberof AnnotationBorderStyle
  10547. * @param {integer} radius - The horizontal corner radius
  10548. */
  10549. setHorizontalCornerRadius:
  10550. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  10551. if (radius === (radius | 0)) {
  10552. this.horizontalCornerRadius = radius;
  10553. }
  10554. },
  10555. /**
  10556. * Set the vertical corner radius (from a Border dictionary).
  10557. *
  10558. * @public
  10559. * @memberof AnnotationBorderStyle
  10560. * @param {integer} radius - The vertical corner radius
  10561. */
  10562. setVerticalCornerRadius:
  10563. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  10564. if (radius === (radius | 0)) {
  10565. this.verticalCornerRadius = radius;
  10566. }
  10567. }
  10568. };
  10569. return AnnotationBorderStyle;
  10570. })();
  10571. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10572. function WidgetAnnotation(params) {
  10573. Annotation.call(this, params);
  10574. var dict = params.dict;
  10575. var data = this.data;
  10576. data.fieldValue = stringToPDFString(
  10577. Util.getInheritableProperty(dict, 'V') || '');
  10578. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10579. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10580. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10581. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10582. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10583. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10584. // Building the full field name by collecting the field and
  10585. // its ancestors 'T' data and joining them using '.'.
  10586. var fieldName = [];
  10587. var namedItem = dict;
  10588. var ref = params.ref;
  10589. while (namedItem) {
  10590. var parent = namedItem.get('Parent');
  10591. var parentRef = namedItem.getRaw('Parent');
  10592. var name = namedItem.get('T');
  10593. if (name) {
  10594. fieldName.unshift(stringToPDFString(name));
  10595. } else if (parent && ref) {
  10596. // The field name is absent, that means more than one field
  10597. // with the same name may exist. Replacing the empty name
  10598. // with the '`' plus index in the parent's 'Kids' array.
  10599. // This is not in the PDF spec but necessary to id the
  10600. // the input controls.
  10601. var kids = parent.get('Kids');
  10602. var j, jj;
  10603. for (j = 0, jj = kids.length; j < jj; j++) {
  10604. var kidRef = kids[j];
  10605. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10606. break;
  10607. }
  10608. }
  10609. fieldName.unshift('`' + j);
  10610. }
  10611. namedItem = parent;
  10612. ref = parentRef;
  10613. }
  10614. data.fullName = fieldName.join('.');
  10615. }
  10616. var parent = Annotation.prototype;
  10617. Util.inherit(WidgetAnnotation, Annotation, {
  10618. isViewable: function WidgetAnnotation_isViewable() {
  10619. if (this.data.fieldType === 'Sig') {
  10620. warn('unimplemented annotation type: Widget signature');
  10621. return false;
  10622. }
  10623. return parent.isViewable.call(this);
  10624. }
  10625. });
  10626. return WidgetAnnotation;
  10627. })();
  10628. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10629. function TextWidgetAnnotation(params) {
  10630. WidgetAnnotation.call(this, params);
  10631. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10632. this.data.annotationType = AnnotationType.WIDGET;
  10633. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10634. }
  10635. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10636. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10637. if (this.appearance) {
  10638. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10639. }
  10640. var opList = new OperatorList();
  10641. var data = this.data;
  10642. // Even if there is an appearance stream, ignore it. This is the
  10643. // behaviour used by Adobe Reader.
  10644. if (!data.defaultAppearance) {
  10645. return Promise.resolve(opList);
  10646. }
  10647. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10648. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10649. then(function () {
  10650. return opList;
  10651. });
  10652. }
  10653. });
  10654. return TextWidgetAnnotation;
  10655. })();
  10656. var TextAnnotation = (function TextAnnotationClosure() {
  10657. function TextAnnotation(params) {
  10658. Annotation.call(this, params);
  10659. var dict = params.dict;
  10660. var data = this.data;
  10661. var content = dict.get('Contents');
  10662. var title = dict.get('T');
  10663. data.annotationType = AnnotationType.TEXT;
  10664. data.content = stringToPDFString(content || '');
  10665. data.title = stringToPDFString(title || '');
  10666. data.hasHtml = true;
  10667. if (data.hasAppearance) {
  10668. data.name = 'NoIcon';
  10669. } else {
  10670. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10671. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10672. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10673. }
  10674. if (dict.has('C')) {
  10675. data.hasBgColor = true;
  10676. }
  10677. }
  10678. Util.inherit(TextAnnotation, Annotation, { });
  10679. return TextAnnotation;
  10680. })();
  10681. var LinkAnnotation = (function LinkAnnotationClosure() {
  10682. function LinkAnnotation(params) {
  10683. Annotation.call(this, params);
  10684. var dict = params.dict;
  10685. var data = this.data;
  10686. data.annotationType = AnnotationType.LINK;
  10687. data.hasHtml = true;
  10688. var action = dict.get('A');
  10689. if (action && isDict(action)) {
  10690. var linkType = action.get('S').name;
  10691. if (linkType === 'URI') {
  10692. var url = action.get('URI');
  10693. if (isName(url)) {
  10694. // Some bad PDFs do not put parentheses around relative URLs.
  10695. url = '/' + url.name;
  10696. } else if (url) {
  10697. url = addDefaultProtocolToUrl(url);
  10698. }
  10699. // TODO: pdf spec mentions urls can be relative to a Base
  10700. // entry in the dictionary.
  10701. if (!isValidUrl(url, false)) {
  10702. url = '';
  10703. }
  10704. // According to ISO 32000-1:2008, section 12.6.4.7,
  10705. // URI should to be encoded in 7-bit ASCII.
  10706. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  10707. try {
  10708. data.url = stringToUTF8String(url);
  10709. } catch (e) {
  10710. // Fall back to a simple copy.
  10711. data.url = url;
  10712. }
  10713. } else if (linkType === 'GoTo') {
  10714. data.dest = action.get('D');
  10715. } else if (linkType === 'GoToR') {
  10716. var urlDict = action.get('F');
  10717. if (isDict(urlDict)) {
  10718. // We assume that the 'url' is a Filspec dictionary
  10719. // and fetch the url without checking any further
  10720. url = urlDict.get('F') || '';
  10721. }
  10722. // TODO: pdf reference says that GoToR
  10723. // can also have 'NewWindow' attribute
  10724. if (!isValidUrl(url, false)) {
  10725. url = '';
  10726. }
  10727. data.url = url;
  10728. data.dest = action.get('D');
  10729. } else if (linkType === 'Named') {
  10730. data.action = action.get('N').name;
  10731. } else {
  10732. warn('unrecognized link type: ' + linkType);
  10733. }
  10734. } else if (dict.has('Dest')) {
  10735. // simple destination link
  10736. var dest = dict.get('Dest');
  10737. data.dest = isName(dest) ? dest.name : dest;
  10738. }
  10739. }
  10740. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10741. function addDefaultProtocolToUrl(url) {
  10742. if (url && url.indexOf('www.') === 0) {
  10743. return ('http://' + url);
  10744. }
  10745. return url;
  10746. }
  10747. Util.inherit(LinkAnnotation, Annotation, { });
  10748. return LinkAnnotation;
  10749. })();
  10750. var PDFFunction = (function PDFFunctionClosure() {
  10751. var CONSTRUCT_SAMPLED = 0;
  10752. var CONSTRUCT_INTERPOLATED = 2;
  10753. var CONSTRUCT_STICHED = 3;
  10754. var CONSTRUCT_POSTSCRIPT = 4;
  10755. return {
  10756. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10757. str) {
  10758. var i, ii;
  10759. var length = 1;
  10760. for (i = 0, ii = size.length; i < ii; i++) {
  10761. length *= size[i];
  10762. }
  10763. length *= outputSize;
  10764. var array = new Array(length);
  10765. var codeSize = 0;
  10766. var codeBuf = 0;
  10767. // 32 is a valid bps so shifting won't work
  10768. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10769. var strBytes = str.getBytes((length * bps + 7) / 8);
  10770. var strIdx = 0;
  10771. for (i = 0; i < length; i++) {
  10772. while (codeSize < bps) {
  10773. codeBuf <<= 8;
  10774. codeBuf |= strBytes[strIdx++];
  10775. codeSize += 8;
  10776. }
  10777. codeSize -= bps;
  10778. array[i] = (codeBuf >> codeSize) * sampleMul;
  10779. codeBuf &= (1 << codeSize) - 1;
  10780. }
  10781. return array;
  10782. },
  10783. getIR: function PDFFunction_getIR(xref, fn) {
  10784. var dict = fn.dict;
  10785. if (!dict) {
  10786. dict = fn;
  10787. }
  10788. var types = [this.constructSampled,
  10789. null,
  10790. this.constructInterpolated,
  10791. this.constructStiched,
  10792. this.constructPostScript];
  10793. var typeNum = dict.get('FunctionType');
  10794. var typeFn = types[typeNum];
  10795. if (!typeFn) {
  10796. error('Unknown type of function');
  10797. }
  10798. return typeFn.call(this, fn, dict, xref);
  10799. },
  10800. fromIR: function PDFFunction_fromIR(IR) {
  10801. var type = IR[0];
  10802. switch (type) {
  10803. case CONSTRUCT_SAMPLED:
  10804. return this.constructSampledFromIR(IR);
  10805. case CONSTRUCT_INTERPOLATED:
  10806. return this.constructInterpolatedFromIR(IR);
  10807. case CONSTRUCT_STICHED:
  10808. return this.constructStichedFromIR(IR);
  10809. //case CONSTRUCT_POSTSCRIPT:
  10810. default:
  10811. return this.constructPostScriptFromIR(IR);
  10812. }
  10813. },
  10814. parse: function PDFFunction_parse(xref, fn) {
  10815. var IR = this.getIR(xref, fn);
  10816. return this.fromIR(IR);
  10817. },
  10818. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10819. if (!isArray(fnObj)) {
  10820. // not an array -- parsing as regular function
  10821. return this.parse(xref, fnObj);
  10822. }
  10823. var fnArray = [];
  10824. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10825. var obj = xref.fetchIfRef(fnObj[j]);
  10826. fnArray.push(PDFFunction.parse(xref, obj));
  10827. }
  10828. return function (src, srcOffset, dest, destOffset) {
  10829. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10830. fnArray[i](src, srcOffset, dest, destOffset + i);
  10831. }
  10832. };
  10833. },
  10834. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10835. function toMultiArray(arr) {
  10836. var inputLength = arr.length;
  10837. var out = [];
  10838. var index = 0;
  10839. for (var i = 0; i < inputLength; i += 2) {
  10840. out[index] = [arr[i], arr[i + 1]];
  10841. ++index;
  10842. }
  10843. return out;
  10844. }
  10845. var domain = dict.get('Domain');
  10846. var range = dict.get('Range');
  10847. if (!domain || !range) {
  10848. error('No domain or range');
  10849. }
  10850. var inputSize = domain.length / 2;
  10851. var outputSize = range.length / 2;
  10852. domain = toMultiArray(domain);
  10853. range = toMultiArray(range);
  10854. var size = dict.get('Size');
  10855. var bps = dict.get('BitsPerSample');
  10856. var order = dict.get('Order') || 1;
  10857. if (order !== 1) {
  10858. // No description how cubic spline interpolation works in PDF32000:2008
  10859. // As in poppler, ignoring order, linear interpolation may work as good
  10860. info('No support for cubic spline interpolation: ' + order);
  10861. }
  10862. var encode = dict.get('Encode');
  10863. if (!encode) {
  10864. encode = [];
  10865. for (var i = 0; i < inputSize; ++i) {
  10866. encode.push(0);
  10867. encode.push(size[i] - 1);
  10868. }
  10869. }
  10870. encode = toMultiArray(encode);
  10871. var decode = dict.get('Decode');
  10872. if (!decode) {
  10873. decode = range;
  10874. } else {
  10875. decode = toMultiArray(decode);
  10876. }
  10877. var samples = this.getSampleArray(size, outputSize, bps, str);
  10878. return [
  10879. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10880. outputSize, Math.pow(2, bps) - 1, range
  10881. ];
  10882. },
  10883. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10884. // See chapter 3, page 109 of the PDF reference
  10885. function interpolate(x, xmin, xmax, ymin, ymax) {
  10886. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10887. }
  10888. return function constructSampledFromIRResult(src, srcOffset,
  10889. dest, destOffset) {
  10890. // See chapter 3, page 110 of the PDF reference.
  10891. var m = IR[1];
  10892. var domain = IR[2];
  10893. var encode = IR[3];
  10894. var decode = IR[4];
  10895. var samples = IR[5];
  10896. var size = IR[6];
  10897. var n = IR[7];
  10898. //var mask = IR[8];
  10899. var range = IR[9];
  10900. // Building the cube vertices: its part and sample index
  10901. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10902. var cubeVertices = 1 << m;
  10903. var cubeN = new Float64Array(cubeVertices);
  10904. var cubeVertex = new Uint32Array(cubeVertices);
  10905. var i, j;
  10906. for (j = 0; j < cubeVertices; j++) {
  10907. cubeN[j] = 1;
  10908. }
  10909. var k = n, pos = 1;
  10910. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10911. for (i = 0; i < m; ++i) {
  10912. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10913. var domain_2i = domain[i][0];
  10914. var domain_2i_1 = domain[i][1];
  10915. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10916. domain_2i_1);
  10917. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10918. // Encode_2i, Encode_2i+1)
  10919. var e = interpolate(xi, domain_2i, domain_2i_1,
  10920. encode[i][0], encode[i][1]);
  10921. // e_i' = min(max(e_i, 0), Size_i - 1)
  10922. var size_i = size[i];
  10923. e = Math.min(Math.max(e, 0), size_i - 1);
  10924. // Adjusting the cube: N and vertex sample index
  10925. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10926. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10927. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10928. var offset0 = e0 * k;
  10929. var offset1 = offset0 + k; // e1 * k
  10930. for (j = 0; j < cubeVertices; j++) {
  10931. if (j & pos) {
  10932. cubeN[j] *= n1;
  10933. cubeVertex[j] += offset1;
  10934. } else {
  10935. cubeN[j] *= n0;
  10936. cubeVertex[j] += offset0;
  10937. }
  10938. }
  10939. k *= size_i;
  10940. pos <<= 1;
  10941. }
  10942. for (j = 0; j < n; ++j) {
  10943. // Sum all cube vertices' samples portions
  10944. var rj = 0;
  10945. for (i = 0; i < cubeVertices; i++) {
  10946. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10947. }
  10948. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10949. // Decode_2j, Decode_2j+1)
  10950. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10951. // y_j = min(max(r_j, range_2j), range_2j+1)
  10952. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10953. range[j][1]);
  10954. }
  10955. };
  10956. },
  10957. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10958. dict) {
  10959. var c0 = dict.get('C0') || [0];
  10960. var c1 = dict.get('C1') || [1];
  10961. var n = dict.get('N');
  10962. if (!isArray(c0) || !isArray(c1)) {
  10963. error('Illegal dictionary for interpolated function');
  10964. }
  10965. var length = c0.length;
  10966. var diff = [];
  10967. for (var i = 0; i < length; ++i) {
  10968. diff.push(c1[i] - c0[i]);
  10969. }
  10970. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10971. },
  10972. constructInterpolatedFromIR:
  10973. function PDFFunction_constructInterpolatedFromIR(IR) {
  10974. var c0 = IR[1];
  10975. var diff = IR[2];
  10976. var n = IR[3];
  10977. var length = diff.length;
  10978. return function constructInterpolatedFromIRResult(src, srcOffset,
  10979. dest, destOffset) {
  10980. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10981. for (var j = 0; j < length; ++j) {
  10982. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10983. }
  10984. };
  10985. },
  10986. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10987. var domain = dict.get('Domain');
  10988. if (!domain) {
  10989. error('No domain');
  10990. }
  10991. var inputSize = domain.length / 2;
  10992. if (inputSize !== 1) {
  10993. error('Bad domain for stiched function');
  10994. }
  10995. var fnRefs = dict.get('Functions');
  10996. var fns = [];
  10997. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10998. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10999. }
  11000. var bounds = dict.get('Bounds');
  11001. var encode = dict.get('Encode');
  11002. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  11003. },
  11004. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  11005. var domain = IR[1];
  11006. var bounds = IR[2];
  11007. var encode = IR[3];
  11008. var fnsIR = IR[4];
  11009. var fns = [];
  11010. var tmpBuf = new Float32Array(1);
  11011. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  11012. fns.push(PDFFunction.fromIR(fnsIR[i]));
  11013. }
  11014. return function constructStichedFromIRResult(src, srcOffset,
  11015. dest, destOffset) {
  11016. var clip = function constructStichedFromIRClip(v, min, max) {
  11017. if (v > max) {
  11018. v = max;
  11019. } else if (v < min) {
  11020. v = min;
  11021. }
  11022. return v;
  11023. };
  11024. // clip to domain
  11025. var v = clip(src[srcOffset], domain[0], domain[1]);
  11026. // calulate which bound the value is in
  11027. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  11028. if (v < bounds[i]) {
  11029. break;
  11030. }
  11031. }
  11032. // encode value into domain of function
  11033. var dmin = domain[0];
  11034. if (i > 0) {
  11035. dmin = bounds[i - 1];
  11036. }
  11037. var dmax = domain[1];
  11038. if (i < bounds.length) {
  11039. dmax = bounds[i];
  11040. }
  11041. var rmin = encode[2 * i];
  11042. var rmax = encode[2 * i + 1];
  11043. // Prevent the value from becoming NaN as a result
  11044. // of division by zero (fixes issue6113.pdf).
  11045. tmpBuf[0] = dmin === dmax ? rmin :
  11046. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  11047. // call the appropriate function
  11048. fns[i](tmpBuf, 0, dest, destOffset);
  11049. };
  11050. },
  11051. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  11052. xref) {
  11053. var domain = dict.get('Domain');
  11054. var range = dict.get('Range');
  11055. if (!domain) {
  11056. error('No domain.');
  11057. }
  11058. if (!range) {
  11059. error('No range.');
  11060. }
  11061. var lexer = new PostScriptLexer(fn);
  11062. var parser = new PostScriptParser(lexer);
  11063. var code = parser.parse();
  11064. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  11065. },
  11066. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  11067. IR) {
  11068. var domain = IR[1];
  11069. var range = IR[2];
  11070. var code = IR[3];
  11071. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  11072. if (compiled) {
  11073. // Compiled function consists of simple expressions such as addition,
  11074. // subtraction, Math.max, and also contains 'var' and 'return'
  11075. // statements. See the generation in the PostScriptCompiler below.
  11076. /*jshint -W054 */
  11077. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  11078. }
  11079. info('Unable to compile PS function');
  11080. var numOutputs = range.length >> 1;
  11081. var numInputs = domain.length >> 1;
  11082. var evaluator = new PostScriptEvaluator(code);
  11083. // Cache the values for a big speed up, the cache size is limited though
  11084. // since the number of possible values can be huge from a PS function.
  11085. var cache = {};
  11086. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  11087. // seen in our tests.
  11088. var MAX_CACHE_SIZE = 2048 * 4;
  11089. var cache_available = MAX_CACHE_SIZE;
  11090. var tmpBuf = new Float32Array(numInputs);
  11091. return function constructPostScriptFromIRResult(src, srcOffset,
  11092. dest, destOffset) {
  11093. var i, value;
  11094. var key = '';
  11095. var input = tmpBuf;
  11096. for (i = 0; i < numInputs; i++) {
  11097. value = src[srcOffset + i];
  11098. input[i] = value;
  11099. key += value + '_';
  11100. }
  11101. var cachedValue = cache[key];
  11102. if (cachedValue !== undefined) {
  11103. dest.set(cachedValue, destOffset);
  11104. return;
  11105. }
  11106. var output = new Float32Array(numOutputs);
  11107. var stack = evaluator.execute(input);
  11108. var stackIndex = stack.length - numOutputs;
  11109. for (i = 0; i < numOutputs; i++) {
  11110. value = stack[stackIndex + i];
  11111. var bound = range[i * 2];
  11112. if (value < bound) {
  11113. value = bound;
  11114. } else {
  11115. bound = range[i * 2 +1];
  11116. if (value > bound) {
  11117. value = bound;
  11118. }
  11119. }
  11120. output[i] = value;
  11121. }
  11122. if (cache_available > 0) {
  11123. cache_available--;
  11124. cache[key] = output;
  11125. }
  11126. dest.set(output, destOffset);
  11127. };
  11128. }
  11129. };
  11130. })();
  11131. function isPDFFunction(v) {
  11132. var fnDict;
  11133. if (typeof v !== 'object') {
  11134. return false;
  11135. } else if (isDict(v)) {
  11136. fnDict = v;
  11137. } else if (isStream(v)) {
  11138. fnDict = v.dict;
  11139. } else {
  11140. return false;
  11141. }
  11142. return fnDict.has('FunctionType');
  11143. }
  11144. var PostScriptStack = (function PostScriptStackClosure() {
  11145. var MAX_STACK_SIZE = 100;
  11146. function PostScriptStack(initialStack) {
  11147. this.stack = !initialStack ? [] :
  11148. Array.prototype.slice.call(initialStack, 0);
  11149. }
  11150. PostScriptStack.prototype = {
  11151. push: function PostScriptStack_push(value) {
  11152. if (this.stack.length >= MAX_STACK_SIZE) {
  11153. error('PostScript function stack overflow.');
  11154. }
  11155. this.stack.push(value);
  11156. },
  11157. pop: function PostScriptStack_pop() {
  11158. if (this.stack.length <= 0) {
  11159. error('PostScript function stack underflow.');
  11160. }
  11161. return this.stack.pop();
  11162. },
  11163. copy: function PostScriptStack_copy(n) {
  11164. if (this.stack.length + n >= MAX_STACK_SIZE) {
  11165. error('PostScript function stack overflow.');
  11166. }
  11167. var stack = this.stack;
  11168. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  11169. stack.push(stack[i]);
  11170. }
  11171. },
  11172. index: function PostScriptStack_index(n) {
  11173. this.push(this.stack[this.stack.length - n - 1]);
  11174. },
  11175. // rotate the last n stack elements p times
  11176. roll: function PostScriptStack_roll(n, p) {
  11177. var stack = this.stack;
  11178. var l = stack.length - n;
  11179. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  11180. for (i = l, j = r; i < j; i++, j--) {
  11181. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11182. }
  11183. for (i = l, j = c - 1; i < j; i++, j--) {
  11184. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11185. }
  11186. for (i = c, j = r; i < j; i++, j--) {
  11187. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11188. }
  11189. }
  11190. };
  11191. return PostScriptStack;
  11192. })();
  11193. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  11194. function PostScriptEvaluator(operators) {
  11195. this.operators = operators;
  11196. }
  11197. PostScriptEvaluator.prototype = {
  11198. execute: function PostScriptEvaluator_execute(initialStack) {
  11199. var stack = new PostScriptStack(initialStack);
  11200. var counter = 0;
  11201. var operators = this.operators;
  11202. var length = operators.length;
  11203. var operator, a, b;
  11204. while (counter < length) {
  11205. operator = operators[counter++];
  11206. if (typeof operator === 'number') {
  11207. // Operator is really an operand and should be pushed to the stack.
  11208. stack.push(operator);
  11209. continue;
  11210. }
  11211. switch (operator) {
  11212. // non standard ps operators
  11213. case 'jz': // jump if false
  11214. b = stack.pop();
  11215. a = stack.pop();
  11216. if (!a) {
  11217. counter = b;
  11218. }
  11219. break;
  11220. case 'j': // jump
  11221. a = stack.pop();
  11222. counter = a;
  11223. break;
  11224. // all ps operators in alphabetical order (excluding if/ifelse)
  11225. case 'abs':
  11226. a = stack.pop();
  11227. stack.push(Math.abs(a));
  11228. break;
  11229. case 'add':
  11230. b = stack.pop();
  11231. a = stack.pop();
  11232. stack.push(a + b);
  11233. break;
  11234. case 'and':
  11235. b = stack.pop();
  11236. a = stack.pop();
  11237. if (isBool(a) && isBool(b)) {
  11238. stack.push(a && b);
  11239. } else {
  11240. stack.push(a & b);
  11241. }
  11242. break;
  11243. case 'atan':
  11244. a = stack.pop();
  11245. stack.push(Math.atan(a));
  11246. break;
  11247. case 'bitshift':
  11248. b = stack.pop();
  11249. a = stack.pop();
  11250. if (a > 0) {
  11251. stack.push(a << b);
  11252. } else {
  11253. stack.push(a >> b);
  11254. }
  11255. break;
  11256. case 'ceiling':
  11257. a = stack.pop();
  11258. stack.push(Math.ceil(a));
  11259. break;
  11260. case 'copy':
  11261. a = stack.pop();
  11262. stack.copy(a);
  11263. break;
  11264. case 'cos':
  11265. a = stack.pop();
  11266. stack.push(Math.cos(a));
  11267. break;
  11268. case 'cvi':
  11269. a = stack.pop() | 0;
  11270. stack.push(a);
  11271. break;
  11272. case 'cvr':
  11273. // noop
  11274. break;
  11275. case 'div':
  11276. b = stack.pop();
  11277. a = stack.pop();
  11278. stack.push(a / b);
  11279. break;
  11280. case 'dup':
  11281. stack.copy(1);
  11282. break;
  11283. case 'eq':
  11284. b = stack.pop();
  11285. a = stack.pop();
  11286. stack.push(a === b);
  11287. break;
  11288. case 'exch':
  11289. stack.roll(2, 1);
  11290. break;
  11291. case 'exp':
  11292. b = stack.pop();
  11293. a = stack.pop();
  11294. stack.push(Math.pow(a, b));
  11295. break;
  11296. case 'false':
  11297. stack.push(false);
  11298. break;
  11299. case 'floor':
  11300. a = stack.pop();
  11301. stack.push(Math.floor(a));
  11302. break;
  11303. case 'ge':
  11304. b = stack.pop();
  11305. a = stack.pop();
  11306. stack.push(a >= b);
  11307. break;
  11308. case 'gt':
  11309. b = stack.pop();
  11310. a = stack.pop();
  11311. stack.push(a > b);
  11312. break;
  11313. case 'idiv':
  11314. b = stack.pop();
  11315. a = stack.pop();
  11316. stack.push((a / b) | 0);
  11317. break;
  11318. case 'index':
  11319. a = stack.pop();
  11320. stack.index(a);
  11321. break;
  11322. case 'le':
  11323. b = stack.pop();
  11324. a = stack.pop();
  11325. stack.push(a <= b);
  11326. break;
  11327. case 'ln':
  11328. a = stack.pop();
  11329. stack.push(Math.log(a));
  11330. break;
  11331. case 'log':
  11332. a = stack.pop();
  11333. stack.push(Math.log(a) / Math.LN10);
  11334. break;
  11335. case 'lt':
  11336. b = stack.pop();
  11337. a = stack.pop();
  11338. stack.push(a < b);
  11339. break;
  11340. case 'mod':
  11341. b = stack.pop();
  11342. a = stack.pop();
  11343. stack.push(a % b);
  11344. break;
  11345. case 'mul':
  11346. b = stack.pop();
  11347. a = stack.pop();
  11348. stack.push(a * b);
  11349. break;
  11350. case 'ne':
  11351. b = stack.pop();
  11352. a = stack.pop();
  11353. stack.push(a !== b);
  11354. break;
  11355. case 'neg':
  11356. a = stack.pop();
  11357. stack.push(-a);
  11358. break;
  11359. case 'not':
  11360. a = stack.pop();
  11361. if (isBool(a)) {
  11362. stack.push(!a);
  11363. } else {
  11364. stack.push(~a);
  11365. }
  11366. break;
  11367. case 'or':
  11368. b = stack.pop();
  11369. a = stack.pop();
  11370. if (isBool(a) && isBool(b)) {
  11371. stack.push(a || b);
  11372. } else {
  11373. stack.push(a | b);
  11374. }
  11375. break;
  11376. case 'pop':
  11377. stack.pop();
  11378. break;
  11379. case 'roll':
  11380. b = stack.pop();
  11381. a = stack.pop();
  11382. stack.roll(a, b);
  11383. break;
  11384. case 'round':
  11385. a = stack.pop();
  11386. stack.push(Math.round(a));
  11387. break;
  11388. case 'sin':
  11389. a = stack.pop();
  11390. stack.push(Math.sin(a));
  11391. break;
  11392. case 'sqrt':
  11393. a = stack.pop();
  11394. stack.push(Math.sqrt(a));
  11395. break;
  11396. case 'sub':
  11397. b = stack.pop();
  11398. a = stack.pop();
  11399. stack.push(a - b);
  11400. break;
  11401. case 'true':
  11402. stack.push(true);
  11403. break;
  11404. case 'truncate':
  11405. a = stack.pop();
  11406. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11407. stack.push(a);
  11408. break;
  11409. case 'xor':
  11410. b = stack.pop();
  11411. a = stack.pop();
  11412. if (isBool(a) && isBool(b)) {
  11413. stack.push(a !== b);
  11414. } else {
  11415. stack.push(a ^ b);
  11416. }
  11417. break;
  11418. default:
  11419. error('Unknown operator ' + operator);
  11420. break;
  11421. }
  11422. }
  11423. return stack.stack;
  11424. }
  11425. };
  11426. return PostScriptEvaluator;
  11427. })();
  11428. // Most of the PDFs functions consist of simple operations such as:
  11429. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11430. //
  11431. // We can compile most of such programs, and at the same moment, we can
  11432. // optimize some expressions using basic math properties. Keeping track of
  11433. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11434. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11435. function AstNode(type) {
  11436. this.type = type;
  11437. }
  11438. AstNode.prototype.visit = function (visitor) {
  11439. throw new Error('abstract method');
  11440. };
  11441. function AstArgument(index, min, max) {
  11442. AstNode.call(this, 'args');
  11443. this.index = index;
  11444. this.min = min;
  11445. this.max = max;
  11446. }
  11447. AstArgument.prototype = Object.create(AstNode.prototype);
  11448. AstArgument.prototype.visit = function (visitor) {
  11449. visitor.visitArgument(this);
  11450. };
  11451. function AstLiteral(number) {
  11452. AstNode.call(this, 'literal');
  11453. this.number = number;
  11454. this.min = number;
  11455. this.max = number;
  11456. }
  11457. AstLiteral.prototype = Object.create(AstNode.prototype);
  11458. AstLiteral.prototype.visit = function (visitor) {
  11459. visitor.visitLiteral(this);
  11460. };
  11461. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11462. AstNode.call(this, 'binary');
  11463. this.op = op;
  11464. this.arg1 = arg1;
  11465. this.arg2 = arg2;
  11466. this.min = min;
  11467. this.max = max;
  11468. }
  11469. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11470. AstBinaryOperation.prototype.visit = function (visitor) {
  11471. visitor.visitBinaryOperation(this);
  11472. };
  11473. function AstMin(arg, max) {
  11474. AstNode.call(this, 'max');
  11475. this.arg = arg;
  11476. this.min = arg.min;
  11477. this.max = max;
  11478. }
  11479. AstMin.prototype = Object.create(AstNode.prototype);
  11480. AstMin.prototype.visit = function (visitor) {
  11481. visitor.visitMin(this);
  11482. };
  11483. function AstVariable(index, min, max) {
  11484. AstNode.call(this, 'var');
  11485. this.index = index;
  11486. this.min = min;
  11487. this.max = max;
  11488. }
  11489. AstVariable.prototype = Object.create(AstNode.prototype);
  11490. AstVariable.prototype.visit = function (visitor) {
  11491. visitor.visitVariable(this);
  11492. };
  11493. function AstVariableDefinition(variable, arg) {
  11494. AstNode.call(this, 'definition');
  11495. this.variable = variable;
  11496. this.arg = arg;
  11497. }
  11498. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11499. AstVariableDefinition.prototype.visit = function (visitor) {
  11500. visitor.visitVariableDefinition(this);
  11501. };
  11502. function ExpressionBuilderVisitor() {
  11503. this.parts = [];
  11504. }
  11505. ExpressionBuilderVisitor.prototype = {
  11506. visitArgument: function (arg) {
  11507. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11508. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11509. },
  11510. visitVariable: function (variable) {
  11511. this.parts.push('v', variable.index);
  11512. },
  11513. visitLiteral: function (literal) {
  11514. this.parts.push(literal.number);
  11515. },
  11516. visitBinaryOperation: function (operation) {
  11517. this.parts.push('(');
  11518. operation.arg1.visit(this);
  11519. this.parts.push(' ', operation.op, ' ');
  11520. operation.arg2.visit(this);
  11521. this.parts.push(')');
  11522. },
  11523. visitVariableDefinition: function (definition) {
  11524. this.parts.push('var ');
  11525. definition.variable.visit(this);
  11526. this.parts.push(' = ');
  11527. definition.arg.visit(this);
  11528. this.parts.push(';');
  11529. },
  11530. visitMin: function (max) {
  11531. this.parts.push('Math.min(');
  11532. max.arg.visit(this);
  11533. this.parts.push(', ', max.max, ')');
  11534. },
  11535. toString: function () {
  11536. return this.parts.join('');
  11537. }
  11538. };
  11539. function buildAddOperation(num1, num2) {
  11540. if (num2.type === 'literal' && num2.number === 0) {
  11541. // optimization: second operand is 0
  11542. return num1;
  11543. }
  11544. if (num1.type === 'literal' && num1.number === 0) {
  11545. // optimization: first operand is 0
  11546. return num2;
  11547. }
  11548. if (num2.type === 'literal' && num1.type === 'literal') {
  11549. // optimization: operands operand are literals
  11550. return new AstLiteral(num1.number + num2.number);
  11551. }
  11552. return new AstBinaryOperation('+', num1, num2,
  11553. num1.min + num2.min, num1.max + num2.max);
  11554. }
  11555. function buildMulOperation(num1, num2) {
  11556. if (num2.type === 'literal') {
  11557. // optimization: second operands is a literal...
  11558. if (num2.number === 0) {
  11559. return new AstLiteral(0); // and it's 0
  11560. } else if (num2.number === 1) {
  11561. return num1; // and it's 1
  11562. } else if (num1.type === 'literal') {
  11563. // ... and first operands is a literal too
  11564. return new AstLiteral(num1.number * num2.number);
  11565. }
  11566. }
  11567. if (num1.type === 'literal') {
  11568. // optimization: first operands is a literal...
  11569. if (num1.number === 0) {
  11570. return new AstLiteral(0); // and it's 0
  11571. } else if (num1.number === 1) {
  11572. return num2; // and it's 1
  11573. }
  11574. }
  11575. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11576. num1.max * num2.min, num1.max * num2.max);
  11577. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11578. num1.max * num2.min, num1.max * num2.max);
  11579. return new AstBinaryOperation('*', num1, num2, min, max);
  11580. }
  11581. function buildSubOperation(num1, num2) {
  11582. if (num2.type === 'literal') {
  11583. // optimization: second operands is a literal...
  11584. if (num2.number === 0) {
  11585. return num1; // ... and it's 0
  11586. } else if (num1.type === 'literal') {
  11587. // ... and first operands is a literal too
  11588. return new AstLiteral(num1.number - num2.number);
  11589. }
  11590. }
  11591. if (num2.type === 'binary' && num2.op === '-' &&
  11592. num1.type === 'literal' && num1.number === 1 &&
  11593. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11594. // optimization for case: 1 - (1 - x)
  11595. return num2.arg2;
  11596. }
  11597. return new AstBinaryOperation('-', num1, num2,
  11598. num1.min - num2.max, num1.max - num2.min);
  11599. }
  11600. function buildMinOperation(num1, max) {
  11601. if (num1.min >= max) {
  11602. // optimization: num1 min value is not less than required max
  11603. return new AstLiteral(max); // just returning max
  11604. } else if (num1.max <= max) {
  11605. // optimization: num1 max value is not greater than required max
  11606. return num1; // just returning an argument
  11607. }
  11608. return new AstMin(num1, max);
  11609. }
  11610. function PostScriptCompiler() {}
  11611. PostScriptCompiler.prototype = {
  11612. compile: function PostScriptCompiler_compile(code, domain, range) {
  11613. var stack = [];
  11614. var i, ii;
  11615. var instructions = [];
  11616. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11617. var lastRegister = 0;
  11618. var n, j, min, max;
  11619. var num1, num2, ast1, ast2, tmpVar, item;
  11620. for (i = 0; i < inputSize; i++) {
  11621. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11622. }
  11623. for (i = 0, ii = code.length; i < ii; i++) {
  11624. item = code[i];
  11625. if (typeof item === 'number') {
  11626. stack.push(new AstLiteral(item));
  11627. continue;
  11628. }
  11629. switch (item) {
  11630. case 'add':
  11631. if (stack.length < 2) {
  11632. return null;
  11633. }
  11634. num2 = stack.pop();
  11635. num1 = stack.pop();
  11636. stack.push(buildAddOperation(num1, num2));
  11637. break;
  11638. case 'cvr':
  11639. if (stack.length < 1) {
  11640. return null;
  11641. }
  11642. break;
  11643. case 'mul':
  11644. if (stack.length < 2) {
  11645. return null;
  11646. }
  11647. num2 = stack.pop();
  11648. num1 = stack.pop();
  11649. stack.push(buildMulOperation(num1, num2));
  11650. break;
  11651. case 'sub':
  11652. if (stack.length < 2) {
  11653. return null;
  11654. }
  11655. num2 = stack.pop();
  11656. num1 = stack.pop();
  11657. stack.push(buildSubOperation(num1, num2));
  11658. break;
  11659. case 'exch':
  11660. if (stack.length < 2) {
  11661. return null;
  11662. }
  11663. ast1 = stack.pop(); ast2 = stack.pop();
  11664. stack.push(ast1, ast2);
  11665. break;
  11666. case 'pop':
  11667. if (stack.length < 1) {
  11668. return null;
  11669. }
  11670. stack.pop();
  11671. break;
  11672. case 'index':
  11673. if (stack.length < 1) {
  11674. return null;
  11675. }
  11676. num1 = stack.pop();
  11677. if (num1.type !== 'literal') {
  11678. return null;
  11679. }
  11680. n = num1.number;
  11681. if (n < 0 || (n|0) !== n || stack.length < n) {
  11682. return null;
  11683. }
  11684. ast1 = stack[stack.length - n - 1];
  11685. if (ast1.type === 'literal' || ast1.type === 'var') {
  11686. stack.push(ast1);
  11687. break;
  11688. }
  11689. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11690. stack[stack.length - n - 1] = tmpVar;
  11691. stack.push(tmpVar);
  11692. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11693. break;
  11694. case 'dup':
  11695. if (stack.length < 1) {
  11696. return null;
  11697. }
  11698. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11699. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11700. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11701. // special case of the commands sequence for the min operation
  11702. num1 = stack.pop();
  11703. stack.push(buildMinOperation(num1, code[i + 1]));
  11704. i += 6;
  11705. break;
  11706. }
  11707. ast1 = stack[stack.length - 1];
  11708. if (ast1.type === 'literal' || ast1.type === 'var') {
  11709. // we don't have to save into intermediate variable a literal or
  11710. // variable.
  11711. stack.push(ast1);
  11712. break;
  11713. }
  11714. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11715. stack[stack.length - 1] = tmpVar;
  11716. stack.push(tmpVar);
  11717. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11718. break;
  11719. case 'roll':
  11720. if (stack.length < 2) {
  11721. return null;
  11722. }
  11723. num2 = stack.pop();
  11724. num1 = stack.pop();
  11725. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11726. // both roll operands must be numbers
  11727. return null;
  11728. }
  11729. j = num2.number;
  11730. n = num1.number;
  11731. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11732. // ... and integers
  11733. return null;
  11734. }
  11735. j = ((j % n) + n) % n;
  11736. if (j === 0) {
  11737. break; // just skipping -- there are nothing to rotate
  11738. }
  11739. Array.prototype.push.apply(stack,
  11740. stack.splice(stack.length - n, n - j));
  11741. break;
  11742. default:
  11743. return null; // unsupported operator
  11744. }
  11745. }
  11746. if (stack.length !== outputSize) {
  11747. return null;
  11748. }
  11749. var result = [];
  11750. instructions.forEach(function (instruction) {
  11751. var statementBuilder = new ExpressionBuilderVisitor();
  11752. instruction.visit(statementBuilder);
  11753. result.push(statementBuilder.toString());
  11754. });
  11755. stack.forEach(function (expr, i) {
  11756. var statementBuilder = new ExpressionBuilderVisitor();
  11757. expr.visit(statementBuilder);
  11758. var min = range[i * 2], max = range[i * 2 + 1];
  11759. var out = [statementBuilder.toString()];
  11760. if (min > expr.min) {
  11761. out.unshift('Math.max(', min, ', ');
  11762. out.push(')');
  11763. }
  11764. if (max < expr.max) {
  11765. out.unshift('Math.min(', max, ', ');
  11766. out.push(')');
  11767. }
  11768. out.unshift('dest[destOffset + ', i, '] = ');
  11769. out.push(';');
  11770. result.push(out.join(''));
  11771. });
  11772. return result.join('\n');
  11773. }
  11774. };
  11775. return PostScriptCompiler;
  11776. })();
  11777. var ColorSpace = (function ColorSpaceClosure() {
  11778. // Constructor should define this.numComps, this.defaultColor, this.name
  11779. function ColorSpace() {
  11780. error('should not call ColorSpace constructor');
  11781. }
  11782. ColorSpace.prototype = {
  11783. /**
  11784. * Converts the color value to the RGB color. The color components are
  11785. * located in the src array starting from the srcOffset. Returns the array
  11786. * of the rgb components, each value ranging from [0,255].
  11787. */
  11788. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11789. var rgb = new Uint8Array(3);
  11790. this.getRgbItem(src, srcOffset, rgb, 0);
  11791. return rgb;
  11792. },
  11793. /**
  11794. * Converts the color value to the RGB color, similar to the getRgb method.
  11795. * The result placed into the dest array starting from the destOffset.
  11796. */
  11797. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11798. dest, destOffset) {
  11799. error('Should not call ColorSpace.getRgbItem');
  11800. },
  11801. /**
  11802. * Converts the specified number of the color values to the RGB colors.
  11803. * The colors are located in the src array starting from the srcOffset.
  11804. * The result is placed into the dest array starting from the destOffset.
  11805. * The src array items shall be in [0,2^bits) range, the dest array items
  11806. * will be in [0,255] range. alpha01 indicates how many alpha components
  11807. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11808. * array).
  11809. */
  11810. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11811. dest, destOffset, bits,
  11812. alpha01) {
  11813. error('Should not call ColorSpace.getRgbBuffer');
  11814. },
  11815. /**
  11816. * Determines the number of bytes required to store the result of the
  11817. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11818. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11819. */
  11820. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11821. alpha01) {
  11822. error('Should not call ColorSpace.getOutputLength');
  11823. },
  11824. /**
  11825. * Returns true if source data will be equal the result/output data.
  11826. */
  11827. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11828. return false;
  11829. },
  11830. /**
  11831. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11832. * how many alpha components there are in the dest array; it will be either
  11833. * 0 (RGB array) or 1 (RGBA array).
  11834. */
  11835. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11836. originalHeight, width, height,
  11837. actualHeight, bpc, comps, alpha01) {
  11838. var count = originalWidth * originalHeight;
  11839. var rgbBuf = null;
  11840. var numComponentColors = 1 << bpc;
  11841. var needsResizing = originalHeight !== height || originalWidth !== width;
  11842. var i, ii;
  11843. if (this.isPassthrough(bpc)) {
  11844. rgbBuf = comps;
  11845. } else if (this.numComps === 1 && count > numComponentColors &&
  11846. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11847. // Optimization: create a color map when there is just one component and
  11848. // we are converting more colors than the size of the color map. We
  11849. // don't build the map if the colorspace is gray or rgb since those
  11850. // methods are faster than building a map. This mainly offers big speed
  11851. // ups for indexed and alternate colorspaces.
  11852. //
  11853. // TODO it may be worth while to cache the color map. While running
  11854. // testing I never hit a cache so I will leave that out for now (perhaps
  11855. // we are reparsing colorspaces too much?).
  11856. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11857. new Uint16Array(numComponentColors);
  11858. var key;
  11859. for (i = 0; i < numComponentColors; i++) {
  11860. allColors[i] = i;
  11861. }
  11862. var colorMap = new Uint8Array(numComponentColors * 3);
  11863. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11864. /* alpha01 = */ 0);
  11865. var destPos, rgbPos;
  11866. if (!needsResizing) {
  11867. // Fill in the RGB values directly into |dest|.
  11868. destPos = 0;
  11869. for (i = 0; i < count; ++i) {
  11870. key = comps[i] * 3;
  11871. dest[destPos++] = colorMap[key];
  11872. dest[destPos++] = colorMap[key + 1];
  11873. dest[destPos++] = colorMap[key + 2];
  11874. destPos += alpha01;
  11875. }
  11876. } else {
  11877. rgbBuf = new Uint8Array(count * 3);
  11878. rgbPos = 0;
  11879. for (i = 0; i < count; ++i) {
  11880. key = comps[i] * 3;
  11881. rgbBuf[rgbPos++] = colorMap[key];
  11882. rgbBuf[rgbPos++] = colorMap[key + 1];
  11883. rgbBuf[rgbPos++] = colorMap[key + 2];
  11884. }
  11885. }
  11886. } else {
  11887. if (!needsResizing) {
  11888. // Fill in the RGB values directly into |dest|.
  11889. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11890. alpha01);
  11891. } else {
  11892. rgbBuf = new Uint8Array(count * 3);
  11893. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11894. /* alpha01 = */ 0);
  11895. }
  11896. }
  11897. if (rgbBuf) {
  11898. if (needsResizing) {
  11899. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11900. height, dest, alpha01);
  11901. } else {
  11902. rgbPos = 0;
  11903. destPos = 0;
  11904. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11905. dest[destPos++] = rgbBuf[rgbPos++];
  11906. dest[destPos++] = rgbBuf[rgbPos++];
  11907. dest[destPos++] = rgbBuf[rgbPos++];
  11908. destPos += alpha01;
  11909. }
  11910. }
  11911. }
  11912. },
  11913. /**
  11914. * True if the colorspace has components in the default range of [0, 1].
  11915. * This should be true for all colorspaces except for lab color spaces
  11916. * which are [0,100], [-128, 127], [-128, 127].
  11917. */
  11918. usesZeroToOneRange: true
  11919. };
  11920. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11921. var IR = ColorSpace.parseToIR(cs, xref, res);
  11922. if (IR instanceof AlternateCS) {
  11923. return IR;
  11924. }
  11925. return ColorSpace.fromIR(IR);
  11926. };
  11927. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11928. var name = isArray(IR) ? IR[0] : IR;
  11929. var whitePoint, blackPoint, gamma;
  11930. switch (name) {
  11931. case 'DeviceGrayCS':
  11932. return this.singletons.gray;
  11933. case 'DeviceRgbCS':
  11934. return this.singletons.rgb;
  11935. case 'DeviceCmykCS':
  11936. return this.singletons.cmyk;
  11937. case 'CalGrayCS':
  11938. whitePoint = IR[1].WhitePoint;
  11939. blackPoint = IR[1].BlackPoint;
  11940. gamma = IR[1].Gamma;
  11941. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11942. case 'CalRGBCS':
  11943. whitePoint = IR[1].WhitePoint;
  11944. blackPoint = IR[1].BlackPoint;
  11945. gamma = IR[1].Gamma;
  11946. var matrix = IR[1].Matrix;
  11947. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11948. case 'PatternCS':
  11949. var basePatternCS = IR[1];
  11950. if (basePatternCS) {
  11951. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11952. }
  11953. return new PatternCS(basePatternCS);
  11954. case 'IndexedCS':
  11955. var baseIndexedCS = IR[1];
  11956. var hiVal = IR[2];
  11957. var lookup = IR[3];
  11958. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11959. case 'AlternateCS':
  11960. var numComps = IR[1];
  11961. var alt = IR[2];
  11962. var tintFnIR = IR[3];
  11963. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11964. PDFFunction.fromIR(tintFnIR));
  11965. case 'LabCS':
  11966. whitePoint = IR[1].WhitePoint;
  11967. blackPoint = IR[1].BlackPoint;
  11968. var range = IR[1].Range;
  11969. return new LabCS(whitePoint, blackPoint, range);
  11970. default:
  11971. error('Unknown name ' + name);
  11972. }
  11973. return null;
  11974. };
  11975. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11976. if (isName(cs)) {
  11977. var colorSpaces = res.get('ColorSpace');
  11978. if (isDict(colorSpaces)) {
  11979. var refcs = colorSpaces.get(cs.name);
  11980. if (refcs) {
  11981. cs = refcs;
  11982. }
  11983. }
  11984. }
  11985. cs = xref.fetchIfRef(cs);
  11986. var mode;
  11987. if (isName(cs)) {
  11988. mode = cs.name;
  11989. this.mode = mode;
  11990. switch (mode) {
  11991. case 'DeviceGray':
  11992. case 'G':
  11993. return 'DeviceGrayCS';
  11994. case 'DeviceRGB':
  11995. case 'RGB':
  11996. return 'DeviceRgbCS';
  11997. case 'DeviceCMYK':
  11998. case 'CMYK':
  11999. return 'DeviceCmykCS';
  12000. case 'Pattern':
  12001. return ['PatternCS', null];
  12002. default:
  12003. error('unrecognized colorspace ' + mode);
  12004. }
  12005. } else if (isArray(cs)) {
  12006. mode = xref.fetchIfRef(cs[0]).name;
  12007. this.mode = mode;
  12008. var numComps, params, alt;
  12009. switch (mode) {
  12010. case 'DeviceGray':
  12011. case 'G':
  12012. return 'DeviceGrayCS';
  12013. case 'DeviceRGB':
  12014. case 'RGB':
  12015. return 'DeviceRgbCS';
  12016. case 'DeviceCMYK':
  12017. case 'CMYK':
  12018. return 'DeviceCmykCS';
  12019. case 'CalGray':
  12020. params = xref.fetchIfRef(cs[1]).getAll();
  12021. return ['CalGrayCS', params];
  12022. case 'CalRGB':
  12023. params = xref.fetchIfRef(cs[1]).getAll();
  12024. return ['CalRGBCS', params];
  12025. case 'ICCBased':
  12026. var stream = xref.fetchIfRef(cs[1]);
  12027. var dict = stream.dict;
  12028. numComps = dict.get('N');
  12029. alt = dict.get('Alternate');
  12030. if (alt) {
  12031. var altIR = ColorSpace.parseToIR(alt, xref, res);
  12032. // Parse the /Alternate CS to ensure that the number of components
  12033. // are correct, and also (indirectly) that it is not a PatternCS.
  12034. var altCS = ColorSpace.fromIR(altIR);
  12035. if (altCS.numComps === numComps) {
  12036. return altIR;
  12037. }
  12038. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  12039. }
  12040. if (numComps === 1) {
  12041. return 'DeviceGrayCS';
  12042. } else if (numComps === 3) {
  12043. return 'DeviceRgbCS';
  12044. } else if (numComps === 4) {
  12045. return 'DeviceCmykCS';
  12046. }
  12047. break;
  12048. case 'Pattern':
  12049. var basePatternCS = cs[1] || null;
  12050. if (basePatternCS) {
  12051. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  12052. }
  12053. return ['PatternCS', basePatternCS];
  12054. case 'Indexed':
  12055. case 'I':
  12056. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  12057. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  12058. var lookup = xref.fetchIfRef(cs[3]);
  12059. if (isStream(lookup)) {
  12060. lookup = lookup.getBytes();
  12061. }
  12062. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  12063. case 'Separation':
  12064. case 'DeviceN':
  12065. var name = xref.fetchIfRef(cs[1]);
  12066. numComps = 1;
  12067. if (isName(name)) {
  12068. numComps = 1;
  12069. } else if (isArray(name)) {
  12070. numComps = name.length;
  12071. }
  12072. alt = ColorSpace.parseToIR(cs[2], xref, res);
  12073. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  12074. return ['AlternateCS', numComps, alt, tintFnIR];
  12075. case 'Lab':
  12076. params = xref.fetchIfRef(cs[1]).getAll();
  12077. return ['LabCS', params];
  12078. default:
  12079. error('unimplemented color space object "' + mode + '"');
  12080. }
  12081. } else {
  12082. error('unrecognized color space object: "' + cs + '"');
  12083. }
  12084. return null;
  12085. };
  12086. /**
  12087. * Checks if a decode map matches the default decode map for a color space.
  12088. * This handles the general decode maps where there are two values per
  12089. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  12090. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  12091. * slightly different.
  12092. * @param {Array} decode Decode map (usually from an image).
  12093. * @param {Number} n Number of components the color space has.
  12094. */
  12095. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  12096. if (!isArray(decode)) {
  12097. return true;
  12098. }
  12099. if (n * 2 !== decode.length) {
  12100. warn('The decode map is not the correct length');
  12101. return true;
  12102. }
  12103. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  12104. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  12105. return false;
  12106. }
  12107. }
  12108. return true;
  12109. };
  12110. ColorSpace.singletons = {
  12111. get gray() {
  12112. return shadow(this, 'gray', new DeviceGrayCS());
  12113. },
  12114. get rgb() {
  12115. return shadow(this, 'rgb', new DeviceRgbCS());
  12116. },
  12117. get cmyk() {
  12118. return shadow(this, 'cmyk', new DeviceCmykCS());
  12119. }
  12120. };
  12121. return ColorSpace;
  12122. })();
  12123. /**
  12124. * Alternate color space handles both Separation and DeviceN color spaces. A
  12125. * Separation color space is actually just a DeviceN with one color component.
  12126. * Both color spaces use a tinting function to convert colors to a base color
  12127. * space.
  12128. */
  12129. var AlternateCS = (function AlternateCSClosure() {
  12130. function AlternateCS(numComps, base, tintFn) {
  12131. this.name = 'Alternate';
  12132. this.numComps = numComps;
  12133. this.defaultColor = new Float32Array(numComps);
  12134. for (var i = 0; i < numComps; ++i) {
  12135. this.defaultColor[i] = 1;
  12136. }
  12137. this.base = base;
  12138. this.tintFn = tintFn;
  12139. this.tmpBuf = new Float32Array(base.numComps);
  12140. }
  12141. AlternateCS.prototype = {
  12142. getRgb: ColorSpace.prototype.getRgb,
  12143. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  12144. dest, destOffset) {
  12145. var tmpBuf = this.tmpBuf;
  12146. this.tintFn(src, srcOffset, tmpBuf, 0);
  12147. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  12148. },
  12149. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  12150. dest, destOffset, bits,
  12151. alpha01) {
  12152. var tintFn = this.tintFn;
  12153. var base = this.base;
  12154. var scale = 1 / ((1 << bits) - 1);
  12155. var baseNumComps = base.numComps;
  12156. var usesZeroToOneRange = base.usesZeroToOneRange;
  12157. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  12158. alpha01 === 0;
  12159. var pos = isPassthrough ? destOffset : 0;
  12160. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  12161. var numComps = this.numComps;
  12162. var scaled = new Float32Array(numComps);
  12163. var tinted = new Float32Array(baseNumComps);
  12164. var i, j;
  12165. if (usesZeroToOneRange) {
  12166. for (i = 0; i < count; i++) {
  12167. for (j = 0; j < numComps; j++) {
  12168. scaled[j] = src[srcOffset++] * scale;
  12169. }
  12170. tintFn(scaled, 0, tinted, 0);
  12171. for (j = 0; j < baseNumComps; j++) {
  12172. baseBuf[pos++] = tinted[j] * 255;
  12173. }
  12174. }
  12175. } else {
  12176. for (i = 0; i < count; i++) {
  12177. for (j = 0; j < numComps; j++) {
  12178. scaled[j] = src[srcOffset++] * scale;
  12179. }
  12180. tintFn(scaled, 0, tinted, 0);
  12181. base.getRgbItem(tinted, 0, baseBuf, pos);
  12182. pos += baseNumComps;
  12183. }
  12184. }
  12185. if (!isPassthrough) {
  12186. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  12187. }
  12188. },
  12189. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  12190. alpha01) {
  12191. return this.base.getOutputLength(inputLength *
  12192. this.base.numComps / this.numComps,
  12193. alpha01);
  12194. },
  12195. isPassthrough: ColorSpace.prototype.isPassthrough,
  12196. fillRgb: ColorSpace.prototype.fillRgb,
  12197. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  12198. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12199. },
  12200. usesZeroToOneRange: true
  12201. };
  12202. return AlternateCS;
  12203. })();
  12204. var PatternCS = (function PatternCSClosure() {
  12205. function PatternCS(baseCS) {
  12206. this.name = 'Pattern';
  12207. this.base = baseCS;
  12208. }
  12209. PatternCS.prototype = {};
  12210. return PatternCS;
  12211. })();
  12212. var IndexedCS = (function IndexedCSClosure() {
  12213. function IndexedCS(base, highVal, lookup) {
  12214. this.name = 'Indexed';
  12215. this.numComps = 1;
  12216. this.defaultColor = new Uint8Array([0]);
  12217. this.base = base;
  12218. this.highVal = highVal;
  12219. var baseNumComps = base.numComps;
  12220. var length = baseNumComps * highVal;
  12221. var lookupArray;
  12222. if (isStream(lookup)) {
  12223. lookupArray = new Uint8Array(length);
  12224. var bytes = lookup.getBytes(length);
  12225. lookupArray.set(bytes);
  12226. } else if (isString(lookup)) {
  12227. lookupArray = new Uint8Array(length);
  12228. for (var i = 0; i < length; ++i) {
  12229. lookupArray[i] = lookup.charCodeAt(i);
  12230. }
  12231. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  12232. lookupArray = lookup;
  12233. } else {
  12234. error('Unrecognized lookup table: ' + lookup);
  12235. }
  12236. this.lookup = lookupArray;
  12237. }
  12238. IndexedCS.prototype = {
  12239. getRgb: ColorSpace.prototype.getRgb,
  12240. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  12241. dest, destOffset) {
  12242. var numComps = this.base.numComps;
  12243. var start = src[srcOffset] * numComps;
  12244. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  12245. },
  12246. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  12247. dest, destOffset, bits,
  12248. alpha01) {
  12249. var base = this.base;
  12250. var numComps = base.numComps;
  12251. var outputDelta = base.getOutputLength(numComps, alpha01);
  12252. var lookup = this.lookup;
  12253. for (var i = 0; i < count; ++i) {
  12254. var lookupPos = src[srcOffset++] * numComps;
  12255. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  12256. destOffset += outputDelta;
  12257. }
  12258. },
  12259. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  12260. return this.base.getOutputLength(inputLength * this.base.numComps,
  12261. alpha01);
  12262. },
  12263. isPassthrough: ColorSpace.prototype.isPassthrough,
  12264. fillRgb: ColorSpace.prototype.fillRgb,
  12265. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  12266. // indexed color maps shouldn't be changed
  12267. return true;
  12268. },
  12269. usesZeroToOneRange: true
  12270. };
  12271. return IndexedCS;
  12272. })();
  12273. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  12274. function DeviceGrayCS() {
  12275. this.name = 'DeviceGray';
  12276. this.numComps = 1;
  12277. this.defaultColor = new Float32Array([0]);
  12278. }
  12279. DeviceGrayCS.prototype = {
  12280. getRgb: ColorSpace.prototype.getRgb,
  12281. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  12282. dest, destOffset) {
  12283. var c = (src[srcOffset] * 255) | 0;
  12284. c = c < 0 ? 0 : c > 255 ? 255 : c;
  12285. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  12286. },
  12287. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  12288. dest, destOffset, bits,
  12289. alpha01) {
  12290. var scale = 255 / ((1 << bits) - 1);
  12291. var j = srcOffset, q = destOffset;
  12292. for (var i = 0; i < count; ++i) {
  12293. var c = (scale * src[j++]) | 0;
  12294. dest[q++] = c;
  12295. dest[q++] = c;
  12296. dest[q++] = c;
  12297. q += alpha01;
  12298. }
  12299. },
  12300. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  12301. alpha01) {
  12302. return inputLength * (3 + alpha01);
  12303. },
  12304. isPassthrough: ColorSpace.prototype.isPassthrough,
  12305. fillRgb: ColorSpace.prototype.fillRgb,
  12306. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  12307. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12308. },
  12309. usesZeroToOneRange: true
  12310. };
  12311. return DeviceGrayCS;
  12312. })();
  12313. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  12314. function DeviceRgbCS() {
  12315. this.name = 'DeviceRGB';
  12316. this.numComps = 3;
  12317. this.defaultColor = new Float32Array([0, 0, 0]);
  12318. }
  12319. DeviceRgbCS.prototype = {
  12320. getRgb: ColorSpace.prototype.getRgb,
  12321. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  12322. dest, destOffset) {
  12323. var r = (src[srcOffset] * 255) | 0;
  12324. var g = (src[srcOffset + 1] * 255) | 0;
  12325. var b = (src[srcOffset + 2] * 255) | 0;
  12326. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  12327. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  12328. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  12329. },
  12330. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  12331. dest, destOffset, bits,
  12332. alpha01) {
  12333. if (bits === 8 && alpha01 === 0) {
  12334. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  12335. return;
  12336. }
  12337. var scale = 255 / ((1 << bits) - 1);
  12338. var j = srcOffset, q = destOffset;
  12339. for (var i = 0; i < count; ++i) {
  12340. dest[q++] = (scale * src[j++]) | 0;
  12341. dest[q++] = (scale * src[j++]) | 0;
  12342. dest[q++] = (scale * src[j++]) | 0;
  12343. q += alpha01;
  12344. }
  12345. },
  12346. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12347. alpha01) {
  12348. return (inputLength * (3 + alpha01) / 3) | 0;
  12349. },
  12350. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12351. return bits === 8;
  12352. },
  12353. fillRgb: ColorSpace.prototype.fillRgb,
  12354. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12355. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12356. },
  12357. usesZeroToOneRange: true
  12358. };
  12359. return DeviceRgbCS;
  12360. })();
  12361. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12362. // The coefficients below was found using numerical analysis: the method of
  12363. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12364. // where color_value is the tabular value from the table of sampled RGB colors
  12365. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12366. // CMYK color conversion using the estimation below:
  12367. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12368. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12369. var c = src[srcOffset + 0] * srcScale;
  12370. var m = src[srcOffset + 1] * srcScale;
  12371. var y = src[srcOffset + 2] * srcScale;
  12372. var k = src[srcOffset + 3] * srcScale;
  12373. var r =
  12374. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12375. 18.82290502165302 * y + 212.25662451639585 * k +
  12376. -285.2331026137004) +
  12377. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12378. -17.873870861415444 * k - 5.497006427196366) +
  12379. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12380. 17.5119270841813) +
  12381. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12382. var g =
  12383. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12384. 6.871425592049007 * y + 31.159100130055922 * k +
  12385. -79.2970844816548) +
  12386. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12387. 131.35250912493976 * k - 190.9453302588951) +
  12388. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12389. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12390. var b =
  12391. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12392. 30.89978309703729 * y - 0.23883238689178934 * k +
  12393. -14.183576799673286) +
  12394. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12395. 50.606957656360734 * k - 112.23884253719248) +
  12396. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12397. -193.58209356861505) +
  12398. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12399. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12400. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12401. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12402. }
  12403. function DeviceCmykCS() {
  12404. this.name = 'DeviceCMYK';
  12405. this.numComps = 4;
  12406. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12407. }
  12408. DeviceCmykCS.prototype = {
  12409. getRgb: ColorSpace.prototype.getRgb,
  12410. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12411. dest, destOffset) {
  12412. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12413. },
  12414. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12415. dest, destOffset, bits,
  12416. alpha01) {
  12417. var scale = 1 / ((1 << bits) - 1);
  12418. for (var i = 0; i < count; i++) {
  12419. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12420. srcOffset += 4;
  12421. destOffset += 3 + alpha01;
  12422. }
  12423. },
  12424. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12425. alpha01) {
  12426. return (inputLength / 4 * (3 + alpha01)) | 0;
  12427. },
  12428. isPassthrough: ColorSpace.prototype.isPassthrough,
  12429. fillRgb: ColorSpace.prototype.fillRgb,
  12430. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12431. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12432. },
  12433. usesZeroToOneRange: true
  12434. };
  12435. return DeviceCmykCS;
  12436. })();
  12437. //
  12438. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12439. //
  12440. var CalGrayCS = (function CalGrayCSClosure() {
  12441. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12442. this.name = 'CalGray';
  12443. this.numComps = 1;
  12444. this.defaultColor = new Float32Array([0]);
  12445. if (!whitePoint) {
  12446. error('WhitePoint missing - required for color space CalGray');
  12447. }
  12448. blackPoint = blackPoint || [0, 0, 0];
  12449. gamma = gamma || 1;
  12450. // Translate arguments to spec variables.
  12451. this.XW = whitePoint[0];
  12452. this.YW = whitePoint[1];
  12453. this.ZW = whitePoint[2];
  12454. this.XB = blackPoint[0];
  12455. this.YB = blackPoint[1];
  12456. this.ZB = blackPoint[2];
  12457. this.G = gamma;
  12458. // Validate variables as per spec.
  12459. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12460. error('Invalid WhitePoint components for ' + this.name +
  12461. ', no fallback available');
  12462. }
  12463. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12464. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12465. this.XB = this.YB = this.ZB = 0;
  12466. }
  12467. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12468. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12469. ', ZB: ' + this.ZB + ', only default values are supported.');
  12470. }
  12471. if (this.G < 1) {
  12472. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12473. ', falling back to default');
  12474. this.G = 1;
  12475. }
  12476. }
  12477. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12478. // A represents a gray component of a calibrated gray space.
  12479. // A <---> AG in the spec
  12480. var A = src[srcOffset] * scale;
  12481. var AG = Math.pow(A, cs.G);
  12482. // Computes L as per spec. ( = cs.YW * AG )
  12483. // Except if other than default BlackPoint values are used.
  12484. var L = cs.YW * AG;
  12485. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12486. // Convert values to rgb range [0, 255].
  12487. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12488. dest[destOffset] = val;
  12489. dest[destOffset + 1] = val;
  12490. dest[destOffset + 2] = val;
  12491. }
  12492. CalGrayCS.prototype = {
  12493. getRgb: ColorSpace.prototype.getRgb,
  12494. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12495. dest, destOffset) {
  12496. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12497. },
  12498. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12499. dest, destOffset, bits,
  12500. alpha01) {
  12501. var scale = 1 / ((1 << bits) - 1);
  12502. for (var i = 0; i < count; ++i) {
  12503. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12504. srcOffset += 1;
  12505. destOffset += 3 + alpha01;
  12506. }
  12507. },
  12508. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12509. return inputLength * (3 + alpha01);
  12510. },
  12511. isPassthrough: ColorSpace.prototype.isPassthrough,
  12512. fillRgb: ColorSpace.prototype.fillRgb,
  12513. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12514. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12515. },
  12516. usesZeroToOneRange: true
  12517. };
  12518. return CalGrayCS;
  12519. })();
  12520. //
  12521. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12522. //
  12523. var CalRGBCS = (function CalRGBCSClosure() {
  12524. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12525. // matrices.
  12526. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12527. 0.8951, 0.2664, -0.1614,
  12528. -0.7502, 1.7135, 0.0367,
  12529. 0.0389, -0.0685, 1.0296]);
  12530. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12531. 0.9869929, -0.1470543, 0.1599627,
  12532. 0.4323053, 0.5183603, 0.0492912,
  12533. -0.0085287, 0.0400428, 0.9684867]);
  12534. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12535. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12536. 3.2404542, -1.5371385, -0.4985314,
  12537. -0.9692660, 1.8760108, 0.0415560,
  12538. 0.0556434, -0.2040259, 1.0572252]);
  12539. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12540. var tempNormalizeMatrix = new Float32Array(3);
  12541. var tempConvertMatrix1 = new Float32Array(3);
  12542. var tempConvertMatrix2 = new Float32Array(3);
  12543. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12544. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12545. this.name = 'CalRGB';
  12546. this.numComps = 3;
  12547. this.defaultColor = new Float32Array(3);
  12548. if (!whitePoint) {
  12549. error('WhitePoint missing - required for color space CalRGB');
  12550. }
  12551. blackPoint = blackPoint || new Float32Array(3);
  12552. gamma = gamma || new Float32Array([1, 1, 1]);
  12553. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12554. // Translate arguments to spec variables.
  12555. var XW = whitePoint[0];
  12556. var YW = whitePoint[1];
  12557. var ZW = whitePoint[2];
  12558. this.whitePoint = whitePoint;
  12559. var XB = blackPoint[0];
  12560. var YB = blackPoint[1];
  12561. var ZB = blackPoint[2];
  12562. this.blackPoint = blackPoint;
  12563. this.GR = gamma[0];
  12564. this.GG = gamma[1];
  12565. this.GB = gamma[2];
  12566. this.MXA = matrix[0];
  12567. this.MYA = matrix[1];
  12568. this.MZA = matrix[2];
  12569. this.MXB = matrix[3];
  12570. this.MYB = matrix[4];
  12571. this.MZB = matrix[5];
  12572. this.MXC = matrix[6];
  12573. this.MYC = matrix[7];
  12574. this.MZC = matrix[8];
  12575. // Validate variables as per spec.
  12576. if (XW < 0 || ZW < 0 || YW !== 1) {
  12577. error('Invalid WhitePoint components for ' + this.name +
  12578. ', no fallback available');
  12579. }
  12580. if (XB < 0 || YB < 0 || ZB < 0) {
  12581. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12582. ', ' + ZB + '], falling back to default');
  12583. this.blackPoint = new Float32Array(3);
  12584. }
  12585. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12586. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12587. '] for ' + this.name + ', falling back to default');
  12588. this.GR = this.GG = this.GB = 1;
  12589. }
  12590. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12591. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12592. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12593. info('Invalid Matrix for ' + this.name + ' [' +
  12594. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12595. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12596. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12597. '], falling back to default');
  12598. this.MXA = this.MYB = this.MZC = 1;
  12599. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12600. }
  12601. }
  12602. function matrixProduct(a, b, result) {
  12603. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12604. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12605. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12606. }
  12607. function convertToFlat(sourceWhitePoint, LMS, result) {
  12608. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12609. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12610. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12611. }
  12612. function convertToD65(sourceWhitePoint, LMS, result) {
  12613. var D65X = 0.95047;
  12614. var D65Y = 1;
  12615. var D65Z = 1.08883;
  12616. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12617. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12618. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12619. }
  12620. function sRGBTransferFunction(color) {
  12621. // See http://en.wikipedia.org/wiki/SRGB.
  12622. if (color <= 0.0031308){
  12623. return adjustToRange(0, 1, 12.92 * color);
  12624. }
  12625. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12626. }
  12627. function adjustToRange(min, max, value) {
  12628. return Math.max(min, Math.min(max, value));
  12629. }
  12630. function decodeL(L) {
  12631. if (L < 0) {
  12632. return -decodeL(-L);
  12633. }
  12634. if (L > 8.0) {
  12635. return Math.pow(((L + 16) / 116), 3);
  12636. }
  12637. return L * DECODE_L_CONSTANT;
  12638. }
  12639. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12640. // In case the blackPoint is already the default blackPoint then there is
  12641. // no need to do compensation.
  12642. if (sourceBlackPoint[0] === 0 &&
  12643. sourceBlackPoint[1] === 0 &&
  12644. sourceBlackPoint[2] === 0) {
  12645. result[0] = XYZ_Flat[0];
  12646. result[1] = XYZ_Flat[1];
  12647. result[2] = XYZ_Flat[2];
  12648. return;
  12649. }
  12650. // For the blackPoint calculation details, please see
  12651. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12652. // AdobeBPC.pdf.
  12653. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12654. var zeroDecodeL = decodeL(0);
  12655. var X_DST = zeroDecodeL;
  12656. var X_SRC = decodeL(sourceBlackPoint[0]);
  12657. var Y_DST = zeroDecodeL;
  12658. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12659. var Z_DST = zeroDecodeL;
  12660. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12661. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12662. var X_Offset = 1 - X_Scale;
  12663. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12664. var Y_Offset = 1 - Y_Scale;
  12665. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12666. var Z_Offset = 1 - Z_Scale;
  12667. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12668. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12669. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12670. }
  12671. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12672. // In case the whitePoint is already flat then there is no need to do
  12673. // normalization.
  12674. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12675. result[0] = XYZ_In[0];
  12676. result[1] = XYZ_In[1];
  12677. result[2] = XYZ_In[2];
  12678. return;
  12679. }
  12680. var LMS = result;
  12681. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12682. var LMS_Flat = tempNormalizeMatrix;
  12683. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12684. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12685. }
  12686. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12687. var LMS = result;
  12688. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12689. var LMS_D65 = tempNormalizeMatrix;
  12690. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12691. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12692. }
  12693. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12694. // A, B and C represent a red, green and blue components of a calibrated
  12695. // rgb space.
  12696. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12697. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12698. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12699. // A <---> AGR in the spec
  12700. // B <---> BGG in the spec
  12701. // C <---> CGB in the spec
  12702. var AGR = Math.pow(A, cs.GR);
  12703. var BGG = Math.pow(B, cs.GG);
  12704. var CGB = Math.pow(C, cs.GB);
  12705. // Computes intermediate variables L, M, N as per spec.
  12706. // To decode X, Y, Z values map L, M, N directly to them.
  12707. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12708. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12709. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12710. // The following calculations are based on this document:
  12711. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12712. // AdobeBPC.pdf.
  12713. var XYZ = tempConvertMatrix1;
  12714. XYZ[0] = X;
  12715. XYZ[1] = Y;
  12716. XYZ[2] = Z;
  12717. var XYZ_Flat = tempConvertMatrix2;
  12718. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12719. var XYZ_Black = tempConvertMatrix1;
  12720. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12721. var XYZ_D65 = tempConvertMatrix2;
  12722. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12723. var SRGB = tempConvertMatrix1;
  12724. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12725. var sR = sRGBTransferFunction(SRGB[0]);
  12726. var sG = sRGBTransferFunction(SRGB[1]);
  12727. var sB = sRGBTransferFunction(SRGB[2]);
  12728. // Convert the values to rgb range [0, 255].
  12729. dest[destOffset] = Math.round(sR * 255);
  12730. dest[destOffset + 1] = Math.round(sG * 255);
  12731. dest[destOffset + 2] = Math.round(sB * 255);
  12732. }
  12733. CalRGBCS.prototype = {
  12734. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12735. var rgb = new Uint8Array(3);
  12736. this.getRgbItem(src, srcOffset, rgb, 0);
  12737. return rgb;
  12738. },
  12739. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12740. dest, destOffset) {
  12741. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12742. },
  12743. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12744. dest, destOffset, bits,
  12745. alpha01) {
  12746. var scale = 1 / ((1 << bits) - 1);
  12747. for (var i = 0; i < count; ++i) {
  12748. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12749. srcOffset += 3;
  12750. destOffset += 3 + alpha01;
  12751. }
  12752. },
  12753. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12754. return (inputLength * (3 + alpha01) / 3) | 0;
  12755. },
  12756. isPassthrough: ColorSpace.prototype.isPassthrough,
  12757. fillRgb: ColorSpace.prototype.fillRgb,
  12758. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12759. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12760. },
  12761. usesZeroToOneRange: true
  12762. };
  12763. return CalRGBCS;
  12764. })();
  12765. //
  12766. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12767. //
  12768. var LabCS = (function LabCSClosure() {
  12769. function LabCS(whitePoint, blackPoint, range) {
  12770. this.name = 'Lab';
  12771. this.numComps = 3;
  12772. this.defaultColor = new Float32Array([0, 0, 0]);
  12773. if (!whitePoint) {
  12774. error('WhitePoint missing - required for color space Lab');
  12775. }
  12776. blackPoint = blackPoint || [0, 0, 0];
  12777. range = range || [-100, 100, -100, 100];
  12778. // Translate args to spec variables
  12779. this.XW = whitePoint[0];
  12780. this.YW = whitePoint[1];
  12781. this.ZW = whitePoint[2];
  12782. this.amin = range[0];
  12783. this.amax = range[1];
  12784. this.bmin = range[2];
  12785. this.bmax = range[3];
  12786. // These are here just for completeness - the spec doesn't offer any
  12787. // formulas that use BlackPoint in Lab
  12788. this.XB = blackPoint[0];
  12789. this.YB = blackPoint[1];
  12790. this.ZB = blackPoint[2];
  12791. // Validate vars as per spec
  12792. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12793. error('Invalid WhitePoint components, no fallback available');
  12794. }
  12795. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12796. info('Invalid BlackPoint, falling back to default');
  12797. this.XB = this.YB = this.ZB = 0;
  12798. }
  12799. if (this.amin > this.amax || this.bmin > this.bmax) {
  12800. info('Invalid Range, falling back to defaults');
  12801. this.amin = -100;
  12802. this.amax = 100;
  12803. this.bmin = -100;
  12804. this.bmax = 100;
  12805. }
  12806. }
  12807. // Function g(x) from spec
  12808. function fn_g(x) {
  12809. if (x >= 6 / 29) {
  12810. return x * x * x;
  12811. } else {
  12812. return (108 / 841) * (x - 4 / 29);
  12813. }
  12814. }
  12815. function decode(value, high1, low2, high2) {
  12816. return low2 + (value) * (high2 - low2) / (high1);
  12817. }
  12818. // If decoding is needed maxVal should be 2^bits per component - 1.
  12819. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12820. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12821. // not the usual [0, 1]. If a command like setFillColor is used the src
  12822. // values will already be within the correct range. However, if we are
  12823. // converting an image we have to map the values to the correct range given
  12824. // above.
  12825. // Ls,as,bs <---> L*,a*,b* in the spec
  12826. var Ls = src[srcOffset];
  12827. var as = src[srcOffset + 1];
  12828. var bs = src[srcOffset + 2];
  12829. if (maxVal !== false) {
  12830. Ls = decode(Ls, maxVal, 0, 100);
  12831. as = decode(as, maxVal, cs.amin, cs.amax);
  12832. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12833. }
  12834. // Adjust limits of 'as' and 'bs'
  12835. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12836. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12837. // Computes intermediate variables X,Y,Z as per spec
  12838. var M = (Ls + 16) / 116;
  12839. var L = M + (as / 500);
  12840. var N = M - (bs / 200);
  12841. var X = cs.XW * fn_g(L);
  12842. var Y = cs.YW * fn_g(M);
  12843. var Z = cs.ZW * fn_g(N);
  12844. var r, g, b;
  12845. // Using different conversions for D50 and D65 white points,
  12846. // per http://www.color.org/srgb.pdf
  12847. if (cs.ZW < 1) {
  12848. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12849. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12850. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12851. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12852. } else {
  12853. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12854. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12855. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12856. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12857. }
  12858. // clamp color values to [0,1] range then convert to [0,255] range.
  12859. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12860. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12861. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12862. }
  12863. LabCS.prototype = {
  12864. getRgb: ColorSpace.prototype.getRgb,
  12865. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12866. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12867. },
  12868. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12869. dest, destOffset, bits,
  12870. alpha01) {
  12871. var maxVal = (1 << bits) - 1;
  12872. for (var i = 0; i < count; i++) {
  12873. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12874. srcOffset += 3;
  12875. destOffset += 3 + alpha01;
  12876. }
  12877. },
  12878. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12879. return (inputLength * (3 + alpha01) / 3) | 0;
  12880. },
  12881. isPassthrough: ColorSpace.prototype.isPassthrough,
  12882. fillRgb: ColorSpace.prototype.fillRgb,
  12883. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12884. // XXX: Decoding is handled with the lab conversion because of the strange
  12885. // ranges that are used.
  12886. return true;
  12887. },
  12888. usesZeroToOneRange: false
  12889. };
  12890. return LabCS;
  12891. })();
  12892. var ARCFourCipher = (function ARCFourCipherClosure() {
  12893. function ARCFourCipher(key) {
  12894. this.a = 0;
  12895. this.b = 0;
  12896. var s = new Uint8Array(256);
  12897. var i, j = 0, tmp, keyLength = key.length;
  12898. for (i = 0; i < 256; ++i) {
  12899. s[i] = i;
  12900. }
  12901. for (i = 0; i < 256; ++i) {
  12902. tmp = s[i];
  12903. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12904. s[i] = s[j];
  12905. s[j] = tmp;
  12906. }
  12907. this.s = s;
  12908. }
  12909. ARCFourCipher.prototype = {
  12910. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12911. var i, n = data.length, tmp, tmp2;
  12912. var a = this.a, b = this.b, s = this.s;
  12913. var output = new Uint8Array(n);
  12914. for (i = 0; i < n; ++i) {
  12915. a = (a + 1) & 0xFF;
  12916. tmp = s[a];
  12917. b = (b + tmp) & 0xFF;
  12918. tmp2 = s[b];
  12919. s[a] = tmp2;
  12920. s[b] = tmp;
  12921. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12922. }
  12923. this.a = a;
  12924. this.b = b;
  12925. return output;
  12926. }
  12927. };
  12928. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12929. return ARCFourCipher;
  12930. })();
  12931. var calculateMD5 = (function calculateMD5Closure() {
  12932. var r = new Uint8Array([
  12933. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12934. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12935. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12936. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12937. var k = new Int32Array([
  12938. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12939. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12940. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12941. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12942. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12943. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12944. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12945. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12946. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12947. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12948. -145523070, -1120210379, 718787259, -343485551]);
  12949. function hash(data, offset, length) {
  12950. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12951. // pre-processing
  12952. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12953. var padded = new Uint8Array(paddedLength);
  12954. var i, j, n;
  12955. for (i = 0; i < length; ++i) {
  12956. padded[i] = data[offset++];
  12957. }
  12958. padded[i++] = 0x80;
  12959. n = paddedLength - 8;
  12960. while (i < n) {
  12961. padded[i++] = 0;
  12962. }
  12963. padded[i++] = (length << 3) & 0xFF;
  12964. padded[i++] = (length >> 5) & 0xFF;
  12965. padded[i++] = (length >> 13) & 0xFF;
  12966. padded[i++] = (length >> 21) & 0xFF;
  12967. padded[i++] = (length >>> 29) & 0xFF;
  12968. padded[i++] = 0;
  12969. padded[i++] = 0;
  12970. padded[i++] = 0;
  12971. var w = new Int32Array(16);
  12972. for (i = 0; i < paddedLength;) {
  12973. for (j = 0; j < 16; ++j, i += 4) {
  12974. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12975. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12976. }
  12977. var a = h0, b = h1, c = h2, d = h3, f, g;
  12978. for (j = 0; j < 64; ++j) {
  12979. if (j < 16) {
  12980. f = (b & c) | ((~b) & d);
  12981. g = j;
  12982. } else if (j < 32) {
  12983. f = (d & b) | ((~d) & c);
  12984. g = (5 * j + 1) & 15;
  12985. } else if (j < 48) {
  12986. f = b ^ c ^ d;
  12987. g = (3 * j + 5) & 15;
  12988. } else {
  12989. f = c ^ (b | (~d));
  12990. g = (7 * j) & 15;
  12991. }
  12992. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12993. d = c;
  12994. c = b;
  12995. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12996. a = tmp;
  12997. }
  12998. h0 = (h0 + a) | 0;
  12999. h1 = (h1 + b) | 0;
  13000. h2 = (h2 + c) | 0;
  13001. h3 = (h3 + d) | 0;
  13002. }
  13003. return new Uint8Array([
  13004. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  13005. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  13006. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  13007. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  13008. ]);
  13009. }
  13010. return hash;
  13011. })();
  13012. var Word64 = (function Word64Closure() {
  13013. function Word64(highInteger, lowInteger) {
  13014. this.high = highInteger | 0;
  13015. this.low = lowInteger | 0;
  13016. }
  13017. Word64.prototype = {
  13018. and: function Word64_and(word) {
  13019. this.high &= word.high;
  13020. this.low &= word.low;
  13021. },
  13022. xor: function Word64_xor(word) {
  13023. this.high ^= word.high;
  13024. this.low ^= word.low;
  13025. },
  13026. or: function Word64_or(word) {
  13027. this.high |= word.high;
  13028. this.low |= word.low;
  13029. },
  13030. shiftRight: function Word64_shiftRight(places) {
  13031. if (places >= 32) {
  13032. this.low = (this.high >>> (places - 32)) | 0;
  13033. this.high = 0;
  13034. } else {
  13035. this.low = (this.low >>> places) | (this.high << (32 - places));
  13036. this.high = (this.high >>> places) | 0;
  13037. }
  13038. },
  13039. shiftLeft: function Word64_shiftLeft(places) {
  13040. if (places >= 32) {
  13041. this.high = this.low << (places - 32);
  13042. this.low = 0;
  13043. } else {
  13044. this.high = (this.high << places) | (this.low >>> (32 - places));
  13045. this.low = this.low << places;
  13046. }
  13047. },
  13048. rotateRight: function Word64_rotateRight(places) {
  13049. var low, high;
  13050. if (places & 32) {
  13051. high = this.low;
  13052. low = this.high;
  13053. } else {
  13054. low = this.low;
  13055. high = this.high;
  13056. }
  13057. places &= 31;
  13058. this.low = (low >>> places) | (high << (32 - places));
  13059. this.high = (high >>> places) | (low << (32 - places));
  13060. },
  13061. not: function Word64_not() {
  13062. this.high = ~this.high;
  13063. this.low = ~this.low;
  13064. },
  13065. add: function Word64_add(word) {
  13066. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  13067. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  13068. if (lowAdd > 0xFFFFFFFF) {
  13069. highAdd += 1;
  13070. }
  13071. this.low = lowAdd | 0;
  13072. this.high = highAdd | 0;
  13073. },
  13074. copyTo: function Word64_copyTo(bytes, offset) {
  13075. bytes[offset] = (this.high >>> 24) & 0xFF;
  13076. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  13077. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  13078. bytes[offset + 3] = this.high & 0xFF;
  13079. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  13080. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  13081. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  13082. bytes[offset + 7] = this.low & 0xFF;
  13083. },
  13084. assign: function Word64_assign(word) {
  13085. this.high = word.high;
  13086. this.low = word.low;
  13087. }
  13088. };
  13089. return Word64;
  13090. })();
  13091. var calculateSHA256 = (function calculateSHA256Closure() {
  13092. function rotr(x, n) {
  13093. return (x >>> n) | (x << 32 - n);
  13094. }
  13095. function ch(x, y, z) {
  13096. return (x & y) ^ (~x & z);
  13097. }
  13098. function maj(x, y, z) {
  13099. return (x & y) ^ (x & z) ^ (y & z);
  13100. }
  13101. function sigma(x) {
  13102. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  13103. }
  13104. function sigmaPrime(x) {
  13105. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  13106. }
  13107. function littleSigma(x) {
  13108. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  13109. }
  13110. function littleSigmaPrime(x) {
  13111. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  13112. }
  13113. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  13114. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  13115. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  13116. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  13117. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  13118. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  13119. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  13120. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  13121. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  13122. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  13123. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  13124. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  13125. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  13126. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  13127. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  13128. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  13129. function hash(data, offset, length) {
  13130. // initial hash values
  13131. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  13132. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  13133. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  13134. // pre-processing
  13135. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  13136. var padded = new Uint8Array(paddedLength);
  13137. var i, j, n;
  13138. for (i = 0; i < length; ++i) {
  13139. padded[i] = data[offset++];
  13140. }
  13141. padded[i++] = 0x80;
  13142. n = paddedLength - 8;
  13143. while (i < n) {
  13144. padded[i++] = 0;
  13145. }
  13146. padded[i++] = 0;
  13147. padded[i++] = 0;
  13148. padded[i++] = 0;
  13149. padded[i++] = (length >>> 29) & 0xFF;
  13150. padded[i++] = (length >> 21) & 0xFF;
  13151. padded[i++] = (length >> 13) & 0xFF;
  13152. padded[i++] = (length >> 5) & 0xFF;
  13153. padded[i++] = (length << 3) & 0xFF;
  13154. var w = new Uint32Array(64);
  13155. // for each 512 bit block
  13156. for (i = 0; i < paddedLength;) {
  13157. for (j = 0; j < 16; ++j) {
  13158. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  13159. (padded[i + 2] << 8) | (padded[i + 3]));
  13160. i += 4;
  13161. }
  13162. for (j = 16; j < 64; ++j) {
  13163. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  13164. littleSigma(w[j - 15]) + w[j - 16] | 0;
  13165. }
  13166. var a = h0, b = h1, c = h2, d = h3, e = h4,
  13167. f = h5, g = h6, h = h7, t1, t2;
  13168. for (j = 0; j < 64; ++j) {
  13169. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  13170. t2 = sigma(a) + maj(a, b, c);
  13171. h = g;
  13172. g = f;
  13173. f = e;
  13174. e = (d + t1) | 0;
  13175. d = c;
  13176. c = b;
  13177. b = a;
  13178. a = (t1 + t2) | 0;
  13179. }
  13180. h0 = (h0 + a) | 0;
  13181. h1 = (h1 + b) | 0;
  13182. h2 = (h2 + c) | 0;
  13183. h3 = (h3 + d) | 0;
  13184. h4 = (h4 + e) | 0;
  13185. h5 = (h5 + f) | 0;
  13186. h6 = (h6 + g) | 0;
  13187. h7 = (h7 + h) | 0;
  13188. }
  13189. return new Uint8Array([
  13190. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  13191. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  13192. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  13193. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  13194. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  13195. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  13196. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  13197. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  13198. ]);
  13199. }
  13200. return hash;
  13201. })();
  13202. var calculateSHA512 = (function calculateSHA512Closure() {
  13203. function ch(result, x, y, z, tmp) {
  13204. result.assign(x);
  13205. result.and(y);
  13206. tmp.assign(x);
  13207. tmp.not();
  13208. tmp.and(z);
  13209. result.xor(tmp);
  13210. }
  13211. function maj(result, x, y, z, tmp) {
  13212. result.assign(x);
  13213. result.and(y);
  13214. tmp.assign(x);
  13215. tmp.and(z);
  13216. result.xor(tmp);
  13217. tmp.assign(y);
  13218. tmp.and(z);
  13219. result.xor(tmp);
  13220. }
  13221. function sigma(result, x, tmp) {
  13222. result.assign(x);
  13223. result.rotateRight(28);
  13224. tmp.assign(x);
  13225. tmp.rotateRight(34);
  13226. result.xor(tmp);
  13227. tmp.assign(x);
  13228. tmp.rotateRight(39);
  13229. result.xor(tmp);
  13230. }
  13231. function sigmaPrime(result, x, tmp) {
  13232. result.assign(x);
  13233. result.rotateRight(14);
  13234. tmp.assign(x);
  13235. tmp.rotateRight(18);
  13236. result.xor(tmp);
  13237. tmp.assign(x);
  13238. tmp.rotateRight(41);
  13239. result.xor(tmp);
  13240. }
  13241. function littleSigma(result, x, tmp) {
  13242. result.assign(x);
  13243. result.rotateRight(1);
  13244. tmp.assign(x);
  13245. tmp.rotateRight(8);
  13246. result.xor(tmp);
  13247. tmp.assign(x);
  13248. tmp.shiftRight(7);
  13249. result.xor(tmp);
  13250. }
  13251. function littleSigmaPrime(result, x, tmp) {
  13252. result.assign(x);
  13253. result.rotateRight(19);
  13254. tmp.assign(x);
  13255. tmp.rotateRight(61);
  13256. result.xor(tmp);
  13257. tmp.assign(x);
  13258. tmp.shiftRight(6);
  13259. result.xor(tmp);
  13260. }
  13261. var k = [
  13262. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  13263. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  13264. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  13265. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  13266. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  13267. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  13268. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  13269. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  13270. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  13271. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  13272. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  13273. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  13274. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  13275. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  13276. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  13277. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  13278. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  13279. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  13280. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  13281. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  13282. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  13283. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  13284. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  13285. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  13286. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  13287. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  13288. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  13289. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  13290. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  13291. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  13292. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  13293. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  13294. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  13295. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  13296. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  13297. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  13298. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  13299. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  13300. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  13301. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  13302. function hash(data, offset, length, mode384) {
  13303. mode384 = !!mode384;
  13304. // initial hash values
  13305. var h0, h1, h2, h3, h4, h5, h6, h7;
  13306. if (!mode384) {
  13307. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  13308. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  13309. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  13310. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  13311. h4 = new Word64(0x510e527f, 0xade682d1);
  13312. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  13313. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  13314. h7 = new Word64(0x5be0cd19, 0x137e2179);
  13315. }
  13316. else {
  13317. // SHA384 is exactly the same
  13318. // except with different starting values and a trimmed result
  13319. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  13320. h1 = new Word64(0x629a292a, 0x367cd507);
  13321. h2 = new Word64(0x9159015a, 0x3070dd17);
  13322. h3 = new Word64(0x152fecd8, 0xf70e5939);
  13323. h4 = new Word64(0x67332667, 0xffc00b31);
  13324. h5 = new Word64(0x8eb44a87, 0x68581511);
  13325. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  13326. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  13327. }
  13328. // pre-processing
  13329. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  13330. var padded = new Uint8Array(paddedLength);
  13331. var i, j, n;
  13332. for (i = 0; i < length; ++i) {
  13333. padded[i] = data[offset++];
  13334. }
  13335. padded[i++] = 0x80;
  13336. n = paddedLength - 16;
  13337. while (i < n) {
  13338. padded[i++] = 0;
  13339. }
  13340. padded[i++] = 0;
  13341. padded[i++] = 0;
  13342. padded[i++] = 0;
  13343. padded[i++] = 0;
  13344. padded[i++] = 0;
  13345. padded[i++] = 0;
  13346. padded[i++] = 0;
  13347. padded[i++] = 0;
  13348. padded[i++] = 0;
  13349. padded[i++] = 0;
  13350. padded[i++] = 0;
  13351. padded[i++] = (length >>> 29) & 0xFF;
  13352. padded[i++] = (length >> 21) & 0xFF;
  13353. padded[i++] = (length >> 13) & 0xFF;
  13354. padded[i++] = (length >> 5) & 0xFF;
  13355. padded[i++] = (length << 3) & 0xFF;
  13356. var w = new Array(80);
  13357. for (i = 0; i < 80; i++) {
  13358. w[i] = new Word64(0, 0);
  13359. }
  13360. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13361. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13362. var g = new Word64(0, 0), h = new Word64(0, 0);
  13363. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13364. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13365. // for each 1024 bit block
  13366. for (i = 0; i < paddedLength;) {
  13367. for (j = 0; j < 16; ++j) {
  13368. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13369. (padded[i + 2] << 8) | (padded[i + 3]);
  13370. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13371. (padded[i + 6]) << 8 | (padded[i + 7]);
  13372. i += 8;
  13373. }
  13374. for (j = 16; j < 80; ++j) {
  13375. tmp3 = w[j];
  13376. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13377. tmp3.add(w[j - 7]);
  13378. littleSigma(tmp1, w[j - 15], tmp2);
  13379. tmp3.add(tmp1);
  13380. tmp3.add(w[j - 16]);
  13381. }
  13382. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13383. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13384. for (j = 0; j < 80; ++j) {
  13385. t1.assign(h);
  13386. sigmaPrime(tmp1, e, tmp2);
  13387. t1.add(tmp1);
  13388. ch(tmp1, e, f, g, tmp2);
  13389. t1.add(tmp1);
  13390. t1.add(k[j]);
  13391. t1.add(w[j]);
  13392. sigma(t2, a, tmp2);
  13393. maj(tmp1, a, b, c, tmp2);
  13394. t2.add(tmp1);
  13395. tmp3 = h;
  13396. h = g;
  13397. g = f;
  13398. f = e;
  13399. d.add(t1);
  13400. e = d;
  13401. d = c;
  13402. c = b;
  13403. b = a;
  13404. tmp3.assign(t1);
  13405. tmp3.add(t2);
  13406. a = tmp3;
  13407. }
  13408. h0.add(a);
  13409. h1.add(b);
  13410. h2.add(c);
  13411. h3.add(d);
  13412. h4.add(e);
  13413. h5.add(f);
  13414. h6.add(g);
  13415. h7.add(h);
  13416. }
  13417. var result;
  13418. if (!mode384) {
  13419. result = new Uint8Array(64);
  13420. h0.copyTo(result,0);
  13421. h1.copyTo(result,8);
  13422. h2.copyTo(result,16);
  13423. h3.copyTo(result,24);
  13424. h4.copyTo(result,32);
  13425. h5.copyTo(result,40);
  13426. h6.copyTo(result,48);
  13427. h7.copyTo(result,56);
  13428. }
  13429. else {
  13430. result = new Uint8Array(48);
  13431. h0.copyTo(result,0);
  13432. h1.copyTo(result,8);
  13433. h2.copyTo(result,16);
  13434. h3.copyTo(result,24);
  13435. h4.copyTo(result,32);
  13436. h5.copyTo(result,40);
  13437. }
  13438. return result;
  13439. }
  13440. return hash;
  13441. })();
  13442. var calculateSHA384 = (function calculateSHA384Closure() {
  13443. function hash(data, offset, length) {
  13444. return calculateSHA512(data, offset, length, true);
  13445. }
  13446. return hash;
  13447. })();
  13448. var NullCipher = (function NullCipherClosure() {
  13449. function NullCipher() {
  13450. }
  13451. NullCipher.prototype = {
  13452. decryptBlock: function NullCipher_decryptBlock(data) {
  13453. return data;
  13454. }
  13455. };
  13456. return NullCipher;
  13457. })();
  13458. var AES128Cipher = (function AES128CipherClosure() {
  13459. var rcon = new Uint8Array([
  13460. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13461. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13462. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13463. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13464. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13465. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13466. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13467. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13468. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13469. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13470. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13471. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13472. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13473. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13474. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13475. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13476. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13477. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13478. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13479. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13480. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13481. 0x74, 0xe8, 0xcb, 0x8d]);
  13482. var s = new Uint8Array([
  13483. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13484. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13485. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13486. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13487. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13488. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13489. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13490. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13491. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13492. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13493. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13494. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13495. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13496. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13497. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13498. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13499. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13500. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13501. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13502. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13503. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13504. 0xb0, 0x54, 0xbb, 0x16]);
  13505. var inv_s = new Uint8Array([
  13506. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13507. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13508. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13509. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13510. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13511. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13512. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13513. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13514. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13515. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13516. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13517. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13518. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13519. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13520. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13521. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13522. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13523. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13524. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13525. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13526. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13527. 0x55, 0x21, 0x0c, 0x7d]);
  13528. var mixCol = new Uint8Array(256);
  13529. for (var i = 0; i < 256; i++) {
  13530. if (i < 128) {
  13531. mixCol[i] = i << 1;
  13532. } else {
  13533. mixCol[i] = (i << 1) ^ 0x1b;
  13534. }
  13535. }
  13536. var mix = new Uint32Array([
  13537. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13538. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13539. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13540. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13541. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13542. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13543. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13544. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13545. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13546. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13547. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13548. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13549. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13550. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13551. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13552. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13553. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13554. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13555. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13556. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13557. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13558. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13559. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13560. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13561. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13562. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13563. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13564. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13565. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13566. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13567. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13568. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13569. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13570. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13571. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13572. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13573. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13574. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13575. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13576. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13577. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13578. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13579. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13580. function expandKey128(cipherKey) {
  13581. var b = 176, result = new Uint8Array(b);
  13582. result.set(cipherKey);
  13583. for (var j = 16, i = 1; j < b; ++i) {
  13584. // RotWord
  13585. var t1 = result[j - 3], t2 = result[j - 2],
  13586. t3 = result[j - 1], t4 = result[j - 4];
  13587. // SubWord
  13588. t1 = s[t1];
  13589. t2 = s[t2];
  13590. t3 = s[t3];
  13591. t4 = s[t4];
  13592. // Rcon
  13593. t1 = t1 ^ rcon[i];
  13594. for (var n = 0; n < 4; ++n) {
  13595. result[j] = (t1 ^= result[j - 16]);
  13596. j++;
  13597. result[j] = (t2 ^= result[j - 16]);
  13598. j++;
  13599. result[j] = (t3 ^= result[j - 16]);
  13600. j++;
  13601. result[j] = (t4 ^= result[j - 16]);
  13602. j++;
  13603. }
  13604. }
  13605. return result;
  13606. }
  13607. function decrypt128(input, key) {
  13608. var state = new Uint8Array(16);
  13609. state.set(input);
  13610. var i, j, k;
  13611. var t, u, v;
  13612. // AddRoundKey
  13613. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13614. state[j] ^= key[k];
  13615. }
  13616. for (i = 9; i >= 1; --i) {
  13617. // InvShiftRows
  13618. t = state[13];
  13619. state[13] = state[9];
  13620. state[9] = state[5];
  13621. state[5] = state[1];
  13622. state[1] = t;
  13623. t = state[14];
  13624. u = state[10];
  13625. state[14] = state[6];
  13626. state[10] = state[2];
  13627. state[6] = t;
  13628. state[2] = u;
  13629. t = state[15];
  13630. u = state[11];
  13631. v = state[7];
  13632. state[15] = state[3];
  13633. state[11] = t;
  13634. state[7] = u;
  13635. state[3] = v;
  13636. // InvSubBytes
  13637. for (j = 0; j < 16; ++j) {
  13638. state[j] = inv_s[state[j]];
  13639. }
  13640. // AddRoundKey
  13641. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13642. state[j] ^= key[k];
  13643. }
  13644. // InvMixColumns
  13645. for (j = 0; j < 16; j += 4) {
  13646. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13647. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13648. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13649. (s3 >>> 24) ^ (s3 << 8));
  13650. state[j] = (t >>> 24) & 0xFF;
  13651. state[j + 1] = (t >> 16) & 0xFF;
  13652. state[j + 2] = (t >> 8) & 0xFF;
  13653. state[j + 3] = t & 0xFF;
  13654. }
  13655. }
  13656. // InvShiftRows
  13657. t = state[13];
  13658. state[13] = state[9];
  13659. state[9] = state[5];
  13660. state[5] = state[1];
  13661. state[1] = t;
  13662. t = state[14];
  13663. u = state[10];
  13664. state[14] = state[6];
  13665. state[10] = state[2];
  13666. state[6] = t;
  13667. state[2] = u;
  13668. t = state[15];
  13669. u = state[11];
  13670. v = state[7];
  13671. state[15] = state[3];
  13672. state[11] = t;
  13673. state[7] = u;
  13674. state[3] = v;
  13675. for (j = 0; j < 16; ++j) {
  13676. // InvSubBytes
  13677. state[j] = inv_s[state[j]];
  13678. // AddRoundKey
  13679. state[j] ^= key[j];
  13680. }
  13681. return state;
  13682. }
  13683. function encrypt128(input, key) {
  13684. var t, u, v, k;
  13685. var state = new Uint8Array(16);
  13686. state.set(input);
  13687. for (j = 0; j < 16; ++j) {
  13688. // AddRoundKey
  13689. state[j] ^= key[j];
  13690. }
  13691. for (i = 1; i < 10; i++) {
  13692. //SubBytes
  13693. for (j = 0; j < 16; ++j) {
  13694. state[j] = s[state[j]];
  13695. }
  13696. //ShiftRows
  13697. v = state[1];
  13698. state[1] = state[5];
  13699. state[5] = state[9];
  13700. state[9] = state[13];
  13701. state[13] = v;
  13702. v = state[2];
  13703. u = state[6];
  13704. state[2] = state[10];
  13705. state[6] = state[14];
  13706. state[10] = v;
  13707. state[14] = u;
  13708. v = state[3];
  13709. u = state[7];
  13710. t = state[11];
  13711. state[3] = state[15];
  13712. state[7] = v;
  13713. state[11] = u;
  13714. state[15] = t;
  13715. //MixColumns
  13716. for (var j = 0; j < 16; j += 4) {
  13717. var s0 = state[j + 0], s1 = state[j + 1];
  13718. var s2 = state[j + 2], s3 = state[j + 3];
  13719. t = s0 ^ s1 ^ s2 ^ s3;
  13720. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13721. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13722. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13723. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13724. }
  13725. //AddRoundKey
  13726. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13727. state[j] ^= key[k];
  13728. }
  13729. }
  13730. //SubBytes
  13731. for (j = 0; j < 16; ++j) {
  13732. state[j] = s[state[j]];
  13733. }
  13734. //ShiftRows
  13735. v = state[1];
  13736. state[1] = state[5];
  13737. state[5] = state[9];
  13738. state[9] = state[13];
  13739. state[13] = v;
  13740. v = state[2];
  13741. u = state[6];
  13742. state[2] = state[10];
  13743. state[6] = state[14];
  13744. state[10] = v;
  13745. state[14] = u;
  13746. v = state[3];
  13747. u = state[7];
  13748. t = state[11];
  13749. state[3] = state[15];
  13750. state[7] = v;
  13751. state[11] = u;
  13752. state[15] = t;
  13753. //AddRoundKey
  13754. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13755. state[j] ^= key[k];
  13756. }
  13757. return state;
  13758. }
  13759. function AES128Cipher(key) {
  13760. this.key = expandKey128(key);
  13761. this.buffer = new Uint8Array(16);
  13762. this.bufferPosition = 0;
  13763. }
  13764. function decryptBlock2(data, finalize) {
  13765. var i, j, ii, sourceLength = data.length,
  13766. buffer = this.buffer, bufferLength = this.bufferPosition,
  13767. result = [], iv = this.iv;
  13768. for (i = 0; i < sourceLength; ++i) {
  13769. buffer[bufferLength] = data[i];
  13770. ++bufferLength;
  13771. if (bufferLength < 16) {
  13772. continue;
  13773. }
  13774. // buffer is full, decrypting
  13775. var plain = decrypt128(buffer, this.key);
  13776. // xor-ing the IV vector to get plain text
  13777. for (j = 0; j < 16; ++j) {
  13778. plain[j] ^= iv[j];
  13779. }
  13780. iv = buffer;
  13781. result.push(plain);
  13782. buffer = new Uint8Array(16);
  13783. bufferLength = 0;
  13784. }
  13785. // saving incomplete buffer
  13786. this.buffer = buffer;
  13787. this.bufferLength = bufferLength;
  13788. this.iv = iv;
  13789. if (result.length === 0) {
  13790. return new Uint8Array([]);
  13791. }
  13792. // combining plain text blocks into one
  13793. var outputLength = 16 * result.length;
  13794. if (finalize) {
  13795. // undo a padding that is described in RFC 2898
  13796. var lastBlock = result[result.length - 1];
  13797. var psLen = lastBlock[15];
  13798. if (psLen <= 16) {
  13799. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13800. if (lastBlock[i] !== psLen) {
  13801. // Invalid padding, assume that the block has no padding.
  13802. psLen = 0;
  13803. break;
  13804. }
  13805. }
  13806. outputLength -= psLen;
  13807. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13808. }
  13809. }
  13810. var output = new Uint8Array(outputLength);
  13811. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13812. output.set(result[i], j);
  13813. }
  13814. return output;
  13815. }
  13816. AES128Cipher.prototype = {
  13817. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13818. var i, sourceLength = data.length;
  13819. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13820. // waiting for IV values -- they are at the start of the stream
  13821. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13822. buffer[bufferLength] = data[i];
  13823. }
  13824. if (bufferLength < 16) {
  13825. // need more data
  13826. this.bufferLength = bufferLength;
  13827. return new Uint8Array([]);
  13828. }
  13829. this.iv = buffer;
  13830. this.buffer = new Uint8Array(16);
  13831. this.bufferLength = 0;
  13832. // starting decryption
  13833. this.decryptBlock = decryptBlock2;
  13834. return this.decryptBlock(data.subarray(16), finalize);
  13835. },
  13836. encrypt: function AES128Cipher_encrypt(data, iv) {
  13837. var i, j, ii, sourceLength = data.length,
  13838. buffer = this.buffer, bufferLength = this.bufferPosition,
  13839. result = [];
  13840. if (!iv) {
  13841. iv = new Uint8Array(16);
  13842. }
  13843. for (i = 0; i < sourceLength; ++i) {
  13844. buffer[bufferLength] = data[i];
  13845. ++bufferLength;
  13846. if (bufferLength < 16) {
  13847. continue;
  13848. }
  13849. for (j = 0; j < 16; ++j) {
  13850. buffer[j] ^= iv[j];
  13851. }
  13852. // buffer is full, encrypting
  13853. var cipher = encrypt128(buffer, this.key);
  13854. iv = cipher;
  13855. result.push(cipher);
  13856. buffer = new Uint8Array(16);
  13857. bufferLength = 0;
  13858. }
  13859. // saving incomplete buffer
  13860. this.buffer = buffer;
  13861. this.bufferLength = bufferLength;
  13862. this.iv = iv;
  13863. if (result.length === 0) {
  13864. return new Uint8Array([]);
  13865. }
  13866. // combining plain text blocks into one
  13867. var outputLength = 16 * result.length;
  13868. var output = new Uint8Array(outputLength);
  13869. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13870. output.set(result[i], j);
  13871. }
  13872. return output;
  13873. }
  13874. };
  13875. return AES128Cipher;
  13876. })();
  13877. var AES256Cipher = (function AES256CipherClosure() {
  13878. var rcon = new Uint8Array([
  13879. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13880. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13881. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13882. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13883. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13884. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13885. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13886. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13887. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13888. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13889. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13890. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13891. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13892. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13893. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13894. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13895. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13896. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13897. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13898. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13899. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13900. 0x74, 0xe8, 0xcb, 0x8d]);
  13901. var s = new Uint8Array([
  13902. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13903. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13904. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13905. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13906. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13907. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13908. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13909. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13910. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13911. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13912. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13913. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13914. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13915. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13916. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13917. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13918. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13919. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13920. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13921. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13922. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13923. 0xb0, 0x54, 0xbb, 0x16]);
  13924. var inv_s = new Uint8Array([
  13925. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13926. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13927. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13928. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13929. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13930. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13931. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13932. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13933. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13934. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13935. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13936. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13937. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13938. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13939. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13940. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13941. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13942. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13943. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13944. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13945. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13946. 0x55, 0x21, 0x0c, 0x7d]);
  13947. var mixCol = new Uint8Array(256);
  13948. for (var i = 0; i < 256; i++) {
  13949. if (i < 128) {
  13950. mixCol[i] = i << 1;
  13951. } else {
  13952. mixCol[i] = (i << 1) ^ 0x1b;
  13953. }
  13954. }
  13955. var mix = new Uint32Array([
  13956. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13957. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13958. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13959. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13960. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13961. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13962. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13963. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13964. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13965. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13966. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13967. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13968. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13969. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13970. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13971. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13972. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13973. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13974. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13975. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13976. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13977. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13978. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13979. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13980. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13981. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13982. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13983. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13984. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13985. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13986. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13987. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13988. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13989. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13990. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13991. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13992. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13993. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13994. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13995. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13996. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13997. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13998. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13999. function expandKey256(cipherKey) {
  14000. var b = 240, result = new Uint8Array(b);
  14001. var r = 1;
  14002. result.set(cipherKey);
  14003. for (var j = 32, i = 1; j < b; ++i) {
  14004. if (j % 32 === 16) {
  14005. t1 = s[t1];
  14006. t2 = s[t2];
  14007. t3 = s[t3];
  14008. t4 = s[t4];
  14009. } else if (j % 32 === 0) {
  14010. // RotWord
  14011. var t1 = result[j - 3], t2 = result[j - 2],
  14012. t3 = result[j - 1], t4 = result[j - 4];
  14013. // SubWord
  14014. t1 = s[t1];
  14015. t2 = s[t2];
  14016. t3 = s[t3];
  14017. t4 = s[t4];
  14018. // Rcon
  14019. t1 = t1 ^ r;
  14020. if ((r <<= 1) >= 256) {
  14021. r = (r ^ 0x1b) & 0xFF;
  14022. }
  14023. }
  14024. for (var n = 0; n < 4; ++n) {
  14025. result[j] = (t1 ^= result[j - 32]);
  14026. j++;
  14027. result[j] = (t2 ^= result[j - 32]);
  14028. j++;
  14029. result[j] = (t3 ^= result[j - 32]);
  14030. j++;
  14031. result[j] = (t4 ^= result[j - 32]);
  14032. j++;
  14033. }
  14034. }
  14035. return result;
  14036. }
  14037. function decrypt256(input, key) {
  14038. var state = new Uint8Array(16);
  14039. state.set(input);
  14040. var i, j, k;
  14041. var t, u, v;
  14042. // AddRoundKey
  14043. for (j = 0, k = 224; j < 16; ++j, ++k) {
  14044. state[j] ^= key[k];
  14045. }
  14046. for (i = 13; i >= 1; --i) {
  14047. // InvShiftRows
  14048. t = state[13];
  14049. state[13] = state[9];
  14050. state[9] = state[5];
  14051. state[5] = state[1];
  14052. state[1] = t;
  14053. t = state[14];
  14054. u = state[10];
  14055. state[14] = state[6];
  14056. state[10] = state[2];
  14057. state[6] = t;
  14058. state[2] = u;
  14059. t = state[15];
  14060. u = state[11];
  14061. v = state[7];
  14062. state[15] = state[3];
  14063. state[11] = t;
  14064. state[7] = u;
  14065. state[3] = v;
  14066. // InvSubBytes
  14067. for (j = 0; j < 16; ++j) {
  14068. state[j] = inv_s[state[j]];
  14069. }
  14070. // AddRoundKey
  14071. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14072. state[j] ^= key[k];
  14073. }
  14074. // InvMixColumns
  14075. for (j = 0; j < 16; j += 4) {
  14076. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  14077. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  14078. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  14079. (s3 >>> 24) ^ (s3 << 8));
  14080. state[j] = (t >>> 24) & 0xFF;
  14081. state[j + 1] = (t >> 16) & 0xFF;
  14082. state[j + 2] = (t >> 8) & 0xFF;
  14083. state[j + 3] = t & 0xFF;
  14084. }
  14085. }
  14086. // InvShiftRows
  14087. t = state[13];
  14088. state[13] = state[9];
  14089. state[9] = state[5];
  14090. state[5] = state[1];
  14091. state[1] = t;
  14092. t = state[14];
  14093. u = state[10];
  14094. state[14] = state[6];
  14095. state[10] = state[2];
  14096. state[6] = t;
  14097. state[2] = u;
  14098. t = state[15];
  14099. u = state[11];
  14100. v = state[7];
  14101. state[15] = state[3];
  14102. state[11] = t;
  14103. state[7] = u;
  14104. state[3] = v;
  14105. for (j = 0; j < 16; ++j) {
  14106. // InvSubBytes
  14107. state[j] = inv_s[state[j]];
  14108. // AddRoundKey
  14109. state[j] ^= key[j];
  14110. }
  14111. return state;
  14112. }
  14113. function encrypt256(input, key) {
  14114. var t, u, v, k;
  14115. var state = new Uint8Array(16);
  14116. state.set(input);
  14117. for (j = 0; j < 16; ++j) {
  14118. // AddRoundKey
  14119. state[j] ^= key[j];
  14120. }
  14121. for (i = 1; i < 14; i++) {
  14122. //SubBytes
  14123. for (j = 0; j < 16; ++j) {
  14124. state[j] = s[state[j]];
  14125. }
  14126. //ShiftRows
  14127. v = state[1];
  14128. state[1] = state[5];
  14129. state[5] = state[9];
  14130. state[9] = state[13];
  14131. state[13] = v;
  14132. v = state[2];
  14133. u = state[6];
  14134. state[2] = state[10];
  14135. state[6] = state[14];
  14136. state[10] = v;
  14137. state[14] = u;
  14138. v = state[3];
  14139. u = state[7];
  14140. t = state[11];
  14141. state[3] = state[15];
  14142. state[7] = v;
  14143. state[11] = u;
  14144. state[15] = t;
  14145. //MixColumns
  14146. for (var j = 0; j < 16; j += 4) {
  14147. var s0 = state[j + 0], s1 = state[j + 1];
  14148. var s2 = state[j + 2], s3 = state[j + 3];
  14149. t = s0 ^ s1 ^ s2 ^ s3;
  14150. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  14151. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  14152. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  14153. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  14154. }
  14155. //AddRoundKey
  14156. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14157. state[j] ^= key[k];
  14158. }
  14159. }
  14160. //SubBytes
  14161. for (j = 0; j < 16; ++j) {
  14162. state[j] = s[state[j]];
  14163. }
  14164. //ShiftRows
  14165. v = state[1];
  14166. state[1] = state[5];
  14167. state[5] = state[9];
  14168. state[9] = state[13];
  14169. state[13] = v;
  14170. v = state[2];
  14171. u = state[6];
  14172. state[2] = state[10];
  14173. state[6] = state[14];
  14174. state[10] = v;
  14175. state[14] = u;
  14176. v = state[3];
  14177. u = state[7];
  14178. t = state[11];
  14179. state[3] = state[15];
  14180. state[7] = v;
  14181. state[11] = u;
  14182. state[15] = t;
  14183. //AddRoundKey
  14184. for (j = 0, k = 224; j < 16; ++j, ++k) {
  14185. state[j] ^= key[k];
  14186. }
  14187. return state;
  14188. }
  14189. function AES256Cipher(key) {
  14190. this.key = expandKey256(key);
  14191. this.buffer = new Uint8Array(16);
  14192. this.bufferPosition = 0;
  14193. }
  14194. function decryptBlock2(data, finalize) {
  14195. var i, j, ii, sourceLength = data.length,
  14196. buffer = this.buffer, bufferLength = this.bufferPosition,
  14197. result = [], iv = this.iv;
  14198. for (i = 0; i < sourceLength; ++i) {
  14199. buffer[bufferLength] = data[i];
  14200. ++bufferLength;
  14201. if (bufferLength < 16) {
  14202. continue;
  14203. }
  14204. // buffer is full, decrypting
  14205. var plain = decrypt256(buffer, this.key);
  14206. // xor-ing the IV vector to get plain text
  14207. for (j = 0; j < 16; ++j) {
  14208. plain[j] ^= iv[j];
  14209. }
  14210. iv = buffer;
  14211. result.push(plain);
  14212. buffer = new Uint8Array(16);
  14213. bufferLength = 0;
  14214. }
  14215. // saving incomplete buffer
  14216. this.buffer = buffer;
  14217. this.bufferLength = bufferLength;
  14218. this.iv = iv;
  14219. if (result.length === 0) {
  14220. return new Uint8Array([]);
  14221. }
  14222. // combining plain text blocks into one
  14223. var outputLength = 16 * result.length;
  14224. if (finalize) {
  14225. // undo a padding that is described in RFC 2898
  14226. var lastBlock = result[result.length - 1];
  14227. var psLen = lastBlock[15];
  14228. if (psLen <= 16) {
  14229. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  14230. if (lastBlock[i] !== psLen) {
  14231. // Invalid padding, assume that the block has no padding.
  14232. psLen = 0;
  14233. break;
  14234. }
  14235. }
  14236. outputLength -= psLen;
  14237. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  14238. }
  14239. }
  14240. var output = new Uint8Array(outputLength);
  14241. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14242. output.set(result[i], j);
  14243. }
  14244. return output;
  14245. }
  14246. AES256Cipher.prototype = {
  14247. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  14248. var i, sourceLength = data.length;
  14249. var buffer = this.buffer, bufferLength = this.bufferPosition;
  14250. // if not supplied an IV wait for IV values
  14251. // they are at the start of the stream
  14252. if (iv) {
  14253. this.iv = iv;
  14254. } else {
  14255. for (i = 0; bufferLength < 16 &&
  14256. i < sourceLength; ++i, ++bufferLength) {
  14257. buffer[bufferLength] = data[i];
  14258. }
  14259. if (bufferLength < 16) {
  14260. //need more data
  14261. this.bufferLength = bufferLength;
  14262. return new Uint8Array([]);
  14263. }
  14264. this.iv = buffer;
  14265. data = data.subarray(16);
  14266. }
  14267. this.buffer = new Uint8Array(16);
  14268. this.bufferLength = 0;
  14269. // starting decryption
  14270. this.decryptBlock = decryptBlock2;
  14271. return this.decryptBlock(data, finalize);
  14272. },
  14273. encrypt: function AES256Cipher_encrypt(data, iv) {
  14274. var i, j, ii, sourceLength = data.length,
  14275. buffer = this.buffer, bufferLength = this.bufferPosition,
  14276. result = [];
  14277. if (!iv) {
  14278. iv = new Uint8Array(16);
  14279. }
  14280. for (i = 0; i < sourceLength; ++i) {
  14281. buffer[bufferLength] = data[i];
  14282. ++bufferLength;
  14283. if (bufferLength < 16) {
  14284. continue;
  14285. }
  14286. for (j = 0; j < 16; ++j) {
  14287. buffer[j] ^= iv[j];
  14288. }
  14289. // buffer is full, encrypting
  14290. var cipher = encrypt256(buffer, this.key);
  14291. this.iv = cipher;
  14292. result.push(cipher);
  14293. buffer = new Uint8Array(16);
  14294. bufferLength = 0;
  14295. }
  14296. // saving incomplete buffer
  14297. this.buffer = buffer;
  14298. this.bufferLength = bufferLength;
  14299. this.iv = iv;
  14300. if (result.length === 0) {
  14301. return new Uint8Array([]);
  14302. }
  14303. // combining plain text blocks into one
  14304. var outputLength = 16 * result.length;
  14305. var output = new Uint8Array(outputLength);
  14306. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14307. output.set(result[i], j);
  14308. }
  14309. return output;
  14310. }
  14311. };
  14312. return AES256Cipher;
  14313. })();
  14314. var PDF17 = (function PDF17Closure() {
  14315. function compareByteArrays(array1, array2) {
  14316. if (array1.length !== array2.length) {
  14317. return false;
  14318. }
  14319. for (var i = 0; i < array1.length; i++) {
  14320. if (array1[i] !== array2[i]) {
  14321. return false;
  14322. }
  14323. }
  14324. return true;
  14325. }
  14326. function PDF17() {
  14327. }
  14328. PDF17.prototype = {
  14329. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  14330. ownerValidationSalt,
  14331. userBytes,
  14332. ownerPassword) {
  14333. var hashData = new Uint8Array(password.length + 56);
  14334. hashData.set(password, 0);
  14335. hashData.set(ownerValidationSalt, password.length);
  14336. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14337. var result = calculateSHA256(hashData, 0, hashData.length);
  14338. return compareByteArrays(result, ownerPassword);
  14339. },
  14340. checkUserPassword: function PDF17_checkUserPassword(password,
  14341. userValidationSalt,
  14342. userPassword) {
  14343. var hashData = new Uint8Array(password.length + 8);
  14344. hashData.set(password, 0);
  14345. hashData.set(userValidationSalt, password.length);
  14346. var result = calculateSHA256(hashData, 0, hashData.length);
  14347. return compareByteArrays(result, userPassword);
  14348. },
  14349. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14350. ownerEncryption) {
  14351. var hashData = new Uint8Array(password.length + 56);
  14352. hashData.set(password, 0);
  14353. hashData.set(ownerKeySalt, password.length);
  14354. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14355. var key = calculateSHA256(hashData, 0, hashData.length);
  14356. var cipher = new AES256Cipher(key);
  14357. return cipher.decryptBlock(ownerEncryption,
  14358. false,
  14359. new Uint8Array(16));
  14360. },
  14361. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14362. userEncryption) {
  14363. var hashData = new Uint8Array(password.length + 8);
  14364. hashData.set(password, 0);
  14365. hashData.set(userKeySalt, password.length);
  14366. //key is the decryption key for the UE string
  14367. var key = calculateSHA256(hashData, 0, hashData.length);
  14368. var cipher = new AES256Cipher(key);
  14369. return cipher.decryptBlock(userEncryption,
  14370. false,
  14371. new Uint8Array(16));
  14372. }
  14373. };
  14374. return PDF17;
  14375. })();
  14376. var PDF20 = (function PDF20Closure() {
  14377. function concatArrays(array1, array2) {
  14378. var t = new Uint8Array(array1.length + array2.length);
  14379. t.set(array1, 0);
  14380. t.set(array2, array1.length);
  14381. return t;
  14382. }
  14383. function calculatePDF20Hash(password, input, userBytes) {
  14384. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14385. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14386. var e = [0];
  14387. var i = 0;
  14388. while (i < 64 || e[e.length - 1] > i - 32) {
  14389. var arrayLength = password.length + k.length + userBytes.length;
  14390. var k1 = new Uint8Array(arrayLength * 64);
  14391. var array = concatArrays(password, k);
  14392. array = concatArrays(array, userBytes);
  14393. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14394. k1.set(array, pos);
  14395. }
  14396. //AES128 CBC NO PADDING with
  14397. //first 16 bytes of k as the key and the second 16 as the iv.
  14398. var cipher = new AES128Cipher(k.subarray(0, 16));
  14399. e = cipher.encrypt(k1, k.subarray(16, 32));
  14400. //Now we have to take the first 16 bytes of an unsigned
  14401. //big endian integer... and compute the remainder
  14402. //modulo 3.... That is a fairly large number and
  14403. //JavaScript isn't going to handle that well...
  14404. //So we're using a trick that allows us to perform
  14405. //modulo math byte by byte
  14406. var remainder = 0;
  14407. for (var z = 0; z < 16; z++) {
  14408. remainder *= (256 % 3);
  14409. remainder %= 3;
  14410. remainder += ((e[z] >>> 0) % 3);
  14411. remainder %= 3;
  14412. }
  14413. if (remainder === 0) {
  14414. k = calculateSHA256(e, 0, e.length);
  14415. }
  14416. else if (remainder === 1) {
  14417. k = calculateSHA384(e, 0, e.length);
  14418. }
  14419. else if (remainder === 2) {
  14420. k = calculateSHA512(e, 0, e.length);
  14421. }
  14422. i++;
  14423. }
  14424. return k.subarray(0, 32);
  14425. }
  14426. function PDF20() {
  14427. }
  14428. function compareByteArrays(array1, array2) {
  14429. if (array1.length !== array2.length) {
  14430. return false;
  14431. }
  14432. for (var i = 0; i < array1.length; i++) {
  14433. if (array1[i] !== array2[i]) {
  14434. return false;
  14435. }
  14436. }
  14437. return true;
  14438. }
  14439. PDF20.prototype = {
  14440. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14441. return calculatePDF20Hash(password, concatBytes, userBytes);
  14442. },
  14443. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14444. ownerValidationSalt,
  14445. userBytes,
  14446. ownerPassword) {
  14447. var hashData = new Uint8Array(password.length + 56);
  14448. hashData.set(password, 0);
  14449. hashData.set(ownerValidationSalt, password.length);
  14450. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14451. var result = calculatePDF20Hash(password, hashData, userBytes);
  14452. return compareByteArrays(result, ownerPassword);
  14453. },
  14454. checkUserPassword: function PDF20_checkUserPassword(password,
  14455. userValidationSalt,
  14456. userPassword) {
  14457. var hashData = new Uint8Array(password.length + 8);
  14458. hashData.set(password, 0);
  14459. hashData.set(userValidationSalt, password.length);
  14460. var result = calculatePDF20Hash(password, hashData, []);
  14461. return compareByteArrays(result, userPassword);
  14462. },
  14463. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14464. ownerEncryption) {
  14465. var hashData = new Uint8Array(password.length + 56);
  14466. hashData.set(password, 0);
  14467. hashData.set(ownerKeySalt, password.length);
  14468. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14469. var key = calculatePDF20Hash(password, hashData, userBytes);
  14470. var cipher = new AES256Cipher(key);
  14471. return cipher.decryptBlock(ownerEncryption,
  14472. false,
  14473. new Uint8Array(16));
  14474. },
  14475. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14476. userEncryption) {
  14477. var hashData = new Uint8Array(password.length + 8);
  14478. hashData.set(password, 0);
  14479. hashData.set(userKeySalt, password.length);
  14480. //key is the decryption key for the UE string
  14481. var key = calculatePDF20Hash(password, hashData, []);
  14482. var cipher = new AES256Cipher(key);
  14483. return cipher.decryptBlock(userEncryption,
  14484. false,
  14485. new Uint8Array(16));
  14486. }
  14487. };
  14488. return PDF20;
  14489. })();
  14490. var CipherTransform = (function CipherTransformClosure() {
  14491. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14492. this.stringCipherConstructor = stringCipherConstructor;
  14493. this.streamCipherConstructor = streamCipherConstructor;
  14494. }
  14495. CipherTransform.prototype = {
  14496. createStream: function CipherTransform_createStream(stream, length) {
  14497. var cipher = new this.streamCipherConstructor();
  14498. return new DecryptStream(stream, length,
  14499. function cipherTransformDecryptStream(data, finalize) {
  14500. return cipher.decryptBlock(data, finalize);
  14501. }
  14502. );
  14503. },
  14504. decryptString: function CipherTransform_decryptString(s) {
  14505. var cipher = new this.stringCipherConstructor();
  14506. var data = stringToBytes(s);
  14507. data = cipher.decryptBlock(data, true);
  14508. return bytesToString(data);
  14509. }
  14510. };
  14511. return CipherTransform;
  14512. })();
  14513. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14514. var defaultPasswordBytes = new Uint8Array([
  14515. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14516. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14517. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14518. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14519. function createEncryptionKey20(revision, password, ownerPassword,
  14520. ownerValidationSalt, ownerKeySalt, uBytes,
  14521. userPassword, userValidationSalt, userKeySalt,
  14522. ownerEncryption, userEncryption, perms) {
  14523. if (password) {
  14524. var passwordLength = Math.min(127, password.length);
  14525. password = password.subarray(0, passwordLength);
  14526. } else {
  14527. password = [];
  14528. }
  14529. var pdfAlgorithm;
  14530. if (revision === 6) {
  14531. pdfAlgorithm = new PDF20();
  14532. } else {
  14533. pdfAlgorithm = new PDF17();
  14534. }
  14535. if (pdfAlgorithm) {
  14536. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14537. userPassword)) {
  14538. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14539. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  14540. ownerValidationSalt,
  14541. uBytes,
  14542. ownerPassword)) {
  14543. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14544. ownerEncryption);
  14545. }
  14546. }
  14547. return null;
  14548. }
  14549. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14550. flags, revision, keyLength, encryptMetadata) {
  14551. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14552. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14553. if (password) {
  14554. n = Math.min(32, password.length);
  14555. for (; i < n; ++i) {
  14556. hashData[i] = password[i];
  14557. }
  14558. }
  14559. j = 0;
  14560. while (i < 32) {
  14561. hashData[i++] = defaultPasswordBytes[j++];
  14562. }
  14563. // as now the padded password in the hashData[0..i]
  14564. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14565. hashData[i++] = ownerPassword[j];
  14566. }
  14567. hashData[i++] = flags & 0xFF;
  14568. hashData[i++] = (flags >> 8) & 0xFF;
  14569. hashData[i++] = (flags >> 16) & 0xFF;
  14570. hashData[i++] = (flags >>> 24) & 0xFF;
  14571. for (j = 0, n = fileId.length; j < n; ++j) {
  14572. hashData[i++] = fileId[j];
  14573. }
  14574. if (revision >= 4 && !encryptMetadata) {
  14575. hashData[i++] = 0xFF;
  14576. hashData[i++] = 0xFF;
  14577. hashData[i++] = 0xFF;
  14578. hashData[i++] = 0xFF;
  14579. }
  14580. var hash = calculateMD5(hashData, 0, i);
  14581. var keyLengthInBytes = keyLength >> 3;
  14582. if (revision >= 3) {
  14583. for (j = 0; j < 50; ++j) {
  14584. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14585. }
  14586. }
  14587. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14588. var cipher, checkData;
  14589. if (revision >= 3) {
  14590. for (i = 0; i < 32; ++i) {
  14591. hashData[i] = defaultPasswordBytes[i];
  14592. }
  14593. for (j = 0, n = fileId.length; j < n; ++j) {
  14594. hashData[i++] = fileId[j];
  14595. }
  14596. cipher = new ARCFourCipher(encryptionKey);
  14597. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14598. n = encryptionKey.length;
  14599. var derivedKey = new Uint8Array(n), k;
  14600. for (j = 1; j <= 19; ++j) {
  14601. for (k = 0; k < n; ++k) {
  14602. derivedKey[k] = encryptionKey[k] ^ j;
  14603. }
  14604. cipher = new ARCFourCipher(derivedKey);
  14605. checkData = cipher.encryptBlock(checkData);
  14606. }
  14607. for (j = 0, n = checkData.length; j < n; ++j) {
  14608. if (userPassword[j] !== checkData[j]) {
  14609. return null;
  14610. }
  14611. }
  14612. } else {
  14613. cipher = new ARCFourCipher(encryptionKey);
  14614. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14615. for (j = 0, n = checkData.length; j < n; ++j) {
  14616. if (userPassword[j] !== checkData[j]) {
  14617. return null;
  14618. }
  14619. }
  14620. }
  14621. return encryptionKey;
  14622. }
  14623. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14624. var hashData = new Uint8Array(32), i = 0, j, n;
  14625. n = Math.min(32, password.length);
  14626. for (; i < n; ++i) {
  14627. hashData[i] = password[i];
  14628. }
  14629. j = 0;
  14630. while (i < 32) {
  14631. hashData[i++] = defaultPasswordBytes[j++];
  14632. }
  14633. var hash = calculateMD5(hashData, 0, i);
  14634. var keyLengthInBytes = keyLength >> 3;
  14635. if (revision >= 3) {
  14636. for (j = 0; j < 50; ++j) {
  14637. hash = calculateMD5(hash, 0, hash.length);
  14638. }
  14639. }
  14640. var cipher, userPassword;
  14641. if (revision >= 3) {
  14642. userPassword = ownerPassword;
  14643. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14644. for (j = 19; j >= 0; j--) {
  14645. for (k = 0; k < keyLengthInBytes; ++k) {
  14646. derivedKey[k] = hash[k] ^ j;
  14647. }
  14648. cipher = new ARCFourCipher(derivedKey);
  14649. userPassword = cipher.encryptBlock(userPassword);
  14650. }
  14651. } else {
  14652. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14653. userPassword = cipher.encryptBlock(ownerPassword);
  14654. }
  14655. return userPassword;
  14656. }
  14657. var identityName = Name.get('Identity');
  14658. function CipherTransformFactory(dict, fileId, password) {
  14659. var filter = dict.get('Filter');
  14660. if (!isName(filter) || filter.name !== 'Standard') {
  14661. error('unknown encryption method');
  14662. }
  14663. this.dict = dict;
  14664. var algorithm = dict.get('V');
  14665. if (!isInt(algorithm) ||
  14666. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14667. algorithm !== 5)) {
  14668. error('unsupported encryption algorithm');
  14669. }
  14670. this.algorithm = algorithm;
  14671. var keyLength = dict.get('Length') || 40;
  14672. if (!isInt(keyLength) ||
  14673. keyLength < 40 || (keyLength % 8) !== 0) {
  14674. error('invalid key length');
  14675. }
  14676. // prepare keys
  14677. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14678. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14679. var flags = dict.get('P');
  14680. var revision = dict.get('R');
  14681. // meaningful when V is 4 or 5
  14682. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14683. dict.get('EncryptMetadata') !== false);
  14684. this.encryptMetadata = encryptMetadata;
  14685. var fileIdBytes = stringToBytes(fileId);
  14686. var passwordBytes;
  14687. if (password) {
  14688. if (revision === 6) {
  14689. try {
  14690. password = utf8StringToString(password);
  14691. } catch (ex) {
  14692. warn('CipherTransformFactory: ' +
  14693. 'Unable to convert UTF8 encoded password.');
  14694. }
  14695. }
  14696. passwordBytes = stringToBytes(password);
  14697. }
  14698. var encryptionKey;
  14699. if (algorithm !== 5) {
  14700. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14701. ownerPassword, userPassword, flags,
  14702. revision, keyLength, encryptMetadata);
  14703. }
  14704. else {
  14705. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14706. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14707. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14708. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14709. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14710. var ownerEncryption = stringToBytes(dict.get('OE'));
  14711. var userEncryption = stringToBytes(dict.get('UE'));
  14712. var perms = stringToBytes(dict.get('Perms'));
  14713. encryptionKey =
  14714. createEncryptionKey20(revision, passwordBytes,
  14715. ownerPassword, ownerValidationSalt,
  14716. ownerKeySalt, uBytes,
  14717. userPassword, userValidationSalt,
  14718. userKeySalt, ownerEncryption,
  14719. userEncryption, perms);
  14720. }
  14721. if (!encryptionKey && !password) {
  14722. throw new PasswordException('No password given',
  14723. PasswordResponses.NEED_PASSWORD);
  14724. } else if (!encryptionKey && password) {
  14725. // Attempting use the password as an owner password
  14726. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14727. revision, keyLength);
  14728. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14729. ownerPassword, userPassword, flags,
  14730. revision, keyLength, encryptMetadata);
  14731. }
  14732. if (!encryptionKey) {
  14733. throw new PasswordException('Incorrect Password',
  14734. PasswordResponses.INCORRECT_PASSWORD);
  14735. }
  14736. this.encryptionKey = encryptionKey;
  14737. if (algorithm >= 4) {
  14738. this.cf = dict.get('CF');
  14739. this.stmf = dict.get('StmF') || identityName;
  14740. this.strf = dict.get('StrF') || identityName;
  14741. this.eff = dict.get('EFF') || this.stmf;
  14742. }
  14743. }
  14744. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14745. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14746. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14747. key[i] = encryptionKey[i];
  14748. }
  14749. key[i++] = num & 0xFF;
  14750. key[i++] = (num >> 8) & 0xFF;
  14751. key[i++] = (num >> 16) & 0xFF;
  14752. key[i++] = gen & 0xFF;
  14753. key[i++] = (gen >> 8) & 0xFF;
  14754. if (isAes) {
  14755. key[i++] = 0x73;
  14756. key[i++] = 0x41;
  14757. key[i++] = 0x6C;
  14758. key[i++] = 0x54;
  14759. }
  14760. var hash = calculateMD5(key, 0, i);
  14761. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14762. }
  14763. function buildCipherConstructor(cf, name, num, gen, key) {
  14764. var cryptFilter = cf.get(name.name);
  14765. var cfm;
  14766. if (cryptFilter !== null && cryptFilter !== undefined) {
  14767. cfm = cryptFilter.get('CFM');
  14768. }
  14769. if (!cfm || cfm.name === 'None') {
  14770. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14771. return new NullCipher();
  14772. };
  14773. }
  14774. if ('V2' === cfm.name) {
  14775. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14776. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14777. };
  14778. }
  14779. if ('AESV2' === cfm.name) {
  14780. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14781. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14782. };
  14783. }
  14784. if ('AESV3' === cfm.name) {
  14785. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14786. return new AES256Cipher(key);
  14787. };
  14788. }
  14789. error('Unknown crypto method');
  14790. }
  14791. CipherTransformFactory.prototype = {
  14792. createCipherTransform:
  14793. function CipherTransformFactory_createCipherTransform(num, gen) {
  14794. if (this.algorithm === 4 || this.algorithm === 5) {
  14795. return new CipherTransform(
  14796. buildCipherConstructor(this.cf, this.stmf,
  14797. num, gen, this.encryptionKey),
  14798. buildCipherConstructor(this.cf, this.strf,
  14799. num, gen, this.encryptionKey));
  14800. }
  14801. // algorithms 1 and 2
  14802. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14803. var cipherConstructor = function buildCipherCipherConstructor() {
  14804. return new ARCFourCipher(key);
  14805. };
  14806. return new CipherTransform(cipherConstructor, cipherConstructor);
  14807. }
  14808. };
  14809. return CipherTransformFactory;
  14810. })();
  14811. var ShadingType = {
  14812. FUNCTION_BASED: 1,
  14813. AXIAL: 2,
  14814. RADIAL: 3,
  14815. FREE_FORM_MESH: 4,
  14816. LATTICE_FORM_MESH: 5,
  14817. COONS_PATCH_MESH: 6,
  14818. TENSOR_PATCH_MESH: 7
  14819. };
  14820. var Pattern = (function PatternClosure() {
  14821. // Constructor should define this.getPattern
  14822. function Pattern() {
  14823. error('should not call Pattern constructor');
  14824. }
  14825. Pattern.prototype = {
  14826. // Input: current Canvas context
  14827. // Output: the appropriate fillStyle or strokeStyle
  14828. getPattern: function Pattern_getPattern(ctx) {
  14829. error('Should not call Pattern.getStyle: ' + ctx);
  14830. }
  14831. };
  14832. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14833. res) {
  14834. var dict = isStream(shading) ? shading.dict : shading;
  14835. var type = dict.get('ShadingType');
  14836. try {
  14837. switch (type) {
  14838. case ShadingType.AXIAL:
  14839. case ShadingType.RADIAL:
  14840. // Both radial and axial shadings are handled by RadialAxial shading.
  14841. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14842. case ShadingType.FREE_FORM_MESH:
  14843. case ShadingType.LATTICE_FORM_MESH:
  14844. case ShadingType.COONS_PATCH_MESH:
  14845. case ShadingType.TENSOR_PATCH_MESH:
  14846. return new Shadings.Mesh(shading, matrix, xref, res);
  14847. default:
  14848. throw new Error('Unsupported ShadingType: ' + type);
  14849. }
  14850. } catch (ex) {
  14851. if (ex instanceof MissingDataException) {
  14852. throw ex;
  14853. }
  14854. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14855. warn(ex);
  14856. return new Shadings.Dummy();
  14857. }
  14858. };
  14859. return Pattern;
  14860. })();
  14861. var Shadings = {};
  14862. // A small number to offset the first/last color stops so we can insert ones to
  14863. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14864. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14865. // internally so we have to go bigger.
  14866. Shadings.SMALL_NUMBER = 1e-2;
  14867. // Radial and axial shading have very similar implementations
  14868. // If needed, the implementations can be broken into two classes
  14869. Shadings.RadialAxial = (function RadialAxialClosure() {
  14870. function RadialAxial(dict, matrix, xref, res) {
  14871. this.matrix = matrix;
  14872. this.coordsArr = dict.get('Coords');
  14873. this.shadingType = dict.get('ShadingType');
  14874. this.type = 'Pattern';
  14875. var cs = dict.get('ColorSpace', 'CS');
  14876. cs = ColorSpace.parse(cs, xref, res);
  14877. this.cs = cs;
  14878. var t0 = 0.0, t1 = 1.0;
  14879. if (dict.has('Domain')) {
  14880. var domainArr = dict.get('Domain');
  14881. t0 = domainArr[0];
  14882. t1 = domainArr[1];
  14883. }
  14884. var extendStart = false, extendEnd = false;
  14885. if (dict.has('Extend')) {
  14886. var extendArr = dict.get('Extend');
  14887. extendStart = extendArr[0];
  14888. extendEnd = extendArr[1];
  14889. }
  14890. if (this.shadingType === ShadingType.RADIAL &&
  14891. (!extendStart || !extendEnd)) {
  14892. // Radial gradient only currently works if either circle is fully within
  14893. // the other circle.
  14894. var x1 = this.coordsArr[0];
  14895. var y1 = this.coordsArr[1];
  14896. var r1 = this.coordsArr[2];
  14897. var x2 = this.coordsArr[3];
  14898. var y2 = this.coordsArr[4];
  14899. var r2 = this.coordsArr[5];
  14900. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14901. if (r1 <= r2 + distance &&
  14902. r2 <= r1 + distance) {
  14903. warn('Unsupported radial gradient.');
  14904. }
  14905. }
  14906. this.extendStart = extendStart;
  14907. this.extendEnd = extendEnd;
  14908. var fnObj = dict.get('Function');
  14909. var fn = PDFFunction.parseArray(xref, fnObj);
  14910. // 10 samples seems good enough for now, but probably won't work
  14911. // if there are sharp color changes. Ideally, we would implement
  14912. // the spec faithfully and add lossless optimizations.
  14913. var diff = t1 - t0;
  14914. var step = diff / 10;
  14915. var colorStops = this.colorStops = [];
  14916. // Protect against bad domains so we don't end up in an infinte loop below.
  14917. if (t0 >= t1 || step <= 0) {
  14918. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14919. // now.
  14920. info('Bad shading domain.');
  14921. return;
  14922. }
  14923. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14924. var rgbColor;
  14925. for (var i = t0; i <= t1; i += step) {
  14926. ratio[0] = i;
  14927. fn(ratio, 0, color, 0);
  14928. rgbColor = cs.getRgb(color, 0);
  14929. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14930. colorStops.push([(i - t0) / diff, cssColor]);
  14931. }
  14932. var background = 'transparent';
  14933. if (dict.has('Background')) {
  14934. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14935. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14936. }
  14937. if (!extendStart) {
  14938. // Insert a color stop at the front and offset the first real color stop
  14939. // so it doesn't conflict with the one we insert.
  14940. colorStops.unshift([0, background]);
  14941. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14942. }
  14943. if (!extendEnd) {
  14944. // Same idea as above in extendStart but for the end.
  14945. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14946. colorStops.push([1, background]);
  14947. }
  14948. this.colorStops = colorStops;
  14949. }
  14950. RadialAxial.prototype = {
  14951. getIR: function RadialAxial_getIR() {
  14952. var coordsArr = this.coordsArr;
  14953. var shadingType = this.shadingType;
  14954. var type, p0, p1, r0, r1;
  14955. if (shadingType === ShadingType.AXIAL) {
  14956. p0 = [coordsArr[0], coordsArr[1]];
  14957. p1 = [coordsArr[2], coordsArr[3]];
  14958. r0 = null;
  14959. r1 = null;
  14960. type = 'axial';
  14961. } else if (shadingType === ShadingType.RADIAL) {
  14962. p0 = [coordsArr[0], coordsArr[1]];
  14963. p1 = [coordsArr[3], coordsArr[4]];
  14964. r0 = coordsArr[2];
  14965. r1 = coordsArr[5];
  14966. type = 'radial';
  14967. } else {
  14968. error('getPattern type unknown: ' + shadingType);
  14969. }
  14970. var matrix = this.matrix;
  14971. if (matrix) {
  14972. p0 = Util.applyTransform(p0, matrix);
  14973. p1 = Util.applyTransform(p1, matrix);
  14974. }
  14975. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14976. }
  14977. };
  14978. return RadialAxial;
  14979. })();
  14980. // All mesh shading. For now, they will be presented as set of the triangles
  14981. // to be drawn on the canvas and rgb color for each vertex.
  14982. Shadings.Mesh = (function MeshClosure() {
  14983. function MeshStreamReader(stream, context) {
  14984. this.stream = stream;
  14985. this.context = context;
  14986. this.buffer = 0;
  14987. this.bufferLength = 0;
  14988. var numComps = context.numComps;
  14989. this.tmpCompsBuf = new Float32Array(numComps);
  14990. var csNumComps = context.colorSpace.numComps;
  14991. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14992. this.tmpCompsBuf;
  14993. }
  14994. MeshStreamReader.prototype = {
  14995. get hasData() {
  14996. if (this.stream.end) {
  14997. return this.stream.pos < this.stream.end;
  14998. }
  14999. if (this.bufferLength > 0) {
  15000. return true;
  15001. }
  15002. var nextByte = this.stream.getByte();
  15003. if (nextByte < 0) {
  15004. return false;
  15005. }
  15006. this.buffer = nextByte;
  15007. this.bufferLength = 8;
  15008. return true;
  15009. },
  15010. readBits: function MeshStreamReader_readBits(n) {
  15011. var buffer = this.buffer;
  15012. var bufferLength = this.bufferLength;
  15013. if (n === 32) {
  15014. if (bufferLength === 0) {
  15015. return ((this.stream.getByte() << 24) |
  15016. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  15017. this.stream.getByte()) >>> 0;
  15018. }
  15019. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  15020. (this.stream.getByte() << 8) | this.stream.getByte();
  15021. var nextByte = this.stream.getByte();
  15022. this.buffer = nextByte & ((1 << bufferLength) - 1);
  15023. return ((buffer << (8 - bufferLength)) |
  15024. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  15025. }
  15026. if (n === 8 && bufferLength === 0) {
  15027. return this.stream.getByte();
  15028. }
  15029. while (bufferLength < n) {
  15030. buffer = (buffer << 8) | this.stream.getByte();
  15031. bufferLength += 8;
  15032. }
  15033. bufferLength -= n;
  15034. this.bufferLength = bufferLength;
  15035. this.buffer = buffer & ((1 << bufferLength) - 1);
  15036. return buffer >> bufferLength;
  15037. },
  15038. align: function MeshStreamReader_align() {
  15039. this.buffer = 0;
  15040. this.bufferLength = 0;
  15041. },
  15042. readFlag: function MeshStreamReader_readFlag() {
  15043. return this.readBits(this.context.bitsPerFlag);
  15044. },
  15045. readCoordinate: function MeshStreamReader_readCoordinate() {
  15046. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  15047. var xi = this.readBits(bitsPerCoordinate);
  15048. var yi = this.readBits(bitsPerCoordinate);
  15049. var decode = this.context.decode;
  15050. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  15051. 2.3283064365386963e-10; // 2 ^ -32
  15052. return [
  15053. xi * scale * (decode[1] - decode[0]) + decode[0],
  15054. yi * scale * (decode[3] - decode[2]) + decode[2]
  15055. ];
  15056. },
  15057. readComponents: function MeshStreamReader_readComponents() {
  15058. var numComps = this.context.numComps;
  15059. var bitsPerComponent = this.context.bitsPerComponent;
  15060. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  15061. 2.3283064365386963e-10; // 2 ^ -32
  15062. var decode = this.context.decode;
  15063. var components = this.tmpCompsBuf;
  15064. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  15065. var ci = this.readBits(bitsPerComponent);
  15066. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  15067. }
  15068. var color = this.tmpCsCompsBuf;
  15069. if (this.context.colorFn) {
  15070. this.context.colorFn(components, 0, color, 0);
  15071. }
  15072. return this.context.colorSpace.getRgb(color, 0);
  15073. }
  15074. };
  15075. function decodeType4Shading(mesh, reader) {
  15076. var coords = mesh.coords;
  15077. var colors = mesh.colors;
  15078. var operators = [];
  15079. var ps = []; // not maintaining cs since that will match ps
  15080. var verticesLeft = 0; // assuming we have all data to start a new triangle
  15081. while (reader.hasData) {
  15082. var f = reader.readFlag();
  15083. var coord = reader.readCoordinate();
  15084. var color = reader.readComponents();
  15085. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  15086. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  15087. switch (f) {
  15088. case 0:
  15089. verticesLeft = 3;
  15090. break;
  15091. case 1:
  15092. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  15093. verticesLeft = 1;
  15094. break;
  15095. case 2:
  15096. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  15097. verticesLeft = 1;
  15098. break;
  15099. }
  15100. operators.push(f);
  15101. }
  15102. ps.push(coords.length);
  15103. coords.push(coord);
  15104. colors.push(color);
  15105. verticesLeft--;
  15106. reader.align();
  15107. }
  15108. mesh.figures.push({
  15109. type: 'triangles',
  15110. coords: new Int32Array(ps),
  15111. colors: new Int32Array(ps),
  15112. });
  15113. }
  15114. function decodeType5Shading(mesh, reader, verticesPerRow) {
  15115. var coords = mesh.coords;
  15116. var colors = mesh.colors;
  15117. var ps = []; // not maintaining cs since that will match ps
  15118. while (reader.hasData) {
  15119. var coord = reader.readCoordinate();
  15120. var color = reader.readComponents();
  15121. ps.push(coords.length);
  15122. coords.push(coord);
  15123. colors.push(color);
  15124. }
  15125. mesh.figures.push({
  15126. type: 'lattice',
  15127. coords: new Int32Array(ps),
  15128. colors: new Int32Array(ps),
  15129. verticesPerRow: verticesPerRow
  15130. });
  15131. }
  15132. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  15133. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  15134. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  15135. var getB = (function getBClosure() {
  15136. function buildB(count) {
  15137. var lut = [];
  15138. for (var i = 0; i <= count; i++) {
  15139. var t = i / count, t_ = 1 - t;
  15140. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  15141. 3 * t * t * t_, t * t * t]));
  15142. }
  15143. return lut;
  15144. }
  15145. var cache = [];
  15146. return function getB(count) {
  15147. if (!cache[count]) {
  15148. cache[count] = buildB(count);
  15149. }
  15150. return cache[count];
  15151. };
  15152. })();
  15153. function buildFigureFromPatch(mesh, index) {
  15154. var figure = mesh.figures[index];
  15155. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  15156. var coords = mesh.coords, colors = mesh.colors;
  15157. var pi = figure.coords;
  15158. var ci = figure.colors;
  15159. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  15160. coords[pi[12]][0], coords[pi[15]][0]);
  15161. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  15162. coords[pi[12]][1], coords[pi[15]][1]);
  15163. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  15164. coords[pi[12]][0], coords[pi[15]][0]);
  15165. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  15166. coords[pi[12]][1], coords[pi[15]][1]);
  15167. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  15168. (mesh.bounds[2] - mesh.bounds[0]));
  15169. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  15170. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  15171. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  15172. (mesh.bounds[3] - mesh.bounds[1]));
  15173. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  15174. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  15175. var verticesPerRow = splitXBy + 1;
  15176. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  15177. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  15178. var k = 0;
  15179. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  15180. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  15181. c2 = colors[ci[2]], c3 = colors[ci[3]];
  15182. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  15183. for (var row = 0; row <= splitYBy; row++) {
  15184. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  15185. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  15186. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  15187. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  15188. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  15189. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  15190. for (var col = 0; col <= splitXBy; col++, k++) {
  15191. if ((row === 0 || row === splitYBy) &&
  15192. (col === 0 || col === splitXBy)) {
  15193. continue;
  15194. }
  15195. var x = 0, y = 0;
  15196. var q = 0;
  15197. for (var i = 0; i <= 3; i++) {
  15198. for (var j = 0; j <= 3; j++, q++) {
  15199. var m = bRow[row][i] * bCol[col][j];
  15200. x += coords[pi[q]][0] * m;
  15201. y += coords[pi[q]][1] * m;
  15202. }
  15203. }
  15204. figureCoords[k] = coords.length;
  15205. coords.push([x, y]);
  15206. figureColors[k] = colors.length;
  15207. var newColor = new Uint8Array(3);
  15208. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  15209. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  15210. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  15211. colors.push(newColor);
  15212. }
  15213. }
  15214. figureCoords[0] = pi[0];
  15215. figureColors[0] = ci[0];
  15216. figureCoords[splitXBy] = pi[3];
  15217. figureColors[splitXBy] = ci[1];
  15218. figureCoords[verticesPerRow * splitYBy] = pi[12];
  15219. figureColors[verticesPerRow * splitYBy] = ci[2];
  15220. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  15221. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  15222. mesh.figures[index] = {
  15223. type: 'lattice',
  15224. coords: figureCoords,
  15225. colors: figureColors,
  15226. verticesPerRow: verticesPerRow
  15227. };
  15228. }
  15229. function decodeType6Shading(mesh, reader) {
  15230. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  15231. var coords = mesh.coords;
  15232. var colors = mesh.colors;
  15233. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  15234. var cs = new Int32Array(4); // c00, c30, c03, c33
  15235. while (reader.hasData) {
  15236. var f = reader.readFlag();
  15237. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  15238. var i, ii;
  15239. var pi = coords.length;
  15240. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  15241. coords.push(reader.readCoordinate());
  15242. }
  15243. var ci = colors.length;
  15244. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15245. colors.push(reader.readComponents());
  15246. }
  15247. var tmp1, tmp2, tmp3, tmp4;
  15248. switch (f) {
  15249. case 0:
  15250. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15251. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  15252. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  15253. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15254. cs[2] = ci + 1; cs[3] = ci + 2;
  15255. cs[0] = ci; cs[1] = ci + 3;
  15256. break;
  15257. case 1:
  15258. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15259. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15260. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15261. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  15262. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15263. tmp1 = cs[2]; tmp2 = cs[3];
  15264. cs[2] = tmp2; cs[3] = ci;
  15265. cs[0] = tmp1; cs[1] = ci + 1;
  15266. break;
  15267. case 2:
  15268. tmp1 = ps[15];
  15269. tmp2 = ps[11];
  15270. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15271. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15272. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  15273. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15274. tmp1 = cs[3];
  15275. cs[2] = cs[1]; cs[3] = ci;
  15276. cs[0] = tmp1; cs[1] = ci + 1;
  15277. break;
  15278. case 3:
  15279. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15280. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15281. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  15282. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15283. cs[2] = cs[0]; cs[3] = ci;
  15284. cs[0] = cs[1]; cs[1] = ci + 1;
  15285. break;
  15286. }
  15287. // set p11, p12, p21, p22
  15288. ps[5] = coords.length;
  15289. coords.push([
  15290. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  15291. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  15292. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  15293. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  15294. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  15295. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  15296. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  15297. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  15298. ]);
  15299. ps[6] = coords.length;
  15300. coords.push([
  15301. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  15302. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  15303. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  15304. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  15305. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  15306. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  15307. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  15308. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  15309. ]);
  15310. ps[9] = coords.length;
  15311. coords.push([
  15312. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  15313. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  15314. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  15315. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  15316. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  15317. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  15318. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  15319. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  15320. ]);
  15321. ps[10] = coords.length;
  15322. coords.push([
  15323. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  15324. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  15325. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  15326. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  15327. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  15328. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  15329. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  15330. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  15331. ]);
  15332. mesh.figures.push({
  15333. type: 'patch',
  15334. coords: new Int32Array(ps), // making copies of ps and cs
  15335. colors: new Int32Array(cs)
  15336. });
  15337. }
  15338. }
  15339. function decodeType7Shading(mesh, reader) {
  15340. var coords = mesh.coords;
  15341. var colors = mesh.colors;
  15342. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  15343. var cs = new Int32Array(4); // c00, c30, c03, c33
  15344. while (reader.hasData) {
  15345. var f = reader.readFlag();
  15346. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15347. var i, ii;
  15348. var pi = coords.length;
  15349. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15350. coords.push(reader.readCoordinate());
  15351. }
  15352. var ci = colors.length;
  15353. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15354. colors.push(reader.readComponents());
  15355. }
  15356. var tmp1, tmp2, tmp3, tmp4;
  15357. switch (f) {
  15358. case 0:
  15359. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15360. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15361. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15362. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15363. cs[2] = ci + 1; cs[3] = ci + 2;
  15364. cs[0] = ci; cs[1] = ci + 3;
  15365. break;
  15366. case 1:
  15367. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15368. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15369. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15370. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15371. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15372. tmp1 = cs[2]; tmp2 = cs[3];
  15373. cs[2] = tmp2; cs[3] = ci;
  15374. cs[0] = tmp1; cs[1] = ci + 1;
  15375. break;
  15376. case 2:
  15377. tmp1 = ps[15];
  15378. tmp2 = ps[11];
  15379. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15380. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15381. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15382. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15383. tmp1 = cs[3];
  15384. cs[2] = cs[1]; cs[3] = ci;
  15385. cs[0] = tmp1; cs[1] = ci + 1;
  15386. break;
  15387. case 3:
  15388. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15389. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15390. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15391. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15392. cs[2] = cs[0]; cs[3] = ci;
  15393. cs[0] = cs[1]; cs[1] = ci + 1;
  15394. break;
  15395. }
  15396. mesh.figures.push({
  15397. type: 'patch',
  15398. coords: new Int32Array(ps), // making copies of ps and cs
  15399. colors: new Int32Array(cs)
  15400. });
  15401. }
  15402. }
  15403. function updateBounds(mesh) {
  15404. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15405. maxX = minX, maxY = minY;
  15406. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15407. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15408. minX = minX > x ? x : minX;
  15409. minY = minY > y ? y : minY;
  15410. maxX = maxX < x ? x : maxX;
  15411. maxY = maxY < y ? y : maxY;
  15412. }
  15413. mesh.bounds = [minX, minY, maxX, maxY];
  15414. }
  15415. function packData(mesh) {
  15416. var i, ii, j, jj;
  15417. var coords = mesh.coords;
  15418. var coordsPacked = new Float32Array(coords.length * 2);
  15419. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15420. var xy = coords[i];
  15421. coordsPacked[j++] = xy[0];
  15422. coordsPacked[j++] = xy[1];
  15423. }
  15424. mesh.coords = coordsPacked;
  15425. var colors = mesh.colors;
  15426. var colorsPacked = new Uint8Array(colors.length * 3);
  15427. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15428. var c = colors[i];
  15429. colorsPacked[j++] = c[0];
  15430. colorsPacked[j++] = c[1];
  15431. colorsPacked[j++] = c[2];
  15432. }
  15433. mesh.colors = colorsPacked;
  15434. var figures = mesh.figures;
  15435. for (i = 0, ii = figures.length; i < ii; i++) {
  15436. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15437. for (j = 0, jj = ps.length; j < jj; j++) {
  15438. ps[j] *= 2;
  15439. cs[j] *= 3;
  15440. }
  15441. }
  15442. }
  15443. function Mesh(stream, matrix, xref, res) {
  15444. assert(isStream(stream), 'Mesh data is not a stream');
  15445. var dict = stream.dict;
  15446. this.matrix = matrix;
  15447. this.shadingType = dict.get('ShadingType');
  15448. this.type = 'Pattern';
  15449. this.bbox = dict.get('BBox');
  15450. var cs = dict.get('ColorSpace', 'CS');
  15451. cs = ColorSpace.parse(cs, xref, res);
  15452. this.cs = cs;
  15453. this.background = dict.has('Background') ?
  15454. cs.getRgb(dict.get('Background'), 0) : null;
  15455. var fnObj = dict.get('Function');
  15456. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15457. this.coords = [];
  15458. this.colors = [];
  15459. this.figures = [];
  15460. var decodeContext = {
  15461. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15462. bitsPerComponent: dict.get('BitsPerComponent'),
  15463. bitsPerFlag: dict.get('BitsPerFlag'),
  15464. decode: dict.get('Decode'),
  15465. colorFn: fn,
  15466. colorSpace: cs,
  15467. numComps: fn ? 1 : cs.numComps
  15468. };
  15469. var reader = new MeshStreamReader(stream, decodeContext);
  15470. var patchMesh = false;
  15471. switch (this.shadingType) {
  15472. case ShadingType.FREE_FORM_MESH:
  15473. decodeType4Shading(this, reader);
  15474. break;
  15475. case ShadingType.LATTICE_FORM_MESH:
  15476. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15477. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15478. decodeType5Shading(this, reader, verticesPerRow);
  15479. break;
  15480. case ShadingType.COONS_PATCH_MESH:
  15481. decodeType6Shading(this, reader);
  15482. patchMesh = true;
  15483. break;
  15484. case ShadingType.TENSOR_PATCH_MESH:
  15485. decodeType7Shading(this, reader);
  15486. patchMesh = true;
  15487. break;
  15488. default:
  15489. error('Unsupported mesh type.');
  15490. break;
  15491. }
  15492. if (patchMesh) {
  15493. // dirty bounds calculation for determining, how dense shall be triangles
  15494. updateBounds(this);
  15495. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15496. buildFigureFromPatch(this, i);
  15497. }
  15498. }
  15499. // calculate bounds
  15500. updateBounds(this);
  15501. packData(this);
  15502. }
  15503. Mesh.prototype = {
  15504. getIR: function Mesh_getIR() {
  15505. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15506. this.bounds, this.matrix, this.bbox, this.background];
  15507. }
  15508. };
  15509. return Mesh;
  15510. })();
  15511. Shadings.Dummy = (function DummyClosure() {
  15512. function Dummy() {
  15513. this.type = 'Pattern';
  15514. }
  15515. Dummy.prototype = {
  15516. getIR: function Dummy_getIR() {
  15517. return ['Dummy'];
  15518. }
  15519. };
  15520. return Dummy;
  15521. })();
  15522. function getTilingPatternIR(operatorList, dict, args) {
  15523. var matrix = dict.get('Matrix');
  15524. var bbox = dict.get('BBox');
  15525. var xstep = dict.get('XStep');
  15526. var ystep = dict.get('YStep');
  15527. var paintType = dict.get('PaintType');
  15528. var tilingType = dict.get('TilingType');
  15529. return [
  15530. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15531. paintType, tilingType
  15532. ];
  15533. }
  15534. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15535. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15536. uniquePrefix, idCounters, fontCache) {
  15537. this.pdfManager = pdfManager;
  15538. this.xref = xref;
  15539. this.handler = handler;
  15540. this.pageIndex = pageIndex;
  15541. this.uniquePrefix = uniquePrefix;
  15542. this.idCounters = idCounters;
  15543. this.fontCache = fontCache;
  15544. }
  15545. // Trying to minimize Date.now() usage and check every 100 time
  15546. var TIME_SLOT_DURATION_MS = 20;
  15547. var CHECK_TIME_EVERY = 100;
  15548. function TimeSlotManager() {
  15549. this.reset();
  15550. }
  15551. TimeSlotManager.prototype = {
  15552. check: function TimeSlotManager_check() {
  15553. if (++this.checked < CHECK_TIME_EVERY) {
  15554. return false;
  15555. }
  15556. this.checked = 0;
  15557. return this.endTime <= Date.now();
  15558. },
  15559. reset: function TimeSlotManager_reset() {
  15560. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15561. this.checked = 0;
  15562. }
  15563. };
  15564. var deferred = Promise.resolve();
  15565. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15566. PartialEvaluator.prototype = {
  15567. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15568. if (!isDict(resources)) {
  15569. return false;
  15570. }
  15571. var processed = Object.create(null);
  15572. if (resources.objId) {
  15573. processed[resources.objId] = true;
  15574. }
  15575. var nodes = [resources];
  15576. while (nodes.length) {
  15577. var key;
  15578. var node = nodes.shift();
  15579. // First check the current resources for blend modes.
  15580. var graphicStates = node.get('ExtGState');
  15581. if (isDict(graphicStates)) {
  15582. graphicStates = graphicStates.getAll();
  15583. for (key in graphicStates) {
  15584. var graphicState = graphicStates[key];
  15585. var bm = graphicState['BM'];
  15586. if (isName(bm) && bm.name !== 'Normal') {
  15587. return true;
  15588. }
  15589. }
  15590. }
  15591. // Descend into the XObjects to look for more resources and blend modes.
  15592. var xObjects = node.get('XObject');
  15593. if (!isDict(xObjects)) {
  15594. continue;
  15595. }
  15596. xObjects = xObjects.getAll();
  15597. for (key in xObjects) {
  15598. var xObject = xObjects[key];
  15599. if (!isStream(xObject)) {
  15600. continue;
  15601. }
  15602. if (xObject.dict.objId) {
  15603. if (processed[xObject.dict.objId]) {
  15604. // stream has objId and is processed already
  15605. continue;
  15606. }
  15607. processed[xObject.dict.objId] = true;
  15608. }
  15609. var xResources = xObject.dict.get('Resources');
  15610. // Checking objId to detect an infinite loop.
  15611. if (isDict(xResources) &&
  15612. (!xResources.objId || !processed[xResources.objId])) {
  15613. nodes.push(xResources);
  15614. if (xResources.objId) {
  15615. processed[xResources.objId] = true;
  15616. }
  15617. }
  15618. }
  15619. }
  15620. return false;
  15621. },
  15622. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15623. xobj, smask,
  15624. operatorList,
  15625. initialState) {
  15626. var matrix = xobj.dict.getArray('Matrix');
  15627. var bbox = xobj.dict.getArray('BBox');
  15628. var group = xobj.dict.get('Group');
  15629. if (group) {
  15630. var groupOptions = {
  15631. matrix: matrix,
  15632. bbox: bbox,
  15633. smask: smask,
  15634. isolated: false,
  15635. knockout: false
  15636. };
  15637. var groupSubtype = group.get('S');
  15638. var colorSpace;
  15639. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15640. groupOptions.isolated = (group.get('I') || false);
  15641. groupOptions.knockout = (group.get('K') || false);
  15642. colorSpace = (group.has('CS') ?
  15643. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15644. }
  15645. if (smask && smask.backdrop) {
  15646. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15647. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15648. }
  15649. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15650. }
  15651. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15652. return this.getOperatorList(xobj,
  15653. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15654. then(function () {
  15655. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15656. if (group) {
  15657. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15658. }
  15659. });
  15660. },
  15661. buildPaintImageXObject:
  15662. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15663. inline, operatorList,
  15664. cacheKey, imageCache) {
  15665. var self = this;
  15666. var dict = image.dict;
  15667. var w = dict.get('Width', 'W');
  15668. var h = dict.get('Height', 'H');
  15669. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15670. warn('Image dimensions are missing, or not numbers.');
  15671. return;
  15672. }
  15673. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15674. warn('Image exceeded maximum allowed size and was removed.');
  15675. return;
  15676. }
  15677. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15678. var imgData, args;
  15679. if (imageMask) {
  15680. // This depends on a tmpCanvas being filled with the
  15681. // current fillStyle, such that processing the pixel
  15682. // data can't be done here. Instead of creating a
  15683. // complete PDFImage, only read the information needed
  15684. // for later.
  15685. var width = dict.get('Width', 'W');
  15686. var height = dict.get('Height', 'H');
  15687. var bitStrideLength = (width + 7) >> 3;
  15688. var imgArray = image.getBytes(bitStrideLength * height);
  15689. var decode = dict.get('Decode', 'D');
  15690. var inverseDecode = (!!decode && decode[0] > 0);
  15691. imgData = PDFImage.createMask(imgArray, width, height,
  15692. image instanceof DecodeStream,
  15693. inverseDecode);
  15694. imgData.cached = true;
  15695. args = [imgData];
  15696. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15697. if (cacheKey) {
  15698. imageCache[cacheKey] = {
  15699. fn: OPS.paintImageMaskXObject,
  15700. args: args
  15701. };
  15702. }
  15703. return;
  15704. }
  15705. var softMask = (dict.get('SMask', 'SM') || false);
  15706. var mask = (dict.get('Mask') || false);
  15707. var SMALL_IMAGE_DIMENSIONS = 200;
  15708. // Inlining small images into the queue as RGB data
  15709. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15710. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15711. var imageObj = new PDFImage(this.xref, resources, image,
  15712. inline, null, null);
  15713. // We force the use of RGBA_32BPP images here, because we can't handle
  15714. // any other kind.
  15715. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15716. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15717. return;
  15718. }
  15719. // If there is no imageMask, create the PDFImage and a lot
  15720. // of image processing can be done here.
  15721. var uniquePrefix = (this.uniquePrefix || '');
  15722. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15723. operatorList.addDependency(objId);
  15724. args = [objId, w, h];
  15725. if (!softMask && !mask && image instanceof JpegStream &&
  15726. image.isNativelySupported(this.xref, resources)) {
  15727. // These JPEGs don't need any more processing so we can just send it.
  15728. operatorList.addOp(OPS.paintJpegXObject, args);
  15729. this.handler.send('obj',
  15730. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15731. return;
  15732. }
  15733. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15734. then(function(imageObj) {
  15735. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15736. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15737. [imgData.data.buffer]);
  15738. }).then(undefined, function (reason) {
  15739. warn('Unable to decode image: ' + reason);
  15740. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15741. });
  15742. operatorList.addOp(OPS.paintImageXObject, args);
  15743. if (cacheKey) {
  15744. imageCache[cacheKey] = {
  15745. fn: OPS.paintImageXObject,
  15746. args: args
  15747. };
  15748. }
  15749. },
  15750. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15751. operatorList,
  15752. stateManager) {
  15753. var smaskContent = smask.get('G');
  15754. var smaskOptions = {
  15755. subtype: smask.get('S').name,
  15756. backdrop: smask.get('BC')
  15757. };
  15758. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15759. operatorList, stateManager.state.clone());
  15760. },
  15761. handleTilingType:
  15762. function PartialEvaluator_handleTilingType(fn, args, resources,
  15763. pattern, patternDict,
  15764. operatorList) {
  15765. // Create an IR of the pattern code.
  15766. var tilingOpList = new OperatorList();
  15767. return this.getOperatorList(pattern,
  15768. (patternDict.get('Resources') || resources), tilingOpList).
  15769. then(function () {
  15770. // Add the dependencies to the parent operator list so they are
  15771. // resolved before sub operator list is executed synchronously.
  15772. operatorList.addDependencies(tilingOpList.dependencies);
  15773. operatorList.addOp(fn, getTilingPatternIR({
  15774. fnArray: tilingOpList.fnArray,
  15775. argsArray: tilingOpList.argsArray
  15776. }, patternDict, args));
  15777. });
  15778. },
  15779. handleSetFont:
  15780. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15781. operatorList, state) {
  15782. // TODO(mack): Not needed?
  15783. var fontName;
  15784. if (fontArgs) {
  15785. fontArgs = fontArgs.slice();
  15786. fontName = fontArgs[0].name;
  15787. }
  15788. var self = this;
  15789. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15790. function (translated) {
  15791. if (!translated.font.isType3Font) {
  15792. return translated;
  15793. }
  15794. return translated.loadType3Data(self, resources, operatorList).then(
  15795. function () {
  15796. return translated;
  15797. });
  15798. }).then(function (translated) {
  15799. state.font = translated.font;
  15800. translated.send(self.handler);
  15801. return translated.loadedName;
  15802. });
  15803. },
  15804. handleText: function PartialEvaluator_handleText(chars, state) {
  15805. var font = state.font;
  15806. var glyphs = font.charsToGlyphs(chars);
  15807. var isAddToPathSet = !!(state.textRenderingMode &
  15808. TextRenderingMode.ADD_TO_PATH_FLAG);
  15809. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15810. var buildPath = function (fontChar) {
  15811. if (!font.renderer.hasBuiltPath(fontChar)) {
  15812. var path = font.renderer.getPathJs(fontChar);
  15813. this.handler.send('commonobj', [
  15814. font.loadedName + '_path_' + fontChar,
  15815. 'FontPath',
  15816. path
  15817. ]);
  15818. }
  15819. }.bind(this);
  15820. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15821. var glyph = glyphs[i];
  15822. if (glyph === null) {
  15823. continue;
  15824. }
  15825. buildPath(glyph.fontChar);
  15826. // If the glyph has an accent we need to build a path for its
  15827. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15828. var accent = glyph.accent;
  15829. if (accent && accent.fontChar) {
  15830. buildPath(accent.fontChar);
  15831. }
  15832. }
  15833. }
  15834. return glyphs;
  15835. },
  15836. setGState: function PartialEvaluator_setGState(resources, gState,
  15837. operatorList, xref,
  15838. stateManager) {
  15839. // This array holds the converted/processed state data.
  15840. var gStateObj = [];
  15841. var gStateMap = gState.map;
  15842. var self = this;
  15843. var promise = Promise.resolve();
  15844. for (var key in gStateMap) {
  15845. var value = gStateMap[key];
  15846. switch (key) {
  15847. case 'Type':
  15848. break;
  15849. case 'LW':
  15850. case 'LC':
  15851. case 'LJ':
  15852. case 'ML':
  15853. case 'D':
  15854. case 'RI':
  15855. case 'FL':
  15856. case 'CA':
  15857. case 'ca':
  15858. gStateObj.push([key, value]);
  15859. break;
  15860. case 'Font':
  15861. promise = promise.then(function () {
  15862. return self.handleSetFont(resources, null, value[0],
  15863. operatorList, stateManager.state).
  15864. then(function (loadedName) {
  15865. operatorList.addDependency(loadedName);
  15866. gStateObj.push([key, [loadedName, value[1]]]);
  15867. });
  15868. });
  15869. break;
  15870. case 'BM':
  15871. gStateObj.push([key, value]);
  15872. break;
  15873. case 'SMask':
  15874. if (isName(value) && value.name === 'None') {
  15875. gStateObj.push([key, false]);
  15876. break;
  15877. }
  15878. var dict = xref.fetchIfRef(value);
  15879. if (isDict(dict)) {
  15880. promise = promise.then(function () {
  15881. return self.handleSMask(dict, resources, operatorList,
  15882. stateManager);
  15883. });
  15884. gStateObj.push([key, true]);
  15885. } else {
  15886. warn('Unsupported SMask type');
  15887. }
  15888. break;
  15889. // Only generate info log messages for the following since
  15890. // they are unlikely to have a big impact on the rendering.
  15891. case 'OP':
  15892. case 'op':
  15893. case 'OPM':
  15894. case 'BG':
  15895. case 'BG2':
  15896. case 'UCR':
  15897. case 'UCR2':
  15898. case 'TR':
  15899. case 'TR2':
  15900. case 'HT':
  15901. case 'SM':
  15902. case 'SA':
  15903. case 'AIS':
  15904. case 'TK':
  15905. // TODO implement these operators.
  15906. info('graphic state operator ' + key);
  15907. break;
  15908. default:
  15909. info('Unknown graphic state operator ' + key);
  15910. break;
  15911. }
  15912. }
  15913. return promise.then(function () {
  15914. if (gStateObj.length >= 0) {
  15915. operatorList.addOp(OPS.setGState, [gStateObj]);
  15916. }
  15917. });
  15918. },
  15919. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15920. resources) {
  15921. function errorFont() {
  15922. return Promise.resolve(new TranslatedFont('g_font_error',
  15923. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15924. }
  15925. var fontRef;
  15926. if (font) { // Loading by ref.
  15927. assert(isRef(font));
  15928. fontRef = font;
  15929. } else { // Loading by name.
  15930. var fontRes = resources.get('Font');
  15931. if (fontRes) {
  15932. fontRef = fontRes.getRaw(fontName);
  15933. } else {
  15934. warn('fontRes not available');
  15935. return errorFont();
  15936. }
  15937. }
  15938. if (!fontRef) {
  15939. warn('fontRef not available');
  15940. return errorFont();
  15941. }
  15942. if (this.fontCache.has(fontRef)) {
  15943. return this.fontCache.get(fontRef);
  15944. }
  15945. font = xref.fetchIfRef(fontRef);
  15946. if (!isDict(font)) {
  15947. return errorFont();
  15948. }
  15949. // We are holding font.translated references just for fontRef that are not
  15950. // dictionaries (Dict). See explanation below.
  15951. if (font.translated) {
  15952. return font.translated;
  15953. }
  15954. var fontCapability = createPromiseCapability();
  15955. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15956. var descriptor = preEvaluatedFont.descriptor;
  15957. var fontID = fontRef.num + '_' + fontRef.gen;
  15958. if (isDict(descriptor)) {
  15959. if (!descriptor.fontAliases) {
  15960. descriptor.fontAliases = Object.create(null);
  15961. }
  15962. var fontAliases = descriptor.fontAliases;
  15963. var hash = preEvaluatedFont.hash;
  15964. if (fontAliases[hash]) {
  15965. var aliasFontRef = fontAliases[hash].aliasRef;
  15966. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15967. this.fontCache.putAlias(fontRef, aliasFontRef);
  15968. return this.fontCache.get(fontRef);
  15969. }
  15970. }
  15971. if (!fontAliases[hash]) {
  15972. fontAliases[hash] = {
  15973. fontID: Font.getFontID()
  15974. };
  15975. }
  15976. fontAliases[hash].aliasRef = fontRef;
  15977. fontID = fontAliases[hash].fontID;
  15978. }
  15979. // Workaround for bad PDF generators that don't reference fonts
  15980. // properly, i.e. by not using an object identifier.
  15981. // Check if the fontRef is a Dict (as opposed to a standard object),
  15982. // in which case we don't cache the font and instead reference it by
  15983. // fontName in font.loadedName below.
  15984. var fontRefIsDict = isDict(fontRef);
  15985. if (!fontRefIsDict) {
  15986. this.fontCache.put(fontRef, fontCapability.promise);
  15987. }
  15988. // Keep track of each font we translated so the caller can
  15989. // load them asynchronously before calling display on a page.
  15990. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15991. fontName.replace(/\W/g, '') : fontID);
  15992. font.translated = fontCapability.promise;
  15993. // TODO move promises into translate font
  15994. var translatedPromise;
  15995. try {
  15996. translatedPromise = Promise.resolve(
  15997. this.translateFont(preEvaluatedFont, xref));
  15998. } catch (e) {
  15999. translatedPromise = Promise.reject(e);
  16000. }
  16001. translatedPromise.then(function (translatedFont) {
  16002. if (translatedFont.fontType !== undefined) {
  16003. var xrefFontStats = xref.stats.fontTypes;
  16004. xrefFontStats[translatedFont.fontType] = true;
  16005. }
  16006. fontCapability.resolve(new TranslatedFont(font.loadedName,
  16007. translatedFont, font));
  16008. }, function (reason) {
  16009. // TODO fontCapability.reject?
  16010. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  16011. try {
  16012. // error, but it's still nice to have font type reported
  16013. var descriptor = preEvaluatedFont.descriptor;
  16014. var fontFile3 = descriptor && descriptor.get('FontFile3');
  16015. var subtype = fontFile3 && fontFile3.get('Subtype');
  16016. var fontType = getFontType(preEvaluatedFont.type,
  16017. subtype && subtype.name);
  16018. var xrefFontStats = xref.stats.fontTypes;
  16019. xrefFontStats[fontType] = true;
  16020. } catch (ex) { }
  16021. fontCapability.resolve(new TranslatedFont(font.loadedName,
  16022. new ErrorFont(reason instanceof Error ? reason.message : reason),
  16023. font));
  16024. });
  16025. return fontCapability.promise;
  16026. },
  16027. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  16028. var lastIndex = operatorList.length - 1;
  16029. if (!args) {
  16030. args = [];
  16031. }
  16032. if (lastIndex < 0 ||
  16033. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  16034. operatorList.addOp(OPS.constructPath, [[fn], args]);
  16035. } else {
  16036. var opArgs = operatorList.argsArray[lastIndex];
  16037. opArgs[0].push(fn);
  16038. Array.prototype.push.apply(opArgs[1], args);
  16039. }
  16040. },
  16041. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  16042. cs, patterns, resources, xref) {
  16043. // compile tiling patterns
  16044. var patternName = args[args.length - 1];
  16045. // SCN/scn applies patterns along with normal colors
  16046. var pattern;
  16047. if (isName(patternName) &&
  16048. (pattern = patterns.get(patternName.name))) {
  16049. var dict = (isStream(pattern) ? pattern.dict : pattern);
  16050. var typeNum = dict.get('PatternType');
  16051. if (typeNum === TILING_PATTERN) {
  16052. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  16053. return this.handleTilingType(fn, color, resources, pattern,
  16054. dict, operatorList);
  16055. } else if (typeNum === SHADING_PATTERN) {
  16056. var shading = dict.get('Shading');
  16057. var matrix = dict.get('Matrix');
  16058. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  16059. operatorList.addOp(fn, pattern.getIR());
  16060. return Promise.resolve();
  16061. } else {
  16062. return Promise.reject('Unknown PatternType: ' + typeNum);
  16063. }
  16064. }
  16065. // TODO shall we fail here?
  16066. operatorList.addOp(fn, args);
  16067. return Promise.resolve();
  16068. },
  16069. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  16070. resources,
  16071. operatorList,
  16072. initialState) {
  16073. var self = this;
  16074. var xref = this.xref;
  16075. var imageCache = {};
  16076. assert(operatorList);
  16077. resources = (resources || Dict.empty);
  16078. var xobjs = (resources.get('XObject') || Dict.empty);
  16079. var patterns = (resources.get('Pattern') || Dict.empty);
  16080. var stateManager = new StateManager(initialState || new EvalState());
  16081. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  16082. var timeSlotManager = new TimeSlotManager();
  16083. return new Promise(function next(resolve, reject) {
  16084. timeSlotManager.reset();
  16085. var stop, operation = {}, i, ii, cs;
  16086. while (!(stop = timeSlotManager.check())) {
  16087. // The arguments parsed by read() are used beyond this loop, so we
  16088. // cannot reuse the same array on each iteration. Therefore we pass
  16089. // in |null| as the initial value (see the comment on
  16090. // EvaluatorPreprocessor_read() for why).
  16091. operation.args = null;
  16092. if (!(preprocessor.read(operation))) {
  16093. break;
  16094. }
  16095. var args = operation.args;
  16096. var fn = operation.fn;
  16097. switch (fn | 0) {
  16098. case OPS.paintXObject:
  16099. if (args[0].code) {
  16100. break;
  16101. }
  16102. // eagerly compile XForm objects
  16103. var name = args[0].name;
  16104. if (!name) {
  16105. warn('XObject must be referred to by name.');
  16106. continue;
  16107. }
  16108. if (imageCache[name] !== undefined) {
  16109. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  16110. args = null;
  16111. continue;
  16112. }
  16113. var xobj = xobjs.get(name);
  16114. if (xobj) {
  16115. assert(isStream(xobj), 'XObject should be a stream');
  16116. var type = xobj.dict.get('Subtype');
  16117. assert(isName(type),
  16118. 'XObject should have a Name subtype');
  16119. if (type.name === 'Form') {
  16120. stateManager.save();
  16121. return self.buildFormXObject(resources, xobj, null,
  16122. operatorList,
  16123. stateManager.state.clone()).
  16124. then(function () {
  16125. stateManager.restore();
  16126. next(resolve, reject);
  16127. }, reject);
  16128. } else if (type.name === 'Image') {
  16129. self.buildPaintImageXObject(resources, xobj, false,
  16130. operatorList, name, imageCache);
  16131. args = null;
  16132. continue;
  16133. } else if (type.name === 'PS') {
  16134. // PostScript XObjects are unused when viewing documents.
  16135. // See section 4.7.1 of Adobe's PDF reference.
  16136. info('Ignored XObject subtype PS');
  16137. continue;
  16138. } else {
  16139. error('Unhandled XObject subtype ' + type.name);
  16140. }
  16141. }
  16142. break;
  16143. case OPS.setFont:
  16144. var fontSize = args[1];
  16145. // eagerly collect all fonts
  16146. return self.handleSetFont(resources, args, null,
  16147. operatorList, stateManager.state).
  16148. then(function (loadedName) {
  16149. operatorList.addDependency(loadedName);
  16150. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  16151. next(resolve, reject);
  16152. }, reject);
  16153. case OPS.endInlineImage:
  16154. var cacheKey = args[0].cacheKey;
  16155. if (cacheKey) {
  16156. var cacheEntry = imageCache[cacheKey];
  16157. if (cacheEntry !== undefined) {
  16158. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  16159. args = null;
  16160. continue;
  16161. }
  16162. }
  16163. self.buildPaintImageXObject(resources, args[0], true,
  16164. operatorList, cacheKey, imageCache);
  16165. args = null;
  16166. continue;
  16167. case OPS.showText:
  16168. args[0] = self.handleText(args[0], stateManager.state);
  16169. break;
  16170. case OPS.showSpacedText:
  16171. var arr = args[0];
  16172. var combinedGlyphs = [];
  16173. var arrLength = arr.length;
  16174. var state = stateManager.state;
  16175. for (i = 0; i < arrLength; ++i) {
  16176. var arrItem = arr[i];
  16177. if (isString(arrItem)) {
  16178. Array.prototype.push.apply(combinedGlyphs,
  16179. self.handleText(arrItem, state));
  16180. } else if (isNum(arrItem)) {
  16181. combinedGlyphs.push(arrItem);
  16182. }
  16183. }
  16184. args[0] = combinedGlyphs;
  16185. fn = OPS.showText;
  16186. break;
  16187. case OPS.nextLineShowText:
  16188. operatorList.addOp(OPS.nextLine);
  16189. args[0] = self.handleText(args[0], stateManager.state);
  16190. fn = OPS.showText;
  16191. break;
  16192. case OPS.nextLineSetSpacingShowText:
  16193. operatorList.addOp(OPS.nextLine);
  16194. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  16195. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  16196. args[0] = self.handleText(args[0], stateManager.state);
  16197. fn = OPS.showText;
  16198. break;
  16199. case OPS.setTextRenderingMode:
  16200. stateManager.state.textRenderingMode = args[0];
  16201. break;
  16202. case OPS.setFillColorSpace:
  16203. stateManager.state.fillColorSpace =
  16204. ColorSpace.parse(args[0], xref, resources);
  16205. continue;
  16206. case OPS.setStrokeColorSpace:
  16207. stateManager.state.strokeColorSpace =
  16208. ColorSpace.parse(args[0], xref, resources);
  16209. continue;
  16210. case OPS.setFillColor:
  16211. cs = stateManager.state.fillColorSpace;
  16212. args = cs.getRgb(args, 0);
  16213. fn = OPS.setFillRGBColor;
  16214. break;
  16215. case OPS.setStrokeColor:
  16216. cs = stateManager.state.strokeColorSpace;
  16217. args = cs.getRgb(args, 0);
  16218. fn = OPS.setStrokeRGBColor;
  16219. break;
  16220. case OPS.setFillGray:
  16221. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  16222. args = ColorSpace.singletons.gray.getRgb(args, 0);
  16223. fn = OPS.setFillRGBColor;
  16224. break;
  16225. case OPS.setStrokeGray:
  16226. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  16227. args = ColorSpace.singletons.gray.getRgb(args, 0);
  16228. fn = OPS.setStrokeRGBColor;
  16229. break;
  16230. case OPS.setFillCMYKColor:
  16231. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  16232. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  16233. fn = OPS.setFillRGBColor;
  16234. break;
  16235. case OPS.setStrokeCMYKColor:
  16236. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  16237. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  16238. fn = OPS.setStrokeRGBColor;
  16239. break;
  16240. case OPS.setFillRGBColor:
  16241. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  16242. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  16243. break;
  16244. case OPS.setStrokeRGBColor:
  16245. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  16246. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  16247. break;
  16248. case OPS.setFillColorN:
  16249. cs = stateManager.state.fillColorSpace;
  16250. if (cs.name === 'Pattern') {
  16251. return self.handleColorN(operatorList, OPS.setFillColorN,
  16252. args, cs, patterns, resources, xref).then(function() {
  16253. next(resolve, reject);
  16254. }, reject);
  16255. }
  16256. args = cs.getRgb(args, 0);
  16257. fn = OPS.setFillRGBColor;
  16258. break;
  16259. case OPS.setStrokeColorN:
  16260. cs = stateManager.state.strokeColorSpace;
  16261. if (cs.name === 'Pattern') {
  16262. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  16263. args, cs, patterns, resources, xref).then(function() {
  16264. next(resolve, reject);
  16265. }, reject);
  16266. }
  16267. args = cs.getRgb(args, 0);
  16268. fn = OPS.setStrokeRGBColor;
  16269. break;
  16270. case OPS.shadingFill:
  16271. var shadingRes = resources.get('Shading');
  16272. if (!shadingRes) {
  16273. error('No shading resource found');
  16274. }
  16275. var shading = shadingRes.get(args[0].name);
  16276. if (!shading) {
  16277. error('No shading object found');
  16278. }
  16279. var shadingFill = Pattern.parseShading(shading, null, xref,
  16280. resources);
  16281. var patternIR = shadingFill.getIR();
  16282. args = [patternIR];
  16283. fn = OPS.shadingFill;
  16284. break;
  16285. case OPS.setGState:
  16286. var dictName = args[0];
  16287. var extGState = resources.get('ExtGState');
  16288. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16289. break;
  16290. }
  16291. var gState = extGState.get(dictName.name);
  16292. return self.setGState(resources, gState, operatorList, xref,
  16293. stateManager).then(function() {
  16294. next(resolve, reject);
  16295. }, reject);
  16296. case OPS.moveTo:
  16297. case OPS.lineTo:
  16298. case OPS.curveTo:
  16299. case OPS.curveTo2:
  16300. case OPS.curveTo3:
  16301. case OPS.closePath:
  16302. self.buildPath(operatorList, fn, args);
  16303. continue;
  16304. case OPS.rectangle:
  16305. self.buildPath(operatorList, fn, args);
  16306. continue;
  16307. }
  16308. operatorList.addOp(fn, args);
  16309. }
  16310. if (stop) {
  16311. deferred.then(function () {
  16312. next(resolve, reject);
  16313. });
  16314. return;
  16315. }
  16316. // Some PDFs don't close all restores inside object/form.
  16317. // Closing those for them.
  16318. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  16319. operatorList.addOp(OPS.restore, []);
  16320. }
  16321. resolve();
  16322. });
  16323. },
  16324. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  16325. stateManager) {
  16326. stateManager = (stateManager || new StateManager(new TextState()));
  16327. var textContent = {
  16328. items: [],
  16329. styles: Object.create(null)
  16330. };
  16331. var bidiTexts = textContent.items;
  16332. var SPACE_FACTOR = 0.3;
  16333. var MULTI_SPACE_FACTOR = 1.5;
  16334. var self = this;
  16335. var xref = this.xref;
  16336. resources = (xref.fetchIfRef(resources) || Dict.empty);
  16337. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  16338. var xobjs = null;
  16339. var xobjsCache = {};
  16340. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  16341. var textState;
  16342. function newTextChunk() {
  16343. var font = textState.font;
  16344. if (!(font.loadedName in textContent.styles)) {
  16345. textContent.styles[font.loadedName] = {
  16346. fontFamily: font.fallbackName,
  16347. ascent: font.ascent,
  16348. descent: font.descent,
  16349. vertical: font.vertical
  16350. };
  16351. }
  16352. return {
  16353. // |str| is initially an array which we push individual chars to, and
  16354. // then runBidi() overwrites it with the final string.
  16355. str: [],
  16356. dir: null,
  16357. width: 0,
  16358. height: 0,
  16359. transform: null,
  16360. fontName: font.loadedName
  16361. };
  16362. }
  16363. function runBidi(textChunk) {
  16364. var str = textChunk.str.join('');
  16365. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  16366. textChunk.str = bidiResult.str;
  16367. textChunk.dir = bidiResult.dir;
  16368. return textChunk;
  16369. }
  16370. function handleSetFont(fontName, fontRef) {
  16371. return self.loadFont(fontName, fontRef, xref, resources).
  16372. then(function (translated) {
  16373. textState.font = translated.font;
  16374. textState.fontMatrix = translated.font.fontMatrix ||
  16375. FONT_IDENTITY_MATRIX;
  16376. });
  16377. }
  16378. function buildTextGeometry(chars, textChunk) {
  16379. var font = textState.font;
  16380. textChunk = textChunk || newTextChunk();
  16381. if (!textChunk.transform) {
  16382. // 9.4.4 Text Space Details
  16383. var tsm = [textState.fontSize * textState.textHScale, 0,
  16384. 0, textState.fontSize,
  16385. 0, textState.textRise];
  16386. if (font.isType3Font &&
  16387. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  16388. textState.fontSize === 1) {
  16389. var glyphHeight = font.bbox[3] - font.bbox[1];
  16390. if (glyphHeight > 0) {
  16391. glyphHeight = glyphHeight * textState.fontMatrix[3];
  16392. tsm[3] *= glyphHeight;
  16393. }
  16394. }
  16395. var trm = textChunk.transform = Util.transform(textState.ctm,
  16396. Util.transform(textState.textMatrix, tsm));
  16397. if (!font.vertical) {
  16398. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16399. } else {
  16400. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16401. }
  16402. }
  16403. var width = 0;
  16404. var height = 0;
  16405. var glyphs = font.charsToGlyphs(chars);
  16406. var defaultVMetrics = font.defaultVMetrics;
  16407. for (var i = 0; i < glyphs.length; i++) {
  16408. var glyph = glyphs[i];
  16409. if (!glyph) { // Previous glyph was a space.
  16410. width += textState.wordSpacing * textState.textHScale;
  16411. continue;
  16412. }
  16413. var vMetricX = null;
  16414. var vMetricY = null;
  16415. var glyphWidth = null;
  16416. if (font.vertical) {
  16417. if (glyph.vmetric) {
  16418. glyphWidth = glyph.vmetric[0];
  16419. vMetricX = glyph.vmetric[1];
  16420. vMetricY = glyph.vmetric[2];
  16421. } else {
  16422. glyphWidth = glyph.width;
  16423. vMetricX = glyph.width * 0.5;
  16424. vMetricY = defaultVMetrics[2];
  16425. }
  16426. } else {
  16427. glyphWidth = glyph.width;
  16428. }
  16429. var glyphUnicode = glyph.unicode;
  16430. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16431. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16432. }
  16433. glyphUnicode = reverseIfRtl(glyphUnicode);
  16434. // The following will calculate the x and y of the individual glyphs.
  16435. // if (font.vertical) {
  16436. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16437. // textState.fontMatrix[0];
  16438. // tsm[5] -= vMetricY * textState.fontSize *
  16439. // textState.fontMatrix[0];
  16440. // }
  16441. // var trm = Util.transform(textState.textMatrix, tsm);
  16442. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16443. // var x = pt[0];
  16444. // var y = pt[1];
  16445. var charSpacing = 0;
  16446. if (textChunk.str.length > 0) {
  16447. // Apply char spacing only when there are chars.
  16448. // As a result there is only spacing between glyphs.
  16449. charSpacing = textState.charSpacing;
  16450. }
  16451. var tx = 0;
  16452. var ty = 0;
  16453. if (!font.vertical) {
  16454. var w0 = glyphWidth * textState.fontMatrix[0];
  16455. tx = (w0 * textState.fontSize + charSpacing) *
  16456. textState.textHScale;
  16457. width += tx;
  16458. } else {
  16459. var w1 = glyphWidth * textState.fontMatrix[0];
  16460. ty = w1 * textState.fontSize + charSpacing;
  16461. height += ty;
  16462. }
  16463. textState.translateTextMatrix(tx, ty);
  16464. textChunk.str.push(glyphUnicode);
  16465. }
  16466. var a = textState.textLineMatrix[0];
  16467. var b = textState.textLineMatrix[1];
  16468. var scaleLineX = Math.sqrt(a * a + b * b);
  16469. a = textState.ctm[0];
  16470. b = textState.ctm[1];
  16471. var scaleCtmX = Math.sqrt(a * a + b * b);
  16472. if (!font.vertical) {
  16473. textChunk.width += width * scaleCtmX * scaleLineX;
  16474. } else {
  16475. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16476. }
  16477. return textChunk;
  16478. }
  16479. var timeSlotManager = new TimeSlotManager();
  16480. return new Promise(function next(resolve, reject) {
  16481. timeSlotManager.reset();
  16482. var stop, operation = {}, args = [];
  16483. while (!(stop = timeSlotManager.check())) {
  16484. // The arguments parsed by read() are not used beyond this loop, so
  16485. // we can reuse the same array on every iteration, thus avoiding
  16486. // unnecessary allocations.
  16487. args.length = 0;
  16488. operation.args = args;
  16489. if (!(preprocessor.read(operation))) {
  16490. break;
  16491. }
  16492. textState = stateManager.state;
  16493. var fn = operation.fn;
  16494. args = operation.args;
  16495. switch (fn | 0) {
  16496. case OPS.setFont:
  16497. textState.fontSize = args[1];
  16498. return handleSetFont(args[0].name).then(function() {
  16499. next(resolve, reject);
  16500. }, reject);
  16501. case OPS.setTextRise:
  16502. textState.textRise = args[0];
  16503. break;
  16504. case OPS.setHScale:
  16505. textState.textHScale = args[0] / 100;
  16506. break;
  16507. case OPS.setLeading:
  16508. textState.leading = args[0];
  16509. break;
  16510. case OPS.moveText:
  16511. textState.translateTextLineMatrix(args[0], args[1]);
  16512. textState.textMatrix = textState.textLineMatrix.slice();
  16513. break;
  16514. case OPS.setLeadingMoveText:
  16515. textState.leading = -args[1];
  16516. textState.translateTextLineMatrix(args[0], args[1]);
  16517. textState.textMatrix = textState.textLineMatrix.slice();
  16518. break;
  16519. case OPS.nextLine:
  16520. textState.carriageReturn();
  16521. break;
  16522. case OPS.setTextMatrix:
  16523. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16524. args[4], args[5]);
  16525. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16526. args[4], args[5]);
  16527. break;
  16528. case OPS.setCharSpacing:
  16529. textState.charSpacing = args[0];
  16530. break;
  16531. case OPS.setWordSpacing:
  16532. textState.wordSpacing = args[0];
  16533. break;
  16534. case OPS.beginText:
  16535. textState.textMatrix = IDENTITY_MATRIX.slice();
  16536. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16537. break;
  16538. case OPS.showSpacedText:
  16539. var items = args[0];
  16540. var textChunk = newTextChunk();
  16541. var offset;
  16542. for (var j = 0, jj = items.length; j < jj; j++) {
  16543. if (typeof items[j] === 'string') {
  16544. buildTextGeometry(items[j], textChunk);
  16545. } else {
  16546. // PDF Specification 5.3.2 states:
  16547. // The number is expressed in thousandths of a unit of text
  16548. // space.
  16549. // This amount is subtracted from the current horizontal or
  16550. // vertical coordinate, depending on the writing mode.
  16551. // In the default coordinate system, a positive adjustment
  16552. // has the effect of moving the next glyph painted either to
  16553. // the left or down by the given amount.
  16554. var val = items[j] * textState.fontSize / 1000;
  16555. if (textState.font.vertical) {
  16556. offset = val * textState.textMatrix[3];
  16557. textState.translateTextMatrix(0, offset);
  16558. // Value needs to be added to height to paint down.
  16559. textChunk.height += offset;
  16560. } else {
  16561. offset = val * textState.textHScale *
  16562. textState.textMatrix[0];
  16563. textState.translateTextMatrix(offset, 0);
  16564. // Value needs to be subtracted from width to paint left.
  16565. textChunk.width -= offset;
  16566. }
  16567. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16568. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16569. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16570. fakeSpaces = Math.round(fakeSpaces);
  16571. while (fakeSpaces--) {
  16572. textChunk.str.push(' ');
  16573. }
  16574. } else if (fakeSpaces > SPACE_FACTOR) {
  16575. textChunk.str.push(' ');
  16576. }
  16577. }
  16578. }
  16579. }
  16580. bidiTexts.push(runBidi(textChunk));
  16581. break;
  16582. case OPS.showText:
  16583. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16584. break;
  16585. case OPS.nextLineShowText:
  16586. textState.carriageReturn();
  16587. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16588. break;
  16589. case OPS.nextLineSetSpacingShowText:
  16590. textState.wordSpacing = args[0];
  16591. textState.charSpacing = args[1];
  16592. textState.carriageReturn();
  16593. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16594. break;
  16595. case OPS.paintXObject:
  16596. if (args[0].code) {
  16597. break;
  16598. }
  16599. if (!xobjs) {
  16600. xobjs = (resources.get('XObject') || Dict.empty);
  16601. }
  16602. var name = args[0].name;
  16603. if (xobjsCache.key === name) {
  16604. if (xobjsCache.texts) {
  16605. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16606. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16607. }
  16608. break;
  16609. }
  16610. var xobj = xobjs.get(name);
  16611. if (!xobj) {
  16612. break;
  16613. }
  16614. assert(isStream(xobj), 'XObject should be a stream');
  16615. var type = xobj.dict.get('Subtype');
  16616. assert(isName(type),
  16617. 'XObject should have a Name subtype');
  16618. if ('Form' !== type.name) {
  16619. xobjsCache.key = name;
  16620. xobjsCache.texts = null;
  16621. break;
  16622. }
  16623. stateManager.save();
  16624. var matrix = xobj.dict.get('Matrix');
  16625. if (isArray(matrix) && matrix.length === 6) {
  16626. stateManager.transform(matrix);
  16627. }
  16628. return self.getTextContent(xobj,
  16629. xobj.dict.get('Resources') || resources, stateManager).
  16630. then(function (formTextContent) {
  16631. Util.appendToArray(bidiTexts, formTextContent.items);
  16632. Util.extendObj(textContent.styles, formTextContent.styles);
  16633. stateManager.restore();
  16634. xobjsCache.key = name;
  16635. xobjsCache.texts = formTextContent;
  16636. next(resolve, reject);
  16637. }, reject);
  16638. case OPS.setGState:
  16639. var dictName = args[0];
  16640. var extGState = resources.get('ExtGState');
  16641. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16642. break;
  16643. }
  16644. var gsStateMap = extGState.get(dictName.name);
  16645. var gsStateFont = null;
  16646. for (var key in gsStateMap) {
  16647. if (key === 'Font') {
  16648. assert(!gsStateFont);
  16649. gsStateFont = gsStateMap[key];
  16650. }
  16651. }
  16652. if (gsStateFont) {
  16653. textState.fontSize = gsStateFont[1];
  16654. return handleSetFont(gsStateFont[0]).then(function() {
  16655. next(resolve, reject);
  16656. }, reject);
  16657. }
  16658. break;
  16659. } // switch
  16660. } // while
  16661. if (stop) {
  16662. deferred.then(function () {
  16663. next(resolve, reject);
  16664. });
  16665. return;
  16666. }
  16667. resolve(textContent);
  16668. });
  16669. },
  16670. extractDataStructures: function
  16671. partialEvaluatorExtractDataStructures(dict, baseDict,
  16672. xref, properties) {
  16673. // 9.10.2
  16674. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16675. if (toUnicode) {
  16676. properties.toUnicode = this.readToUnicode(toUnicode);
  16677. }
  16678. if (properties.composite) {
  16679. // CIDSystemInfo helps to match CID to glyphs
  16680. var cidSystemInfo = dict.get('CIDSystemInfo');
  16681. if (isDict(cidSystemInfo)) {
  16682. properties.cidSystemInfo = {
  16683. registry: cidSystemInfo.get('Registry'),
  16684. ordering: cidSystemInfo.get('Ordering'),
  16685. supplement: cidSystemInfo.get('Supplement')
  16686. };
  16687. }
  16688. var cidToGidMap = dict.get('CIDToGIDMap');
  16689. if (isStream(cidToGidMap)) {
  16690. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16691. }
  16692. }
  16693. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16694. // and depends on the font type. The base encoding and differences are
  16695. // read here, but the encoding that is actually used is chosen during
  16696. // glyph mapping in the font.
  16697. // TODO: Loading the built in encoding in the font would allow the
  16698. // differences to be merged in here not require us to hold on to it.
  16699. var differences = [];
  16700. var baseEncodingName = null;
  16701. var encoding;
  16702. if (dict.has('Encoding')) {
  16703. encoding = dict.get('Encoding');
  16704. if (isDict(encoding)) {
  16705. baseEncodingName = encoding.get('BaseEncoding');
  16706. baseEncodingName = (isName(baseEncodingName) ?
  16707. baseEncodingName.name : null);
  16708. // Load the differences between the base and original
  16709. if (encoding.has('Differences')) {
  16710. var diffEncoding = encoding.get('Differences');
  16711. var index = 0;
  16712. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16713. var data = diffEncoding[j];
  16714. if (isNum(data)) {
  16715. index = data;
  16716. } else if (isName(data)) {
  16717. differences[index++] = data.name;
  16718. } else if (isRef(data)) {
  16719. diffEncoding[j--] = xref.fetch(data);
  16720. continue;
  16721. } else {
  16722. error('Invalid entry in \'Differences\' array: ' + data);
  16723. }
  16724. }
  16725. }
  16726. } else if (isName(encoding)) {
  16727. baseEncodingName = encoding.name;
  16728. } else {
  16729. error('Encoding is not a Name nor a Dict');
  16730. }
  16731. // According to table 114 if the encoding is a named encoding it must be
  16732. // one of these predefined encodings.
  16733. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16734. baseEncodingName !== 'MacExpertEncoding' &&
  16735. baseEncodingName !== 'WinAnsiEncoding')) {
  16736. baseEncodingName = null;
  16737. }
  16738. }
  16739. if (baseEncodingName) {
  16740. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16741. } else {
  16742. encoding = (properties.type === 'TrueType' ?
  16743. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16744. // The Symbolic attribute can be misused for regular fonts
  16745. // Heuristic: we have to check if the font is a standard one also
  16746. if (!!(properties.flags & FontFlags.Symbolic)) {
  16747. encoding = Encodings.MacRomanEncoding;
  16748. if (!properties.file) {
  16749. if (/Symbol/i.test(properties.name)) {
  16750. encoding = Encodings.SymbolSetEncoding;
  16751. } else if (/Dingbats/i.test(properties.name)) {
  16752. encoding = Encodings.ZapfDingbatsEncoding;
  16753. }
  16754. }
  16755. }
  16756. properties.defaultEncoding = encoding;
  16757. }
  16758. properties.differences = differences;
  16759. properties.baseEncodingName = baseEncodingName;
  16760. properties.dict = dict;
  16761. },
  16762. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16763. var cmap, cmapObj = toUnicode;
  16764. if (isName(cmapObj)) {
  16765. cmap = CMapFactory.create(cmapObj,
  16766. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16767. if (cmap instanceof IdentityCMap) {
  16768. return new IdentityToUnicodeMap(0, 0xFFFF);
  16769. }
  16770. return new ToUnicodeMap(cmap.getMap());
  16771. } else if (isStream(cmapObj)) {
  16772. cmap = CMapFactory.create(cmapObj,
  16773. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16774. if (cmap instanceof IdentityCMap) {
  16775. return new IdentityToUnicodeMap(0, 0xFFFF);
  16776. }
  16777. var map = new Array(cmap.length);
  16778. // Convert UTF-16BE
  16779. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16780. // to iterate over all keys.
  16781. cmap.forEach(function(charCode, token) {
  16782. var str = [];
  16783. for (var k = 0; k < token.length; k += 2) {
  16784. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16785. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16786. str.push(w1);
  16787. continue;
  16788. }
  16789. k += 2;
  16790. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16791. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16792. }
  16793. map[charCode] = String.fromCharCode.apply(String, str);
  16794. });
  16795. return new ToUnicodeMap(map);
  16796. }
  16797. return null;
  16798. },
  16799. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16800. // Extract the encoding from the CIDToGIDMap
  16801. var glyphsData = cidToGidStream.getBytes();
  16802. // Set encoding 0 to later verify the font has an encoding
  16803. var result = [];
  16804. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16805. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16806. if (glyphID === 0) {
  16807. continue;
  16808. }
  16809. var code = j >> 1;
  16810. result[code] = glyphID;
  16811. }
  16812. return result;
  16813. },
  16814. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16815. descriptor,
  16816. properties) {
  16817. var glyphsWidths = [];
  16818. var defaultWidth = 0;
  16819. var glyphsVMetrics = [];
  16820. var defaultVMetrics;
  16821. var i, ii, j, jj, start, code, widths;
  16822. if (properties.composite) {
  16823. defaultWidth = dict.get('DW') || 1000;
  16824. widths = dict.get('W');
  16825. if (widths) {
  16826. for (i = 0, ii = widths.length; i < ii; i++) {
  16827. start = widths[i++];
  16828. code = xref.fetchIfRef(widths[i]);
  16829. if (isArray(code)) {
  16830. for (j = 0, jj = code.length; j < jj; j++) {
  16831. glyphsWidths[start++] = code[j];
  16832. }
  16833. } else {
  16834. var width = widths[++i];
  16835. for (j = start; j <= code; j++) {
  16836. glyphsWidths[j] = width;
  16837. }
  16838. }
  16839. }
  16840. }
  16841. if (properties.vertical) {
  16842. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16843. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16844. vmetrics = dict.get('W2');
  16845. if (vmetrics) {
  16846. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16847. start = vmetrics[i++];
  16848. code = xref.fetchIfRef(vmetrics[i]);
  16849. if (isArray(code)) {
  16850. for (j = 0, jj = code.length; j < jj; j++) {
  16851. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16852. }
  16853. } else {
  16854. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16855. for (j = start; j <= code; j++) {
  16856. glyphsVMetrics[j] = vmetric;
  16857. }
  16858. }
  16859. }
  16860. }
  16861. }
  16862. } else {
  16863. var firstChar = properties.firstChar;
  16864. widths = dict.get('Widths');
  16865. if (widths) {
  16866. j = firstChar;
  16867. for (i = 0, ii = widths.length; i < ii; i++) {
  16868. glyphsWidths[j++] = widths[i];
  16869. }
  16870. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16871. } else {
  16872. // Trying get the BaseFont metrics (see comment above).
  16873. var baseFontName = dict.get('BaseFont');
  16874. if (isName(baseFontName)) {
  16875. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16876. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16877. properties);
  16878. defaultWidth = metrics.defaultWidth;
  16879. }
  16880. }
  16881. }
  16882. // Heuristic: detection of monospace font by checking all non-zero widths
  16883. var isMonospace = true;
  16884. var firstWidth = defaultWidth;
  16885. for (var glyph in glyphsWidths) {
  16886. var glyphWidth = glyphsWidths[glyph];
  16887. if (!glyphWidth) {
  16888. continue;
  16889. }
  16890. if (!firstWidth) {
  16891. firstWidth = glyphWidth;
  16892. continue;
  16893. }
  16894. if (firstWidth !== glyphWidth) {
  16895. isMonospace = false;
  16896. break;
  16897. }
  16898. }
  16899. if (isMonospace) {
  16900. properties.flags |= FontFlags.FixedPitch;
  16901. }
  16902. properties.defaultWidth = defaultWidth;
  16903. properties.widths = glyphsWidths;
  16904. properties.defaultVMetrics = defaultVMetrics;
  16905. properties.vmetrics = glyphsVMetrics;
  16906. },
  16907. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16908. // Simulating descriptor flags attribute
  16909. var fontNameWoStyle = baseFontName.split('-')[0];
  16910. return (fontNameWoStyle in serifFonts) ||
  16911. (fontNameWoStyle.search(/serif/gi) !== -1);
  16912. },
  16913. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16914. var defaultWidth = 0;
  16915. var widths = [];
  16916. var monospace = false;
  16917. var lookupName = (stdFontMap[name] || name);
  16918. if (!(lookupName in Metrics)) {
  16919. // Use default fonts for looking up font metrics if the passed
  16920. // font is not a base font
  16921. if (this.isSerifFont(name)) {
  16922. lookupName = 'Times-Roman';
  16923. } else {
  16924. lookupName = 'Helvetica';
  16925. }
  16926. }
  16927. var glyphWidths = Metrics[lookupName];
  16928. if (isNum(glyphWidths)) {
  16929. defaultWidth = glyphWidths;
  16930. monospace = true;
  16931. } else {
  16932. widths = glyphWidths;
  16933. }
  16934. return {
  16935. defaultWidth: defaultWidth,
  16936. monospace: monospace,
  16937. widths: widths
  16938. };
  16939. },
  16940. buildCharCodeToWidth:
  16941. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16942. properties) {
  16943. var widths = Object.create(null);
  16944. var differences = properties.differences;
  16945. var encoding = properties.defaultEncoding;
  16946. for (var charCode = 0; charCode < 256; charCode++) {
  16947. if (charCode in differences &&
  16948. widthsByGlyphName[differences[charCode]]) {
  16949. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16950. continue;
  16951. }
  16952. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16953. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16954. continue;
  16955. }
  16956. }
  16957. return widths;
  16958. },
  16959. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16960. var baseDict = dict;
  16961. var type = dict.get('Subtype');
  16962. assert(isName(type), 'invalid font Subtype');
  16963. var composite = false;
  16964. var uint8array;
  16965. if (type.name === 'Type0') {
  16966. // If font is a composite
  16967. // - get the descendant font
  16968. // - set the type according to the descendant font
  16969. // - get the FontDescriptor from the descendant font
  16970. var df = dict.get('DescendantFonts');
  16971. if (!df) {
  16972. error('Descendant fonts are not specified');
  16973. }
  16974. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16975. type = dict.get('Subtype');
  16976. assert(isName(type), 'invalid font Subtype');
  16977. composite = true;
  16978. }
  16979. var descriptor = dict.get('FontDescriptor');
  16980. if (descriptor) {
  16981. var hash = new MurmurHash3_64();
  16982. var encoding = baseDict.getRaw('Encoding');
  16983. if (isName(encoding)) {
  16984. hash.update(encoding.name);
  16985. } else if (isRef(encoding)) {
  16986. hash.update(encoding.num + '_' + encoding.gen);
  16987. } else if (isDict(encoding)) {
  16988. var keys = encoding.getKeys();
  16989. for (var i = 0, ii = keys.length; i < ii; i++) {
  16990. var entry = encoding.getRaw(keys[i]);
  16991. if (isName(entry)) {
  16992. hash.update(entry.name);
  16993. } else if (isRef(entry)) {
  16994. hash.update(entry.num + '_' + entry.gen);
  16995. } else if (isArray(entry)) { // 'Differences' entry.
  16996. // Ideally we should check the contents of the array, but to avoid
  16997. // parsing it here and then again in |extractDataStructures|,
  16998. // we only use the array length for now (fixes bug1157493.pdf).
  16999. hash.update(entry.length.toString());
  17000. }
  17001. }
  17002. }
  17003. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  17004. if (isStream(toUnicode)) {
  17005. var stream = toUnicode.str || toUnicode;
  17006. uint8array = stream.buffer ?
  17007. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  17008. new Uint8Array(stream.bytes.buffer,
  17009. stream.start, stream.end - stream.start);
  17010. hash.update(uint8array);
  17011. } else if (isName(toUnicode)) {
  17012. hash.update(toUnicode.name);
  17013. }
  17014. var widths = dict.get('Widths') || baseDict.get('Widths');
  17015. if (widths) {
  17016. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  17017. hash.update(uint8array);
  17018. }
  17019. }
  17020. return {
  17021. descriptor: descriptor,
  17022. dict: dict,
  17023. baseDict: baseDict,
  17024. composite: composite,
  17025. type: type.name,
  17026. hash: hash ? hash.hexdigest() : ''
  17027. };
  17028. },
  17029. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  17030. xref) {
  17031. var baseDict = preEvaluatedFont.baseDict;
  17032. var dict = preEvaluatedFont.dict;
  17033. var composite = preEvaluatedFont.composite;
  17034. var descriptor = preEvaluatedFont.descriptor;
  17035. var type = preEvaluatedFont.type;
  17036. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  17037. var properties;
  17038. if (!descriptor) {
  17039. if (type === 'Type3') {
  17040. // FontDescriptor is only required for Type3 fonts when the document
  17041. // is a tagged pdf. Create a barbebones one to get by.
  17042. descriptor = new Dict(null);
  17043. descriptor.set('FontName', Name.get(type));
  17044. descriptor.set('FontBBox', dict.get('FontBBox'));
  17045. } else {
  17046. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  17047. // FontDescriptor was not required.
  17048. // This case is here for compatibility.
  17049. var baseFontName = dict.get('BaseFont');
  17050. if (!isName(baseFontName)) {
  17051. error('Base font is not specified');
  17052. }
  17053. // Using base font name as a font name.
  17054. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  17055. var metrics = this.getBaseFontMetrics(baseFontName);
  17056. // Simulating descriptor flags attribute
  17057. var fontNameWoStyle = baseFontName.split('-')[0];
  17058. var flags =
  17059. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  17060. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  17061. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  17062. FontFlags.Nonsymbolic);
  17063. properties = {
  17064. type: type,
  17065. name: baseFontName,
  17066. widths: metrics.widths,
  17067. defaultWidth: metrics.defaultWidth,
  17068. flags: flags,
  17069. firstChar: 0,
  17070. lastChar: maxCharIndex
  17071. };
  17072. this.extractDataStructures(dict, dict, xref, properties);
  17073. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  17074. properties);
  17075. return new Font(baseFontName, null, properties);
  17076. }
  17077. }
  17078. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  17079. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  17080. // to ignore this rule when a variant of a standart font is used.
  17081. // TODO Fill the width array depending on which of the base font this is
  17082. // a variant.
  17083. var firstChar = (dict.get('FirstChar') || 0);
  17084. var lastChar = (dict.get('LastChar') || maxCharIndex);
  17085. var fontName = descriptor.get('FontName');
  17086. var baseFont = dict.get('BaseFont');
  17087. // Some bad PDFs have a string as the font name.
  17088. if (isString(fontName)) {
  17089. fontName = Name.get(fontName);
  17090. }
  17091. if (isString(baseFont)) {
  17092. baseFont = Name.get(baseFont);
  17093. }
  17094. if (type !== 'Type3') {
  17095. var fontNameStr = fontName && fontName.name;
  17096. var baseFontStr = baseFont && baseFont.name;
  17097. if (fontNameStr !== baseFontStr) {
  17098. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  17099. '" but should be the same as the Font\'s BaseFont "' +
  17100. baseFontStr + '"');
  17101. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  17102. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  17103. if (fontNameStr && baseFontStr &&
  17104. baseFontStr.indexOf(fontNameStr) === 0) {
  17105. fontName = baseFont;
  17106. }
  17107. }
  17108. }
  17109. fontName = (fontName || baseFont);
  17110. assert(isName(fontName), 'invalid font name');
  17111. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  17112. if (fontFile) {
  17113. if (fontFile.dict) {
  17114. var subtype = fontFile.dict.get('Subtype');
  17115. if (subtype) {
  17116. subtype = subtype.name;
  17117. }
  17118. var length1 = fontFile.dict.get('Length1');
  17119. var length2 = fontFile.dict.get('Length2');
  17120. }
  17121. }
  17122. properties = {
  17123. type: type,
  17124. name: fontName.name,
  17125. subtype: subtype,
  17126. file: fontFile,
  17127. length1: length1,
  17128. length2: length2,
  17129. loadedName: baseDict.loadedName,
  17130. composite: composite,
  17131. wideChars: composite,
  17132. fixedPitch: false,
  17133. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  17134. firstChar: firstChar || 0,
  17135. lastChar: (lastChar || maxCharIndex),
  17136. bbox: descriptor.get('FontBBox'),
  17137. ascent: descriptor.get('Ascent'),
  17138. descent: descriptor.get('Descent'),
  17139. xHeight: descriptor.get('XHeight'),
  17140. capHeight: descriptor.get('CapHeight'),
  17141. flags: descriptor.get('Flags'),
  17142. italicAngle: descriptor.get('ItalicAngle'),
  17143. coded: false
  17144. };
  17145. if (composite) {
  17146. var cidEncoding = baseDict.get('Encoding');
  17147. if (isName(cidEncoding)) {
  17148. properties.cidEncoding = cidEncoding.name;
  17149. }
  17150. properties.cMap = CMapFactory.create(cidEncoding,
  17151. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17152. properties.vertical = properties.cMap.vertical;
  17153. }
  17154. this.extractDataStructures(dict, baseDict, xref, properties);
  17155. this.extractWidths(dict, xref, descriptor, properties);
  17156. if (type === 'Type3') {
  17157. properties.isType3Font = true;
  17158. }
  17159. return new Font(fontName.name, fontFile, properties);
  17160. }
  17161. };
  17162. return PartialEvaluator;
  17163. })();
  17164. var TranslatedFont = (function TranslatedFontClosure() {
  17165. function TranslatedFont(loadedName, font, dict) {
  17166. this.loadedName = loadedName;
  17167. this.font = font;
  17168. this.dict = dict;
  17169. this.type3Loaded = null;
  17170. this.sent = false;
  17171. }
  17172. TranslatedFont.prototype = {
  17173. send: function (handler) {
  17174. if (this.sent) {
  17175. return;
  17176. }
  17177. var fontData = this.font.exportData();
  17178. handler.send('commonobj', [
  17179. this.loadedName,
  17180. 'Font',
  17181. fontData
  17182. ]);
  17183. this.sent = true;
  17184. },
  17185. loadType3Data: function (evaluator, resources, parentOperatorList) {
  17186. assert(this.font.isType3Font);
  17187. if (this.type3Loaded) {
  17188. return this.type3Loaded;
  17189. }
  17190. var translatedFont = this.font;
  17191. var loadCharProcsPromise = Promise.resolve();
  17192. var charProcs = this.dict.get('CharProcs').getAll();
  17193. var fontResources = this.dict.get('Resources') || resources;
  17194. var charProcKeys = Object.keys(charProcs);
  17195. var charProcOperatorList = {};
  17196. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  17197. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  17198. var glyphStream = charProcs[key];
  17199. var operatorList = new OperatorList();
  17200. return evaluator.getOperatorList(glyphStream, fontResources,
  17201. operatorList).then(function () {
  17202. charProcOperatorList[key] = operatorList.getIR();
  17203. // Add the dependencies to the parent operator list so they are
  17204. // resolved before sub operator list is executed synchronously.
  17205. parentOperatorList.addDependencies(operatorList.dependencies);
  17206. }, function (reason) {
  17207. warn('Type3 font resource \"' + key + '\" is not available');
  17208. var operatorList = new OperatorList();
  17209. charProcOperatorList[key] = operatorList.getIR();
  17210. });
  17211. }.bind(this, charProcKeys[i]));
  17212. }
  17213. this.type3Loaded = loadCharProcsPromise.then(function () {
  17214. translatedFont.charProcOperatorList = charProcOperatorList;
  17215. });
  17216. return this.type3Loaded;
  17217. }
  17218. };
  17219. return TranslatedFont;
  17220. })();
  17221. var OperatorList = (function OperatorListClosure() {
  17222. var CHUNK_SIZE = 1000;
  17223. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  17224. function getTransfers(queue) {
  17225. var transfers = [];
  17226. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17227. for (var i = 0, ii = queue.length; i < ii; i++) {
  17228. switch (fnArray[i]) {
  17229. case OPS.paintInlineImageXObject:
  17230. case OPS.paintInlineImageXObjectGroup:
  17231. case OPS.paintImageMaskXObject:
  17232. var arg = argsArray[i][0]; // first param in imgData
  17233. if (!arg.cached) {
  17234. transfers.push(arg.data.buffer);
  17235. }
  17236. break;
  17237. }
  17238. }
  17239. return transfers;
  17240. }
  17241. function OperatorList(intent, messageHandler, pageIndex) {
  17242. this.messageHandler = messageHandler;
  17243. this.fnArray = [];
  17244. this.argsArray = [];
  17245. this.dependencies = {};
  17246. this.pageIndex = pageIndex;
  17247. this.intent = intent;
  17248. }
  17249. OperatorList.prototype = {
  17250. get length() {
  17251. return this.argsArray.length;
  17252. },
  17253. addOp: function(fn, args) {
  17254. this.fnArray.push(fn);
  17255. this.argsArray.push(args);
  17256. if (this.messageHandler) {
  17257. if (this.fnArray.length >= CHUNK_SIZE) {
  17258. this.flush();
  17259. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  17260. (fn === OPS.restore || fn === OPS.endText)) {
  17261. // heuristic to flush on boundary of restore or endText
  17262. this.flush();
  17263. }
  17264. }
  17265. },
  17266. addDependency: function(dependency) {
  17267. if (dependency in this.dependencies) {
  17268. return;
  17269. }
  17270. this.dependencies[dependency] = true;
  17271. this.addOp(OPS.dependency, [dependency]);
  17272. },
  17273. addDependencies: function(dependencies) {
  17274. for (var key in dependencies) {
  17275. this.addDependency(key);
  17276. }
  17277. },
  17278. addOpList: function(opList) {
  17279. Util.extendObj(this.dependencies, opList.dependencies);
  17280. for (var i = 0, ii = opList.length; i < ii; i++) {
  17281. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  17282. }
  17283. },
  17284. getIR: function() {
  17285. return {
  17286. fnArray: this.fnArray,
  17287. argsArray: this.argsArray,
  17288. length: this.length
  17289. };
  17290. },
  17291. flush: function(lastChunk) {
  17292. if (this.intent !== 'oplist') {
  17293. new QueueOptimizer().optimize(this);
  17294. }
  17295. var transfers = getTransfers(this);
  17296. this.messageHandler.send('RenderPageChunk', {
  17297. operatorList: {
  17298. fnArray: this.fnArray,
  17299. argsArray: this.argsArray,
  17300. lastChunk: lastChunk,
  17301. length: this.length
  17302. },
  17303. pageIndex: this.pageIndex,
  17304. intent: this.intent
  17305. }, transfers);
  17306. this.dependencies = {};
  17307. this.fnArray.length = 0;
  17308. this.argsArray.length = 0;
  17309. }
  17310. };
  17311. return OperatorList;
  17312. })();
  17313. var StateManager = (function StateManagerClosure() {
  17314. function StateManager(initialState) {
  17315. this.state = initialState;
  17316. this.stateStack = [];
  17317. }
  17318. StateManager.prototype = {
  17319. save: function () {
  17320. var old = this.state;
  17321. this.stateStack.push(this.state);
  17322. this.state = old.clone();
  17323. },
  17324. restore: function () {
  17325. var prev = this.stateStack.pop();
  17326. if (prev) {
  17327. this.state = prev;
  17328. }
  17329. },
  17330. transform: function (args) {
  17331. this.state.ctm = Util.transform(this.state.ctm, args);
  17332. }
  17333. };
  17334. return StateManager;
  17335. })();
  17336. var TextState = (function TextStateClosure() {
  17337. function TextState() {
  17338. this.ctm = new Float32Array(IDENTITY_MATRIX);
  17339. this.fontSize = 0;
  17340. this.font = null;
  17341. this.fontMatrix = FONT_IDENTITY_MATRIX;
  17342. this.textMatrix = IDENTITY_MATRIX.slice();
  17343. this.textLineMatrix = IDENTITY_MATRIX.slice();
  17344. this.charSpacing = 0;
  17345. this.wordSpacing = 0;
  17346. this.leading = 0;
  17347. this.textHScale = 1;
  17348. this.textRise = 0;
  17349. }
  17350. TextState.prototype = {
  17351. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17352. var m = this.textMatrix;
  17353. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17354. },
  17355. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17356. var m = this.textLineMatrix;
  17357. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17358. },
  17359. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  17360. var m = this.textMatrix;
  17361. m[4] = m[0] * x + m[2] * y + m[4];
  17362. m[5] = m[1] * x + m[3] * y + m[5];
  17363. },
  17364. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  17365. var m = this.textLineMatrix;
  17366. m[4] = m[0] * x + m[2] * y + m[4];
  17367. m[5] = m[1] * x + m[3] * y + m[5];
  17368. },
  17369. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  17370. // 9.4.4 Text Space Details
  17371. var tsm = [this.fontSize * this.textHScale, 0,
  17372. 0, this.fontSize,
  17373. 0, this.textRise];
  17374. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  17375. },
  17376. carriageReturn: function TextState_carriageReturn() {
  17377. this.translateTextLineMatrix(0, -this.leading);
  17378. this.textMatrix = this.textLineMatrix.slice();
  17379. },
  17380. clone: function TextState_clone() {
  17381. var clone = Object.create(this);
  17382. clone.textMatrix = this.textMatrix.slice();
  17383. clone.textLineMatrix = this.textLineMatrix.slice();
  17384. clone.fontMatrix = this.fontMatrix.slice();
  17385. return clone;
  17386. }
  17387. };
  17388. return TextState;
  17389. })();
  17390. var EvalState = (function EvalStateClosure() {
  17391. function EvalState() {
  17392. this.ctm = new Float32Array(IDENTITY_MATRIX);
  17393. this.font = null;
  17394. this.textRenderingMode = TextRenderingMode.FILL;
  17395. this.fillColorSpace = ColorSpace.singletons.gray;
  17396. this.strokeColorSpace = ColorSpace.singletons.gray;
  17397. }
  17398. EvalState.prototype = {
  17399. clone: function CanvasExtraState_clone() {
  17400. return Object.create(this);
  17401. },
  17402. };
  17403. return EvalState;
  17404. })();
  17405. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17406. // Specifies properties for each command
  17407. //
  17408. // If variableArgs === true: [0, `numArgs`] expected
  17409. // If variableArgs === false: exactly `numArgs` expected
  17410. var OP_MAP = {
  17411. // Graphic state
  17412. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17413. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17414. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17415. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17416. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17417. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17418. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17419. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17420. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17421. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17422. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17423. // Path
  17424. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17425. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17426. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17427. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17428. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17429. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17430. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17431. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17432. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17433. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17434. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17435. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17436. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17437. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17438. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17439. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17440. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17441. // Clipping
  17442. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17443. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17444. // Text
  17445. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17446. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17447. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17448. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17449. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17450. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17451. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17452. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17453. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17454. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17455. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17456. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17457. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17458. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17459. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17460. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17461. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17462. variableArgs: false },
  17463. // Type3 fonts
  17464. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17465. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17466. // Color
  17467. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17468. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17469. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17470. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17471. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17472. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17473. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17474. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17475. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17476. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17477. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17478. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17479. // Shading
  17480. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17481. // Images
  17482. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17483. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17484. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17485. // XObjects
  17486. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17487. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17488. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17489. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17490. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17491. variableArgs: false },
  17492. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17493. // Compatibility
  17494. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17495. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17496. // (reserved partial commands for the lexer)
  17497. BM: null,
  17498. BD: null,
  17499. 'true': null,
  17500. fa: null,
  17501. fal: null,
  17502. fals: null,
  17503. 'false': null,
  17504. nu: null,
  17505. nul: null,
  17506. 'null': null
  17507. };
  17508. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17509. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17510. // dictionary
  17511. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17512. this.stateManager = stateManager;
  17513. this.nonProcessedArgs = [];
  17514. }
  17515. EvaluatorPreprocessor.prototype = {
  17516. get savedStatesDepth() {
  17517. return this.stateManager.stateStack.length;
  17518. },
  17519. // |operation| is an object with two fields:
  17520. //
  17521. // - |fn| is an out param.
  17522. //
  17523. // - |args| is an inout param. On entry, it should have one of two values.
  17524. //
  17525. // - An empty array. This indicates that the caller is providing the
  17526. // array in which the args will be stored in. The caller should use
  17527. // this value if it can reuse a single array for each call to read().
  17528. //
  17529. // - |null|. This indicates that the caller needs this function to create
  17530. // the array in which any args are stored in. If there are zero args,
  17531. // this function will leave |operation.args| as |null| (thus avoiding
  17532. // allocations that would occur if we used an empty array to represent
  17533. // zero arguments). Otherwise, it will replace |null| with a new array
  17534. // containing the arguments. The caller should use this value if it
  17535. // cannot reuse an array for each call to read().
  17536. //
  17537. // These two modes are present because this function is very hot and so
  17538. // avoiding allocations where possible is worthwhile.
  17539. //
  17540. read: function EvaluatorPreprocessor_read(operation) {
  17541. var args = operation.args;
  17542. while (true) {
  17543. var obj = this.parser.getObj();
  17544. if (isCmd(obj)) {
  17545. var cmd = obj.cmd;
  17546. // Check that the command is valid
  17547. var opSpec = OP_MAP[cmd];
  17548. if (!opSpec) {
  17549. warn('Unknown command "' + cmd + '"');
  17550. continue;
  17551. }
  17552. var fn = opSpec.id;
  17553. var numArgs = opSpec.numArgs;
  17554. var argsLength = args !== null ? args.length : 0;
  17555. if (!opSpec.variableArgs) {
  17556. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17557. if (argsLength !== numArgs) {
  17558. var nonProcessedArgs = this.nonProcessedArgs;
  17559. while (argsLength > numArgs) {
  17560. nonProcessedArgs.push(args.shift());
  17561. argsLength--;
  17562. }
  17563. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17564. if (!args) {
  17565. args = [];
  17566. }
  17567. args.unshift(nonProcessedArgs.pop());
  17568. argsLength++;
  17569. }
  17570. }
  17571. if (argsLength < numArgs) {
  17572. // If we receive too few args, it's not possible to possible
  17573. // to execute the command, so skip the command
  17574. info('Command ' + fn + ': because expected ' +
  17575. numArgs + ' args, but received ' + argsLength +
  17576. ' args; skipping');
  17577. args = null;
  17578. continue;
  17579. }
  17580. } else if (argsLength > numArgs) {
  17581. info('Command ' + fn + ': expected [0,' + numArgs +
  17582. '] args, but received ' + argsLength + ' args');
  17583. }
  17584. // TODO figure out how to type-check vararg functions
  17585. this.preprocessCommand(fn, args);
  17586. operation.fn = fn;
  17587. operation.args = args;
  17588. return true;
  17589. } else {
  17590. if (isEOF(obj)) {
  17591. return false; // no more commands
  17592. }
  17593. // argument
  17594. if (obj !== null) {
  17595. if (!args) {
  17596. args = [];
  17597. }
  17598. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17599. assert(args.length <= 33, 'Too many arguments');
  17600. }
  17601. }
  17602. }
  17603. },
  17604. preprocessCommand:
  17605. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17606. switch (fn | 0) {
  17607. case OPS.save:
  17608. this.stateManager.save();
  17609. break;
  17610. case OPS.restore:
  17611. this.stateManager.restore();
  17612. break;
  17613. case OPS.transform:
  17614. this.stateManager.transform(args);
  17615. break;
  17616. }
  17617. }
  17618. };
  17619. return EvaluatorPreprocessor;
  17620. })();
  17621. var QueueOptimizer = (function QueueOptimizerClosure() {
  17622. function addState(parentState, pattern, fn) {
  17623. var state = parentState;
  17624. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17625. var item = pattern[i];
  17626. state = (state[item] || (state[item] = []));
  17627. }
  17628. state[pattern[pattern.length - 1]] = fn;
  17629. }
  17630. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17631. argsArray) {
  17632. // Handles special case of mainly LaTeX documents which use image masks to
  17633. // draw lines with the current fill style.
  17634. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17635. // have been found at iFirstSave.
  17636. var iFirstPIMXO = iFirstSave + 2;
  17637. for (var i = 0; i < count; i++) {
  17638. var arg = argsArray[iFirstPIMXO + 4 * i];
  17639. var imageMask = arg.length === 1 && arg[0];
  17640. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17641. (!imageMask.data.length ||
  17642. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17643. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17644. continue;
  17645. }
  17646. break;
  17647. }
  17648. return count - i;
  17649. }
  17650. var InitialState = [];
  17651. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17652. // sequences with one |paintInlineImageXObjectGroup| operation.
  17653. addState(InitialState,
  17654. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17655. function foundInlineImageGroup(context) {
  17656. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17657. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17658. var MAX_WIDTH = 1000;
  17659. var IMAGE_PADDING = 1;
  17660. var fnArray = context.fnArray, argsArray = context.argsArray;
  17661. var curr = context.iCurr;
  17662. var iFirstSave = curr - 3;
  17663. var iFirstTransform = curr - 2;
  17664. var iFirstPIIXO = curr - 1;
  17665. // Look for the quartets.
  17666. var i = iFirstSave + 4;
  17667. var ii = fnArray.length;
  17668. while (i + 3 < ii) {
  17669. if (fnArray[i] !== OPS.save ||
  17670. fnArray[i + 1] !== OPS.transform ||
  17671. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17672. fnArray[i + 3] !== OPS.restore) {
  17673. break; // ops don't match
  17674. }
  17675. i += 4;
  17676. }
  17677. // At this point, i is the index of the first op past the last valid
  17678. // quartet.
  17679. var count = Math.min((i - iFirstSave) / 4,
  17680. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17681. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17682. return i;
  17683. }
  17684. // assuming that heights of those image is too small (~1 pixel)
  17685. // packing as much as possible by lines
  17686. var maxX = 0;
  17687. var map = [], maxLineHeight = 0;
  17688. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17689. var q;
  17690. for (q = 0; q < count; q++) {
  17691. var transform = argsArray[iFirstTransform + (q << 2)];
  17692. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17693. if (currentX + img.width > MAX_WIDTH) {
  17694. // starting new line
  17695. maxX = Math.max(maxX, currentX);
  17696. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17697. currentX = 0;
  17698. maxLineHeight = 0;
  17699. }
  17700. map.push({
  17701. transform: transform,
  17702. x: currentX, y: currentY,
  17703. w: img.width, h: img.height
  17704. });
  17705. currentX += img.width + 2 * IMAGE_PADDING;
  17706. maxLineHeight = Math.max(maxLineHeight, img.height);
  17707. }
  17708. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17709. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17710. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17711. var imgRowSize = imgWidth << 2;
  17712. for (q = 0; q < count; q++) {
  17713. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17714. // Copy image by lines and extends pixels into padding.
  17715. var rowSize = map[q].w << 2;
  17716. var dataOffset = 0;
  17717. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17718. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17719. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17720. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17721. dataOffset += rowSize;
  17722. offset += imgRowSize;
  17723. }
  17724. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17725. while (offset >= 0) {
  17726. data[offset - 4] = data[offset];
  17727. data[offset - 3] = data[offset + 1];
  17728. data[offset - 2] = data[offset + 2];
  17729. data[offset - 1] = data[offset + 3];
  17730. data[offset + rowSize] = data[offset + rowSize - 4];
  17731. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17732. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17733. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17734. offset -= imgRowSize;
  17735. }
  17736. }
  17737. // Replace queue items.
  17738. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17739. argsArray.splice(iFirstSave, count * 4,
  17740. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17741. data: imgData }, map]);
  17742. return iFirstSave + 1;
  17743. });
  17744. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17745. // sequences with one |paintImageMaskXObjectGroup| or one
  17746. // |paintImageMaskXObjectRepeat| operation.
  17747. addState(InitialState,
  17748. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17749. function foundImageMaskGroup(context) {
  17750. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17751. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17752. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17753. var fnArray = context.fnArray, argsArray = context.argsArray;
  17754. var curr = context.iCurr;
  17755. var iFirstSave = curr - 3;
  17756. var iFirstTransform = curr - 2;
  17757. var iFirstPIMXO = curr - 1;
  17758. // Look for the quartets.
  17759. var i = iFirstSave + 4;
  17760. var ii = fnArray.length;
  17761. while (i + 3 < ii) {
  17762. if (fnArray[i] !== OPS.save ||
  17763. fnArray[i + 1] !== OPS.transform ||
  17764. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17765. fnArray[i + 3] !== OPS.restore) {
  17766. break; // ops don't match
  17767. }
  17768. i += 4;
  17769. }
  17770. // At this point, i is the index of the first op past the last valid
  17771. // quartet.
  17772. var count = (i - iFirstSave) / 4;
  17773. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17774. argsArray);
  17775. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17776. return i;
  17777. }
  17778. var q;
  17779. var isSameImage = false;
  17780. var iTransform, transformArgs;
  17781. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17782. if (argsArray[iFirstTransform][1] === 0 &&
  17783. argsArray[iFirstTransform][2] === 0) {
  17784. isSameImage = true;
  17785. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17786. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17787. iTransform = iFirstTransform + 4;
  17788. var iPIMXO = iFirstPIMXO + 4;
  17789. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17790. transformArgs = argsArray[iTransform];
  17791. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17792. transformArgs[0] !== firstTransformArg0 ||
  17793. transformArgs[1] !== 0 ||
  17794. transformArgs[2] !== 0 ||
  17795. transformArgs[3] !== firstTransformArg3) {
  17796. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17797. isSameImage = false;
  17798. } else {
  17799. count = q;
  17800. }
  17801. break; // different image or transform
  17802. }
  17803. }
  17804. }
  17805. if (isSameImage) {
  17806. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17807. var positions = new Float32Array(count * 2);
  17808. iTransform = iFirstTransform;
  17809. for (q = 0; q < count; q++, iTransform += 4) {
  17810. transformArgs = argsArray[iTransform];
  17811. positions[(q << 1)] = transformArgs[4];
  17812. positions[(q << 1) + 1] = transformArgs[5];
  17813. }
  17814. // Replace queue items.
  17815. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17816. argsArray.splice(iFirstSave, count * 4,
  17817. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17818. } else {
  17819. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17820. var images = [];
  17821. for (q = 0; q < count; q++) {
  17822. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17823. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17824. images.push({ data: maskParams.data, width: maskParams.width,
  17825. height: maskParams.height,
  17826. transform: transformArgs });
  17827. }
  17828. // Replace queue items.
  17829. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17830. argsArray.splice(iFirstSave, count * 4, [images]);
  17831. }
  17832. return iFirstSave + 1;
  17833. });
  17834. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17835. // with one paintImageXObjectRepeat operation, if the |transform| and
  17836. // |paintImageXObjectRepeat| ops are appropriate.
  17837. addState(InitialState,
  17838. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17839. function (context) {
  17840. var MIN_IMAGES_IN_BLOCK = 3;
  17841. var MAX_IMAGES_IN_BLOCK = 1000;
  17842. var fnArray = context.fnArray, argsArray = context.argsArray;
  17843. var curr = context.iCurr;
  17844. var iFirstSave = curr - 3;
  17845. var iFirstTransform = curr - 2;
  17846. var iFirstPIXO = curr - 1;
  17847. var iFirstRestore = curr;
  17848. if (argsArray[iFirstTransform][1] !== 0 ||
  17849. argsArray[iFirstTransform][2] !== 0) {
  17850. return iFirstRestore + 1; // transform has the wrong form
  17851. }
  17852. // Look for the quartets.
  17853. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17854. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17855. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17856. var i = iFirstSave + 4;
  17857. var ii = fnArray.length;
  17858. while (i + 3 < ii) {
  17859. if (fnArray[i] !== OPS.save ||
  17860. fnArray[i + 1] !== OPS.transform ||
  17861. fnArray[i + 2] !== OPS.paintImageXObject ||
  17862. fnArray[i + 3] !== OPS.restore) {
  17863. break; // ops don't match
  17864. }
  17865. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17866. argsArray[i + 1][1] !== 0 ||
  17867. argsArray[i + 1][2] !== 0 ||
  17868. argsArray[i + 1][3] !== firstTransformArg3) {
  17869. break; // transforms don't match
  17870. }
  17871. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17872. break; // images don't match
  17873. }
  17874. i += 4;
  17875. }
  17876. // At this point, i is the index of the first op past the last valid
  17877. // quartet.
  17878. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17879. if (count < MIN_IMAGES_IN_BLOCK) {
  17880. return i;
  17881. }
  17882. // Extract the (x,y) positions from all of the matching transforms.
  17883. var positions = new Float32Array(count * 2);
  17884. var iTransform = iFirstTransform;
  17885. for (var q = 0; q < count; q++, iTransform += 4) {
  17886. var transformArgs = argsArray[iTransform];
  17887. positions[(q << 1)] = transformArgs[4];
  17888. positions[(q << 1) + 1] = transformArgs[5];
  17889. }
  17890. // Replace queue items.
  17891. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17892. positions];
  17893. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17894. argsArray.splice(iFirstSave, count * 4, args);
  17895. return iFirstSave + 1;
  17896. });
  17897. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17898. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17899. // sequences, if the font for each one is the same.
  17900. addState(InitialState,
  17901. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17902. function (context) {
  17903. var MIN_CHARS_IN_BLOCK = 3;
  17904. var MAX_CHARS_IN_BLOCK = 1000;
  17905. var fnArray = context.fnArray, argsArray = context.argsArray;
  17906. var curr = context.iCurr;
  17907. var iFirstBeginText = curr - 4;
  17908. var iFirstSetFont = curr - 3;
  17909. var iFirstSetTextMatrix = curr - 2;
  17910. var iFirstShowText = curr - 1;
  17911. var iFirstEndText = curr;
  17912. // Look for the quintets.
  17913. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17914. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17915. var i = iFirstBeginText + 5;
  17916. var ii = fnArray.length;
  17917. while (i + 4 < ii) {
  17918. if (fnArray[i] !== OPS.beginText ||
  17919. fnArray[i + 1] !== OPS.setFont ||
  17920. fnArray[i + 2] !== OPS.setTextMatrix ||
  17921. fnArray[i + 3] !== OPS.showText ||
  17922. fnArray[i + 4] !== OPS.endText) {
  17923. break; // ops don't match
  17924. }
  17925. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17926. argsArray[i + 1][1] !== firstSetFontArg1) {
  17927. break; // fonts don't match
  17928. }
  17929. i += 5;
  17930. }
  17931. // At this point, i is the index of the first op past the last valid
  17932. // quintet.
  17933. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17934. if (count < MIN_CHARS_IN_BLOCK) {
  17935. return i;
  17936. }
  17937. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17938. // showText, endText), include that as well. (E.g. <something> might be
  17939. // |dependency|.)
  17940. var iFirst = iFirstBeginText;
  17941. if (iFirstBeginText >= 4 &&
  17942. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17943. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17944. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17945. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17946. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17947. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17948. count++;
  17949. iFirst -= 5;
  17950. }
  17951. // Remove (endText, beginText, setFont) trios.
  17952. var iEndText = iFirst + 4;
  17953. for (var q = 1; q < count; q++) {
  17954. fnArray.splice(iEndText, 3);
  17955. argsArray.splice(iEndText, 3);
  17956. iEndText += 2;
  17957. }
  17958. return iEndText + 1;
  17959. });
  17960. function QueueOptimizer() {}
  17961. QueueOptimizer.prototype = {
  17962. optimize: function QueueOptimizer_optimize(queue) {
  17963. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17964. var context = {
  17965. iCurr: 0,
  17966. fnArray: fnArray,
  17967. argsArray: argsArray
  17968. };
  17969. var state;
  17970. var i = 0, ii = fnArray.length;
  17971. while (i < ii) {
  17972. state = (state || InitialState)[fnArray[i]];
  17973. if (typeof state === 'function') { // we found some handler
  17974. context.iCurr = i;
  17975. // state() returns the index of the first non-matching op (if we
  17976. // didn't match) or the first op past the modified ops (if we did
  17977. // match and replace).
  17978. i = state(context);
  17979. state = undefined; // reset the state machine
  17980. ii = context.fnArray.length;
  17981. } else {
  17982. i++;
  17983. }
  17984. }
  17985. }
  17986. };
  17987. return QueueOptimizer;
  17988. })();
  17989. var BUILT_IN_CMAPS = [
  17990. // << Start unicode maps.
  17991. 'Adobe-GB1-UCS2',
  17992. 'Adobe-CNS1-UCS2',
  17993. 'Adobe-Japan1-UCS2',
  17994. 'Adobe-Korea1-UCS2',
  17995. // >> End unicode maps.
  17996. '78-EUC-H',
  17997. '78-EUC-V',
  17998. '78-H',
  17999. '78-RKSJ-H',
  18000. '78-RKSJ-V',
  18001. '78-V',
  18002. '78ms-RKSJ-H',
  18003. '78ms-RKSJ-V',
  18004. '83pv-RKSJ-H',
  18005. '90ms-RKSJ-H',
  18006. '90ms-RKSJ-V',
  18007. '90msp-RKSJ-H',
  18008. '90msp-RKSJ-V',
  18009. '90pv-RKSJ-H',
  18010. '90pv-RKSJ-V',
  18011. 'Add-H',
  18012. 'Add-RKSJ-H',
  18013. 'Add-RKSJ-V',
  18014. 'Add-V',
  18015. 'Adobe-CNS1-0',
  18016. 'Adobe-CNS1-1',
  18017. 'Adobe-CNS1-2',
  18018. 'Adobe-CNS1-3',
  18019. 'Adobe-CNS1-4',
  18020. 'Adobe-CNS1-5',
  18021. 'Adobe-CNS1-6',
  18022. 'Adobe-GB1-0',
  18023. 'Adobe-GB1-1',
  18024. 'Adobe-GB1-2',
  18025. 'Adobe-GB1-3',
  18026. 'Adobe-GB1-4',
  18027. 'Adobe-GB1-5',
  18028. 'Adobe-Japan1-0',
  18029. 'Adobe-Japan1-1',
  18030. 'Adobe-Japan1-2',
  18031. 'Adobe-Japan1-3',
  18032. 'Adobe-Japan1-4',
  18033. 'Adobe-Japan1-5',
  18034. 'Adobe-Japan1-6',
  18035. 'Adobe-Korea1-0',
  18036. 'Adobe-Korea1-1',
  18037. 'Adobe-Korea1-2',
  18038. 'B5-H',
  18039. 'B5-V',
  18040. 'B5pc-H',
  18041. 'B5pc-V',
  18042. 'CNS-EUC-H',
  18043. 'CNS-EUC-V',
  18044. 'CNS1-H',
  18045. 'CNS1-V',
  18046. 'CNS2-H',
  18047. 'CNS2-V',
  18048. 'ETHK-B5-H',
  18049. 'ETHK-B5-V',
  18050. 'ETen-B5-H',
  18051. 'ETen-B5-V',
  18052. 'ETenms-B5-H',
  18053. 'ETenms-B5-V',
  18054. 'EUC-H',
  18055. 'EUC-V',
  18056. 'Ext-H',
  18057. 'Ext-RKSJ-H',
  18058. 'Ext-RKSJ-V',
  18059. 'Ext-V',
  18060. 'GB-EUC-H',
  18061. 'GB-EUC-V',
  18062. 'GB-H',
  18063. 'GB-V',
  18064. 'GBK-EUC-H',
  18065. 'GBK-EUC-V',
  18066. 'GBK2K-H',
  18067. 'GBK2K-V',
  18068. 'GBKp-EUC-H',
  18069. 'GBKp-EUC-V',
  18070. 'GBT-EUC-H',
  18071. 'GBT-EUC-V',
  18072. 'GBT-H',
  18073. 'GBT-V',
  18074. 'GBTpc-EUC-H',
  18075. 'GBTpc-EUC-V',
  18076. 'GBpc-EUC-H',
  18077. 'GBpc-EUC-V',
  18078. 'H',
  18079. 'HKdla-B5-H',
  18080. 'HKdla-B5-V',
  18081. 'HKdlb-B5-H',
  18082. 'HKdlb-B5-V',
  18083. 'HKgccs-B5-H',
  18084. 'HKgccs-B5-V',
  18085. 'HKm314-B5-H',
  18086. 'HKm314-B5-V',
  18087. 'HKm471-B5-H',
  18088. 'HKm471-B5-V',
  18089. 'HKscs-B5-H',
  18090. 'HKscs-B5-V',
  18091. 'Hankaku',
  18092. 'Hiragana',
  18093. 'KSC-EUC-H',
  18094. 'KSC-EUC-V',
  18095. 'KSC-H',
  18096. 'KSC-Johab-H',
  18097. 'KSC-Johab-V',
  18098. 'KSC-V',
  18099. 'KSCms-UHC-H',
  18100. 'KSCms-UHC-HW-H',
  18101. 'KSCms-UHC-HW-V',
  18102. 'KSCms-UHC-V',
  18103. 'KSCpc-EUC-H',
  18104. 'KSCpc-EUC-V',
  18105. 'Katakana',
  18106. 'NWP-H',
  18107. 'NWP-V',
  18108. 'RKSJ-H',
  18109. 'RKSJ-V',
  18110. 'Roman',
  18111. 'UniCNS-UCS2-H',
  18112. 'UniCNS-UCS2-V',
  18113. 'UniCNS-UTF16-H',
  18114. 'UniCNS-UTF16-V',
  18115. 'UniCNS-UTF32-H',
  18116. 'UniCNS-UTF32-V',
  18117. 'UniCNS-UTF8-H',
  18118. 'UniCNS-UTF8-V',
  18119. 'UniGB-UCS2-H',
  18120. 'UniGB-UCS2-V',
  18121. 'UniGB-UTF16-H',
  18122. 'UniGB-UTF16-V',
  18123. 'UniGB-UTF32-H',
  18124. 'UniGB-UTF32-V',
  18125. 'UniGB-UTF8-H',
  18126. 'UniGB-UTF8-V',
  18127. 'UniJIS-UCS2-H',
  18128. 'UniJIS-UCS2-HW-H',
  18129. 'UniJIS-UCS2-HW-V',
  18130. 'UniJIS-UCS2-V',
  18131. 'UniJIS-UTF16-H',
  18132. 'UniJIS-UTF16-V',
  18133. 'UniJIS-UTF32-H',
  18134. 'UniJIS-UTF32-V',
  18135. 'UniJIS-UTF8-H',
  18136. 'UniJIS-UTF8-V',
  18137. 'UniJIS2004-UTF16-H',
  18138. 'UniJIS2004-UTF16-V',
  18139. 'UniJIS2004-UTF32-H',
  18140. 'UniJIS2004-UTF32-V',
  18141. 'UniJIS2004-UTF8-H',
  18142. 'UniJIS2004-UTF8-V',
  18143. 'UniJISPro-UCS2-HW-V',
  18144. 'UniJISPro-UCS2-V',
  18145. 'UniJISPro-UTF8-V',
  18146. 'UniJISX0213-UTF32-H',
  18147. 'UniJISX0213-UTF32-V',
  18148. 'UniJISX02132004-UTF32-H',
  18149. 'UniJISX02132004-UTF32-V',
  18150. 'UniKS-UCS2-H',
  18151. 'UniKS-UCS2-V',
  18152. 'UniKS-UTF16-H',
  18153. 'UniKS-UTF16-V',
  18154. 'UniKS-UTF32-H',
  18155. 'UniKS-UTF32-V',
  18156. 'UniKS-UTF8-H',
  18157. 'UniKS-UTF8-V',
  18158. 'V',
  18159. 'WP-Symbol'];
  18160. // CMap, not to be confused with TrueType's cmap.
  18161. var CMap = (function CMapClosure() {
  18162. function CMap(builtInCMap) {
  18163. // Codespace ranges are stored as follows:
  18164. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  18165. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  18166. this.codespaceRanges = [[], [], [], []];
  18167. this.numCodespaceRanges = 0;
  18168. // Map entries have one of two forms.
  18169. // - cid chars are 16-bit unsigned integers, stored as integers.
  18170. // - bf chars are variable-length byte sequences, stored as strings, with
  18171. // one byte per character.
  18172. this._map = [];
  18173. this.name = '';
  18174. this.vertical = false;
  18175. this.useCMap = null;
  18176. this.builtInCMap = builtInCMap;
  18177. }
  18178. CMap.prototype = {
  18179. addCodespaceRange: function(n, low, high) {
  18180. this.codespaceRanges[n - 1].push(low, high);
  18181. this.numCodespaceRanges++;
  18182. },
  18183. mapCidRange: function(low, high, dstLow) {
  18184. while (low <= high) {
  18185. this._map[low++] = dstLow++;
  18186. }
  18187. },
  18188. mapBfRange: function(low, high, dstLow) {
  18189. var lastByte = dstLow.length - 1;
  18190. while (low <= high) {
  18191. this._map[low++] = dstLow;
  18192. // Only the last byte has to be incremented.
  18193. dstLow = dstLow.substr(0, lastByte) +
  18194. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  18195. }
  18196. },
  18197. mapBfRangeToArray: function(low, high, array) {
  18198. var i = 0, ii = array.length;
  18199. while (low <= high && i < ii) {
  18200. this._map[low] = array[i++];
  18201. ++low;
  18202. }
  18203. },
  18204. // This is used for both bf and cid chars.
  18205. mapOne: function(src, dst) {
  18206. this._map[src] = dst;
  18207. },
  18208. lookup: function(code) {
  18209. return this._map[code];
  18210. },
  18211. contains: function(code) {
  18212. return this._map[code] !== undefined;
  18213. },
  18214. forEach: function(callback) {
  18215. // Most maps have fewer than 65536 entries, and for those we use normal
  18216. // array iteration. But really sparse tables are possible -- e.g. with
  18217. // indices in the *billions*. For such tables we use for..in, which isn't
  18218. // ideal because it stringifies the indices for all present elements, but
  18219. // it does avoid iterating over every undefined entry.
  18220. var map = this._map;
  18221. var length = map.length;
  18222. var i;
  18223. if (length <= 0x10000) {
  18224. for (i = 0; i < length; i++) {
  18225. if (map[i] !== undefined) {
  18226. callback(i, map[i]);
  18227. }
  18228. }
  18229. } else {
  18230. for (i in this._map) {
  18231. callback(i, map[i]);
  18232. }
  18233. }
  18234. },
  18235. charCodeOf: function(value) {
  18236. return this._map.indexOf(value);
  18237. },
  18238. getMap: function() {
  18239. return this._map;
  18240. },
  18241. readCharCode: function(str, offset, out) {
  18242. var c = 0;
  18243. var codespaceRanges = this.codespaceRanges;
  18244. var codespaceRangesLen = this.codespaceRanges.length;
  18245. // 9.7.6.2 CMap Mapping
  18246. // The code length is at most 4.
  18247. for (var n = 0; n < codespaceRangesLen; n++) {
  18248. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  18249. // Check each codespace range to see if it falls within.
  18250. var codespaceRange = codespaceRanges[n];
  18251. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  18252. var low = codespaceRange[k++];
  18253. var high = codespaceRange[k++];
  18254. if (c >= low && c <= high) {
  18255. out.charcode = c;
  18256. out.length = n + 1;
  18257. return;
  18258. }
  18259. }
  18260. }
  18261. out.charcode = 0;
  18262. out.length = 1;
  18263. },
  18264. get length() {
  18265. return this._map.length;
  18266. },
  18267. get isIdentityCMap() {
  18268. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  18269. return false;
  18270. }
  18271. if (this._map.length !== 0x10000) {
  18272. return false;
  18273. }
  18274. for (var i = 0; i < 0x10000; i++) {
  18275. if (this._map[i] !== i) {
  18276. return false;
  18277. }
  18278. }
  18279. return true;
  18280. }
  18281. };
  18282. return CMap;
  18283. })();
  18284. // A special case of CMap, where the _map array implicitly has a length of
  18285. // 65536 and each element is equal to its index.
  18286. var IdentityCMap = (function IdentityCMapClosure() {
  18287. function IdentityCMap(vertical, n) {
  18288. CMap.call(this);
  18289. this.vertical = vertical;
  18290. this.addCodespaceRange(n, 0, 0xffff);
  18291. }
  18292. Util.inherit(IdentityCMap, CMap, {});
  18293. IdentityCMap.prototype = {
  18294. addCodespaceRange: CMap.prototype.addCodespaceRange,
  18295. mapCidRange: function(low, high, dstLow) {
  18296. error('should not call mapCidRange');
  18297. },
  18298. mapBfRange: function(low, high, dstLow) {
  18299. error('should not call mapBfRange');
  18300. },
  18301. mapBfRangeToArray: function(low, high, array) {
  18302. error('should not call mapBfRangeToArray');
  18303. },
  18304. mapOne: function(src, dst) {
  18305. error('should not call mapCidOne');
  18306. },
  18307. lookup: function(code) {
  18308. return (isInt(code) && code <= 0xffff) ? code : undefined;
  18309. },
  18310. contains: function(code) {
  18311. return isInt(code) && code <= 0xffff;
  18312. },
  18313. forEach: function(callback) {
  18314. for (var i = 0; i <= 0xffff; i++) {
  18315. callback(i, i);
  18316. }
  18317. },
  18318. charCodeOf: function(value) {
  18319. return (isInt(value) && value <= 0xffff) ? value : -1;
  18320. },
  18321. getMap: function() {
  18322. // Sometimes identity maps must be instantiated, but it's rare.
  18323. var map = new Array(0x10000);
  18324. for (var i = 0; i <= 0xffff; i++) {
  18325. map[i] = i;
  18326. }
  18327. return map;
  18328. },
  18329. readCharCode: CMap.prototype.readCharCode,
  18330. get length() {
  18331. return 0x10000;
  18332. },
  18333. get isIdentityCMap() {
  18334. error('should not access .isIdentityCMap');
  18335. }
  18336. };
  18337. return IdentityCMap;
  18338. })();
  18339. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  18340. function fetchBinaryData(url) {
  18341. var nonBinaryRequest = PDFJS.disableWorker;
  18342. var request = new XMLHttpRequest();
  18343. request.open('GET', url, false);
  18344. if (!nonBinaryRequest) {
  18345. try {
  18346. request.responseType = 'arraybuffer';
  18347. nonBinaryRequest = request.responseType !== 'arraybuffer';
  18348. } catch (e) {
  18349. nonBinaryRequest = true;
  18350. }
  18351. }
  18352. if (nonBinaryRequest && request.overrideMimeType) {
  18353. request.overrideMimeType('text/plain; charset=x-user-defined');
  18354. }
  18355. request.send(null);
  18356. if (nonBinaryRequest ? !request.responseText : !request.response) {
  18357. error('Unable to get binary cMap at: ' + url);
  18358. }
  18359. if (nonBinaryRequest) {
  18360. var data = Array.prototype.map.call(request.responseText, function (ch) {
  18361. return ch.charCodeAt(0) & 255;
  18362. });
  18363. return new Uint8Array(data);
  18364. }
  18365. return new Uint8Array(request.response);
  18366. }
  18367. function hexToInt(a, size) {
  18368. var n = 0;
  18369. for (var i = 0; i <= size; i++) {
  18370. n = (n << 8) | a[i];
  18371. }
  18372. return n >>> 0;
  18373. }
  18374. function hexToStr(a, size) {
  18375. // This code is hot. Special-case some common values to avoid creating an
  18376. // object with subarray().
  18377. if (size === 1) {
  18378. return String.fromCharCode(a[0], a[1]);
  18379. }
  18380. if (size === 3) {
  18381. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  18382. }
  18383. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  18384. }
  18385. function addHex(a, b, size) {
  18386. var c = 0;
  18387. for (var i = size; i >= 0; i--) {
  18388. c += a[i] + b[i];
  18389. a[i] = c & 255;
  18390. c >>= 8;
  18391. }
  18392. }
  18393. function incHex(a, size) {
  18394. var c = 1;
  18395. for (var i = size; i >= 0 && c > 0; i--) {
  18396. c += a[i];
  18397. a[i] = c & 255;
  18398. c >>= 8;
  18399. }
  18400. }
  18401. var MAX_NUM_SIZE = 16;
  18402. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  18403. function BinaryCMapStream(data) {
  18404. this.buffer = data;
  18405. this.pos = 0;
  18406. this.end = data.length;
  18407. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  18408. }
  18409. BinaryCMapStream.prototype = {
  18410. readByte: function () {
  18411. if (this.pos >= this.end) {
  18412. return -1;
  18413. }
  18414. return this.buffer[this.pos++];
  18415. },
  18416. readNumber: function () {
  18417. var n = 0;
  18418. var last;
  18419. do {
  18420. var b = this.readByte();
  18421. if (b < 0) {
  18422. error('unexpected EOF in bcmap');
  18423. }
  18424. last = !(b & 0x80);
  18425. n = (n << 7) | (b & 0x7F);
  18426. } while (!last);
  18427. return n;
  18428. },
  18429. readSigned: function () {
  18430. var n = this.readNumber();
  18431. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18432. },
  18433. readHex: function (num, size) {
  18434. num.set(this.buffer.subarray(this.pos,
  18435. this.pos + size + 1));
  18436. this.pos += size + 1;
  18437. },
  18438. readHexNumber: function (num, size) {
  18439. var last;
  18440. var stack = this.tmpBuf, sp = 0;
  18441. do {
  18442. var b = this.readByte();
  18443. if (b < 0) {
  18444. error('unexpected EOF in bcmap');
  18445. }
  18446. last = !(b & 0x80);
  18447. stack[sp++] = b & 0x7F;
  18448. } while (!last);
  18449. var i = size, buffer = 0, bufferSize = 0;
  18450. while (i >= 0) {
  18451. while (bufferSize < 8 && stack.length > 0) {
  18452. buffer = (stack[--sp] << bufferSize) | buffer;
  18453. bufferSize += 7;
  18454. }
  18455. num[i] = buffer & 255;
  18456. i--;
  18457. buffer >>= 8;
  18458. bufferSize -= 8;
  18459. }
  18460. },
  18461. readHexSigned: function (num, size) {
  18462. this.readHexNumber(num, size);
  18463. var sign = num[size] & 1 ? 255 : 0;
  18464. var c = 0;
  18465. for (var i = 0; i <= size; i++) {
  18466. c = ((c & 1) << 8) | num[i];
  18467. num[i] = (c >> 1) ^ sign;
  18468. }
  18469. },
  18470. readString: function () {
  18471. var len = this.readNumber();
  18472. var s = '';
  18473. for (var i = 0; i < len; i++) {
  18474. s += String.fromCharCode(this.readNumber());
  18475. }
  18476. return s;
  18477. }
  18478. };
  18479. function processBinaryCMap(url, cMap, extend) {
  18480. var data = fetchBinaryData(url);
  18481. var stream = new BinaryCMapStream(data);
  18482. var header = stream.readByte();
  18483. cMap.vertical = !!(header & 1);
  18484. var useCMap = null;
  18485. var start = new Uint8Array(MAX_NUM_SIZE);
  18486. var end = new Uint8Array(MAX_NUM_SIZE);
  18487. var char = new Uint8Array(MAX_NUM_SIZE);
  18488. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18489. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18490. var code;
  18491. var b;
  18492. while ((b = stream.readByte()) >= 0) {
  18493. var type = b >> 5;
  18494. if (type === 7) { // metadata, e.g. comment or usecmap
  18495. switch (b & 0x1F) {
  18496. case 0:
  18497. stream.readString(); // skipping comment
  18498. break;
  18499. case 1:
  18500. useCMap = stream.readString();
  18501. break;
  18502. }
  18503. continue;
  18504. }
  18505. var sequence = !!(b & 0x10);
  18506. var dataSize = b & 15;
  18507. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18508. var ucs2DataSize = 1;
  18509. var subitemsCount = stream.readNumber();
  18510. var i;
  18511. switch (type) {
  18512. case 0: // codespacerange
  18513. stream.readHex(start, dataSize);
  18514. stream.readHexNumber(end, dataSize);
  18515. addHex(end, start, dataSize);
  18516. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18517. hexToInt(end, dataSize));
  18518. for (i = 1; i < subitemsCount; i++) {
  18519. incHex(end, dataSize);
  18520. stream.readHexNumber(start, dataSize);
  18521. addHex(start, end, dataSize);
  18522. stream.readHexNumber(end, dataSize);
  18523. addHex(end, start, dataSize);
  18524. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18525. hexToInt(end, dataSize));
  18526. }
  18527. break;
  18528. case 1: // notdefrange
  18529. stream.readHex(start, dataSize);
  18530. stream.readHexNumber(end, dataSize);
  18531. addHex(end, start, dataSize);
  18532. code = stream.readNumber();
  18533. // undefined range, skipping
  18534. for (i = 1; i < subitemsCount; i++) {
  18535. incHex(end, dataSize);
  18536. stream.readHexNumber(start, dataSize);
  18537. addHex(start, end, dataSize);
  18538. stream.readHexNumber(end, dataSize);
  18539. addHex(end, start, dataSize);
  18540. code = stream.readNumber();
  18541. // nop
  18542. }
  18543. break;
  18544. case 2: // cidchar
  18545. stream.readHex(char, dataSize);
  18546. code = stream.readNumber();
  18547. cMap.mapOne(hexToInt(char, dataSize), code);
  18548. for (i = 1; i < subitemsCount; i++) {
  18549. incHex(char, dataSize);
  18550. if (!sequence) {
  18551. stream.readHexNumber(tmp, dataSize);
  18552. addHex(char, tmp, dataSize);
  18553. }
  18554. code = stream.readSigned() + (code + 1);
  18555. cMap.mapOne(hexToInt(char, dataSize), code);
  18556. }
  18557. break;
  18558. case 3: // cidrange
  18559. stream.readHex(start, dataSize);
  18560. stream.readHexNumber(end, dataSize);
  18561. addHex(end, start, dataSize);
  18562. code = stream.readNumber();
  18563. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18564. code);
  18565. for (i = 1; i < subitemsCount; i++) {
  18566. incHex(end, dataSize);
  18567. if (!sequence) {
  18568. stream.readHexNumber(start, dataSize);
  18569. addHex(start, end, dataSize);
  18570. } else {
  18571. start.set(end);
  18572. }
  18573. stream.readHexNumber(end, dataSize);
  18574. addHex(end, start, dataSize);
  18575. code = stream.readNumber();
  18576. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18577. code);
  18578. }
  18579. break;
  18580. case 4: // bfchar
  18581. stream.readHex(char, ucs2DataSize);
  18582. stream.readHex(charCode, dataSize);
  18583. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18584. hexToStr(charCode, dataSize));
  18585. for (i = 1; i < subitemsCount; i++) {
  18586. incHex(char, ucs2DataSize);
  18587. if (!sequence) {
  18588. stream.readHexNumber(tmp, ucs2DataSize);
  18589. addHex(char, tmp, ucs2DataSize);
  18590. }
  18591. incHex(charCode, dataSize);
  18592. stream.readHexSigned(tmp, dataSize);
  18593. addHex(charCode, tmp, dataSize);
  18594. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18595. hexToStr(charCode, dataSize));
  18596. }
  18597. break;
  18598. case 5: // bfrange
  18599. stream.readHex(start, ucs2DataSize);
  18600. stream.readHexNumber(end, ucs2DataSize);
  18601. addHex(end, start, ucs2DataSize);
  18602. stream.readHex(charCode, dataSize);
  18603. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18604. hexToInt(end, ucs2DataSize),
  18605. hexToStr(charCode, dataSize));
  18606. for (i = 1; i < subitemsCount; i++) {
  18607. incHex(end, ucs2DataSize);
  18608. if (!sequence) {
  18609. stream.readHexNumber(start, ucs2DataSize);
  18610. addHex(start, end, ucs2DataSize);
  18611. } else {
  18612. start.set(end);
  18613. }
  18614. stream.readHexNumber(end, ucs2DataSize);
  18615. addHex(end, start, ucs2DataSize);
  18616. stream.readHex(charCode, dataSize);
  18617. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18618. hexToInt(end, ucs2DataSize),
  18619. hexToStr(charCode, dataSize));
  18620. }
  18621. break;
  18622. default:
  18623. error('Unknown type: ' + type);
  18624. break;
  18625. }
  18626. }
  18627. if (useCMap) {
  18628. extend(useCMap);
  18629. }
  18630. return cMap;
  18631. }
  18632. function BinaryCMapReader() {}
  18633. BinaryCMapReader.prototype = {
  18634. read: processBinaryCMap
  18635. };
  18636. return BinaryCMapReader;
  18637. })();
  18638. var CMapFactory = (function CMapFactoryClosure() {
  18639. function strToInt(str) {
  18640. var a = 0;
  18641. for (var i = 0; i < str.length; i++) {
  18642. a = (a << 8) | str.charCodeAt(i);
  18643. }
  18644. return a >>> 0;
  18645. }
  18646. function expectString(obj) {
  18647. if (!isString(obj)) {
  18648. error('Malformed CMap: expected string.');
  18649. }
  18650. }
  18651. function expectInt(obj) {
  18652. if (!isInt(obj)) {
  18653. error('Malformed CMap: expected int.');
  18654. }
  18655. }
  18656. function parseBfChar(cMap, lexer) {
  18657. while (true) {
  18658. var obj = lexer.getObj();
  18659. if (isEOF(obj)) {
  18660. break;
  18661. }
  18662. if (isCmd(obj, 'endbfchar')) {
  18663. return;
  18664. }
  18665. expectString(obj);
  18666. var src = strToInt(obj);
  18667. obj = lexer.getObj();
  18668. // TODO are /dstName used?
  18669. expectString(obj);
  18670. var dst = obj;
  18671. cMap.mapOne(src, dst);
  18672. }
  18673. }
  18674. function parseBfRange(cMap, lexer) {
  18675. while (true) {
  18676. var obj = lexer.getObj();
  18677. if (isEOF(obj)) {
  18678. break;
  18679. }
  18680. if (isCmd(obj, 'endbfrange')) {
  18681. return;
  18682. }
  18683. expectString(obj);
  18684. var low = strToInt(obj);
  18685. obj = lexer.getObj();
  18686. expectString(obj);
  18687. var high = strToInt(obj);
  18688. obj = lexer.getObj();
  18689. if (isInt(obj) || isString(obj)) {
  18690. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18691. cMap.mapBfRange(low, high, dstLow);
  18692. } else if (isCmd(obj, '[')) {
  18693. obj = lexer.getObj();
  18694. var array = [];
  18695. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18696. array.push(obj);
  18697. obj = lexer.getObj();
  18698. }
  18699. cMap.mapBfRangeToArray(low, high, array);
  18700. } else {
  18701. break;
  18702. }
  18703. }
  18704. error('Invalid bf range.');
  18705. }
  18706. function parseCidChar(cMap, lexer) {
  18707. while (true) {
  18708. var obj = lexer.getObj();
  18709. if (isEOF(obj)) {
  18710. break;
  18711. }
  18712. if (isCmd(obj, 'endcidchar')) {
  18713. return;
  18714. }
  18715. expectString(obj);
  18716. var src = strToInt(obj);
  18717. obj = lexer.getObj();
  18718. expectInt(obj);
  18719. var dst = obj;
  18720. cMap.mapOne(src, dst);
  18721. }
  18722. }
  18723. function parseCidRange(cMap, lexer) {
  18724. while (true) {
  18725. var obj = lexer.getObj();
  18726. if (isEOF(obj)) {
  18727. break;
  18728. }
  18729. if (isCmd(obj, 'endcidrange')) {
  18730. return;
  18731. }
  18732. expectString(obj);
  18733. var low = strToInt(obj);
  18734. obj = lexer.getObj();
  18735. expectString(obj);
  18736. var high = strToInt(obj);
  18737. obj = lexer.getObj();
  18738. expectInt(obj);
  18739. var dstLow = obj;
  18740. cMap.mapCidRange(low, high, dstLow);
  18741. }
  18742. }
  18743. function parseCodespaceRange(cMap, lexer) {
  18744. while (true) {
  18745. var obj = lexer.getObj();
  18746. if (isEOF(obj)) {
  18747. break;
  18748. }
  18749. if (isCmd(obj, 'endcodespacerange')) {
  18750. return;
  18751. }
  18752. if (!isString(obj)) {
  18753. break;
  18754. }
  18755. var low = strToInt(obj);
  18756. obj = lexer.getObj();
  18757. if (!isString(obj)) {
  18758. break;
  18759. }
  18760. var high = strToInt(obj);
  18761. cMap.addCodespaceRange(obj.length, low, high);
  18762. }
  18763. error('Invalid codespace range.');
  18764. }
  18765. function parseWMode(cMap, lexer) {
  18766. var obj = lexer.getObj();
  18767. if (isInt(obj)) {
  18768. cMap.vertical = !!obj;
  18769. }
  18770. }
  18771. function parseCMapName(cMap, lexer) {
  18772. var obj = lexer.getObj();
  18773. if (isName(obj) && isString(obj.name)) {
  18774. cMap.name = obj.name;
  18775. }
  18776. }
  18777. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18778. var previous;
  18779. var embededUseCMap;
  18780. objLoop: while (true) {
  18781. var obj = lexer.getObj();
  18782. if (isEOF(obj)) {
  18783. break;
  18784. } else if (isName(obj)) {
  18785. if (obj.name === 'WMode') {
  18786. parseWMode(cMap, lexer);
  18787. } else if (obj.name === 'CMapName') {
  18788. parseCMapName(cMap, lexer);
  18789. }
  18790. previous = obj;
  18791. } else if (isCmd(obj)) {
  18792. switch (obj.cmd) {
  18793. case 'endcmap':
  18794. break objLoop;
  18795. case 'usecmap':
  18796. if (isName(previous)) {
  18797. embededUseCMap = previous.name;
  18798. }
  18799. break;
  18800. case 'begincodespacerange':
  18801. parseCodespaceRange(cMap, lexer);
  18802. break;
  18803. case 'beginbfchar':
  18804. parseBfChar(cMap, lexer);
  18805. break;
  18806. case 'begincidchar':
  18807. parseCidChar(cMap, lexer);
  18808. break;
  18809. case 'beginbfrange':
  18810. parseBfRange(cMap, lexer);
  18811. break;
  18812. case 'begincidrange':
  18813. parseCidRange(cMap, lexer);
  18814. break;
  18815. }
  18816. }
  18817. }
  18818. if (!useCMap && embededUseCMap) {
  18819. // Load the usecmap definition from the file only if there wasn't one
  18820. // specified.
  18821. useCMap = embededUseCMap;
  18822. }
  18823. if (useCMap) {
  18824. extendCMap(cMap, builtInCMapParams, useCMap);
  18825. }
  18826. }
  18827. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18828. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18829. // If there aren't any code space ranges defined clone all the parent ones
  18830. // into this cMap.
  18831. if (cMap.numCodespaceRanges === 0) {
  18832. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18833. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18834. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18835. }
  18836. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18837. }
  18838. // Merge the map into the current one, making sure not to override
  18839. // any previously defined entries.
  18840. cMap.useCMap.forEach(function(key, value) {
  18841. if (!cMap.contains(key)) {
  18842. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18843. }
  18844. });
  18845. }
  18846. function parseBinaryCMap(name, builtInCMapParams) {
  18847. var url = builtInCMapParams.url + name + '.bcmap';
  18848. var cMap = new CMap(true);
  18849. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18850. extendCMap(cMap, builtInCMapParams, useCMap);
  18851. });
  18852. return cMap;
  18853. }
  18854. function createBuiltInCMap(name, builtInCMapParams) {
  18855. if (name === 'Identity-H') {
  18856. return new IdentityCMap(false, 2);
  18857. } else if (name === 'Identity-V') {
  18858. return new IdentityCMap(true, 2);
  18859. }
  18860. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18861. error('Unknown cMap name: ' + name);
  18862. }
  18863. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18864. if (builtInCMapParams.packed) {
  18865. return parseBinaryCMap(name, builtInCMapParams);
  18866. }
  18867. var request = new XMLHttpRequest();
  18868. var url = builtInCMapParams.url + name;
  18869. request.open('GET', url, false);
  18870. request.send(null);
  18871. if (!request.responseText) {
  18872. error('Unable to get cMap at: ' + url);
  18873. }
  18874. var cMap = new CMap(true);
  18875. var lexer = new Lexer(new StringStream(request.responseText));
  18876. parseCMap(cMap, lexer, builtInCMapParams, null);
  18877. return cMap;
  18878. }
  18879. return {
  18880. create: function (encoding, builtInCMapParams, useCMap) {
  18881. if (isName(encoding)) {
  18882. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18883. } else if (isStream(encoding)) {
  18884. var cMap = new CMap();
  18885. var lexer = new Lexer(encoding);
  18886. try {
  18887. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18888. } catch (e) {
  18889. warn('Invalid CMap data. ' + e);
  18890. }
  18891. if (cMap.isIdentityCMap) {
  18892. return createBuiltInCMap(cMap.name, builtInCMapParams);
  18893. }
  18894. return cMap;
  18895. }
  18896. error('Encoding required.');
  18897. }
  18898. };
  18899. })();
  18900. // Unicode Private Use Area
  18901. var PRIVATE_USE_OFFSET_START = 0xE000;
  18902. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18903. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18904. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18905. // except for Type 3 fonts
  18906. var PDF_GLYPH_SPACE_UNITS = 1000;
  18907. // Hinting is currently disabled due to unknown problems on windows
  18908. // in tracemonkey and various other pdfs with type1 fonts.
  18909. var HINTING_ENABLED = false;
  18910. // Accented charactars are not displayed properly on windows, using this flag
  18911. // to control analysis of seac charstrings.
  18912. var SEAC_ANALYSIS_ENABLED = false;
  18913. var FontFlags = {
  18914. FixedPitch: 1,
  18915. Serif: 2,
  18916. Symbolic: 4,
  18917. Script: 8,
  18918. Nonsymbolic: 32,
  18919. Italic: 64,
  18920. AllCap: 65536,
  18921. SmallCap: 131072,
  18922. ForceBold: 262144
  18923. };
  18924. var Encodings = {
  18925. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18926. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18927. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18928. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18929. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18930. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18931. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18932. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18933. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18934. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18935. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18936. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18937. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18938. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18939. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18940. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18941. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18942. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18943. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18944. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18945. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18946. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18947. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18948. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18949. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18950. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18951. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18952. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18953. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18954. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18955. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18956. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18957. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18958. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18959. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18960. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18961. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18962. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18963. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18964. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18965. 'Ydieresissmall'],
  18966. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18967. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18968. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18969. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18970. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18971. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18972. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18973. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18974. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18975. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18976. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18977. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18978. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18979. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18980. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18981. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18982. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18983. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18984. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18985. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18986. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18987. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18988. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18989. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18990. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18991. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18992. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18993. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18994. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18995. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18996. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18997. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18998. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18999. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  19000. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  19001. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  19002. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  19003. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  19004. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  19005. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  19006. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19007. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19008. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19009. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  19010. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19011. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19012. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19013. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19014. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19015. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  19016. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  19017. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  19018. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  19019. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  19020. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19021. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  19022. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  19023. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  19024. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  19025. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  19026. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  19027. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  19028. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  19029. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  19030. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  19031. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  19032. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  19033. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  19034. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  19035. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  19036. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  19037. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  19038. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  19039. 'ogonek', 'caron'],
  19040. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19041. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19042. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19043. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  19044. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19045. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19046. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19047. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19048. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19049. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  19050. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  19051. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  19052. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19053. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  19054. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  19055. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  19056. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  19057. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  19058. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  19059. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  19060. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  19061. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  19062. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  19063. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  19064. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  19065. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19066. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19067. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19068. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  19069. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19070. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19071. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19072. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19073. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19074. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  19075. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  19076. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  19077. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  19078. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  19079. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  19080. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  19081. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  19082. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  19083. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  19084. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  19085. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  19086. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  19087. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  19088. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  19089. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  19090. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  19091. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  19092. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  19093. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  19094. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  19095. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  19096. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  19097. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  19098. 'ydieresis'],
  19099. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19100. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19101. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  19102. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  19103. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  19104. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  19105. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  19106. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  19107. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  19108. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  19109. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  19110. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  19111. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  19112. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  19113. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  19114. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19115. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  19116. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  19117. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  19118. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  19119. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  19120. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  19121. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  19122. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  19123. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  19124. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  19125. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  19126. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  19127. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  19128. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  19129. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  19130. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  19131. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  19132. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  19133. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  19134. 'bracerightbt'],
  19135. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19136. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19137. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  19138. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  19139. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  19140. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  19141. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  19142. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  19143. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  19144. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  19145. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  19146. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  19147. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  19148. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  19149. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  19150. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  19151. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  19152. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  19153. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  19154. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  19155. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  19156. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  19157. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  19158. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  19159. };
  19160. /**
  19161. * Hold a map of decoded fonts and of the standard fourteen Type1
  19162. * fonts and their acronyms.
  19163. */
  19164. var stdFontMap = {
  19165. 'ArialNarrow': 'Helvetica',
  19166. 'ArialNarrow-Bold': 'Helvetica-Bold',
  19167. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  19168. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  19169. 'ArialBlack': 'Helvetica',
  19170. 'ArialBlack-Bold': 'Helvetica-Bold',
  19171. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  19172. 'ArialBlack-Italic': 'Helvetica-Oblique',
  19173. 'Arial': 'Helvetica',
  19174. 'Arial-Bold': 'Helvetica-Bold',
  19175. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  19176. 'Arial-Italic': 'Helvetica-Oblique',
  19177. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  19178. 'Arial-BoldMT': 'Helvetica-Bold',
  19179. 'Arial-ItalicMT': 'Helvetica-Oblique',
  19180. 'ArialMT': 'Helvetica',
  19181. 'Courier-Bold': 'Courier-Bold',
  19182. 'Courier-BoldItalic': 'Courier-BoldOblique',
  19183. 'Courier-Italic': 'Courier-Oblique',
  19184. 'CourierNew': 'Courier',
  19185. 'CourierNew-Bold': 'Courier-Bold',
  19186. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  19187. 'CourierNew-Italic': 'Courier-Oblique',
  19188. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  19189. 'CourierNewPS-BoldMT': 'Courier-Bold',
  19190. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  19191. 'CourierNewPSMT': 'Courier',
  19192. 'Helvetica': 'Helvetica',
  19193. 'Helvetica-Bold': 'Helvetica-Bold',
  19194. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  19195. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  19196. 'Helvetica-Italic': 'Helvetica-Oblique',
  19197. 'Helvetica-Oblique':'Helvetica-Oblique',
  19198. 'Symbol-Bold': 'Symbol',
  19199. 'Symbol-BoldItalic': 'Symbol',
  19200. 'Symbol-Italic': 'Symbol',
  19201. 'TimesNewRoman': 'Times-Roman',
  19202. 'TimesNewRoman-Bold': 'Times-Bold',
  19203. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  19204. 'TimesNewRoman-Italic': 'Times-Italic',
  19205. 'TimesNewRomanPS': 'Times-Roman',
  19206. 'TimesNewRomanPS-Bold': 'Times-Bold',
  19207. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  19208. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  19209. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  19210. 'TimesNewRomanPS-Italic': 'Times-Italic',
  19211. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  19212. 'TimesNewRomanPSMT': 'Times-Roman',
  19213. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  19214. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  19215. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  19216. };
  19217. /**
  19218. * Holds the map of the non-standard fonts that might be included as a standard
  19219. * fonts without glyph data.
  19220. */
  19221. var nonStdFontMap = {
  19222. 'CenturyGothic': 'Helvetica',
  19223. 'CenturyGothic-Bold': 'Helvetica-Bold',
  19224. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  19225. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  19226. 'ComicSansMS': 'Comic Sans MS',
  19227. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  19228. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  19229. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  19230. 'LucidaConsole': 'Courier',
  19231. 'LucidaConsole-Bold': 'Courier-Bold',
  19232. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  19233. 'LucidaConsole-Italic': 'Courier-Oblique',
  19234. 'MS-Gothic': 'MS Gothic',
  19235. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  19236. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  19237. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  19238. 'MS-Mincho': 'MS Mincho',
  19239. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  19240. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  19241. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  19242. 'MS-PGothic': 'MS PGothic',
  19243. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  19244. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  19245. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  19246. 'MS-PMincho': 'MS PMincho',
  19247. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  19248. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  19249. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  19250. 'Wingdings': 'ZapfDingbats'
  19251. };
  19252. var serifFonts = {
  19253. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  19254. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  19255. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  19256. 'Arno': true, 'Aster': true, 'Aurora': true,
  19257. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  19258. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  19259. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  19260. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  19261. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  19262. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  19263. 'Cartier': true, 'Caslon': true, 'Catull': true,
  19264. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  19265. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  19266. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  19267. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  19268. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  19269. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  19270. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  19271. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  19272. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  19273. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  19274. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  19275. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  19276. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  19277. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  19278. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  19279. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  19280. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  19281. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  19282. 'Miller': true, 'Minion': true, 'Modern': true,
  19283. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  19284. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  19285. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  19286. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  19287. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  19288. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  19289. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  19290. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  19291. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  19292. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  19293. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  19294. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  19295. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  19296. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  19297. };
  19298. var symbolsFonts = {
  19299. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  19300. };
  19301. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  19302. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  19303. // glyphs, but common for some set of the standard fonts.
  19304. var GlyphMapForStandardFonts = {
  19305. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  19306. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  19307. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  19308. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  19309. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  19310. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  19311. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  19312. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  19313. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  19314. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  19315. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  19316. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  19317. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  19318. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  19319. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  19320. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  19321. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  19322. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  19323. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  19324. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  19325. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  19326. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  19327. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  19328. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  19329. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  19330. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  19331. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  19332. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  19333. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  19334. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  19335. '298': 380, '305': 963,
  19336. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  19337. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  19338. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  19339. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  19340. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  19341. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  19342. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  19343. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  19344. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  19345. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  19346. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  19347. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  19348. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  19349. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  19350. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  19351. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  19352. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  19353. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  19354. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  19355. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  19356. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  19357. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  19358. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  19359. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  19360. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  19361. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  19362. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  19363. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  19364. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  19365. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  19366. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  19367. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  19368. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  19369. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  19370. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  19371. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  19372. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  19373. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  19374. };
  19375. // The glyph map for ArialBlack differs slightly from the glyph map used for
  19376. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  19377. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  19378. var SupplementalGlyphMapForArialBlack = {
  19379. '227': 322, '264': 261, '291': 346,
  19380. };
  19381. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  19382. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  19383. // to the similar equivalents in the normal characters range.
  19384. var SpecialPUASymbols = {
  19385. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  19386. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  19387. '63720': 0x00AE, // registersans (0xF8E8) => registered
  19388. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  19389. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  19390. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  19391. '63729': 0x23A7, // bracelefttp (0xF8F1)
  19392. '63730': 0x23A8, // braceleftmid (0xF8F2)
  19393. '63731': 0x23A9, // braceleftbt (0xF8F3)
  19394. '63740': 0x23AB, // bracerighttp (0xF8FC)
  19395. '63741': 0x23AC, // bracerightmid (0xF8FD)
  19396. '63742': 0x23AD, // bracerightbt (0xF8FE)
  19397. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  19398. '63727': 0x23A2, // bracketleftex (0xF8EF)
  19399. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  19400. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  19401. '63738': 0x23A5, // bracketrightex (0xF8FA)
  19402. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  19403. '63723': 0x239B, // parenlefttp (0xF8EB)
  19404. '63724': 0x239C, // parenleftex (0xF8EC)
  19405. '63725': 0x239D, // parenleftbt (0xF8ED)
  19406. '63734': 0x239E, // parenrighttp (0xF8F6)
  19407. '63735': 0x239F, // parenrightex (0xF8F7)
  19408. '63736': 0x23A0, // parenrightbt (0xF8F8)
  19409. };
  19410. function mapSpecialUnicodeValues(code) {
  19411. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  19412. return 0;
  19413. } else if (code >= 0xF600 && code <= 0xF8FF) {
  19414. return (SpecialPUASymbols[code] || code);
  19415. }
  19416. return code;
  19417. }
  19418. var UnicodeRanges = [
  19419. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  19420. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  19421. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  19422. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  19423. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  19424. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  19425. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  19426. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  19427. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  19428. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  19429. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  19430. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  19431. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  19432. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  19433. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  19434. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  19435. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  19436. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  19437. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  19438. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  19439. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  19440. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  19441. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  19442. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  19443. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  19444. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  19445. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  19446. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19447. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19448. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19449. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19450. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19451. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19452. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19453. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19454. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19455. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19456. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19457. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19458. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19459. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19460. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19461. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19462. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19463. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19464. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19465. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19466. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19467. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19468. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19469. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19470. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19471. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19472. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19473. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19474. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19475. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19476. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19477. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19478. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19479. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19480. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19481. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19482. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19483. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19484. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19485. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19486. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19487. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19488. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19489. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19490. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19491. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19492. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19493. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19494. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19495. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19496. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19497. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19498. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19499. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19500. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19501. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19502. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19503. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19504. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19505. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19506. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19507. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19508. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19509. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19510. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19511. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19512. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19513. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19514. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19515. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19516. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19517. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19518. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19519. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19520. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19521. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19522. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19523. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19524. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19525. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19526. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19527. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19528. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19529. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19530. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19531. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19532. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19533. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19534. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19535. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19536. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19537. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19538. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19539. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19540. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19541. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19542. ];
  19543. var MacStandardGlyphOrdering = [
  19544. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19545. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19546. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19547. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19548. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19549. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19550. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19551. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19552. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19553. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19554. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19555. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19556. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19557. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19558. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19559. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19560. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19561. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19562. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19563. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19564. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19565. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19566. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19567. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19568. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19569. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19570. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19571. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19572. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19573. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19574. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19575. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19576. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19577. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19578. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19579. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19580. function getUnicodeRangeFor(value) {
  19581. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19582. var range = UnicodeRanges[i];
  19583. if (value >= range.begin && value < range.end) {
  19584. return i;
  19585. }
  19586. }
  19587. return -1;
  19588. }
  19589. function isRTLRangeFor(value) {
  19590. var range = UnicodeRanges[13];
  19591. if (value >= range.begin && value < range.end) {
  19592. return true;
  19593. }
  19594. range = UnicodeRanges[11];
  19595. if (value >= range.begin && value < range.end) {
  19596. return true;
  19597. }
  19598. return false;
  19599. }
  19600. // The normalization table is obtained by filtering the Unicode characters
  19601. // database with <compat> entries.
  19602. var NormalizedUnicodes = {
  19603. '\u00A8': '\u0020\u0308',
  19604. '\u00AF': '\u0020\u0304',
  19605. '\u00B4': '\u0020\u0301',
  19606. '\u00B5': '\u03BC',
  19607. '\u00B8': '\u0020\u0327',
  19608. '\u0132': '\u0049\u004A',
  19609. '\u0133': '\u0069\u006A',
  19610. '\u013F': '\u004C\u00B7',
  19611. '\u0140': '\u006C\u00B7',
  19612. '\u0149': '\u02BC\u006E',
  19613. '\u017F': '\u0073',
  19614. '\u01C4': '\u0044\u017D',
  19615. '\u01C5': '\u0044\u017E',
  19616. '\u01C6': '\u0064\u017E',
  19617. '\u01C7': '\u004C\u004A',
  19618. '\u01C8': '\u004C\u006A',
  19619. '\u01C9': '\u006C\u006A',
  19620. '\u01CA': '\u004E\u004A',
  19621. '\u01CB': '\u004E\u006A',
  19622. '\u01CC': '\u006E\u006A',
  19623. '\u01F1': '\u0044\u005A',
  19624. '\u01F2': '\u0044\u007A',
  19625. '\u01F3': '\u0064\u007A',
  19626. '\u02D8': '\u0020\u0306',
  19627. '\u02D9': '\u0020\u0307',
  19628. '\u02DA': '\u0020\u030A',
  19629. '\u02DB': '\u0020\u0328',
  19630. '\u02DC': '\u0020\u0303',
  19631. '\u02DD': '\u0020\u030B',
  19632. '\u037A': '\u0020\u0345',
  19633. '\u0384': '\u0020\u0301',
  19634. '\u03D0': '\u03B2',
  19635. '\u03D1': '\u03B8',
  19636. '\u03D2': '\u03A5',
  19637. '\u03D5': '\u03C6',
  19638. '\u03D6': '\u03C0',
  19639. '\u03F0': '\u03BA',
  19640. '\u03F1': '\u03C1',
  19641. '\u03F2': '\u03C2',
  19642. '\u03F4': '\u0398',
  19643. '\u03F5': '\u03B5',
  19644. '\u03F9': '\u03A3',
  19645. '\u0587': '\u0565\u0582',
  19646. '\u0675': '\u0627\u0674',
  19647. '\u0676': '\u0648\u0674',
  19648. '\u0677': '\u06C7\u0674',
  19649. '\u0678': '\u064A\u0674',
  19650. '\u0E33': '\u0E4D\u0E32',
  19651. '\u0EB3': '\u0ECD\u0EB2',
  19652. '\u0EDC': '\u0EAB\u0E99',
  19653. '\u0EDD': '\u0EAB\u0EA1',
  19654. '\u0F77': '\u0FB2\u0F81',
  19655. '\u0F79': '\u0FB3\u0F81',
  19656. '\u1E9A': '\u0061\u02BE',
  19657. '\u1FBD': '\u0020\u0313',
  19658. '\u1FBF': '\u0020\u0313',
  19659. '\u1FC0': '\u0020\u0342',
  19660. '\u1FFE': '\u0020\u0314',
  19661. '\u2002': '\u0020',
  19662. '\u2003': '\u0020',
  19663. '\u2004': '\u0020',
  19664. '\u2005': '\u0020',
  19665. '\u2006': '\u0020',
  19666. '\u2008': '\u0020',
  19667. '\u2009': '\u0020',
  19668. '\u200A': '\u0020',
  19669. '\u2017': '\u0020\u0333',
  19670. '\u2024': '\u002E',
  19671. '\u2025': '\u002E\u002E',
  19672. '\u2026': '\u002E\u002E\u002E',
  19673. '\u2033': '\u2032\u2032',
  19674. '\u2034': '\u2032\u2032\u2032',
  19675. '\u2036': '\u2035\u2035',
  19676. '\u2037': '\u2035\u2035\u2035',
  19677. '\u203C': '\u0021\u0021',
  19678. '\u203E': '\u0020\u0305',
  19679. '\u2047': '\u003F\u003F',
  19680. '\u2048': '\u003F\u0021',
  19681. '\u2049': '\u0021\u003F',
  19682. '\u2057': '\u2032\u2032\u2032\u2032',
  19683. '\u205F': '\u0020',
  19684. '\u20A8': '\u0052\u0073',
  19685. '\u2100': '\u0061\u002F\u0063',
  19686. '\u2101': '\u0061\u002F\u0073',
  19687. '\u2103': '\u00B0\u0043',
  19688. '\u2105': '\u0063\u002F\u006F',
  19689. '\u2106': '\u0063\u002F\u0075',
  19690. '\u2107': '\u0190',
  19691. '\u2109': '\u00B0\u0046',
  19692. '\u2116': '\u004E\u006F',
  19693. '\u2121': '\u0054\u0045\u004C',
  19694. '\u2135': '\u05D0',
  19695. '\u2136': '\u05D1',
  19696. '\u2137': '\u05D2',
  19697. '\u2138': '\u05D3',
  19698. '\u213B': '\u0046\u0041\u0058',
  19699. '\u2160': '\u0049',
  19700. '\u2161': '\u0049\u0049',
  19701. '\u2162': '\u0049\u0049\u0049',
  19702. '\u2163': '\u0049\u0056',
  19703. '\u2164': '\u0056',
  19704. '\u2165': '\u0056\u0049',
  19705. '\u2166': '\u0056\u0049\u0049',
  19706. '\u2167': '\u0056\u0049\u0049\u0049',
  19707. '\u2168': '\u0049\u0058',
  19708. '\u2169': '\u0058',
  19709. '\u216A': '\u0058\u0049',
  19710. '\u216B': '\u0058\u0049\u0049',
  19711. '\u216C': '\u004C',
  19712. '\u216D': '\u0043',
  19713. '\u216E': '\u0044',
  19714. '\u216F': '\u004D',
  19715. '\u2170': '\u0069',
  19716. '\u2171': '\u0069\u0069',
  19717. '\u2172': '\u0069\u0069\u0069',
  19718. '\u2173': '\u0069\u0076',
  19719. '\u2174': '\u0076',
  19720. '\u2175': '\u0076\u0069',
  19721. '\u2176': '\u0076\u0069\u0069',
  19722. '\u2177': '\u0076\u0069\u0069\u0069',
  19723. '\u2178': '\u0069\u0078',
  19724. '\u2179': '\u0078',
  19725. '\u217A': '\u0078\u0069',
  19726. '\u217B': '\u0078\u0069\u0069',
  19727. '\u217C': '\u006C',
  19728. '\u217D': '\u0063',
  19729. '\u217E': '\u0064',
  19730. '\u217F': '\u006D',
  19731. '\u222C': '\u222B\u222B',
  19732. '\u222D': '\u222B\u222B\u222B',
  19733. '\u222F': '\u222E\u222E',
  19734. '\u2230': '\u222E\u222E\u222E',
  19735. '\u2474': '\u0028\u0031\u0029',
  19736. '\u2475': '\u0028\u0032\u0029',
  19737. '\u2476': '\u0028\u0033\u0029',
  19738. '\u2477': '\u0028\u0034\u0029',
  19739. '\u2478': '\u0028\u0035\u0029',
  19740. '\u2479': '\u0028\u0036\u0029',
  19741. '\u247A': '\u0028\u0037\u0029',
  19742. '\u247B': '\u0028\u0038\u0029',
  19743. '\u247C': '\u0028\u0039\u0029',
  19744. '\u247D': '\u0028\u0031\u0030\u0029',
  19745. '\u247E': '\u0028\u0031\u0031\u0029',
  19746. '\u247F': '\u0028\u0031\u0032\u0029',
  19747. '\u2480': '\u0028\u0031\u0033\u0029',
  19748. '\u2481': '\u0028\u0031\u0034\u0029',
  19749. '\u2482': '\u0028\u0031\u0035\u0029',
  19750. '\u2483': '\u0028\u0031\u0036\u0029',
  19751. '\u2484': '\u0028\u0031\u0037\u0029',
  19752. '\u2485': '\u0028\u0031\u0038\u0029',
  19753. '\u2486': '\u0028\u0031\u0039\u0029',
  19754. '\u2487': '\u0028\u0032\u0030\u0029',
  19755. '\u2488': '\u0031\u002E',
  19756. '\u2489': '\u0032\u002E',
  19757. '\u248A': '\u0033\u002E',
  19758. '\u248B': '\u0034\u002E',
  19759. '\u248C': '\u0035\u002E',
  19760. '\u248D': '\u0036\u002E',
  19761. '\u248E': '\u0037\u002E',
  19762. '\u248F': '\u0038\u002E',
  19763. '\u2490': '\u0039\u002E',
  19764. '\u2491': '\u0031\u0030\u002E',
  19765. '\u2492': '\u0031\u0031\u002E',
  19766. '\u2493': '\u0031\u0032\u002E',
  19767. '\u2494': '\u0031\u0033\u002E',
  19768. '\u2495': '\u0031\u0034\u002E',
  19769. '\u2496': '\u0031\u0035\u002E',
  19770. '\u2497': '\u0031\u0036\u002E',
  19771. '\u2498': '\u0031\u0037\u002E',
  19772. '\u2499': '\u0031\u0038\u002E',
  19773. '\u249A': '\u0031\u0039\u002E',
  19774. '\u249B': '\u0032\u0030\u002E',
  19775. '\u249C': '\u0028\u0061\u0029',
  19776. '\u249D': '\u0028\u0062\u0029',
  19777. '\u249E': '\u0028\u0063\u0029',
  19778. '\u249F': '\u0028\u0064\u0029',
  19779. '\u24A0': '\u0028\u0065\u0029',
  19780. '\u24A1': '\u0028\u0066\u0029',
  19781. '\u24A2': '\u0028\u0067\u0029',
  19782. '\u24A3': '\u0028\u0068\u0029',
  19783. '\u24A4': '\u0028\u0069\u0029',
  19784. '\u24A5': '\u0028\u006A\u0029',
  19785. '\u24A6': '\u0028\u006B\u0029',
  19786. '\u24A7': '\u0028\u006C\u0029',
  19787. '\u24A8': '\u0028\u006D\u0029',
  19788. '\u24A9': '\u0028\u006E\u0029',
  19789. '\u24AA': '\u0028\u006F\u0029',
  19790. '\u24AB': '\u0028\u0070\u0029',
  19791. '\u24AC': '\u0028\u0071\u0029',
  19792. '\u24AD': '\u0028\u0072\u0029',
  19793. '\u24AE': '\u0028\u0073\u0029',
  19794. '\u24AF': '\u0028\u0074\u0029',
  19795. '\u24B0': '\u0028\u0075\u0029',
  19796. '\u24B1': '\u0028\u0076\u0029',
  19797. '\u24B2': '\u0028\u0077\u0029',
  19798. '\u24B3': '\u0028\u0078\u0029',
  19799. '\u24B4': '\u0028\u0079\u0029',
  19800. '\u24B5': '\u0028\u007A\u0029',
  19801. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19802. '\u2A74': '\u003A\u003A\u003D',
  19803. '\u2A75': '\u003D\u003D',
  19804. '\u2A76': '\u003D\u003D\u003D',
  19805. '\u2E9F': '\u6BCD',
  19806. '\u2EF3': '\u9F9F',
  19807. '\u2F00': '\u4E00',
  19808. '\u2F01': '\u4E28',
  19809. '\u2F02': '\u4E36',
  19810. '\u2F03': '\u4E3F',
  19811. '\u2F04': '\u4E59',
  19812. '\u2F05': '\u4E85',
  19813. '\u2F06': '\u4E8C',
  19814. '\u2F07': '\u4EA0',
  19815. '\u2F08': '\u4EBA',
  19816. '\u2F09': '\u513F',
  19817. '\u2F0A': '\u5165',
  19818. '\u2F0B': '\u516B',
  19819. '\u2F0C': '\u5182',
  19820. '\u2F0D': '\u5196',
  19821. '\u2F0E': '\u51AB',
  19822. '\u2F0F': '\u51E0',
  19823. '\u2F10': '\u51F5',
  19824. '\u2F11': '\u5200',
  19825. '\u2F12': '\u529B',
  19826. '\u2F13': '\u52F9',
  19827. '\u2F14': '\u5315',
  19828. '\u2F15': '\u531A',
  19829. '\u2F16': '\u5338',
  19830. '\u2F17': '\u5341',
  19831. '\u2F18': '\u535C',
  19832. '\u2F19': '\u5369',
  19833. '\u2F1A': '\u5382',
  19834. '\u2F1B': '\u53B6',
  19835. '\u2F1C': '\u53C8',
  19836. '\u2F1D': '\u53E3',
  19837. '\u2F1E': '\u56D7',
  19838. '\u2F1F': '\u571F',
  19839. '\u2F20': '\u58EB',
  19840. '\u2F21': '\u5902',
  19841. '\u2F22': '\u590A',
  19842. '\u2F23': '\u5915',
  19843. '\u2F24': '\u5927',
  19844. '\u2F25': '\u5973',
  19845. '\u2F26': '\u5B50',
  19846. '\u2F27': '\u5B80',
  19847. '\u2F28': '\u5BF8',
  19848. '\u2F29': '\u5C0F',
  19849. '\u2F2A': '\u5C22',
  19850. '\u2F2B': '\u5C38',
  19851. '\u2F2C': '\u5C6E',
  19852. '\u2F2D': '\u5C71',
  19853. '\u2F2E': '\u5DDB',
  19854. '\u2F2F': '\u5DE5',
  19855. '\u2F30': '\u5DF1',
  19856. '\u2F31': '\u5DFE',
  19857. '\u2F32': '\u5E72',
  19858. '\u2F33': '\u5E7A',
  19859. '\u2F34': '\u5E7F',
  19860. '\u2F35': '\u5EF4',
  19861. '\u2F36': '\u5EFE',
  19862. '\u2F37': '\u5F0B',
  19863. '\u2F38': '\u5F13',
  19864. '\u2F39': '\u5F50',
  19865. '\u2F3A': '\u5F61',
  19866. '\u2F3B': '\u5F73',
  19867. '\u2F3C': '\u5FC3',
  19868. '\u2F3D': '\u6208',
  19869. '\u2F3E': '\u6236',
  19870. '\u2F3F': '\u624B',
  19871. '\u2F40': '\u652F',
  19872. '\u2F41': '\u6534',
  19873. '\u2F42': '\u6587',
  19874. '\u2F43': '\u6597',
  19875. '\u2F44': '\u65A4',
  19876. '\u2F45': '\u65B9',
  19877. '\u2F46': '\u65E0',
  19878. '\u2F47': '\u65E5',
  19879. '\u2F48': '\u66F0',
  19880. '\u2F49': '\u6708',
  19881. '\u2F4A': '\u6728',
  19882. '\u2F4B': '\u6B20',
  19883. '\u2F4C': '\u6B62',
  19884. '\u2F4D': '\u6B79',
  19885. '\u2F4E': '\u6BB3',
  19886. '\u2F4F': '\u6BCB',
  19887. '\u2F50': '\u6BD4',
  19888. '\u2F51': '\u6BDB',
  19889. '\u2F52': '\u6C0F',
  19890. '\u2F53': '\u6C14',
  19891. '\u2F54': '\u6C34',
  19892. '\u2F55': '\u706B',
  19893. '\u2F56': '\u722A',
  19894. '\u2F57': '\u7236',
  19895. '\u2F58': '\u723B',
  19896. '\u2F59': '\u723F',
  19897. '\u2F5A': '\u7247',
  19898. '\u2F5B': '\u7259',
  19899. '\u2F5C': '\u725B',
  19900. '\u2F5D': '\u72AC',
  19901. '\u2F5E': '\u7384',
  19902. '\u2F5F': '\u7389',
  19903. '\u2F60': '\u74DC',
  19904. '\u2F61': '\u74E6',
  19905. '\u2F62': '\u7518',
  19906. '\u2F63': '\u751F',
  19907. '\u2F64': '\u7528',
  19908. '\u2F65': '\u7530',
  19909. '\u2F66': '\u758B',
  19910. '\u2F67': '\u7592',
  19911. '\u2F68': '\u7676',
  19912. '\u2F69': '\u767D',
  19913. '\u2F6A': '\u76AE',
  19914. '\u2F6B': '\u76BF',
  19915. '\u2F6C': '\u76EE',
  19916. '\u2F6D': '\u77DB',
  19917. '\u2F6E': '\u77E2',
  19918. '\u2F6F': '\u77F3',
  19919. '\u2F70': '\u793A',
  19920. '\u2F71': '\u79B8',
  19921. '\u2F72': '\u79BE',
  19922. '\u2F73': '\u7A74',
  19923. '\u2F74': '\u7ACB',
  19924. '\u2F75': '\u7AF9',
  19925. '\u2F76': '\u7C73',
  19926. '\u2F77': '\u7CF8',
  19927. '\u2F78': '\u7F36',
  19928. '\u2F79': '\u7F51',
  19929. '\u2F7A': '\u7F8A',
  19930. '\u2F7B': '\u7FBD',
  19931. '\u2F7C': '\u8001',
  19932. '\u2F7D': '\u800C',
  19933. '\u2F7E': '\u8012',
  19934. '\u2F7F': '\u8033',
  19935. '\u2F80': '\u807F',
  19936. '\u2F81': '\u8089',
  19937. '\u2F82': '\u81E3',
  19938. '\u2F83': '\u81EA',
  19939. '\u2F84': '\u81F3',
  19940. '\u2F85': '\u81FC',
  19941. '\u2F86': '\u820C',
  19942. '\u2F87': '\u821B',
  19943. '\u2F88': '\u821F',
  19944. '\u2F89': '\u826E',
  19945. '\u2F8A': '\u8272',
  19946. '\u2F8B': '\u8278',
  19947. '\u2F8C': '\u864D',
  19948. '\u2F8D': '\u866B',
  19949. '\u2F8E': '\u8840',
  19950. '\u2F8F': '\u884C',
  19951. '\u2F90': '\u8863',
  19952. '\u2F91': '\u897E',
  19953. '\u2F92': '\u898B',
  19954. '\u2F93': '\u89D2',
  19955. '\u2F94': '\u8A00',
  19956. '\u2F95': '\u8C37',
  19957. '\u2F96': '\u8C46',
  19958. '\u2F97': '\u8C55',
  19959. '\u2F98': '\u8C78',
  19960. '\u2F99': '\u8C9D',
  19961. '\u2F9A': '\u8D64',
  19962. '\u2F9B': '\u8D70',
  19963. '\u2F9C': '\u8DB3',
  19964. '\u2F9D': '\u8EAB',
  19965. '\u2F9E': '\u8ECA',
  19966. '\u2F9F': '\u8F9B',
  19967. '\u2FA0': '\u8FB0',
  19968. '\u2FA1': '\u8FB5',
  19969. '\u2FA2': '\u9091',
  19970. '\u2FA3': '\u9149',
  19971. '\u2FA4': '\u91C6',
  19972. '\u2FA5': '\u91CC',
  19973. '\u2FA6': '\u91D1',
  19974. '\u2FA7': '\u9577',
  19975. '\u2FA8': '\u9580',
  19976. '\u2FA9': '\u961C',
  19977. '\u2FAA': '\u96B6',
  19978. '\u2FAB': '\u96B9',
  19979. '\u2FAC': '\u96E8',
  19980. '\u2FAD': '\u9751',
  19981. '\u2FAE': '\u975E',
  19982. '\u2FAF': '\u9762',
  19983. '\u2FB0': '\u9769',
  19984. '\u2FB1': '\u97CB',
  19985. '\u2FB2': '\u97ED',
  19986. '\u2FB3': '\u97F3',
  19987. '\u2FB4': '\u9801',
  19988. '\u2FB5': '\u98A8',
  19989. '\u2FB6': '\u98DB',
  19990. '\u2FB7': '\u98DF',
  19991. '\u2FB8': '\u9996',
  19992. '\u2FB9': '\u9999',
  19993. '\u2FBA': '\u99AC',
  19994. '\u2FBB': '\u9AA8',
  19995. '\u2FBC': '\u9AD8',
  19996. '\u2FBD': '\u9ADF',
  19997. '\u2FBE': '\u9B25',
  19998. '\u2FBF': '\u9B2F',
  19999. '\u2FC0': '\u9B32',
  20000. '\u2FC1': '\u9B3C',
  20001. '\u2FC2': '\u9B5A',
  20002. '\u2FC3': '\u9CE5',
  20003. '\u2FC4': '\u9E75',
  20004. '\u2FC5': '\u9E7F',
  20005. '\u2FC6': '\u9EA5',
  20006. '\u2FC7': '\u9EBB',
  20007. '\u2FC8': '\u9EC3',
  20008. '\u2FC9': '\u9ECD',
  20009. '\u2FCA': '\u9ED1',
  20010. '\u2FCB': '\u9EF9',
  20011. '\u2FCC': '\u9EFD',
  20012. '\u2FCD': '\u9F0E',
  20013. '\u2FCE': '\u9F13',
  20014. '\u2FCF': '\u9F20',
  20015. '\u2FD0': '\u9F3B',
  20016. '\u2FD1': '\u9F4A',
  20017. '\u2FD2': '\u9F52',
  20018. '\u2FD3': '\u9F8D',
  20019. '\u2FD4': '\u9F9C',
  20020. '\u2FD5': '\u9FA0',
  20021. '\u3036': '\u3012',
  20022. '\u3038': '\u5341',
  20023. '\u3039': '\u5344',
  20024. '\u303A': '\u5345',
  20025. '\u309B': '\u0020\u3099',
  20026. '\u309C': '\u0020\u309A',
  20027. '\u3131': '\u1100',
  20028. '\u3132': '\u1101',
  20029. '\u3133': '\u11AA',
  20030. '\u3134': '\u1102',
  20031. '\u3135': '\u11AC',
  20032. '\u3136': '\u11AD',
  20033. '\u3137': '\u1103',
  20034. '\u3138': '\u1104',
  20035. '\u3139': '\u1105',
  20036. '\u313A': '\u11B0',
  20037. '\u313B': '\u11B1',
  20038. '\u313C': '\u11B2',
  20039. '\u313D': '\u11B3',
  20040. '\u313E': '\u11B4',
  20041. '\u313F': '\u11B5',
  20042. '\u3140': '\u111A',
  20043. '\u3141': '\u1106',
  20044. '\u3142': '\u1107',
  20045. '\u3143': '\u1108',
  20046. '\u3144': '\u1121',
  20047. '\u3145': '\u1109',
  20048. '\u3146': '\u110A',
  20049. '\u3147': '\u110B',
  20050. '\u3148': '\u110C',
  20051. '\u3149': '\u110D',
  20052. '\u314A': '\u110E',
  20053. '\u314B': '\u110F',
  20054. '\u314C': '\u1110',
  20055. '\u314D': '\u1111',
  20056. '\u314E': '\u1112',
  20057. '\u314F': '\u1161',
  20058. '\u3150': '\u1162',
  20059. '\u3151': '\u1163',
  20060. '\u3152': '\u1164',
  20061. '\u3153': '\u1165',
  20062. '\u3154': '\u1166',
  20063. '\u3155': '\u1167',
  20064. '\u3156': '\u1168',
  20065. '\u3157': '\u1169',
  20066. '\u3158': '\u116A',
  20067. '\u3159': '\u116B',
  20068. '\u315A': '\u116C',
  20069. '\u315B': '\u116D',
  20070. '\u315C': '\u116E',
  20071. '\u315D': '\u116F',
  20072. '\u315E': '\u1170',
  20073. '\u315F': '\u1171',
  20074. '\u3160': '\u1172',
  20075. '\u3161': '\u1173',
  20076. '\u3162': '\u1174',
  20077. '\u3163': '\u1175',
  20078. '\u3164': '\u1160',
  20079. '\u3165': '\u1114',
  20080. '\u3166': '\u1115',
  20081. '\u3167': '\u11C7',
  20082. '\u3168': '\u11C8',
  20083. '\u3169': '\u11CC',
  20084. '\u316A': '\u11CE',
  20085. '\u316B': '\u11D3',
  20086. '\u316C': '\u11D7',
  20087. '\u316D': '\u11D9',
  20088. '\u316E': '\u111C',
  20089. '\u316F': '\u11DD',
  20090. '\u3170': '\u11DF',
  20091. '\u3171': '\u111D',
  20092. '\u3172': '\u111E',
  20093. '\u3173': '\u1120',
  20094. '\u3174': '\u1122',
  20095. '\u3175': '\u1123',
  20096. '\u3176': '\u1127',
  20097. '\u3177': '\u1129',
  20098. '\u3178': '\u112B',
  20099. '\u3179': '\u112C',
  20100. '\u317A': '\u112D',
  20101. '\u317B': '\u112E',
  20102. '\u317C': '\u112F',
  20103. '\u317D': '\u1132',
  20104. '\u317E': '\u1136',
  20105. '\u317F': '\u1140',
  20106. '\u3180': '\u1147',
  20107. '\u3181': '\u114C',
  20108. '\u3182': '\u11F1',
  20109. '\u3183': '\u11F2',
  20110. '\u3184': '\u1157',
  20111. '\u3185': '\u1158',
  20112. '\u3186': '\u1159',
  20113. '\u3187': '\u1184',
  20114. '\u3188': '\u1185',
  20115. '\u3189': '\u1188',
  20116. '\u318A': '\u1191',
  20117. '\u318B': '\u1192',
  20118. '\u318C': '\u1194',
  20119. '\u318D': '\u119E',
  20120. '\u318E': '\u11A1',
  20121. '\u3200': '\u0028\u1100\u0029',
  20122. '\u3201': '\u0028\u1102\u0029',
  20123. '\u3202': '\u0028\u1103\u0029',
  20124. '\u3203': '\u0028\u1105\u0029',
  20125. '\u3204': '\u0028\u1106\u0029',
  20126. '\u3205': '\u0028\u1107\u0029',
  20127. '\u3206': '\u0028\u1109\u0029',
  20128. '\u3207': '\u0028\u110B\u0029',
  20129. '\u3208': '\u0028\u110C\u0029',
  20130. '\u3209': '\u0028\u110E\u0029',
  20131. '\u320A': '\u0028\u110F\u0029',
  20132. '\u320B': '\u0028\u1110\u0029',
  20133. '\u320C': '\u0028\u1111\u0029',
  20134. '\u320D': '\u0028\u1112\u0029',
  20135. '\u320E': '\u0028\u1100\u1161\u0029',
  20136. '\u320F': '\u0028\u1102\u1161\u0029',
  20137. '\u3210': '\u0028\u1103\u1161\u0029',
  20138. '\u3211': '\u0028\u1105\u1161\u0029',
  20139. '\u3212': '\u0028\u1106\u1161\u0029',
  20140. '\u3213': '\u0028\u1107\u1161\u0029',
  20141. '\u3214': '\u0028\u1109\u1161\u0029',
  20142. '\u3215': '\u0028\u110B\u1161\u0029',
  20143. '\u3216': '\u0028\u110C\u1161\u0029',
  20144. '\u3217': '\u0028\u110E\u1161\u0029',
  20145. '\u3218': '\u0028\u110F\u1161\u0029',
  20146. '\u3219': '\u0028\u1110\u1161\u0029',
  20147. '\u321A': '\u0028\u1111\u1161\u0029',
  20148. '\u321B': '\u0028\u1112\u1161\u0029',
  20149. '\u321C': '\u0028\u110C\u116E\u0029',
  20150. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  20151. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  20152. '\u3220': '\u0028\u4E00\u0029',
  20153. '\u3221': '\u0028\u4E8C\u0029',
  20154. '\u3222': '\u0028\u4E09\u0029',
  20155. '\u3223': '\u0028\u56DB\u0029',
  20156. '\u3224': '\u0028\u4E94\u0029',
  20157. '\u3225': '\u0028\u516D\u0029',
  20158. '\u3226': '\u0028\u4E03\u0029',
  20159. '\u3227': '\u0028\u516B\u0029',
  20160. '\u3228': '\u0028\u4E5D\u0029',
  20161. '\u3229': '\u0028\u5341\u0029',
  20162. '\u322A': '\u0028\u6708\u0029',
  20163. '\u322B': '\u0028\u706B\u0029',
  20164. '\u322C': '\u0028\u6C34\u0029',
  20165. '\u322D': '\u0028\u6728\u0029',
  20166. '\u322E': '\u0028\u91D1\u0029',
  20167. '\u322F': '\u0028\u571F\u0029',
  20168. '\u3230': '\u0028\u65E5\u0029',
  20169. '\u3231': '\u0028\u682A\u0029',
  20170. '\u3232': '\u0028\u6709\u0029',
  20171. '\u3233': '\u0028\u793E\u0029',
  20172. '\u3234': '\u0028\u540D\u0029',
  20173. '\u3235': '\u0028\u7279\u0029',
  20174. '\u3236': '\u0028\u8CA1\u0029',
  20175. '\u3237': '\u0028\u795D\u0029',
  20176. '\u3238': '\u0028\u52B4\u0029',
  20177. '\u3239': '\u0028\u4EE3\u0029',
  20178. '\u323A': '\u0028\u547C\u0029',
  20179. '\u323B': '\u0028\u5B66\u0029',
  20180. '\u323C': '\u0028\u76E3\u0029',
  20181. '\u323D': '\u0028\u4F01\u0029',
  20182. '\u323E': '\u0028\u8CC7\u0029',
  20183. '\u323F': '\u0028\u5354\u0029',
  20184. '\u3240': '\u0028\u796D\u0029',
  20185. '\u3241': '\u0028\u4F11\u0029',
  20186. '\u3242': '\u0028\u81EA\u0029',
  20187. '\u3243': '\u0028\u81F3\u0029',
  20188. '\u32C0': '\u0031\u6708',
  20189. '\u32C1': '\u0032\u6708',
  20190. '\u32C2': '\u0033\u6708',
  20191. '\u32C3': '\u0034\u6708',
  20192. '\u32C4': '\u0035\u6708',
  20193. '\u32C5': '\u0036\u6708',
  20194. '\u32C6': '\u0037\u6708',
  20195. '\u32C7': '\u0038\u6708',
  20196. '\u32C8': '\u0039\u6708',
  20197. '\u32C9': '\u0031\u0030\u6708',
  20198. '\u32CA': '\u0031\u0031\u6708',
  20199. '\u32CB': '\u0031\u0032\u6708',
  20200. '\u3358': '\u0030\u70B9',
  20201. '\u3359': '\u0031\u70B9',
  20202. '\u335A': '\u0032\u70B9',
  20203. '\u335B': '\u0033\u70B9',
  20204. '\u335C': '\u0034\u70B9',
  20205. '\u335D': '\u0035\u70B9',
  20206. '\u335E': '\u0036\u70B9',
  20207. '\u335F': '\u0037\u70B9',
  20208. '\u3360': '\u0038\u70B9',
  20209. '\u3361': '\u0039\u70B9',
  20210. '\u3362': '\u0031\u0030\u70B9',
  20211. '\u3363': '\u0031\u0031\u70B9',
  20212. '\u3364': '\u0031\u0032\u70B9',
  20213. '\u3365': '\u0031\u0033\u70B9',
  20214. '\u3366': '\u0031\u0034\u70B9',
  20215. '\u3367': '\u0031\u0035\u70B9',
  20216. '\u3368': '\u0031\u0036\u70B9',
  20217. '\u3369': '\u0031\u0037\u70B9',
  20218. '\u336A': '\u0031\u0038\u70B9',
  20219. '\u336B': '\u0031\u0039\u70B9',
  20220. '\u336C': '\u0032\u0030\u70B9',
  20221. '\u336D': '\u0032\u0031\u70B9',
  20222. '\u336E': '\u0032\u0032\u70B9',
  20223. '\u336F': '\u0032\u0033\u70B9',
  20224. '\u3370': '\u0032\u0034\u70B9',
  20225. '\u33E0': '\u0031\u65E5',
  20226. '\u33E1': '\u0032\u65E5',
  20227. '\u33E2': '\u0033\u65E5',
  20228. '\u33E3': '\u0034\u65E5',
  20229. '\u33E4': '\u0035\u65E5',
  20230. '\u33E5': '\u0036\u65E5',
  20231. '\u33E6': '\u0037\u65E5',
  20232. '\u33E7': '\u0038\u65E5',
  20233. '\u33E8': '\u0039\u65E5',
  20234. '\u33E9': '\u0031\u0030\u65E5',
  20235. '\u33EA': '\u0031\u0031\u65E5',
  20236. '\u33EB': '\u0031\u0032\u65E5',
  20237. '\u33EC': '\u0031\u0033\u65E5',
  20238. '\u33ED': '\u0031\u0034\u65E5',
  20239. '\u33EE': '\u0031\u0035\u65E5',
  20240. '\u33EF': '\u0031\u0036\u65E5',
  20241. '\u33F0': '\u0031\u0037\u65E5',
  20242. '\u33F1': '\u0031\u0038\u65E5',
  20243. '\u33F2': '\u0031\u0039\u65E5',
  20244. '\u33F3': '\u0032\u0030\u65E5',
  20245. '\u33F4': '\u0032\u0031\u65E5',
  20246. '\u33F5': '\u0032\u0032\u65E5',
  20247. '\u33F6': '\u0032\u0033\u65E5',
  20248. '\u33F7': '\u0032\u0034\u65E5',
  20249. '\u33F8': '\u0032\u0035\u65E5',
  20250. '\u33F9': '\u0032\u0036\u65E5',
  20251. '\u33FA': '\u0032\u0037\u65E5',
  20252. '\u33FB': '\u0032\u0038\u65E5',
  20253. '\u33FC': '\u0032\u0039\u65E5',
  20254. '\u33FD': '\u0033\u0030\u65E5',
  20255. '\u33FE': '\u0033\u0031\u65E5',
  20256. '\uFB00': '\u0066\u0066',
  20257. '\uFB01': '\u0066\u0069',
  20258. '\uFB02': '\u0066\u006C',
  20259. '\uFB03': '\u0066\u0066\u0069',
  20260. '\uFB04': '\u0066\u0066\u006C',
  20261. '\uFB05': '\u017F\u0074',
  20262. '\uFB06': '\u0073\u0074',
  20263. '\uFB13': '\u0574\u0576',
  20264. '\uFB14': '\u0574\u0565',
  20265. '\uFB15': '\u0574\u056B',
  20266. '\uFB16': '\u057E\u0576',
  20267. '\uFB17': '\u0574\u056D',
  20268. '\uFB4F': '\u05D0\u05DC',
  20269. '\uFB50': '\u0671',
  20270. '\uFB51': '\u0671',
  20271. '\uFB52': '\u067B',
  20272. '\uFB53': '\u067B',
  20273. '\uFB54': '\u067B',
  20274. '\uFB55': '\u067B',
  20275. '\uFB56': '\u067E',
  20276. '\uFB57': '\u067E',
  20277. '\uFB58': '\u067E',
  20278. '\uFB59': '\u067E',
  20279. '\uFB5A': '\u0680',
  20280. '\uFB5B': '\u0680',
  20281. '\uFB5C': '\u0680',
  20282. '\uFB5D': '\u0680',
  20283. '\uFB5E': '\u067A',
  20284. '\uFB5F': '\u067A',
  20285. '\uFB60': '\u067A',
  20286. '\uFB61': '\u067A',
  20287. '\uFB62': '\u067F',
  20288. '\uFB63': '\u067F',
  20289. '\uFB64': '\u067F',
  20290. '\uFB65': '\u067F',
  20291. '\uFB66': '\u0679',
  20292. '\uFB67': '\u0679',
  20293. '\uFB68': '\u0679',
  20294. '\uFB69': '\u0679',
  20295. '\uFB6A': '\u06A4',
  20296. '\uFB6B': '\u06A4',
  20297. '\uFB6C': '\u06A4',
  20298. '\uFB6D': '\u06A4',
  20299. '\uFB6E': '\u06A6',
  20300. '\uFB6F': '\u06A6',
  20301. '\uFB70': '\u06A6',
  20302. '\uFB71': '\u06A6',
  20303. '\uFB72': '\u0684',
  20304. '\uFB73': '\u0684',
  20305. '\uFB74': '\u0684',
  20306. '\uFB75': '\u0684',
  20307. '\uFB76': '\u0683',
  20308. '\uFB77': '\u0683',
  20309. '\uFB78': '\u0683',
  20310. '\uFB79': '\u0683',
  20311. '\uFB7A': '\u0686',
  20312. '\uFB7B': '\u0686',
  20313. '\uFB7C': '\u0686',
  20314. '\uFB7D': '\u0686',
  20315. '\uFB7E': '\u0687',
  20316. '\uFB7F': '\u0687',
  20317. '\uFB80': '\u0687',
  20318. '\uFB81': '\u0687',
  20319. '\uFB82': '\u068D',
  20320. '\uFB83': '\u068D',
  20321. '\uFB84': '\u068C',
  20322. '\uFB85': '\u068C',
  20323. '\uFB86': '\u068E',
  20324. '\uFB87': '\u068E',
  20325. '\uFB88': '\u0688',
  20326. '\uFB89': '\u0688',
  20327. '\uFB8A': '\u0698',
  20328. '\uFB8B': '\u0698',
  20329. '\uFB8C': '\u0691',
  20330. '\uFB8D': '\u0691',
  20331. '\uFB8E': '\u06A9',
  20332. '\uFB8F': '\u06A9',
  20333. '\uFB90': '\u06A9',
  20334. '\uFB91': '\u06A9',
  20335. '\uFB92': '\u06AF',
  20336. '\uFB93': '\u06AF',
  20337. '\uFB94': '\u06AF',
  20338. '\uFB95': '\u06AF',
  20339. '\uFB96': '\u06B3',
  20340. '\uFB97': '\u06B3',
  20341. '\uFB98': '\u06B3',
  20342. '\uFB99': '\u06B3',
  20343. '\uFB9A': '\u06B1',
  20344. '\uFB9B': '\u06B1',
  20345. '\uFB9C': '\u06B1',
  20346. '\uFB9D': '\u06B1',
  20347. '\uFB9E': '\u06BA',
  20348. '\uFB9F': '\u06BA',
  20349. '\uFBA0': '\u06BB',
  20350. '\uFBA1': '\u06BB',
  20351. '\uFBA2': '\u06BB',
  20352. '\uFBA3': '\u06BB',
  20353. '\uFBA4': '\u06C0',
  20354. '\uFBA5': '\u06C0',
  20355. '\uFBA6': '\u06C1',
  20356. '\uFBA7': '\u06C1',
  20357. '\uFBA8': '\u06C1',
  20358. '\uFBA9': '\u06C1',
  20359. '\uFBAA': '\u06BE',
  20360. '\uFBAB': '\u06BE',
  20361. '\uFBAC': '\u06BE',
  20362. '\uFBAD': '\u06BE',
  20363. '\uFBAE': '\u06D2',
  20364. '\uFBAF': '\u06D2',
  20365. '\uFBB0': '\u06D3',
  20366. '\uFBB1': '\u06D3',
  20367. '\uFBD3': '\u06AD',
  20368. '\uFBD4': '\u06AD',
  20369. '\uFBD5': '\u06AD',
  20370. '\uFBD6': '\u06AD',
  20371. '\uFBD7': '\u06C7',
  20372. '\uFBD8': '\u06C7',
  20373. '\uFBD9': '\u06C6',
  20374. '\uFBDA': '\u06C6',
  20375. '\uFBDB': '\u06C8',
  20376. '\uFBDC': '\u06C8',
  20377. '\uFBDD': '\u0677',
  20378. '\uFBDE': '\u06CB',
  20379. '\uFBDF': '\u06CB',
  20380. '\uFBE0': '\u06C5',
  20381. '\uFBE1': '\u06C5',
  20382. '\uFBE2': '\u06C9',
  20383. '\uFBE3': '\u06C9',
  20384. '\uFBE4': '\u06D0',
  20385. '\uFBE5': '\u06D0',
  20386. '\uFBE6': '\u06D0',
  20387. '\uFBE7': '\u06D0',
  20388. '\uFBE8': '\u0649',
  20389. '\uFBE9': '\u0649',
  20390. '\uFBEA': '\u0626\u0627',
  20391. '\uFBEB': '\u0626\u0627',
  20392. '\uFBEC': '\u0626\u06D5',
  20393. '\uFBED': '\u0626\u06D5',
  20394. '\uFBEE': '\u0626\u0648',
  20395. '\uFBEF': '\u0626\u0648',
  20396. '\uFBF0': '\u0626\u06C7',
  20397. '\uFBF1': '\u0626\u06C7',
  20398. '\uFBF2': '\u0626\u06C6',
  20399. '\uFBF3': '\u0626\u06C6',
  20400. '\uFBF4': '\u0626\u06C8',
  20401. '\uFBF5': '\u0626\u06C8',
  20402. '\uFBF6': '\u0626\u06D0',
  20403. '\uFBF7': '\u0626\u06D0',
  20404. '\uFBF8': '\u0626\u06D0',
  20405. '\uFBF9': '\u0626\u0649',
  20406. '\uFBFA': '\u0626\u0649',
  20407. '\uFBFB': '\u0626\u0649',
  20408. '\uFBFC': '\u06CC',
  20409. '\uFBFD': '\u06CC',
  20410. '\uFBFE': '\u06CC',
  20411. '\uFBFF': '\u06CC',
  20412. '\uFC00': '\u0626\u062C',
  20413. '\uFC01': '\u0626\u062D',
  20414. '\uFC02': '\u0626\u0645',
  20415. '\uFC03': '\u0626\u0649',
  20416. '\uFC04': '\u0626\u064A',
  20417. '\uFC05': '\u0628\u062C',
  20418. '\uFC06': '\u0628\u062D',
  20419. '\uFC07': '\u0628\u062E',
  20420. '\uFC08': '\u0628\u0645',
  20421. '\uFC09': '\u0628\u0649',
  20422. '\uFC0A': '\u0628\u064A',
  20423. '\uFC0B': '\u062A\u062C',
  20424. '\uFC0C': '\u062A\u062D',
  20425. '\uFC0D': '\u062A\u062E',
  20426. '\uFC0E': '\u062A\u0645',
  20427. '\uFC0F': '\u062A\u0649',
  20428. '\uFC10': '\u062A\u064A',
  20429. '\uFC11': '\u062B\u062C',
  20430. '\uFC12': '\u062B\u0645',
  20431. '\uFC13': '\u062B\u0649',
  20432. '\uFC14': '\u062B\u064A',
  20433. '\uFC15': '\u062C\u062D',
  20434. '\uFC16': '\u062C\u0645',
  20435. '\uFC17': '\u062D\u062C',
  20436. '\uFC18': '\u062D\u0645',
  20437. '\uFC19': '\u062E\u062C',
  20438. '\uFC1A': '\u062E\u062D',
  20439. '\uFC1B': '\u062E\u0645',
  20440. '\uFC1C': '\u0633\u062C',
  20441. '\uFC1D': '\u0633\u062D',
  20442. '\uFC1E': '\u0633\u062E',
  20443. '\uFC1F': '\u0633\u0645',
  20444. '\uFC20': '\u0635\u062D',
  20445. '\uFC21': '\u0635\u0645',
  20446. '\uFC22': '\u0636\u062C',
  20447. '\uFC23': '\u0636\u062D',
  20448. '\uFC24': '\u0636\u062E',
  20449. '\uFC25': '\u0636\u0645',
  20450. '\uFC26': '\u0637\u062D',
  20451. '\uFC27': '\u0637\u0645',
  20452. '\uFC28': '\u0638\u0645',
  20453. '\uFC29': '\u0639\u062C',
  20454. '\uFC2A': '\u0639\u0645',
  20455. '\uFC2B': '\u063A\u062C',
  20456. '\uFC2C': '\u063A\u0645',
  20457. '\uFC2D': '\u0641\u062C',
  20458. '\uFC2E': '\u0641\u062D',
  20459. '\uFC2F': '\u0641\u062E',
  20460. '\uFC30': '\u0641\u0645',
  20461. '\uFC31': '\u0641\u0649',
  20462. '\uFC32': '\u0641\u064A',
  20463. '\uFC33': '\u0642\u062D',
  20464. '\uFC34': '\u0642\u0645',
  20465. '\uFC35': '\u0642\u0649',
  20466. '\uFC36': '\u0642\u064A',
  20467. '\uFC37': '\u0643\u0627',
  20468. '\uFC38': '\u0643\u062C',
  20469. '\uFC39': '\u0643\u062D',
  20470. '\uFC3A': '\u0643\u062E',
  20471. '\uFC3B': '\u0643\u0644',
  20472. '\uFC3C': '\u0643\u0645',
  20473. '\uFC3D': '\u0643\u0649',
  20474. '\uFC3E': '\u0643\u064A',
  20475. '\uFC3F': '\u0644\u062C',
  20476. '\uFC40': '\u0644\u062D',
  20477. '\uFC41': '\u0644\u062E',
  20478. '\uFC42': '\u0644\u0645',
  20479. '\uFC43': '\u0644\u0649',
  20480. '\uFC44': '\u0644\u064A',
  20481. '\uFC45': '\u0645\u062C',
  20482. '\uFC46': '\u0645\u062D',
  20483. '\uFC47': '\u0645\u062E',
  20484. '\uFC48': '\u0645\u0645',
  20485. '\uFC49': '\u0645\u0649',
  20486. '\uFC4A': '\u0645\u064A',
  20487. '\uFC4B': '\u0646\u062C',
  20488. '\uFC4C': '\u0646\u062D',
  20489. '\uFC4D': '\u0646\u062E',
  20490. '\uFC4E': '\u0646\u0645',
  20491. '\uFC4F': '\u0646\u0649',
  20492. '\uFC50': '\u0646\u064A',
  20493. '\uFC51': '\u0647\u062C',
  20494. '\uFC52': '\u0647\u0645',
  20495. '\uFC53': '\u0647\u0649',
  20496. '\uFC54': '\u0647\u064A',
  20497. '\uFC55': '\u064A\u062C',
  20498. '\uFC56': '\u064A\u062D',
  20499. '\uFC57': '\u064A\u062E',
  20500. '\uFC58': '\u064A\u0645',
  20501. '\uFC59': '\u064A\u0649',
  20502. '\uFC5A': '\u064A\u064A',
  20503. '\uFC5B': '\u0630\u0670',
  20504. '\uFC5C': '\u0631\u0670',
  20505. '\uFC5D': '\u0649\u0670',
  20506. '\uFC5E': '\u0020\u064C\u0651',
  20507. '\uFC5F': '\u0020\u064D\u0651',
  20508. '\uFC60': '\u0020\u064E\u0651',
  20509. '\uFC61': '\u0020\u064F\u0651',
  20510. '\uFC62': '\u0020\u0650\u0651',
  20511. '\uFC63': '\u0020\u0651\u0670',
  20512. '\uFC64': '\u0626\u0631',
  20513. '\uFC65': '\u0626\u0632',
  20514. '\uFC66': '\u0626\u0645',
  20515. '\uFC67': '\u0626\u0646',
  20516. '\uFC68': '\u0626\u0649',
  20517. '\uFC69': '\u0626\u064A',
  20518. '\uFC6A': '\u0628\u0631',
  20519. '\uFC6B': '\u0628\u0632',
  20520. '\uFC6C': '\u0628\u0645',
  20521. '\uFC6D': '\u0628\u0646',
  20522. '\uFC6E': '\u0628\u0649',
  20523. '\uFC6F': '\u0628\u064A',
  20524. '\uFC70': '\u062A\u0631',
  20525. '\uFC71': '\u062A\u0632',
  20526. '\uFC72': '\u062A\u0645',
  20527. '\uFC73': '\u062A\u0646',
  20528. '\uFC74': '\u062A\u0649',
  20529. '\uFC75': '\u062A\u064A',
  20530. '\uFC76': '\u062B\u0631',
  20531. '\uFC77': '\u062B\u0632',
  20532. '\uFC78': '\u062B\u0645',
  20533. '\uFC79': '\u062B\u0646',
  20534. '\uFC7A': '\u062B\u0649',
  20535. '\uFC7B': '\u062B\u064A',
  20536. '\uFC7C': '\u0641\u0649',
  20537. '\uFC7D': '\u0641\u064A',
  20538. '\uFC7E': '\u0642\u0649',
  20539. '\uFC7F': '\u0642\u064A',
  20540. '\uFC80': '\u0643\u0627',
  20541. '\uFC81': '\u0643\u0644',
  20542. '\uFC82': '\u0643\u0645',
  20543. '\uFC83': '\u0643\u0649',
  20544. '\uFC84': '\u0643\u064A',
  20545. '\uFC85': '\u0644\u0645',
  20546. '\uFC86': '\u0644\u0649',
  20547. '\uFC87': '\u0644\u064A',
  20548. '\uFC88': '\u0645\u0627',
  20549. '\uFC89': '\u0645\u0645',
  20550. '\uFC8A': '\u0646\u0631',
  20551. '\uFC8B': '\u0646\u0632',
  20552. '\uFC8C': '\u0646\u0645',
  20553. '\uFC8D': '\u0646\u0646',
  20554. '\uFC8E': '\u0646\u0649',
  20555. '\uFC8F': '\u0646\u064A',
  20556. '\uFC90': '\u0649\u0670',
  20557. '\uFC91': '\u064A\u0631',
  20558. '\uFC92': '\u064A\u0632',
  20559. '\uFC93': '\u064A\u0645',
  20560. '\uFC94': '\u064A\u0646',
  20561. '\uFC95': '\u064A\u0649',
  20562. '\uFC96': '\u064A\u064A',
  20563. '\uFC97': '\u0626\u062C',
  20564. '\uFC98': '\u0626\u062D',
  20565. '\uFC99': '\u0626\u062E',
  20566. '\uFC9A': '\u0626\u0645',
  20567. '\uFC9B': '\u0626\u0647',
  20568. '\uFC9C': '\u0628\u062C',
  20569. '\uFC9D': '\u0628\u062D',
  20570. '\uFC9E': '\u0628\u062E',
  20571. '\uFC9F': '\u0628\u0645',
  20572. '\uFCA0': '\u0628\u0647',
  20573. '\uFCA1': '\u062A\u062C',
  20574. '\uFCA2': '\u062A\u062D',
  20575. '\uFCA3': '\u062A\u062E',
  20576. '\uFCA4': '\u062A\u0645',
  20577. '\uFCA5': '\u062A\u0647',
  20578. '\uFCA6': '\u062B\u0645',
  20579. '\uFCA7': '\u062C\u062D',
  20580. '\uFCA8': '\u062C\u0645',
  20581. '\uFCA9': '\u062D\u062C',
  20582. '\uFCAA': '\u062D\u0645',
  20583. '\uFCAB': '\u062E\u062C',
  20584. '\uFCAC': '\u062E\u0645',
  20585. '\uFCAD': '\u0633\u062C',
  20586. '\uFCAE': '\u0633\u062D',
  20587. '\uFCAF': '\u0633\u062E',
  20588. '\uFCB0': '\u0633\u0645',
  20589. '\uFCB1': '\u0635\u062D',
  20590. '\uFCB2': '\u0635\u062E',
  20591. '\uFCB3': '\u0635\u0645',
  20592. '\uFCB4': '\u0636\u062C',
  20593. '\uFCB5': '\u0636\u062D',
  20594. '\uFCB6': '\u0636\u062E',
  20595. '\uFCB7': '\u0636\u0645',
  20596. '\uFCB8': '\u0637\u062D',
  20597. '\uFCB9': '\u0638\u0645',
  20598. '\uFCBA': '\u0639\u062C',
  20599. '\uFCBB': '\u0639\u0645',
  20600. '\uFCBC': '\u063A\u062C',
  20601. '\uFCBD': '\u063A\u0645',
  20602. '\uFCBE': '\u0641\u062C',
  20603. '\uFCBF': '\u0641\u062D',
  20604. '\uFCC0': '\u0641\u062E',
  20605. '\uFCC1': '\u0641\u0645',
  20606. '\uFCC2': '\u0642\u062D',
  20607. '\uFCC3': '\u0642\u0645',
  20608. '\uFCC4': '\u0643\u062C',
  20609. '\uFCC5': '\u0643\u062D',
  20610. '\uFCC6': '\u0643\u062E',
  20611. '\uFCC7': '\u0643\u0644',
  20612. '\uFCC8': '\u0643\u0645',
  20613. '\uFCC9': '\u0644\u062C',
  20614. '\uFCCA': '\u0644\u062D',
  20615. '\uFCCB': '\u0644\u062E',
  20616. '\uFCCC': '\u0644\u0645',
  20617. '\uFCCD': '\u0644\u0647',
  20618. '\uFCCE': '\u0645\u062C',
  20619. '\uFCCF': '\u0645\u062D',
  20620. '\uFCD0': '\u0645\u062E',
  20621. '\uFCD1': '\u0645\u0645',
  20622. '\uFCD2': '\u0646\u062C',
  20623. '\uFCD3': '\u0646\u062D',
  20624. '\uFCD4': '\u0646\u062E',
  20625. '\uFCD5': '\u0646\u0645',
  20626. '\uFCD6': '\u0646\u0647',
  20627. '\uFCD7': '\u0647\u062C',
  20628. '\uFCD8': '\u0647\u0645',
  20629. '\uFCD9': '\u0647\u0670',
  20630. '\uFCDA': '\u064A\u062C',
  20631. '\uFCDB': '\u064A\u062D',
  20632. '\uFCDC': '\u064A\u062E',
  20633. '\uFCDD': '\u064A\u0645',
  20634. '\uFCDE': '\u064A\u0647',
  20635. '\uFCDF': '\u0626\u0645',
  20636. '\uFCE0': '\u0626\u0647',
  20637. '\uFCE1': '\u0628\u0645',
  20638. '\uFCE2': '\u0628\u0647',
  20639. '\uFCE3': '\u062A\u0645',
  20640. '\uFCE4': '\u062A\u0647',
  20641. '\uFCE5': '\u062B\u0645',
  20642. '\uFCE6': '\u062B\u0647',
  20643. '\uFCE7': '\u0633\u0645',
  20644. '\uFCE8': '\u0633\u0647',
  20645. '\uFCE9': '\u0634\u0645',
  20646. '\uFCEA': '\u0634\u0647',
  20647. '\uFCEB': '\u0643\u0644',
  20648. '\uFCEC': '\u0643\u0645',
  20649. '\uFCED': '\u0644\u0645',
  20650. '\uFCEE': '\u0646\u0645',
  20651. '\uFCEF': '\u0646\u0647',
  20652. '\uFCF0': '\u064A\u0645',
  20653. '\uFCF1': '\u064A\u0647',
  20654. '\uFCF2': '\u0640\u064E\u0651',
  20655. '\uFCF3': '\u0640\u064F\u0651',
  20656. '\uFCF4': '\u0640\u0650\u0651',
  20657. '\uFCF5': '\u0637\u0649',
  20658. '\uFCF6': '\u0637\u064A',
  20659. '\uFCF7': '\u0639\u0649',
  20660. '\uFCF8': '\u0639\u064A',
  20661. '\uFCF9': '\u063A\u0649',
  20662. '\uFCFA': '\u063A\u064A',
  20663. '\uFCFB': '\u0633\u0649',
  20664. '\uFCFC': '\u0633\u064A',
  20665. '\uFCFD': '\u0634\u0649',
  20666. '\uFCFE': '\u0634\u064A',
  20667. '\uFCFF': '\u062D\u0649',
  20668. '\uFD00': '\u062D\u064A',
  20669. '\uFD01': '\u062C\u0649',
  20670. '\uFD02': '\u062C\u064A',
  20671. '\uFD03': '\u062E\u0649',
  20672. '\uFD04': '\u062E\u064A',
  20673. '\uFD05': '\u0635\u0649',
  20674. '\uFD06': '\u0635\u064A',
  20675. '\uFD07': '\u0636\u0649',
  20676. '\uFD08': '\u0636\u064A',
  20677. '\uFD09': '\u0634\u062C',
  20678. '\uFD0A': '\u0634\u062D',
  20679. '\uFD0B': '\u0634\u062E',
  20680. '\uFD0C': '\u0634\u0645',
  20681. '\uFD0D': '\u0634\u0631',
  20682. '\uFD0E': '\u0633\u0631',
  20683. '\uFD0F': '\u0635\u0631',
  20684. '\uFD10': '\u0636\u0631',
  20685. '\uFD11': '\u0637\u0649',
  20686. '\uFD12': '\u0637\u064A',
  20687. '\uFD13': '\u0639\u0649',
  20688. '\uFD14': '\u0639\u064A',
  20689. '\uFD15': '\u063A\u0649',
  20690. '\uFD16': '\u063A\u064A',
  20691. '\uFD17': '\u0633\u0649',
  20692. '\uFD18': '\u0633\u064A',
  20693. '\uFD19': '\u0634\u0649',
  20694. '\uFD1A': '\u0634\u064A',
  20695. '\uFD1B': '\u062D\u0649',
  20696. '\uFD1C': '\u062D\u064A',
  20697. '\uFD1D': '\u062C\u0649',
  20698. '\uFD1E': '\u062C\u064A',
  20699. '\uFD1F': '\u062E\u0649',
  20700. '\uFD20': '\u062E\u064A',
  20701. '\uFD21': '\u0635\u0649',
  20702. '\uFD22': '\u0635\u064A',
  20703. '\uFD23': '\u0636\u0649',
  20704. '\uFD24': '\u0636\u064A',
  20705. '\uFD25': '\u0634\u062C',
  20706. '\uFD26': '\u0634\u062D',
  20707. '\uFD27': '\u0634\u062E',
  20708. '\uFD28': '\u0634\u0645',
  20709. '\uFD29': '\u0634\u0631',
  20710. '\uFD2A': '\u0633\u0631',
  20711. '\uFD2B': '\u0635\u0631',
  20712. '\uFD2C': '\u0636\u0631',
  20713. '\uFD2D': '\u0634\u062C',
  20714. '\uFD2E': '\u0634\u062D',
  20715. '\uFD2F': '\u0634\u062E',
  20716. '\uFD30': '\u0634\u0645',
  20717. '\uFD31': '\u0633\u0647',
  20718. '\uFD32': '\u0634\u0647',
  20719. '\uFD33': '\u0637\u0645',
  20720. '\uFD34': '\u0633\u062C',
  20721. '\uFD35': '\u0633\u062D',
  20722. '\uFD36': '\u0633\u062E',
  20723. '\uFD37': '\u0634\u062C',
  20724. '\uFD38': '\u0634\u062D',
  20725. '\uFD39': '\u0634\u062E',
  20726. '\uFD3A': '\u0637\u0645',
  20727. '\uFD3B': '\u0638\u0645',
  20728. '\uFD3C': '\u0627\u064B',
  20729. '\uFD3D': '\u0627\u064B',
  20730. '\uFD50': '\u062A\u062C\u0645',
  20731. '\uFD51': '\u062A\u062D\u062C',
  20732. '\uFD52': '\u062A\u062D\u062C',
  20733. '\uFD53': '\u062A\u062D\u0645',
  20734. '\uFD54': '\u062A\u062E\u0645',
  20735. '\uFD55': '\u062A\u0645\u062C',
  20736. '\uFD56': '\u062A\u0645\u062D',
  20737. '\uFD57': '\u062A\u0645\u062E',
  20738. '\uFD58': '\u062C\u0645\u062D',
  20739. '\uFD59': '\u062C\u0645\u062D',
  20740. '\uFD5A': '\u062D\u0645\u064A',
  20741. '\uFD5B': '\u062D\u0645\u0649',
  20742. '\uFD5C': '\u0633\u062D\u062C',
  20743. '\uFD5D': '\u0633\u062C\u062D',
  20744. '\uFD5E': '\u0633\u062C\u0649',
  20745. '\uFD5F': '\u0633\u0645\u062D',
  20746. '\uFD60': '\u0633\u0645\u062D',
  20747. '\uFD61': '\u0633\u0645\u062C',
  20748. '\uFD62': '\u0633\u0645\u0645',
  20749. '\uFD63': '\u0633\u0645\u0645',
  20750. '\uFD64': '\u0635\u062D\u062D',
  20751. '\uFD65': '\u0635\u062D\u062D',
  20752. '\uFD66': '\u0635\u0645\u0645',
  20753. '\uFD67': '\u0634\u062D\u0645',
  20754. '\uFD68': '\u0634\u062D\u0645',
  20755. '\uFD69': '\u0634\u062C\u064A',
  20756. '\uFD6A': '\u0634\u0645\u062E',
  20757. '\uFD6B': '\u0634\u0645\u062E',
  20758. '\uFD6C': '\u0634\u0645\u0645',
  20759. '\uFD6D': '\u0634\u0645\u0645',
  20760. '\uFD6E': '\u0636\u062D\u0649',
  20761. '\uFD6F': '\u0636\u062E\u0645',
  20762. '\uFD70': '\u0636\u062E\u0645',
  20763. '\uFD71': '\u0637\u0645\u062D',
  20764. '\uFD72': '\u0637\u0645\u062D',
  20765. '\uFD73': '\u0637\u0645\u0645',
  20766. '\uFD74': '\u0637\u0645\u064A',
  20767. '\uFD75': '\u0639\u062C\u0645',
  20768. '\uFD76': '\u0639\u0645\u0645',
  20769. '\uFD77': '\u0639\u0645\u0645',
  20770. '\uFD78': '\u0639\u0645\u0649',
  20771. '\uFD79': '\u063A\u0645\u0645',
  20772. '\uFD7A': '\u063A\u0645\u064A',
  20773. '\uFD7B': '\u063A\u0645\u0649',
  20774. '\uFD7C': '\u0641\u062E\u0645',
  20775. '\uFD7D': '\u0641\u062E\u0645',
  20776. '\uFD7E': '\u0642\u0645\u062D',
  20777. '\uFD7F': '\u0642\u0645\u0645',
  20778. '\uFD80': '\u0644\u062D\u0645',
  20779. '\uFD81': '\u0644\u062D\u064A',
  20780. '\uFD82': '\u0644\u062D\u0649',
  20781. '\uFD83': '\u0644\u062C\u062C',
  20782. '\uFD84': '\u0644\u062C\u062C',
  20783. '\uFD85': '\u0644\u062E\u0645',
  20784. '\uFD86': '\u0644\u062E\u0645',
  20785. '\uFD87': '\u0644\u0645\u062D',
  20786. '\uFD88': '\u0644\u0645\u062D',
  20787. '\uFD89': '\u0645\u062D\u062C',
  20788. '\uFD8A': '\u0645\u062D\u0645',
  20789. '\uFD8B': '\u0645\u062D\u064A',
  20790. '\uFD8C': '\u0645\u062C\u062D',
  20791. '\uFD8D': '\u0645\u062C\u0645',
  20792. '\uFD8E': '\u0645\u062E\u062C',
  20793. '\uFD8F': '\u0645\u062E\u0645',
  20794. '\uFD92': '\u0645\u062C\u062E',
  20795. '\uFD93': '\u0647\u0645\u062C',
  20796. '\uFD94': '\u0647\u0645\u0645',
  20797. '\uFD95': '\u0646\u062D\u0645',
  20798. '\uFD96': '\u0646\u062D\u0649',
  20799. '\uFD97': '\u0646\u062C\u0645',
  20800. '\uFD98': '\u0646\u062C\u0645',
  20801. '\uFD99': '\u0646\u062C\u0649',
  20802. '\uFD9A': '\u0646\u0645\u064A',
  20803. '\uFD9B': '\u0646\u0645\u0649',
  20804. '\uFD9C': '\u064A\u0645\u0645',
  20805. '\uFD9D': '\u064A\u0645\u0645',
  20806. '\uFD9E': '\u0628\u062E\u064A',
  20807. '\uFD9F': '\u062A\u062C\u064A',
  20808. '\uFDA0': '\u062A\u062C\u0649',
  20809. '\uFDA1': '\u062A\u062E\u064A',
  20810. '\uFDA2': '\u062A\u062E\u0649',
  20811. '\uFDA3': '\u062A\u0645\u064A',
  20812. '\uFDA4': '\u062A\u0645\u0649',
  20813. '\uFDA5': '\u062C\u0645\u064A',
  20814. '\uFDA6': '\u062C\u062D\u0649',
  20815. '\uFDA7': '\u062C\u0645\u0649',
  20816. '\uFDA8': '\u0633\u062E\u0649',
  20817. '\uFDA9': '\u0635\u062D\u064A',
  20818. '\uFDAA': '\u0634\u062D\u064A',
  20819. '\uFDAB': '\u0636\u062D\u064A',
  20820. '\uFDAC': '\u0644\u062C\u064A',
  20821. '\uFDAD': '\u0644\u0645\u064A',
  20822. '\uFDAE': '\u064A\u062D\u064A',
  20823. '\uFDAF': '\u064A\u062C\u064A',
  20824. '\uFDB0': '\u064A\u0645\u064A',
  20825. '\uFDB1': '\u0645\u0645\u064A',
  20826. '\uFDB2': '\u0642\u0645\u064A',
  20827. '\uFDB3': '\u0646\u062D\u064A',
  20828. '\uFDB4': '\u0642\u0645\u062D',
  20829. '\uFDB5': '\u0644\u062D\u0645',
  20830. '\uFDB6': '\u0639\u0645\u064A',
  20831. '\uFDB7': '\u0643\u0645\u064A',
  20832. '\uFDB8': '\u0646\u062C\u062D',
  20833. '\uFDB9': '\u0645\u062E\u064A',
  20834. '\uFDBA': '\u0644\u062C\u0645',
  20835. '\uFDBB': '\u0643\u0645\u0645',
  20836. '\uFDBC': '\u0644\u062C\u0645',
  20837. '\uFDBD': '\u0646\u062C\u062D',
  20838. '\uFDBE': '\u062C\u062D\u064A',
  20839. '\uFDBF': '\u062D\u062C\u064A',
  20840. '\uFDC0': '\u0645\u062C\u064A',
  20841. '\uFDC1': '\u0641\u0645\u064A',
  20842. '\uFDC2': '\u0628\u062D\u064A',
  20843. '\uFDC3': '\u0643\u0645\u0645',
  20844. '\uFDC4': '\u0639\u062C\u0645',
  20845. '\uFDC5': '\u0635\u0645\u0645',
  20846. '\uFDC6': '\u0633\u062E\u064A',
  20847. '\uFDC7': '\u0646\u062C\u064A',
  20848. '\uFE49': '\u203E',
  20849. '\uFE4A': '\u203E',
  20850. '\uFE4B': '\u203E',
  20851. '\uFE4C': '\u203E',
  20852. '\uFE4D': '\u005F',
  20853. '\uFE4E': '\u005F',
  20854. '\uFE4F': '\u005F',
  20855. '\uFE80': '\u0621',
  20856. '\uFE81': '\u0622',
  20857. '\uFE82': '\u0622',
  20858. '\uFE83': '\u0623',
  20859. '\uFE84': '\u0623',
  20860. '\uFE85': '\u0624',
  20861. '\uFE86': '\u0624',
  20862. '\uFE87': '\u0625',
  20863. '\uFE88': '\u0625',
  20864. '\uFE89': '\u0626',
  20865. '\uFE8A': '\u0626',
  20866. '\uFE8B': '\u0626',
  20867. '\uFE8C': '\u0626',
  20868. '\uFE8D': '\u0627',
  20869. '\uFE8E': '\u0627',
  20870. '\uFE8F': '\u0628',
  20871. '\uFE90': '\u0628',
  20872. '\uFE91': '\u0628',
  20873. '\uFE92': '\u0628',
  20874. '\uFE93': '\u0629',
  20875. '\uFE94': '\u0629',
  20876. '\uFE95': '\u062A',
  20877. '\uFE96': '\u062A',
  20878. '\uFE97': '\u062A',
  20879. '\uFE98': '\u062A',
  20880. '\uFE99': '\u062B',
  20881. '\uFE9A': '\u062B',
  20882. '\uFE9B': '\u062B',
  20883. '\uFE9C': '\u062B',
  20884. '\uFE9D': '\u062C',
  20885. '\uFE9E': '\u062C',
  20886. '\uFE9F': '\u062C',
  20887. '\uFEA0': '\u062C',
  20888. '\uFEA1': '\u062D',
  20889. '\uFEA2': '\u062D',
  20890. '\uFEA3': '\u062D',
  20891. '\uFEA4': '\u062D',
  20892. '\uFEA5': '\u062E',
  20893. '\uFEA6': '\u062E',
  20894. '\uFEA7': '\u062E',
  20895. '\uFEA8': '\u062E',
  20896. '\uFEA9': '\u062F',
  20897. '\uFEAA': '\u062F',
  20898. '\uFEAB': '\u0630',
  20899. '\uFEAC': '\u0630',
  20900. '\uFEAD': '\u0631',
  20901. '\uFEAE': '\u0631',
  20902. '\uFEAF': '\u0632',
  20903. '\uFEB0': '\u0632',
  20904. '\uFEB1': '\u0633',
  20905. '\uFEB2': '\u0633',
  20906. '\uFEB3': '\u0633',
  20907. '\uFEB4': '\u0633',
  20908. '\uFEB5': '\u0634',
  20909. '\uFEB6': '\u0634',
  20910. '\uFEB7': '\u0634',
  20911. '\uFEB8': '\u0634',
  20912. '\uFEB9': '\u0635',
  20913. '\uFEBA': '\u0635',
  20914. '\uFEBB': '\u0635',
  20915. '\uFEBC': '\u0635',
  20916. '\uFEBD': '\u0636',
  20917. '\uFEBE': '\u0636',
  20918. '\uFEBF': '\u0636',
  20919. '\uFEC0': '\u0636',
  20920. '\uFEC1': '\u0637',
  20921. '\uFEC2': '\u0637',
  20922. '\uFEC3': '\u0637',
  20923. '\uFEC4': '\u0637',
  20924. '\uFEC5': '\u0638',
  20925. '\uFEC6': '\u0638',
  20926. '\uFEC7': '\u0638',
  20927. '\uFEC8': '\u0638',
  20928. '\uFEC9': '\u0639',
  20929. '\uFECA': '\u0639',
  20930. '\uFECB': '\u0639',
  20931. '\uFECC': '\u0639',
  20932. '\uFECD': '\u063A',
  20933. '\uFECE': '\u063A',
  20934. '\uFECF': '\u063A',
  20935. '\uFED0': '\u063A',
  20936. '\uFED1': '\u0641',
  20937. '\uFED2': '\u0641',
  20938. '\uFED3': '\u0641',
  20939. '\uFED4': '\u0641',
  20940. '\uFED5': '\u0642',
  20941. '\uFED6': '\u0642',
  20942. '\uFED7': '\u0642',
  20943. '\uFED8': '\u0642',
  20944. '\uFED9': '\u0643',
  20945. '\uFEDA': '\u0643',
  20946. '\uFEDB': '\u0643',
  20947. '\uFEDC': '\u0643',
  20948. '\uFEDD': '\u0644',
  20949. '\uFEDE': '\u0644',
  20950. '\uFEDF': '\u0644',
  20951. '\uFEE0': '\u0644',
  20952. '\uFEE1': '\u0645',
  20953. '\uFEE2': '\u0645',
  20954. '\uFEE3': '\u0645',
  20955. '\uFEE4': '\u0645',
  20956. '\uFEE5': '\u0646',
  20957. '\uFEE6': '\u0646',
  20958. '\uFEE7': '\u0646',
  20959. '\uFEE8': '\u0646',
  20960. '\uFEE9': '\u0647',
  20961. '\uFEEA': '\u0647',
  20962. '\uFEEB': '\u0647',
  20963. '\uFEEC': '\u0647',
  20964. '\uFEED': '\u0648',
  20965. '\uFEEE': '\u0648',
  20966. '\uFEEF': '\u0649',
  20967. '\uFEF0': '\u0649',
  20968. '\uFEF1': '\u064A',
  20969. '\uFEF2': '\u064A',
  20970. '\uFEF3': '\u064A',
  20971. '\uFEF4': '\u064A',
  20972. '\uFEF5': '\u0644\u0622',
  20973. '\uFEF6': '\u0644\u0622',
  20974. '\uFEF7': '\u0644\u0623',
  20975. '\uFEF8': '\u0644\u0623',
  20976. '\uFEF9': '\u0644\u0625',
  20977. '\uFEFA': '\u0644\u0625',
  20978. '\uFEFB': '\u0644\u0627',
  20979. '\uFEFC': '\u0644\u0627'
  20980. };
  20981. function reverseIfRtl(chars) {
  20982. var charsLength = chars.length;
  20983. //reverse an arabic ligature
  20984. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20985. return chars;
  20986. }
  20987. var s = '';
  20988. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20989. s += chars[ii];
  20990. }
  20991. return s;
  20992. }
  20993. function adjustWidths(properties) {
  20994. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20995. return;
  20996. }
  20997. // adjusting width to fontMatrix scale
  20998. var scale = 0.001 / properties.fontMatrix[0];
  20999. var glyphsWidths = properties.widths;
  21000. for (var glyph in glyphsWidths) {
  21001. glyphsWidths[glyph] *= scale;
  21002. }
  21003. properties.defaultWidth *= scale;
  21004. }
  21005. function getFontType(type, subtype) {
  21006. switch (type) {
  21007. case 'Type1':
  21008. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  21009. case 'CIDFontType0':
  21010. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  21011. FontType.CIDFONTTYPE0;
  21012. case 'OpenType':
  21013. return FontType.OPENTYPE;
  21014. case 'TrueType':
  21015. return FontType.TRUETYPE;
  21016. case 'CIDFontType2':
  21017. return FontType.CIDFONTTYPE2;
  21018. case 'MMType1':
  21019. return FontType.MMTYPE1;
  21020. case 'Type0':
  21021. return FontType.TYPE0;
  21022. default:
  21023. return FontType.UNKNOWN;
  21024. }
  21025. }
  21026. var Glyph = (function GlyphClosure() {
  21027. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  21028. this.fontChar = fontChar;
  21029. this.unicode = unicode;
  21030. this.accent = accent;
  21031. this.width = width;
  21032. this.vmetric = vmetric;
  21033. this.operatorListId = operatorListId;
  21034. }
  21035. Glyph.prototype.matchesForCache =
  21036. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  21037. return this.fontChar === fontChar &&
  21038. this.unicode === unicode &&
  21039. this.accent === accent &&
  21040. this.width === width &&
  21041. this.vmetric === vmetric &&
  21042. this.operatorListId === operatorListId;
  21043. };
  21044. return Glyph;
  21045. })();
  21046. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  21047. function ToUnicodeMap(cmap) {
  21048. // The elements of this._map can be integers or strings, depending on how
  21049. // |cmap| was created.
  21050. this._map = cmap;
  21051. }
  21052. ToUnicodeMap.prototype = {
  21053. get length() {
  21054. return this._map.length;
  21055. },
  21056. forEach: function(callback) {
  21057. for (var charCode in this._map) {
  21058. callback(charCode, this._map[charCode].charCodeAt(0));
  21059. }
  21060. },
  21061. has: function(i) {
  21062. return this._map[i] !== undefined;
  21063. },
  21064. get: function(i) {
  21065. return this._map[i];
  21066. },
  21067. charCodeOf: function(v) {
  21068. return this._map.indexOf(v);
  21069. }
  21070. };
  21071. return ToUnicodeMap;
  21072. })();
  21073. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  21074. function IdentityToUnicodeMap(firstChar, lastChar) {
  21075. this.firstChar = firstChar;
  21076. this.lastChar = lastChar;
  21077. }
  21078. IdentityToUnicodeMap.prototype = {
  21079. get length() {
  21080. return (this.lastChar + 1) - this.firstChar;
  21081. },
  21082. forEach: function (callback) {
  21083. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  21084. callback(i, i);
  21085. }
  21086. },
  21087. has: function (i) {
  21088. return this.firstChar <= i && i <= this.lastChar;
  21089. },
  21090. get: function (i) {
  21091. if (this.firstChar <= i && i <= this.lastChar) {
  21092. return String.fromCharCode(i);
  21093. }
  21094. return undefined;
  21095. },
  21096. charCodeOf: function (v) {
  21097. error('should not call .charCodeOf');
  21098. }
  21099. };
  21100. return IdentityToUnicodeMap;
  21101. })();
  21102. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  21103. function writeInt16(dest, offset, num) {
  21104. dest[offset] = (num >> 8) & 0xFF;
  21105. dest[offset + 1] = num & 0xFF;
  21106. }
  21107. function writeInt32(dest, offset, num) {
  21108. dest[offset] = (num >> 24) & 0xFF;
  21109. dest[offset + 1] = (num >> 16) & 0xFF;
  21110. dest[offset + 2] = (num >> 8) & 0xFF;
  21111. dest[offset + 3] = num & 0xFF;
  21112. }
  21113. function writeData(dest, offset, data) {
  21114. var i, ii;
  21115. if (data instanceof Uint8Array) {
  21116. dest.set(data, offset);
  21117. } else if (typeof data === 'string') {
  21118. for (i = 0, ii = data.length; i < ii; i++) {
  21119. dest[offset++] = data.charCodeAt(i) & 0xFF;
  21120. }
  21121. } else {
  21122. // treating everything else as array
  21123. for (i = 0, ii = data.length; i < ii; i++) {
  21124. dest[offset++] = data[i] & 0xFF;
  21125. }
  21126. }
  21127. }
  21128. function OpenTypeFileBuilder(sfnt) {
  21129. this.sfnt = sfnt;
  21130. this.tables = Object.create(null);
  21131. }
  21132. OpenTypeFileBuilder.getSearchParams =
  21133. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  21134. var maxPower2 = 1, log2 = 0;
  21135. while ((maxPower2 ^ entriesCount) > maxPower2) {
  21136. maxPower2 <<= 1;
  21137. log2++;
  21138. }
  21139. var searchRange = maxPower2 * entrySize;
  21140. return {
  21141. range: searchRange,
  21142. entry: log2,
  21143. rangeShift: entrySize * entriesCount - searchRange
  21144. };
  21145. };
  21146. var OTF_HEADER_SIZE = 12;
  21147. var OTF_TABLE_ENTRY_SIZE = 16;
  21148. OpenTypeFileBuilder.prototype = {
  21149. toArray: function OpenTypeFileBuilder_toArray() {
  21150. var sfnt = this.sfnt;
  21151. // Tables needs to be written by ascendant alphabetic order
  21152. var tables = this.tables;
  21153. var tablesNames = Object.keys(tables);
  21154. tablesNames.sort();
  21155. var numTables = tablesNames.length;
  21156. var i, j, jj, table, tableName;
  21157. // layout the tables data
  21158. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  21159. var tableOffsets = [offset];
  21160. for (i = 0; i < numTables; i++) {
  21161. table = tables[tablesNames[i]];
  21162. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  21163. offset += paddedLength;
  21164. tableOffsets.push(offset);
  21165. }
  21166. var file = new Uint8Array(offset);
  21167. // write the table data first (mostly for checksum)
  21168. for (i = 0; i < numTables; i++) {
  21169. table = tables[tablesNames[i]];
  21170. writeData(file, tableOffsets[i], table);
  21171. }
  21172. // sfnt version (4 bytes)
  21173. if (sfnt === 'true') {
  21174. // Windows hates the Mac TrueType sfnt version number
  21175. sfnt = string32(0x00010000);
  21176. }
  21177. file[0] = sfnt.charCodeAt(0) & 0xFF;
  21178. file[1] = sfnt.charCodeAt(1) & 0xFF;
  21179. file[2] = sfnt.charCodeAt(2) & 0xFF;
  21180. file[3] = sfnt.charCodeAt(3) & 0xFF;
  21181. // numTables (2 bytes)
  21182. writeInt16(file, 4, numTables);
  21183. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  21184. // searchRange (2 bytes)
  21185. writeInt16(file, 6, searchParams.range);
  21186. // entrySelector (2 bytes)
  21187. writeInt16(file, 8, searchParams.entry);
  21188. // rangeShift (2 bytes)
  21189. writeInt16(file, 10, searchParams.rangeShift);
  21190. offset = OTF_HEADER_SIZE;
  21191. // writing table entries
  21192. for (i = 0; i < numTables; i++) {
  21193. tableName = tablesNames[i];
  21194. file[offset] = tableName.charCodeAt(0) & 0xFF;
  21195. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  21196. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  21197. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  21198. // checksum
  21199. var checksum = 0;
  21200. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  21201. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  21202. (file[j + 2] << 8) + file[j + 3];
  21203. checksum = (checksum + quad) | 0;
  21204. }
  21205. writeInt32(file, offset + 4, checksum);
  21206. // offset
  21207. writeInt32(file, offset + 8, tableOffsets[i]);
  21208. // length
  21209. writeInt32(file, offset + 12, tables[tableName].length);
  21210. offset += OTF_TABLE_ENTRY_SIZE;
  21211. }
  21212. return file;
  21213. },
  21214. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  21215. if (tag in this.tables) {
  21216. throw new Error('Table ' + tag + ' already exists');
  21217. }
  21218. this.tables[tag] = data;
  21219. }
  21220. };
  21221. return OpenTypeFileBuilder;
  21222. })();
  21223. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  21224. // issues when they are painted on the canvas, e.g. complex-script shaping or
  21225. // control/whitespace characters. The ranges are listed in pairs: the first item
  21226. // is a code of the first problematic code, the second one is the next
  21227. // non-problematic code. The ranges must be in sorted order.
  21228. var ProblematicCharRanges = new Int32Array([
  21229. // Control characters.
  21230. 0x0000, 0x0020,
  21231. 0x007F, 0x00A1,
  21232. 0x00AD, 0x00AE,
  21233. // Chars that is used in complex-script shaping.
  21234. 0x0600, 0x0780,
  21235. 0x08A0, 0x10A0,
  21236. 0x1780, 0x1800,
  21237. // General punctuation chars.
  21238. 0x2000, 0x2010,
  21239. 0x2011, 0x2012,
  21240. 0x2028, 0x2030,
  21241. 0x205F, 0x2070,
  21242. 0x25CC, 0x25CD,
  21243. // Chars that is used in complex-script shaping.
  21244. 0xAA60, 0xAA80,
  21245. // Specials Unicode block.
  21246. 0xFFF0, 0x10000
  21247. ]);
  21248. /**
  21249. * 'Font' is the class the outside world should use, it encapsulate all the font
  21250. * decoding logics whatever type it is (assuming the font type is supported).
  21251. *
  21252. * For example to read a Type1 font and to attach it to the document:
  21253. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  21254. * type1Font.bind();
  21255. */
  21256. var Font = (function FontClosure() {
  21257. function Font(name, file, properties) {
  21258. var charCode, glyphName, fontChar;
  21259. this.name = name;
  21260. this.loadedName = properties.loadedName;
  21261. this.isType3Font = properties.isType3Font;
  21262. this.sizes = [];
  21263. this.glyphCache = {};
  21264. var names = name.split('+');
  21265. names = names.length > 1 ? names[1] : names[0];
  21266. names = names.split(/[-,_]/g)[0];
  21267. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  21268. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  21269. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  21270. var type = properties.type;
  21271. var subtype = properties.subtype;
  21272. this.type = type;
  21273. this.fallbackName = (this.isMonospace ? 'monospace' :
  21274. (this.isSerifFont ? 'serif' : 'sans-serif'));
  21275. this.differences = properties.differences;
  21276. this.widths = properties.widths;
  21277. this.defaultWidth = properties.defaultWidth;
  21278. this.composite = properties.composite;
  21279. this.wideChars = properties.wideChars;
  21280. this.cMap = properties.cMap;
  21281. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  21282. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  21283. this.fontMatrix = properties.fontMatrix;
  21284. this.bbox = properties.bbox;
  21285. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  21286. this.toFontChar = [];
  21287. if (properties.type === 'Type3') {
  21288. for (charCode = 0; charCode < 256; charCode++) {
  21289. this.toFontChar[charCode] = (this.differences[charCode] ||
  21290. properties.defaultEncoding[charCode]);
  21291. }
  21292. this.fontType = FontType.TYPE3;
  21293. return;
  21294. }
  21295. this.cidEncoding = properties.cidEncoding;
  21296. this.vertical = properties.vertical;
  21297. if (this.vertical) {
  21298. this.vmetrics = properties.vmetrics;
  21299. this.defaultVMetrics = properties.defaultVMetrics;
  21300. }
  21301. if (!file || file.isEmpty) {
  21302. if (file) {
  21303. // Some bad PDF generators will include empty font files,
  21304. // attempting to recover by assuming that no file exists.
  21305. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  21306. }
  21307. this.missingFile = true;
  21308. // The file data is not specified. Trying to fix the font name
  21309. // to be used with the canvas.font.
  21310. var fontName = name.replace(/[,_]/g, '-');
  21311. var isStandardFont = !!stdFontMap[fontName] ||
  21312. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  21313. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  21314. this.bold = (fontName.search(/bold/gi) !== -1);
  21315. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  21316. (fontName.search(/italic/gi) !== -1));
  21317. // Use 'name' instead of 'fontName' here because the original
  21318. // name ArialBlack for example will be replaced by Helvetica.
  21319. this.black = (name.search(/Black/g) !== -1);
  21320. // if at least one width is present, remeasure all chars when exists
  21321. this.remeasure = Object.keys(this.widths).length > 0;
  21322. if (isStandardFont && type === 'CIDFontType2' &&
  21323. properties.cidEncoding.indexOf('Identity-') === 0) {
  21324. // Standard fonts might be embedded as CID font without glyph mapping.
  21325. // Building one based on GlyphMapForStandardFonts.
  21326. var map = [];
  21327. for (charCode in GlyphMapForStandardFonts) {
  21328. map[+charCode] = GlyphMapForStandardFonts[charCode];
  21329. }
  21330. if (/ArialBlack/i.test(name)) {
  21331. for (charCode in SupplementalGlyphMapForArialBlack) {
  21332. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  21333. }
  21334. }
  21335. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  21336. if (!isIdentityUnicode) {
  21337. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  21338. map[+charCode] = unicodeCharCode;
  21339. });
  21340. }
  21341. this.toFontChar = map;
  21342. this.toUnicode = new ToUnicodeMap(map);
  21343. } else if (/Symbol/i.test(fontName)) {
  21344. var symbols = Encodings.SymbolSetEncoding;
  21345. for (charCode in symbols) {
  21346. fontChar = GlyphsUnicode[symbols[charCode]];
  21347. if (!fontChar) {
  21348. continue;
  21349. }
  21350. this.toFontChar[charCode] = fontChar;
  21351. }
  21352. for (charCode in properties.differences) {
  21353. fontChar = GlyphsUnicode[properties.differences[charCode]];
  21354. if (!fontChar) {
  21355. continue;
  21356. }
  21357. this.toFontChar[charCode] = fontChar;
  21358. }
  21359. } else if (/Dingbats/i.test(fontName)) {
  21360. if (/Wingdings/i.test(name)) {
  21361. warn('Wingdings font without embedded font file, ' +
  21362. 'falling back to the ZapfDingbats encoding.');
  21363. }
  21364. var dingbats = Encodings.ZapfDingbatsEncoding;
  21365. for (charCode in dingbats) {
  21366. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  21367. if (!fontChar) {
  21368. continue;
  21369. }
  21370. this.toFontChar[charCode] = fontChar;
  21371. }
  21372. for (charCode in properties.differences) {
  21373. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  21374. if (!fontChar) {
  21375. continue;
  21376. }
  21377. this.toFontChar[charCode] = fontChar;
  21378. }
  21379. } else if (isStandardFont) {
  21380. this.toFontChar = [];
  21381. for (charCode in properties.defaultEncoding) {
  21382. glyphName = (properties.differences[charCode] ||
  21383. properties.defaultEncoding[charCode]);
  21384. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  21385. }
  21386. } else {
  21387. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  21388. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  21389. if (notCidFont) {
  21390. glyphName = (properties.differences[charCode] ||
  21391. properties.defaultEncoding[charCode]);
  21392. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  21393. }
  21394. this.toFontChar[charCode] = unicodeCharCode;
  21395. }.bind(this));
  21396. }
  21397. this.loadedName = fontName.split('-')[0];
  21398. this.loading = false;
  21399. this.fontType = getFontType(type, subtype);
  21400. return;
  21401. }
  21402. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  21403. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  21404. // Some TrueType fonts by mistake claim Type1C
  21405. if (isTrueTypeFile(file)) {
  21406. subtype = 'TrueType';
  21407. } else {
  21408. type = 'Type1';
  21409. }
  21410. }
  21411. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  21412. type = 'CIDFontType0';
  21413. }
  21414. if (subtype === 'OpenType') {
  21415. type = 'OpenType';
  21416. }
  21417. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  21418. if (type === 'CIDFontType0') {
  21419. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  21420. }
  21421. var data;
  21422. switch (type) {
  21423. case 'MMType1':
  21424. info('MMType1 font (' + name + '), falling back to Type1.');
  21425. /* falls through */
  21426. case 'Type1':
  21427. case 'CIDFontType0':
  21428. this.mimetype = 'font/opentype';
  21429. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  21430. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  21431. adjustWidths(properties);
  21432. // Wrap the CFF data inside an OTF font file
  21433. data = this.convert(name, cff, properties);
  21434. break;
  21435. case 'OpenType':
  21436. case 'TrueType':
  21437. case 'CIDFontType2':
  21438. this.mimetype = 'font/opentype';
  21439. // Repair the TrueType file. It is can be damaged in the point of
  21440. // view of the sanitizer
  21441. data = this.checkAndRepair(name, file, properties);
  21442. if (this.isOpenType) {
  21443. type = 'OpenType';
  21444. }
  21445. break;
  21446. default:
  21447. error('Font ' + type + ' is not supported');
  21448. break;
  21449. }
  21450. this.data = data;
  21451. this.fontType = getFontType(type, subtype);
  21452. // Transfer some properties again that could change during font conversion
  21453. this.fontMatrix = properties.fontMatrix;
  21454. this.widths = properties.widths;
  21455. this.defaultWidth = properties.defaultWidth;
  21456. this.encoding = properties.baseEncoding;
  21457. this.seacMap = properties.seacMap;
  21458. this.loading = true;
  21459. }
  21460. Font.getFontID = (function () {
  21461. var ID = 1;
  21462. return function Font_getFontID() {
  21463. return String(ID++);
  21464. };
  21465. })();
  21466. function int16(b0, b1) {
  21467. return (b0 << 8) + b1;
  21468. }
  21469. function int32(b0, b1, b2, b3) {
  21470. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21471. }
  21472. function string16(value) {
  21473. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21474. }
  21475. function safeString16(value) {
  21476. // clamp value to the 16-bit int range
  21477. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  21478. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21479. }
  21480. function isTrueTypeFile(file) {
  21481. var header = file.peekBytes(4);
  21482. return readUint32(header, 0) === 0x00010000;
  21483. }
  21484. function isType1File(file) {
  21485. var header = file.peekBytes(2);
  21486. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  21487. if (header[0] === 0x25 && header[1] === 0x21) {
  21488. return true;
  21489. }
  21490. // ... obviously some fonts violate that part of the specification,
  21491. // please refer to the comment in |Type1Font| below.
  21492. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  21493. return true;
  21494. }
  21495. return false;
  21496. }
  21497. /**
  21498. * Helper function for |adjustMapping|.
  21499. * @return {boolean}
  21500. */
  21501. function isProblematicUnicodeLocation(code) {
  21502. // Using binary search to find a range start.
  21503. var i = 0, j = ProblematicCharRanges.length - 1;
  21504. while (i < j) {
  21505. var c = (i + j + 1) >> 1;
  21506. if (code < ProblematicCharRanges[c]) {
  21507. j = c - 1;
  21508. } else {
  21509. i = c;
  21510. }
  21511. }
  21512. // Even index means code in problematic range.
  21513. return !(i & 1);
  21514. }
  21515. /**
  21516. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  21517. * with their unicode value. It also moves char codes that are in known
  21518. * problematic locations.
  21519. * @return {Object} Two properties:
  21520. * 'toFontChar' - maps original char codes(the value that will be read
  21521. * from commands such as show text) to the char codes that will be used in the
  21522. * font that we build
  21523. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  21524. */
  21525. function adjustMapping(charCodeToGlyphId, properties) {
  21526. var toUnicode = properties.toUnicode;
  21527. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  21528. var isIdentityUnicode =
  21529. properties.toUnicode instanceof IdentityToUnicodeMap;
  21530. var newMap = Object.create(null);
  21531. var toFontChar = [];
  21532. var usedFontCharCodes = [];
  21533. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21534. for (var originalCharCode in charCodeToGlyphId) {
  21535. originalCharCode |= 0;
  21536. var glyphId = charCodeToGlyphId[originalCharCode];
  21537. var fontCharCode = originalCharCode;
  21538. // First try to map the value to a unicode position if a non identity map
  21539. // was created.
  21540. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21541. var unicode = toUnicode.get(fontCharCode);
  21542. // TODO: Try to map ligatures to the correct spot.
  21543. if (unicode.length === 1) {
  21544. fontCharCode = unicode.charCodeAt(0);
  21545. }
  21546. }
  21547. // Try to move control characters, special characters and already mapped
  21548. // characters to the private use area since they will not be drawn by
  21549. // canvas if left in their current position. Also, move characters if the
  21550. // font was symbolic and there is only an identity unicode map since the
  21551. // characters probably aren't in the correct position (fixes an issue
  21552. // with firefox and thuluthfont).
  21553. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21554. isProblematicUnicodeLocation(fontCharCode) ||
  21555. (isSymbolic && isIdentityUnicode)) &&
  21556. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21557. // Loop to try and find a free spot in the private use area.
  21558. do {
  21559. fontCharCode = nextAvailableFontCharCode++;
  21560. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21561. fontCharCode = 0xF020;
  21562. nextAvailableFontCharCode = fontCharCode + 1;
  21563. }
  21564. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21565. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21566. }
  21567. newMap[fontCharCode] = glyphId;
  21568. toFontChar[originalCharCode] = fontCharCode;
  21569. usedFontCharCodes[fontCharCode] = true;
  21570. }
  21571. return {
  21572. toFontChar: toFontChar,
  21573. charCodeToGlyphId: newMap,
  21574. nextAvailableFontCharCode: nextAvailableFontCharCode
  21575. };
  21576. }
  21577. function getRanges(glyphs) {
  21578. // Array.sort() sorts by characters, not numerically, so convert to an
  21579. // array of characters.
  21580. var codes = [];
  21581. for (var charCode in glyphs) {
  21582. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21583. }
  21584. codes.sort(function fontGetRangesSort(a, b) {
  21585. return a.fontCharCode - b.fontCharCode;
  21586. });
  21587. // Split the sorted codes into ranges.
  21588. var ranges = [];
  21589. var length = codes.length;
  21590. for (var n = 0; n < length; ) {
  21591. var start = codes[n].fontCharCode;
  21592. var codeIndices = [codes[n].glyphId];
  21593. ++n;
  21594. var end = start;
  21595. while (n < length && end + 1 === codes[n].fontCharCode) {
  21596. codeIndices.push(codes[n].glyphId);
  21597. ++end;
  21598. ++n;
  21599. if (end === 0xFFFF) {
  21600. break;
  21601. }
  21602. }
  21603. ranges.push([start, end, codeIndices]);
  21604. }
  21605. return ranges;
  21606. }
  21607. function createCmapTable(glyphs) {
  21608. var ranges = getRanges(glyphs);
  21609. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21610. var cmap = '\x00\x00' + // version
  21611. string16(numTables) + // numTables
  21612. '\x00\x03' + // platformID
  21613. '\x00\x01' + // encodingID
  21614. string32(4 + numTables * 8); // start of the table record
  21615. var i, ii, j, jj;
  21616. for (i = ranges.length - 1; i >= 0; --i) {
  21617. if (ranges[i][0] <= 0xFFFF) { break; }
  21618. }
  21619. var bmpLength = i + 1;
  21620. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21621. ranges[i][1] = 0xFFFE;
  21622. }
  21623. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21624. var segCount = bmpLength + trailingRangesCount;
  21625. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21626. // Fill up the 4 parallel arrays describing the segments.
  21627. var startCount = '';
  21628. var endCount = '';
  21629. var idDeltas = '';
  21630. var idRangeOffsets = '';
  21631. var glyphsIds = '';
  21632. var bias = 0;
  21633. var range, start, end, codes;
  21634. for (i = 0, ii = bmpLength; i < ii; i++) {
  21635. range = ranges[i];
  21636. start = range[0];
  21637. end = range[1];
  21638. startCount += string16(start);
  21639. endCount += string16(end);
  21640. codes = range[2];
  21641. var contiguous = true;
  21642. for (j = 1, jj = codes.length; j < jj; ++j) {
  21643. if (codes[j] !== codes[j - 1] + 1) {
  21644. contiguous = false;
  21645. break;
  21646. }
  21647. }
  21648. if (!contiguous) {
  21649. var offset = (segCount - i) * 2 + bias * 2;
  21650. bias += (end - start + 1);
  21651. idDeltas += string16(0);
  21652. idRangeOffsets += string16(offset);
  21653. for (j = 0, jj = codes.length; j < jj; ++j) {
  21654. glyphsIds += string16(codes[j]);
  21655. }
  21656. } else {
  21657. var startCode = codes[0];
  21658. idDeltas += string16((startCode - start) & 0xFFFF);
  21659. idRangeOffsets += string16(0);
  21660. }
  21661. }
  21662. if (trailingRangesCount > 0) {
  21663. endCount += '\xFF\xFF';
  21664. startCount += '\xFF\xFF';
  21665. idDeltas += '\x00\x01';
  21666. idRangeOffsets += '\x00\x00';
  21667. }
  21668. var format314 = '\x00\x00' + // language
  21669. string16(2 * segCount) +
  21670. string16(searchParams.range) +
  21671. string16(searchParams.entry) +
  21672. string16(searchParams.rangeShift) +
  21673. endCount + '\x00\x00' + startCount +
  21674. idDeltas + idRangeOffsets + glyphsIds;
  21675. var format31012 = '';
  21676. var header31012 = '';
  21677. if (numTables > 1) {
  21678. cmap += '\x00\x03' + // platformID
  21679. '\x00\x0A' + // encodingID
  21680. string32(4 + numTables * 8 +
  21681. 4 + format314.length); // start of the table record
  21682. format31012 = '';
  21683. for (i = 0, ii = ranges.length; i < ii; i++) {
  21684. range = ranges[i];
  21685. start = range[0];
  21686. codes = range[2];
  21687. var code = codes[0];
  21688. for (j = 1, jj = codes.length; j < jj; ++j) {
  21689. if (codes[j] !== codes[j - 1] + 1) {
  21690. end = range[0] + j - 1;
  21691. format31012 += string32(start) + // startCharCode
  21692. string32(end) + // endCharCode
  21693. string32(code); // startGlyphID
  21694. start = end + 1;
  21695. code = codes[j];
  21696. }
  21697. }
  21698. format31012 += string32(start) + // startCharCode
  21699. string32(range[1]) + // endCharCode
  21700. string32(code); // startGlyphID
  21701. }
  21702. header31012 = '\x00\x0C' + // format
  21703. '\x00\x00' + // reserved
  21704. string32(format31012.length + 16) + // length
  21705. '\x00\x00\x00\x00' + // language
  21706. string32(format31012.length / 12); // nGroups
  21707. }
  21708. return cmap + '\x00\x04' + // format
  21709. string16(format314.length + 4) + // length
  21710. format314 + header31012 + format31012;
  21711. }
  21712. function validateOS2Table(os2) {
  21713. var stream = new Stream(os2.data);
  21714. var version = stream.getUint16();
  21715. // TODO verify all OS/2 tables fields, but currently we validate only those
  21716. // that give us issues
  21717. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21718. var selection = stream.getUint16();
  21719. if (version < 4 && (selection & 0x0300)) {
  21720. return false;
  21721. }
  21722. var firstChar = stream.getUint16();
  21723. var lastChar = stream.getUint16();
  21724. if (firstChar > lastChar) {
  21725. return false;
  21726. }
  21727. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21728. var usWinAscent = stream.getUint16();
  21729. if (usWinAscent === 0) { // makes font unreadable by windows
  21730. return false;
  21731. }
  21732. // OS/2 appears to be valid, resetting some fields
  21733. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21734. return true;
  21735. }
  21736. function createOS2Table(properties, charstrings, override) {
  21737. override = override || {
  21738. unitsPerEm: 0,
  21739. yMax: 0,
  21740. yMin: 0,
  21741. ascent: 0,
  21742. descent: 0
  21743. };
  21744. var ulUnicodeRange1 = 0;
  21745. var ulUnicodeRange2 = 0;
  21746. var ulUnicodeRange3 = 0;
  21747. var ulUnicodeRange4 = 0;
  21748. var firstCharIndex = null;
  21749. var lastCharIndex = 0;
  21750. if (charstrings) {
  21751. for (var code in charstrings) {
  21752. code |= 0;
  21753. if (firstCharIndex > code || !firstCharIndex) {
  21754. firstCharIndex = code;
  21755. }
  21756. if (lastCharIndex < code) {
  21757. lastCharIndex = code;
  21758. }
  21759. var position = getUnicodeRangeFor(code);
  21760. if (position < 32) {
  21761. ulUnicodeRange1 |= 1 << position;
  21762. } else if (position < 64) {
  21763. ulUnicodeRange2 |= 1 << position - 32;
  21764. } else if (position < 96) {
  21765. ulUnicodeRange3 |= 1 << position - 64;
  21766. } else if (position < 123) {
  21767. ulUnicodeRange4 |= 1 << position - 96;
  21768. } else {
  21769. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21770. }
  21771. }
  21772. } else {
  21773. // TODO
  21774. firstCharIndex = 0;
  21775. lastCharIndex = 255;
  21776. }
  21777. var bbox = properties.bbox || [0, 0, 0, 0];
  21778. var unitsPerEm = (override.unitsPerEm ||
  21779. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21780. // if the font units differ to the PDF glyph space units
  21781. // then scale up the values
  21782. var scale = (properties.ascentScaled ? 1.0 :
  21783. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21784. var typoAscent = (override.ascent ||
  21785. Math.round(scale * (properties.ascent || bbox[3])));
  21786. var typoDescent = (override.descent ||
  21787. Math.round(scale * (properties.descent || bbox[1])));
  21788. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21789. typoDescent = -typoDescent; // fixing incorrect descent
  21790. }
  21791. var winAscent = override.yMax || typoAscent;
  21792. var winDescent = -override.yMin || -typoDescent;
  21793. return '\x00\x03' + // version
  21794. '\x02\x24' + // xAvgCharWidth
  21795. '\x01\xF4' + // usWeightClass
  21796. '\x00\x05' + // usWidthClass
  21797. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21798. '\x02\x8A' + // ySubscriptXSize
  21799. '\x02\xBB' + // ySubscriptYSize
  21800. '\x00\x00' + // ySubscriptXOffset
  21801. '\x00\x8C' + // ySubscriptYOffset
  21802. '\x02\x8A' + // ySuperScriptXSize
  21803. '\x02\xBB' + // ySuperScriptYSize
  21804. '\x00\x00' + // ySuperScriptXOffset
  21805. '\x01\xDF' + // ySuperScriptYOffset
  21806. '\x00\x31' + // yStrikeOutSize
  21807. '\x01\x02' + // yStrikeOutPosition
  21808. '\x00\x00' + // sFamilyClass
  21809. '\x00\x00\x06' +
  21810. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21811. '\x00\x00\x00\x00\x00\x00' + // Panose
  21812. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21813. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21814. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21815. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21816. '\x2A\x32\x31\x2A' + // achVendID
  21817. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21818. string16(firstCharIndex ||
  21819. properties.firstChar) + // usFirstCharIndex
  21820. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21821. string16(typoAscent) + // sTypoAscender
  21822. string16(typoDescent) + // sTypoDescender
  21823. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21824. string16(winAscent) + // usWinAscent
  21825. string16(winDescent) + // usWinDescent
  21826. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21827. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21828. string16(properties.xHeight) + // sxHeight
  21829. string16(properties.capHeight) + // sCapHeight
  21830. string16(0) + // usDefaultChar
  21831. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21832. '\x00\x03'; // usMaxContext
  21833. }
  21834. function createPostTable(properties) {
  21835. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21836. return ('\x00\x03\x00\x00' + // Version number
  21837. string32(angle) + // italicAngle
  21838. '\x00\x00' + // underlinePosition
  21839. '\x00\x00' + // underlineThickness
  21840. string32(properties.fixedPitch) + // isFixedPitch
  21841. '\x00\x00\x00\x00' + // minMemType42
  21842. '\x00\x00\x00\x00' + // maxMemType42
  21843. '\x00\x00\x00\x00' + // minMemType1
  21844. '\x00\x00\x00\x00'); // maxMemType1
  21845. }
  21846. function createNameTable(name, proto) {
  21847. if (!proto) {
  21848. proto = [[], []]; // no strings and unicode strings
  21849. }
  21850. var strings = [
  21851. proto[0][0] || 'Original licence', // 0.Copyright
  21852. proto[0][1] || name, // 1.Font family
  21853. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21854. proto[0][3] || 'uniqueID', // 3.Unique ID
  21855. proto[0][4] || name, // 4.Full font name
  21856. proto[0][5] || 'Version 0.11', // 5.Version
  21857. proto[0][6] || '', // 6.Postscript name
  21858. proto[0][7] || 'Unknown', // 7.Trademark
  21859. proto[0][8] || 'Unknown', // 8.Manufacturer
  21860. proto[0][9] || 'Unknown' // 9.Designer
  21861. ];
  21862. // Mac want 1-byte per character strings while Windows want
  21863. // 2-bytes per character, so duplicate the names table
  21864. var stringsUnicode = [];
  21865. var i, ii, j, jj, str;
  21866. for (i = 0, ii = strings.length; i < ii; i++) {
  21867. str = proto[1][i] || strings[i];
  21868. var strBufUnicode = [];
  21869. for (j = 0, jj = str.length; j < jj; j++) {
  21870. strBufUnicode.push(string16(str.charCodeAt(j)));
  21871. }
  21872. stringsUnicode.push(strBufUnicode.join(''));
  21873. }
  21874. var names = [strings, stringsUnicode];
  21875. var platforms = ['\x00\x01', '\x00\x03'];
  21876. var encodings = ['\x00\x00', '\x00\x01'];
  21877. var languages = ['\x00\x00', '\x04\x09'];
  21878. var namesRecordCount = strings.length * platforms.length;
  21879. var nameTable =
  21880. '\x00\x00' + // format
  21881. string16(namesRecordCount) + // Number of names Record
  21882. string16(namesRecordCount * 12 + 6); // Storage
  21883. // Build the name records field
  21884. var strOffset = 0;
  21885. for (i = 0, ii = platforms.length; i < ii; i++) {
  21886. var strs = names[i];
  21887. for (j = 0, jj = strs.length; j < jj; j++) {
  21888. str = strs[j];
  21889. var nameRecord =
  21890. platforms[i] + // platform ID
  21891. encodings[i] + // encoding ID
  21892. languages[i] + // language ID
  21893. string16(j) + // name ID
  21894. string16(str.length) +
  21895. string16(strOffset);
  21896. nameTable += nameRecord;
  21897. strOffset += str.length;
  21898. }
  21899. }
  21900. nameTable += strings.join('') + stringsUnicode.join('');
  21901. return nameTable;
  21902. }
  21903. Font.prototype = {
  21904. name: null,
  21905. font: null,
  21906. mimetype: null,
  21907. encoding: null,
  21908. get renderer() {
  21909. var renderer = FontRendererFactory.create(this);
  21910. return shadow(this, 'renderer', renderer);
  21911. },
  21912. exportData: function Font_exportData() {
  21913. var data = {};
  21914. for (var i in this) {
  21915. if (this.hasOwnProperty(i)) {
  21916. data[i] = this[i];
  21917. }
  21918. }
  21919. return data;
  21920. },
  21921. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21922. function readTableEntry(file) {
  21923. var tag = bytesToString(file.getBytes(4));
  21924. var checksum = file.getInt32();
  21925. var offset = file.getInt32() >>> 0;
  21926. var length = file.getInt32() >>> 0;
  21927. // Read the table associated data
  21928. var previousPosition = file.pos;
  21929. file.pos = file.start ? file.start : 0;
  21930. file.skip(offset);
  21931. var data = file.getBytes(length);
  21932. file.pos = previousPosition;
  21933. if (tag === 'head') {
  21934. // clearing checksum adjustment
  21935. data[8] = data[9] = data[10] = data[11] = 0;
  21936. data[17] |= 0x20; //Set font optimized for cleartype flag
  21937. }
  21938. return {
  21939. tag: tag,
  21940. checksum: checksum,
  21941. length: length,
  21942. offset: offset,
  21943. data: data
  21944. };
  21945. }
  21946. function readOpenTypeHeader(ttf) {
  21947. return {
  21948. version: bytesToString(ttf.getBytes(4)),
  21949. numTables: ttf.getUint16(),
  21950. searchRange: ttf.getUint16(),
  21951. entrySelector: ttf.getUint16(),
  21952. rangeShift: ttf.getUint16()
  21953. };
  21954. }
  21955. /**
  21956. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21957. * PDF spec
  21958. */
  21959. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  21960. var segment;
  21961. var start = (font.start ? font.start : 0) + cmap.offset;
  21962. font.pos = start;
  21963. var version = font.getUint16();
  21964. var numTables = font.getUint16();
  21965. var potentialTable;
  21966. var canBreak = false;
  21967. // There's an order of preference in terms of which cmap subtable to
  21968. // use:
  21969. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21970. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21971. // The following takes advantage of the fact that the tables are sorted
  21972. // to work.
  21973. for (var i = 0; i < numTables; i++) {
  21974. var platformId = font.getUint16();
  21975. var encodingId = font.getUint16();
  21976. var offset = font.getInt32() >>> 0;
  21977. var useTable = false;
  21978. if (platformId === 0 && encodingId === 0) {
  21979. useTable = true;
  21980. // Continue the loop since there still may be a higher priority
  21981. // table.
  21982. } else if (platformId === 1 && encodingId === 0) {
  21983. useTable = true;
  21984. // Continue the loop since there still may be a higher priority
  21985. // table.
  21986. } else if (platformId === 3 && encodingId === 1 &&
  21987. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  21988. useTable = true;
  21989. if (!isSymbolicFont) {
  21990. canBreak = true;
  21991. }
  21992. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21993. useTable = true;
  21994. canBreak = true;
  21995. }
  21996. if (useTable) {
  21997. potentialTable = {
  21998. platformId: platformId,
  21999. encodingId: encodingId,
  22000. offset: offset
  22001. };
  22002. }
  22003. if (canBreak) {
  22004. break;
  22005. }
  22006. }
  22007. if (potentialTable) {
  22008. font.pos = start + potentialTable.offset;
  22009. }
  22010. if (!potentialTable || font.peekByte() === -1) {
  22011. warn('Could not find a preferred cmap table.');
  22012. return {
  22013. platformId: -1,
  22014. encodingId: -1,
  22015. mappings: [],
  22016. hasShortCmap: false
  22017. };
  22018. }
  22019. var format = font.getUint16();
  22020. var length = font.getUint16();
  22021. var language = font.getUint16();
  22022. var hasShortCmap = false;
  22023. var mappings = [];
  22024. var j, glyphId;
  22025. // TODO(mack): refactor this cmap subtable reading logic out
  22026. if (format === 0) {
  22027. for (j = 0; j < 256; j++) {
  22028. var index = font.getByte();
  22029. if (!index) {
  22030. continue;
  22031. }
  22032. mappings.push({
  22033. charCode: j,
  22034. glyphId: index
  22035. });
  22036. }
  22037. hasShortCmap = true;
  22038. } else if (format === 4) {
  22039. // re-creating the table in format 4 since the encoding
  22040. // might be changed
  22041. var segCount = (font.getUint16() >> 1);
  22042. font.getBytes(6); // skipping range fields
  22043. var segIndex, segments = [];
  22044. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22045. segments.push({ end: font.getUint16() });
  22046. }
  22047. font.getUint16();
  22048. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22049. segments[segIndex].start = font.getUint16();
  22050. }
  22051. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22052. segments[segIndex].delta = font.getUint16();
  22053. }
  22054. var offsetsCount = 0;
  22055. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22056. segment = segments[segIndex];
  22057. var rangeOffset = font.getUint16();
  22058. if (!rangeOffset) {
  22059. segment.offsetIndex = -1;
  22060. continue;
  22061. }
  22062. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  22063. segment.offsetIndex = offsetIndex;
  22064. offsetsCount = Math.max(offsetsCount, offsetIndex +
  22065. segment.end - segment.start + 1);
  22066. }
  22067. var offsets = [];
  22068. for (j = 0; j < offsetsCount; j++) {
  22069. offsets.push(font.getUint16());
  22070. }
  22071. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22072. segment = segments[segIndex];
  22073. start = segment.start;
  22074. var end = segment.end;
  22075. var delta = segment.delta;
  22076. offsetIndex = segment.offsetIndex;
  22077. for (j = start; j <= end; j++) {
  22078. if (j === 0xFFFF) {
  22079. continue;
  22080. }
  22081. glyphId = (offsetIndex < 0 ?
  22082. j : offsets[offsetIndex + j - start]);
  22083. glyphId = (glyphId + delta) & 0xFFFF;
  22084. if (glyphId === 0) {
  22085. continue;
  22086. }
  22087. mappings.push({
  22088. charCode: j,
  22089. glyphId: glyphId
  22090. });
  22091. }
  22092. }
  22093. } else if (format === 6) {
  22094. // Format 6 is a 2-bytes dense mapping, which means the font data
  22095. // lives glue together even if they are pretty far in the unicode
  22096. // table. (This looks weird, so I can have missed something), this
  22097. // works on Linux but seems to fails on Mac so let's rewrite the
  22098. // cmap table to a 3-1-4 style
  22099. var firstCode = font.getUint16();
  22100. var entryCount = font.getUint16();
  22101. for (j = 0; j < entryCount; j++) {
  22102. glyphId = font.getUint16();
  22103. var charCode = firstCode + j;
  22104. mappings.push({
  22105. charCode: charCode,
  22106. glyphId: glyphId
  22107. });
  22108. }
  22109. } else {
  22110. warn('cmap table has unsupported format: ' + format);
  22111. return {
  22112. platformId: -1,
  22113. encodingId: -1,
  22114. mappings: [],
  22115. hasShortCmap: false
  22116. };
  22117. }
  22118. // removing duplicate entries
  22119. mappings.sort(function (a, b) {
  22120. return a.charCode - b.charCode;
  22121. });
  22122. for (i = 1; i < mappings.length; i++) {
  22123. if (mappings[i - 1].charCode === mappings[i].charCode) {
  22124. mappings.splice(i, 1);
  22125. i--;
  22126. }
  22127. }
  22128. return {
  22129. platformId: potentialTable.platformId,
  22130. encodingId: potentialTable.encodingId,
  22131. mappings: mappings,
  22132. hasShortCmap: hasShortCmap
  22133. };
  22134. }
  22135. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  22136. if (!header) {
  22137. if (metrics) {
  22138. metrics.data = null;
  22139. }
  22140. return;
  22141. }
  22142. font.pos = (font.start ? font.start : 0) + header.offset;
  22143. font.pos += header.length - 2;
  22144. var numOfMetrics = font.getUint16();
  22145. if (numOfMetrics > numGlyphs) {
  22146. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  22147. 'greater than the numGlyphs (' + numGlyphs + ')');
  22148. // Reduce numOfMetrics if it is greater than numGlyphs
  22149. numOfMetrics = numGlyphs;
  22150. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  22151. header.data[35] = numOfMetrics & 0x00ff;
  22152. }
  22153. var numOfSidebearings = numGlyphs - numOfMetrics;
  22154. var numMissing = numOfSidebearings -
  22155. ((metrics.length - numOfMetrics * 4) >> 1);
  22156. if (numMissing > 0) {
  22157. // For each missing glyph, we set both the width and lsb to 0 (zero).
  22158. // Since we need to add two properties for each glyph, this explains
  22159. // the use of |numMissing * 2| when initializing the typed array.
  22160. var entries = new Uint8Array(metrics.length + numMissing * 2);
  22161. entries.set(metrics.data);
  22162. metrics.data = entries;
  22163. }
  22164. }
  22165. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  22166. hintsValid) {
  22167. if (sourceEnd - sourceStart <= 12) {
  22168. // glyph with data less than 12 is invalid one
  22169. return 0;
  22170. }
  22171. var glyf = source.subarray(sourceStart, sourceEnd);
  22172. var contoursCount = (glyf[0] << 8) | glyf[1];
  22173. if (contoursCount & 0x8000) {
  22174. // complex glyph, writing as is
  22175. dest.set(glyf, destStart);
  22176. return glyf.length;
  22177. }
  22178. var i, j = 10, flagsCount = 0;
  22179. for (i = 0; i < contoursCount; i++) {
  22180. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  22181. flagsCount = endPoint + 1;
  22182. j += 2;
  22183. }
  22184. // skipping instructions
  22185. var instructionsStart = j;
  22186. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  22187. j += 2 + instructionsLength;
  22188. var instructionsEnd = j;
  22189. // validating flags
  22190. var coordinatesLength = 0;
  22191. for (i = 0; i < flagsCount; i++) {
  22192. var flag = glyf[j++];
  22193. if (flag & 0xC0) {
  22194. // reserved flags must be zero, cleaning up
  22195. glyf[j - 1] = flag & 0x3F;
  22196. }
  22197. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  22198. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  22199. coordinatesLength += xyLength;
  22200. if (flag & 8) {
  22201. var repeat = glyf[j++];
  22202. i += repeat;
  22203. coordinatesLength += repeat * xyLength;
  22204. }
  22205. }
  22206. // glyph without coordinates will be rejected
  22207. if (coordinatesLength === 0) {
  22208. return 0;
  22209. }
  22210. var glyphDataLength = j + coordinatesLength;
  22211. if (glyphDataLength > glyf.length) {
  22212. // not enough data for coordinates
  22213. return 0;
  22214. }
  22215. if (!hintsValid && instructionsLength > 0) {
  22216. dest.set(glyf.subarray(0, instructionsStart), destStart);
  22217. dest.set([0, 0], destStart + instructionsStart);
  22218. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  22219. destStart + instructionsStart + 2);
  22220. glyphDataLength -= instructionsLength;
  22221. if (glyf.length - glyphDataLength > 3) {
  22222. glyphDataLength = (glyphDataLength + 3) & ~3;
  22223. }
  22224. return glyphDataLength;
  22225. }
  22226. if (glyf.length - glyphDataLength > 3) {
  22227. // truncating and aligning to 4 bytes the long glyph data
  22228. glyphDataLength = (glyphDataLength + 3) & ~3;
  22229. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  22230. return glyphDataLength;
  22231. }
  22232. // glyph data is fine
  22233. dest.set(glyf, destStart);
  22234. return glyf.length;
  22235. }
  22236. function sanitizeHead(head, numGlyphs, locaLength) {
  22237. var data = head.data;
  22238. // Validate version:
  22239. // Should always be 0x00010000
  22240. var version = int32(data[0], data[1], data[2], data[3]);
  22241. if (version >> 16 !== 1) {
  22242. info('Attempting to fix invalid version in head table: ' + version);
  22243. data[0] = 0;
  22244. data[1] = 1;
  22245. data[2] = 0;
  22246. data[3] = 0;
  22247. }
  22248. var indexToLocFormat = int16(data[50], data[51]);
  22249. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  22250. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  22251. indexToLocFormat);
  22252. // The value of indexToLocFormat should be 0 if the loca table
  22253. // consists of short offsets, and should be 1 if the loca table
  22254. // consists of long offsets.
  22255. //
  22256. // The number of entries in the loca table should be numGlyphs + 1.
  22257. //
  22258. // Using this information, we can work backwards to deduce if the
  22259. // size of each offset in the loca table, and thus figure out the
  22260. // appropriate value for indexToLocFormat.
  22261. var numGlyphsPlusOne = numGlyphs + 1;
  22262. if (locaLength === numGlyphsPlusOne << 1) {
  22263. // 0x0000 indicates the loca table consists of short offsets
  22264. data[50] = 0;
  22265. data[51] = 0;
  22266. } else if (locaLength === numGlyphsPlusOne << 2) {
  22267. // 0x0001 indicates the loca table consists of long offsets
  22268. data[50] = 0;
  22269. data[51] = 1;
  22270. } else {
  22271. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  22272. }
  22273. }
  22274. }
  22275. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  22276. isGlyphLocationsLong, hintsValid,
  22277. dupFirstEntry) {
  22278. var itemSize, itemDecode, itemEncode;
  22279. if (isGlyphLocationsLong) {
  22280. itemSize = 4;
  22281. itemDecode = function fontItemDecodeLong(data, offset) {
  22282. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22283. (data[offset + 2] << 8) | data[offset + 3];
  22284. };
  22285. itemEncode = function fontItemEncodeLong(data, offset, value) {
  22286. data[offset] = (value >>> 24) & 0xFF;
  22287. data[offset + 1] = (value >> 16) & 0xFF;
  22288. data[offset + 2] = (value >> 8) & 0xFF;
  22289. data[offset + 3] = value & 0xFF;
  22290. };
  22291. } else {
  22292. itemSize = 2;
  22293. itemDecode = function fontItemDecode(data, offset) {
  22294. return (data[offset] << 9) | (data[offset + 1] << 1);
  22295. };
  22296. itemEncode = function fontItemEncode(data, offset, value) {
  22297. data[offset] = (value >> 9) & 0xFF;
  22298. data[offset + 1] = (value >> 1) & 0xFF;
  22299. };
  22300. }
  22301. var locaData = loca.data;
  22302. var locaDataSize = itemSize * (1 + numGlyphs);
  22303. // is loca.data too short or long?
  22304. if (locaData.length !== locaDataSize) {
  22305. locaData = new Uint8Array(locaDataSize);
  22306. locaData.set(loca.data.subarray(0, locaDataSize));
  22307. loca.data = locaData;
  22308. }
  22309. // removing the invalid glyphs
  22310. var oldGlyfData = glyf.data;
  22311. var oldGlyfDataLength = oldGlyfData.length;
  22312. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  22313. var startOffset = itemDecode(locaData, 0);
  22314. var writeOffset = 0;
  22315. var missingGlyphData = {};
  22316. itemEncode(locaData, 0, writeOffset);
  22317. var i, j;
  22318. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  22319. var endOffset = itemDecode(locaData, j);
  22320. if (endOffset > oldGlyfDataLength &&
  22321. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  22322. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  22323. // the glyf table size, which makes last glyph out of range.
  22324. endOffset = oldGlyfDataLength;
  22325. }
  22326. if (endOffset > oldGlyfDataLength) {
  22327. // glyph end offset points outside glyf data, rejecting the glyph
  22328. itemEncode(locaData, j, writeOffset);
  22329. startOffset = endOffset;
  22330. continue;
  22331. }
  22332. if (startOffset === endOffset) {
  22333. missingGlyphData[i] = true;
  22334. }
  22335. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  22336. newGlyfData, writeOffset, hintsValid);
  22337. writeOffset += newLength;
  22338. itemEncode(locaData, j, writeOffset);
  22339. startOffset = endOffset;
  22340. }
  22341. if (writeOffset === 0) {
  22342. // glyf table cannot be empty -- redoing the glyf and loca tables
  22343. // to have single glyph with one point
  22344. var simpleGlyph = new Uint8Array(
  22345. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  22346. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  22347. itemEncode(locaData, j, simpleGlyph.length);
  22348. }
  22349. glyf.data = simpleGlyph;
  22350. return missingGlyphData;
  22351. }
  22352. if (dupFirstEntry) {
  22353. var firstEntryLength = itemDecode(locaData, itemSize);
  22354. if (newGlyfData.length > firstEntryLength + writeOffset) {
  22355. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  22356. } else {
  22357. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  22358. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  22359. }
  22360. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  22361. itemEncode(loca.data, locaData.length - itemSize,
  22362. writeOffset + firstEntryLength);
  22363. } else {
  22364. glyf.data = newGlyfData.subarray(0, writeOffset);
  22365. }
  22366. return missingGlyphData;
  22367. }
  22368. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  22369. var start = (font.start ? font.start : 0) + post.offset;
  22370. font.pos = start;
  22371. var length = post.length, end = start + length;
  22372. var version = font.getInt32();
  22373. // skip rest to the tables
  22374. font.getBytes(28);
  22375. var glyphNames;
  22376. var valid = true;
  22377. var i;
  22378. switch (version) {
  22379. case 0x00010000:
  22380. glyphNames = MacStandardGlyphOrdering;
  22381. break;
  22382. case 0x00020000:
  22383. var numGlyphs = font.getUint16();
  22384. if (numGlyphs !== maxpNumGlyphs) {
  22385. valid = false;
  22386. break;
  22387. }
  22388. var glyphNameIndexes = [];
  22389. for (i = 0; i < numGlyphs; ++i) {
  22390. var index = font.getUint16();
  22391. if (index >= 32768) {
  22392. valid = false;
  22393. break;
  22394. }
  22395. glyphNameIndexes.push(index);
  22396. }
  22397. if (!valid) {
  22398. break;
  22399. }
  22400. var customNames = [];
  22401. var strBuf = [];
  22402. while (font.pos < end) {
  22403. var stringLength = font.getByte();
  22404. strBuf.length = stringLength;
  22405. for (i = 0; i < stringLength; ++i) {
  22406. strBuf[i] = String.fromCharCode(font.getByte());
  22407. }
  22408. customNames.push(strBuf.join(''));
  22409. }
  22410. glyphNames = [];
  22411. for (i = 0; i < numGlyphs; ++i) {
  22412. var j = glyphNameIndexes[i];
  22413. if (j < 258) {
  22414. glyphNames.push(MacStandardGlyphOrdering[j]);
  22415. continue;
  22416. }
  22417. glyphNames.push(customNames[j - 258]);
  22418. }
  22419. break;
  22420. case 0x00030000:
  22421. break;
  22422. default:
  22423. warn('Unknown/unsupported post table version ' + version);
  22424. valid = false;
  22425. if (properties.defaultEncoding) {
  22426. glyphNames = properties.defaultEncoding;
  22427. }
  22428. break;
  22429. }
  22430. properties.glyphNames = glyphNames;
  22431. return valid;
  22432. }
  22433. function readNameTable(nameTable) {
  22434. var start = (font.start ? font.start : 0) + nameTable.offset;
  22435. font.pos = start;
  22436. var names = [[], []];
  22437. var length = nameTable.length, end = start + length;
  22438. var format = font.getUint16();
  22439. var FORMAT_0_HEADER_LENGTH = 6;
  22440. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  22441. // unsupported name table format or table "too" small
  22442. return names;
  22443. }
  22444. var numRecords = font.getUint16();
  22445. var stringsStart = font.getUint16();
  22446. var records = [];
  22447. var NAME_RECORD_LENGTH = 12;
  22448. var i, ii;
  22449. for (i = 0; i < numRecords &&
  22450. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  22451. var r = {
  22452. platform: font.getUint16(),
  22453. encoding: font.getUint16(),
  22454. language: font.getUint16(),
  22455. name: font.getUint16(),
  22456. length: font.getUint16(),
  22457. offset: font.getUint16()
  22458. };
  22459. // using only Macintosh and Windows platform/encoding names
  22460. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  22461. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  22462. records.push(r);
  22463. }
  22464. }
  22465. for (i = 0, ii = records.length; i < ii; i++) {
  22466. var record = records[i];
  22467. var pos = start + stringsStart + record.offset;
  22468. if (pos + record.length > end) {
  22469. continue; // outside of name table, ignoring
  22470. }
  22471. font.pos = pos;
  22472. var nameIndex = record.name;
  22473. if (record.encoding) {
  22474. // unicode
  22475. var str = '';
  22476. for (var j = 0, jj = record.length; j < jj; j += 2) {
  22477. str += String.fromCharCode(font.getUint16());
  22478. }
  22479. names[1][nameIndex] = str;
  22480. } else {
  22481. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  22482. }
  22483. }
  22484. return names;
  22485. }
  22486. var TTOpsStackDeltas = [
  22487. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  22488. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  22489. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  22490. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  22491. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  22492. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  22493. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22494. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  22495. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  22496. // 0xC0-DF == -1 and 0xE0-FF == -2
  22497. function sanitizeTTProgram(table, ttContext) {
  22498. var data = table.data;
  22499. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  22500. var stack = [];
  22501. var callstack = [];
  22502. var functionsCalled = [];
  22503. var tooComplexToFollowFunctions =
  22504. ttContext.tooComplexToFollowFunctions;
  22505. var inFDEF = false, ifLevel = 0, inELSE = 0;
  22506. for (var ii = data.length; i < ii;) {
  22507. var op = data[i++];
  22508. // The TrueType instruction set docs can be found at
  22509. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  22510. if (op === 0x40) { // NPUSHB - pushes n bytes
  22511. n = data[i++];
  22512. if (inFDEF || inELSE) {
  22513. i += n;
  22514. } else {
  22515. for (j = 0; j < n; j++) {
  22516. stack.push(data[i++]);
  22517. }
  22518. }
  22519. } else if (op === 0x41) { // NPUSHW - pushes n words
  22520. n = data[i++];
  22521. if (inFDEF || inELSE) {
  22522. i += n * 2;
  22523. } else {
  22524. for (j = 0; j < n; j++) {
  22525. b = data[i++];
  22526. stack.push((b << 8) | data[i++]);
  22527. }
  22528. }
  22529. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  22530. n = op - 0xB0 + 1;
  22531. if (inFDEF || inELSE) {
  22532. i += n;
  22533. } else {
  22534. for (j = 0; j < n; j++) {
  22535. stack.push(data[i++]);
  22536. }
  22537. }
  22538. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22539. n = op - 0xB8 + 1;
  22540. if (inFDEF || inELSE) {
  22541. i += n * 2;
  22542. } else {
  22543. for (j = 0; j < n; j++) {
  22544. b = data[i++];
  22545. stack.push((b << 8) | data[i++]);
  22546. }
  22547. }
  22548. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22549. if (!inFDEF && !inELSE) {
  22550. // collecting inforamtion about which functions are used
  22551. funcId = stack[stack.length - 1];
  22552. ttContext.functionsUsed[funcId] = true;
  22553. if (funcId in ttContext.functionsStackDeltas) {
  22554. stack.length += ttContext.functionsStackDeltas[funcId];
  22555. } else if (funcId in ttContext.functionsDefined &&
  22556. functionsCalled.indexOf(funcId) < 0) {
  22557. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22558. functionsCalled.push(funcId);
  22559. pc = ttContext.functionsDefined[funcId];
  22560. if (!pc) {
  22561. warn('TT: CALL non-existent function');
  22562. ttContext.hintsValid = false;
  22563. return;
  22564. }
  22565. data = pc.data;
  22566. i = pc.i;
  22567. }
  22568. }
  22569. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22570. if (inFDEF || inELSE) {
  22571. warn('TT: nested FDEFs not allowed');
  22572. tooComplexToFollowFunctions = true;
  22573. }
  22574. inFDEF = true;
  22575. // collecting inforamtion about which functions are defined
  22576. lastDeff = i;
  22577. funcId = stack.pop();
  22578. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22579. } else if (op === 0x2D) { // ENDF - end of function
  22580. if (inFDEF) {
  22581. inFDEF = false;
  22582. lastEndf = i;
  22583. } else {
  22584. pc = callstack.pop();
  22585. if (!pc) {
  22586. warn('TT: ENDF bad stack');
  22587. ttContext.hintsValid = false;
  22588. return;
  22589. }
  22590. funcId = functionsCalled.pop();
  22591. data = pc.data;
  22592. i = pc.i;
  22593. ttContext.functionsStackDeltas[funcId] =
  22594. stack.length - pc.stackTop;
  22595. }
  22596. } else if (op === 0x89) { // IDEF - instruction definition
  22597. if (inFDEF || inELSE) {
  22598. warn('TT: nested IDEFs not allowed');
  22599. tooComplexToFollowFunctions = true;
  22600. }
  22601. inFDEF = true;
  22602. // recording it as a function to track ENDF
  22603. lastDeff = i;
  22604. } else if (op === 0x58) { // IF
  22605. ++ifLevel;
  22606. } else if (op === 0x1B) { // ELSE
  22607. inELSE = ifLevel;
  22608. } else if (op === 0x59) { // EIF
  22609. if (inELSE === ifLevel) {
  22610. inELSE = 0;
  22611. }
  22612. --ifLevel;
  22613. } else if (op === 0x1C) { // JMPR
  22614. if (!inFDEF && !inELSE) {
  22615. var offset = stack[stack.length - 1];
  22616. // only jumping forward to prevent infinite loop
  22617. if (offset > 0) {
  22618. i += offset - 1;
  22619. }
  22620. }
  22621. }
  22622. // Adjusting stack not extactly, but just enough to get function id
  22623. if (!inFDEF && !inELSE) {
  22624. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22625. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22626. if (op >= 0x71 && op <= 0x75) {
  22627. n = stack.pop();
  22628. if (n === n) {
  22629. stackDelta = -n * 2;
  22630. }
  22631. }
  22632. while (stackDelta < 0 && stack.length > 0) {
  22633. stack.pop();
  22634. stackDelta++;
  22635. }
  22636. while (stackDelta > 0) {
  22637. stack.push(NaN); // pushing any number into stack
  22638. stackDelta--;
  22639. }
  22640. }
  22641. }
  22642. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22643. var content = [data];
  22644. if (i > data.length) {
  22645. content.push(new Uint8Array(i - data.length));
  22646. }
  22647. if (lastDeff > lastEndf) {
  22648. warn('TT: complementing a missing function tail');
  22649. // new function definition started, but not finished
  22650. // complete function by [CLEAR, ENDF]
  22651. content.push(new Uint8Array([0x22, 0x2D]));
  22652. }
  22653. foldTTTable(table, content);
  22654. }
  22655. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22656. if (ttContext.tooComplexToFollowFunctions) {
  22657. return;
  22658. }
  22659. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22660. warn('TT: more functions defined than expected');
  22661. ttContext.hintsValid = false;
  22662. return;
  22663. }
  22664. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22665. if (j > maxFunctionDefs) {
  22666. warn('TT: invalid function id: ' + j);
  22667. ttContext.hintsValid = false;
  22668. return;
  22669. }
  22670. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22671. warn('TT: undefined function: ' + j);
  22672. ttContext.hintsValid = false;
  22673. return;
  22674. }
  22675. }
  22676. }
  22677. function foldTTTable(table, content) {
  22678. if (content.length > 1) {
  22679. // concatenating the content items
  22680. var newLength = 0;
  22681. var j, jj;
  22682. for (j = 0, jj = content.length; j < jj; j++) {
  22683. newLength += content[j].length;
  22684. }
  22685. newLength = (newLength + 3) & ~3;
  22686. var result = new Uint8Array(newLength);
  22687. var pos = 0;
  22688. for (j = 0, jj = content.length; j < jj; j++) {
  22689. result.set(content[j], pos);
  22690. pos += content[j].length;
  22691. }
  22692. table.data = result;
  22693. table.length = newLength;
  22694. }
  22695. }
  22696. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22697. var ttContext = {
  22698. functionsDefined: [],
  22699. functionsUsed: [],
  22700. functionsStackDeltas: [],
  22701. tooComplexToFollowFunctions: false,
  22702. hintsValid: true
  22703. };
  22704. if (fpgm) {
  22705. sanitizeTTProgram(fpgm, ttContext);
  22706. }
  22707. if (prep) {
  22708. sanitizeTTProgram(prep, ttContext);
  22709. }
  22710. if (fpgm) {
  22711. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22712. }
  22713. if (cvt && (cvt.length & 1)) {
  22714. var cvtData = new Uint8Array(cvt.length + 1);
  22715. cvtData.set(cvt.data);
  22716. cvt.data = cvtData;
  22717. }
  22718. return ttContext.hintsValid;
  22719. }
  22720. // The following steps modify the original font data, making copy
  22721. font = new Stream(new Uint8Array(font.getBytes()));
  22722. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22723. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22724. var header = readOpenTypeHeader(font);
  22725. var numTables = header.numTables;
  22726. var cff, cffFile;
  22727. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22728. hmtx: null, maxp: null, name: null, post: null };
  22729. var table;
  22730. for (var i = 0; i < numTables; i++) {
  22731. table = readTableEntry(font);
  22732. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22733. continue; // skipping table if it's not a required or optional table
  22734. }
  22735. if (table.length === 0) {
  22736. continue; // skipping empty tables
  22737. }
  22738. tables[table.tag] = table;
  22739. }
  22740. var isTrueType = !tables['CFF '];
  22741. if (!isTrueType) {
  22742. // OpenType font
  22743. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  22744. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22745. // no major tables: throwing everything at CFFFont
  22746. cffFile = new Stream(tables['CFF '].data);
  22747. cff = new CFFFont(cffFile, properties);
  22748. return this.convert(name, cff, properties);
  22749. }
  22750. delete tables.glyf;
  22751. delete tables.loca;
  22752. delete tables.fpgm;
  22753. delete tables.prep;
  22754. delete tables['cvt '];
  22755. this.isOpenType = true;
  22756. } else {
  22757. if (!tables.glyf || !tables.loca) {
  22758. error('Required "glyf" or "loca" tables are not found');
  22759. }
  22760. this.isOpenType = false;
  22761. }
  22762. if (!tables.maxp) {
  22763. error('Required "maxp" table is not found');
  22764. }
  22765. font.pos = (font.start || 0) + tables.maxp.offset;
  22766. var version = font.getInt32();
  22767. var numGlyphs = font.getUint16();
  22768. var maxFunctionDefs = 0;
  22769. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22770. // maxZones can be invalid
  22771. font.pos += 8;
  22772. var maxZones = font.getUint16();
  22773. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22774. tables.maxp.data[14] = 0;
  22775. tables.maxp.data[15] = 2;
  22776. }
  22777. font.pos += 4;
  22778. maxFunctionDefs = font.getUint16();
  22779. }
  22780. var dupFirstEntry = false;
  22781. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22782. properties.toUnicode.get(0) > '\u0000') {
  22783. // oracle's defect (see 3427), duplicating first entry
  22784. dupFirstEntry = true;
  22785. numGlyphs++;
  22786. tables.maxp.data[4] = numGlyphs >> 8;
  22787. tables.maxp.data[5] = numGlyphs & 255;
  22788. }
  22789. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22790. tables['cvt '], maxFunctionDefs);
  22791. if (!hintsValid) {
  22792. delete tables.fpgm;
  22793. delete tables.prep;
  22794. delete tables['cvt '];
  22795. }
  22796. // Ensure the hmtx table contains the advance width and
  22797. // sidebearings information for numGlyphs in the maxp table
  22798. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22799. if (!tables.head) {
  22800. error('Required "head" table is not found');
  22801. }
  22802. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22803. var missingGlyphs = {};
  22804. if (isTrueType) {
  22805. var isGlyphLocationsLong = int16(tables.head.data[50],
  22806. tables.head.data[51]);
  22807. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22808. numGlyphs, isGlyphLocationsLong,
  22809. hintsValid, dupFirstEntry);
  22810. }
  22811. if (!tables.hhea) {
  22812. error('Required "hhea" table is not found');
  22813. }
  22814. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22815. // Sometimes it's 0. That needs to be fixed
  22816. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22817. tables.hhea.data[10] = 0xFF;
  22818. tables.hhea.data[11] = 0xFF;
  22819. }
  22820. // The 'post' table has glyphs names.
  22821. if (tables.post) {
  22822. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22823. if (!valid) {
  22824. tables.post = null;
  22825. }
  22826. }
  22827. var charCodeToGlyphId = [], charCode;
  22828. var toUnicode = properties.toUnicode, widths = properties.widths;
  22829. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  22830. toUnicode.length === 0x10000);
  22831. // Helper function to try to skip mapping of empty glyphs.
  22832. // Note: In some cases, just relying on the glyph data doesn't work,
  22833. // hence we also use a few heuristics to fix various PDF files.
  22834. function hasGlyph(glyphId, charCode, widthCode) {
  22835. if (!missingGlyphs[glyphId]) {
  22836. return true;
  22837. }
  22838. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  22839. return true;
  22840. }
  22841. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  22842. return true;
  22843. }
  22844. return false;
  22845. }
  22846. if (properties.type === 'CIDFontType2') {
  22847. var cidToGidMap = properties.cidToGidMap || [];
  22848. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22849. properties.cMap.forEach(function(charCode, cid) {
  22850. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22851. var glyphId = -1;
  22852. if (isCidToGidMapEmpty) {
  22853. glyphId = charCode;
  22854. } else if (cidToGidMap[cid] !== undefined) {
  22855. glyphId = cidToGidMap[cid];
  22856. }
  22857. if (glyphId >= 0 && glyphId < numGlyphs &&
  22858. hasGlyph(glyphId, charCode, cid)) {
  22859. charCodeToGlyphId[charCode] = glyphId;
  22860. }
  22861. });
  22862. if (dupFirstEntry) {
  22863. charCodeToGlyphId[0] = numGlyphs - 1;
  22864. }
  22865. } else {
  22866. // Most of the following logic in this code branch is based on the
  22867. // 9.6.6.4 of the PDF spec.
  22868. var hasEncoding =
  22869. properties.differences.length > 0 || !!properties.baseEncodingName;
  22870. var cmapTable =
  22871. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  22872. var cmapPlatformId = cmapTable.platformId;
  22873. var cmapEncodingId = cmapTable.encodingId;
  22874. var cmapMappings = cmapTable.mappings;
  22875. var cmapMappingsLength = cmapMappings.length;
  22876. // The spec seems to imply that if the font is symbolic the encoding
  22877. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22878. // where the the font is symbolic and it has an encoding.
  22879. if (hasEncoding &&
  22880. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22881. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22882. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22883. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22884. // When no preferred cmap table was found and |baseEncodingName| is
  22885. // one of the predefined encodings, we seem to obtain a better
  22886. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22887. // TODO: Note that this is a hack which should be removed as soon as
  22888. // we have proper support for more exotic cmap tables.
  22889. var baseEncoding = [];
  22890. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22891. properties.baseEncodingName === 'WinAnsiEncoding') {
  22892. baseEncoding = Encodings[properties.baseEncodingName];
  22893. }
  22894. for (charCode = 0; charCode < 256; charCode++) {
  22895. var glyphName;
  22896. if (this.differences && charCode in this.differences) {
  22897. glyphName = this.differences[charCode];
  22898. } else if (charCode in baseEncoding &&
  22899. baseEncoding[charCode] !== '') {
  22900. glyphName = baseEncoding[charCode];
  22901. } else {
  22902. glyphName = Encodings.StandardEncoding[charCode];
  22903. }
  22904. if (!glyphName) {
  22905. continue;
  22906. }
  22907. var unicodeOrCharCode, isUnicode = false;
  22908. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22909. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22910. isUnicode = true;
  22911. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22912. // TODO: the encoding needs to be updated with mac os table.
  22913. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22914. }
  22915. var found = false;
  22916. for (i = 0; i < cmapMappingsLength; ++i) {
  22917. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  22918. continue;
  22919. }
  22920. var code = isUnicode ? charCode : unicodeOrCharCode;
  22921. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  22922. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22923. found = true;
  22924. break;
  22925. }
  22926. }
  22927. if (!found && properties.glyphNames) {
  22928. // Try to map using the post table.
  22929. var glyphId = properties.glyphNames.indexOf(glyphName);
  22930. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  22931. charCodeToGlyphId[charCode] = glyphId;
  22932. } else {
  22933. charCodeToGlyphId[charCode] = 0; // notdef
  22934. }
  22935. }
  22936. }
  22937. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22938. // Default Unicode semantics, use the charcodes as is.
  22939. for (i = 0; i < cmapMappingsLength; ++i) {
  22940. charCodeToGlyphId[cmapMappings[i].charCode] =
  22941. cmapMappings[i].glyphId;
  22942. }
  22943. } else {
  22944. // For (3, 0) cmap tables:
  22945. // The charcode key being stored in charCodeToGlyphId is the lower
  22946. // byte of the two-byte charcodes of the cmap table since according to
  22947. // the spec: 'each byte from the string shall be prepended with the
  22948. // high byte of the range [of charcodes in the cmap table], to form
  22949. // a two-byte character, which shall be used to select the
  22950. // associated glyph description from the subtable'.
  22951. //
  22952. // For (1, 0) cmap tables:
  22953. // 'single bytes from the string shall be used to look up the
  22954. // associated glyph descriptions from the subtable'. This means
  22955. // charcodes in the cmap will be single bytes, so no-op since
  22956. // glyph.charCode & 0xFF === glyph.charCode
  22957. for (i = 0; i < cmapMappingsLength; ++i) {
  22958. charCode = cmapMappings[i].charCode & 0xFF;
  22959. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22960. }
  22961. }
  22962. }
  22963. if (charCodeToGlyphId.length === 0) {
  22964. // defines at least one glyph
  22965. charCodeToGlyphId[0] = 0;
  22966. }
  22967. // Converting glyphs and ids into font's cmap table
  22968. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22969. this.toFontChar = newMapping.toFontChar;
  22970. tables.cmap = {
  22971. tag: 'cmap',
  22972. data: createCmapTable(newMapping.charCodeToGlyphId)
  22973. };
  22974. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22975. // extract some more font properties from the OpenType head and
  22976. // hhea tables; yMin and descent value are always negative
  22977. var override = {
  22978. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22979. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22980. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22981. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22982. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22983. };
  22984. tables['OS/2'] = {
  22985. tag: 'OS/2',
  22986. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22987. override)
  22988. };
  22989. }
  22990. // Rewrite the 'post' table if needed
  22991. if (!tables.post) {
  22992. tables.post = {
  22993. tag: 'post',
  22994. data: createPostTable(properties)
  22995. };
  22996. }
  22997. if (!isTrueType) {
  22998. try {
  22999. // Trying to repair CFF file
  23000. cffFile = new Stream(tables['CFF '].data);
  23001. var parser = new CFFParser(cffFile, properties);
  23002. cff = parser.parse();
  23003. var compiler = new CFFCompiler(cff);
  23004. tables['CFF '].data = compiler.compile();
  23005. } catch (e) {
  23006. warn('Failed to compile font ' + properties.loadedName);
  23007. }
  23008. }
  23009. // Re-creating 'name' table
  23010. if (!tables.name) {
  23011. tables.name = {
  23012. tag: 'name',
  23013. data: createNameTable(this.name)
  23014. };
  23015. } else {
  23016. // ... using existing 'name' table as prototype
  23017. var namePrototype = readNameTable(tables.name);
  23018. tables.name.data = createNameTable(name, namePrototype);
  23019. }
  23020. var builder = new OpenTypeFileBuilder(header.version);
  23021. for (var tableTag in tables) {
  23022. builder.addTable(tableTag, tables[tableTag].data);
  23023. }
  23024. return builder.toArray();
  23025. },
  23026. convert: function Font_convert(fontName, font, properties) {
  23027. // TODO: Check the charstring widths to determine this.
  23028. properties.fixedPitch = false;
  23029. var mapping = font.getGlyphMapping(properties);
  23030. var newMapping = adjustMapping(mapping, properties);
  23031. this.toFontChar = newMapping.toFontChar;
  23032. var numGlyphs = font.numGlyphs;
  23033. function getCharCodes(charCodeToGlyphId, glyphId) {
  23034. var charCodes = null;
  23035. for (var charCode in charCodeToGlyphId) {
  23036. if (glyphId === charCodeToGlyphId[charCode]) {
  23037. if (!charCodes) {
  23038. charCodes = [];
  23039. }
  23040. charCodes.push(charCode | 0);
  23041. }
  23042. }
  23043. return charCodes;
  23044. }
  23045. function createCharCode(charCodeToGlyphId, glyphId) {
  23046. for (var charCode in charCodeToGlyphId) {
  23047. if (glyphId === charCodeToGlyphId[charCode]) {
  23048. return charCode | 0;
  23049. }
  23050. }
  23051. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  23052. glyphId;
  23053. return newMapping.nextAvailableFontCharCode++;
  23054. }
  23055. var seacs = font.seacs;
  23056. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  23057. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  23058. var charset = font.getCharset();
  23059. var seacMap = Object.create(null);
  23060. for (var glyphId in seacs) {
  23061. glyphId |= 0;
  23062. var seac = seacs[glyphId];
  23063. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  23064. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  23065. var baseGlyphId = charset.indexOf(baseGlyphName);
  23066. var accentGlyphId = charset.indexOf(accentGlyphName);
  23067. if (baseGlyphId < 0 || accentGlyphId < 0) {
  23068. continue;
  23069. }
  23070. var accentOffset = {
  23071. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  23072. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  23073. };
  23074. var charCodes = getCharCodes(mapping, glyphId);
  23075. if (!charCodes) {
  23076. // There's no point in mapping it if the char code was never mapped
  23077. // to begin with.
  23078. continue;
  23079. }
  23080. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  23081. var charCode = charCodes[i];
  23082. // Find a fontCharCode that maps to the base and accent glyphs.
  23083. // If one doesn't exists, create it.
  23084. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  23085. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  23086. baseGlyphId);
  23087. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  23088. accentGlyphId);
  23089. seacMap[charCode] = {
  23090. baseFontCharCode: baseFontCharCode,
  23091. accentFontCharCode: accentFontCharCode,
  23092. accentOffset: accentOffset
  23093. };
  23094. }
  23095. }
  23096. properties.seacMap = seacMap;
  23097. }
  23098. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  23099. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  23100. // PostScript Font Program
  23101. builder.addTable('CFF ', font.data);
  23102. // OS/2 and Windows Specific metrics
  23103. builder.addTable('OS/2', createOS2Table(properties,
  23104. newMapping.charCodeToGlyphId));
  23105. // Character to glyphs mapping
  23106. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  23107. // Font header
  23108. builder.addTable('head',
  23109. '\x00\x01\x00\x00' + // Version number
  23110. '\x00\x00\x10\x00' + // fontRevision
  23111. '\x00\x00\x00\x00' + // checksumAdjustement
  23112. '\x5F\x0F\x3C\xF5' + // magicNumber
  23113. '\x00\x00' + // Flags
  23114. safeString16(unitsPerEm) + // unitsPerEM
  23115. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  23116. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  23117. '\x00\x00' + // xMin
  23118. safeString16(properties.descent) + // yMin
  23119. '\x0F\xFF' + // xMax
  23120. safeString16(properties.ascent) + // yMax
  23121. string16(properties.italicAngle ? 2 : 0) + // macStyle
  23122. '\x00\x11' + // lowestRecPPEM
  23123. '\x00\x00' + // fontDirectionHint
  23124. '\x00\x00' + // indexToLocFormat
  23125. '\x00\x00'); // glyphDataFormat
  23126. // Horizontal header
  23127. builder.addTable('hhea',
  23128. '\x00\x01\x00\x00' + // Version number
  23129. safeString16(properties.ascent) + // Typographic Ascent
  23130. safeString16(properties.descent) + // Typographic Descent
  23131. '\x00\x00' + // Line Gap
  23132. '\xFF\xFF' + // advanceWidthMax
  23133. '\x00\x00' + // minLeftSidebearing
  23134. '\x00\x00' + // minRightSidebearing
  23135. '\x00\x00' + // xMaxExtent
  23136. safeString16(properties.capHeight) + // caretSlopeRise
  23137. safeString16(Math.tan(properties.italicAngle) *
  23138. properties.xHeight) + // caretSlopeRun
  23139. '\x00\x00' + // caretOffset
  23140. '\x00\x00' + // -reserved-
  23141. '\x00\x00' + // -reserved-
  23142. '\x00\x00' + // -reserved-
  23143. '\x00\x00' + // -reserved-
  23144. '\x00\x00' + // metricDataFormat
  23145. string16(numGlyphs)); // Number of HMetrics
  23146. // Horizontal metrics
  23147. builder.addTable('hmtx', (function fontFieldsHmtx() {
  23148. var charstrings = font.charstrings;
  23149. var cffWidths = font.cff ? font.cff.widths : null;
  23150. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  23151. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  23152. var width = 0;
  23153. if (charstrings) {
  23154. var charstring = charstrings[i - 1];
  23155. width = 'width' in charstring ? charstring.width : 0;
  23156. } else if (cffWidths) {
  23157. width = Math.ceil(cffWidths[i] || 0);
  23158. }
  23159. hmtx += string16(width) + string16(0);
  23160. }
  23161. return hmtx;
  23162. })());
  23163. // Maximum profile
  23164. builder.addTable('maxp',
  23165. '\x00\x00\x50\x00' + // Version number
  23166. string16(numGlyphs)); // Num of glyphs
  23167. // Naming tables
  23168. builder.addTable('name', createNameTable(fontName));
  23169. // PostScript informations
  23170. builder.addTable('post', createPostTable(properties));
  23171. return builder.toArray();
  23172. },
  23173. /**
  23174. * Builds a char code to unicode map based on section 9.10 of the spec.
  23175. * @param {Object} properties Font properties object.
  23176. * @return {Object} A ToUnicodeMap object.
  23177. */
  23178. buildToUnicode: function Font_buildToUnicode(properties) {
  23179. // Section 9.10.2 Mapping Character Codes to Unicode Values
  23180. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  23181. return properties.toUnicode;
  23182. }
  23183. // According to the spec if the font is a simple font we should only map
  23184. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  23185. // the differences array only contains adobe standard or symbol set names,
  23186. // in pratice it seems better to always try to create a toUnicode
  23187. // map based of the default encoding.
  23188. var toUnicode, charcode;
  23189. if (!properties.composite /* is simple font */) {
  23190. toUnicode = [];
  23191. var encoding = properties.defaultEncoding.slice();
  23192. var baseEncodingName = properties.baseEncodingName;
  23193. // Merge in the differences array.
  23194. var differences = properties.differences;
  23195. for (charcode in differences) {
  23196. encoding[charcode] = differences[charcode];
  23197. }
  23198. for (charcode in encoding) {
  23199. // a) Map the character code to a character name.
  23200. var glyphName = encoding[charcode];
  23201. // b) Look up the character name in the Adobe Glyph List (see the
  23202. // Bibliography) to obtain the corresponding Unicode value.
  23203. if (glyphName === '') {
  23204. continue;
  23205. } else if (GlyphsUnicode[glyphName] === undefined) {
  23206. // (undocumented) c) Few heuristics to recognize unknown glyphs
  23207. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  23208. var code = 0;
  23209. switch (glyphName[0]) {
  23210. case 'G': // Gxx glyph
  23211. if (glyphName.length === 3) {
  23212. code = parseInt(glyphName.substr(1), 16);
  23213. }
  23214. break;
  23215. case 'g': // g00xx glyph
  23216. if (glyphName.length === 5) {
  23217. code = parseInt(glyphName.substr(1), 16);
  23218. }
  23219. break;
  23220. case 'C': // Cddd glyph
  23221. case 'c': // cddd glyph
  23222. if (glyphName.length >= 3) {
  23223. code = +glyphName.substr(1);
  23224. }
  23225. break;
  23226. }
  23227. if (code) {
  23228. // If |baseEncodingName| is one the predefined encodings,
  23229. // and |code| equals |charcode|, using the glyph defined in the
  23230. // baseEncoding seems to yield a better |toUnicode| mapping
  23231. // (fixes issue 5070).
  23232. if (baseEncodingName && code === +charcode) {
  23233. var baseEncoding = Encodings[baseEncodingName];
  23234. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  23235. toUnicode[charcode] =
  23236. String.fromCharCode(GlyphsUnicode[glyphName]);
  23237. continue;
  23238. }
  23239. }
  23240. toUnicode[charcode] = String.fromCharCode(code);
  23241. }
  23242. continue;
  23243. }
  23244. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  23245. }
  23246. return new ToUnicodeMap(toUnicode);
  23247. }
  23248. // If the font is a composite font that uses one of the predefined CMaps
  23249. // listed in Table 118 (except Identity–H and Identity–V) or whose
  23250. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  23251. // Adobe-Korea1 character collection:
  23252. if (properties.composite && (
  23253. (properties.cMap.builtInCMap &&
  23254. !(properties.cMap instanceof IdentityCMap)) ||
  23255. (properties.cidSystemInfo.registry === 'Adobe' &&
  23256. (properties.cidSystemInfo.ordering === 'GB1' ||
  23257. properties.cidSystemInfo.ordering === 'CNS1' ||
  23258. properties.cidSystemInfo.ordering === 'Japan1' ||
  23259. properties.cidSystemInfo.ordering === 'Korea1')))) {
  23260. // Then:
  23261. // a) Map the character code to a character identifier (CID) according
  23262. // to the font’s CMap.
  23263. // b) Obtain the registry and ordering of the character collection used
  23264. // by the font’s CMap (for example, Adobe and Japan1) from its
  23265. // CIDSystemInfo dictionary.
  23266. var registry = properties.cidSystemInfo.registry;
  23267. var ordering = properties.cidSystemInfo.ordering;
  23268. // c) Construct a second CMap name by concatenating the registry and
  23269. // ordering obtained in step (b) in the format registry–ordering–UCS2
  23270. // (for example, Adobe–Japan1–UCS2).
  23271. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  23272. // d) Obtain the CMap with the name constructed in step (c) (available
  23273. // from the ASN Web site; see the Bibliography).
  23274. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  23275. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  23276. var cMap = properties.cMap;
  23277. toUnicode = [];
  23278. cMap.forEach(function(charcode, cid) {
  23279. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  23280. // e) Map the CID obtained in step (a) according to the CMap obtained
  23281. // in step (d), producing a Unicode value.
  23282. var ucs2 = ucs2CMap.lookup(cid);
  23283. if (ucs2) {
  23284. toUnicode[charcode] =
  23285. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  23286. ucs2.charCodeAt(1));
  23287. }
  23288. });
  23289. return new ToUnicodeMap(toUnicode);
  23290. }
  23291. // The viewer's choice, just use an identity map.
  23292. return new IdentityToUnicodeMap(properties.firstChar,
  23293. properties.lastChar);
  23294. },
  23295. get spaceWidth() {
  23296. if ('_shadowWidth' in this) {
  23297. return this._shadowWidth;
  23298. }
  23299. // trying to estimate space character width
  23300. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  23301. var width;
  23302. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  23303. var glyphName = possibleSpaceReplacements[i];
  23304. // if possible, getting width by glyph name
  23305. if (glyphName in this.widths) {
  23306. width = this.widths[glyphName];
  23307. break;
  23308. }
  23309. var glyphUnicode = GlyphsUnicode[glyphName];
  23310. // finding the charcode via unicodeToCID map
  23311. var charcode = 0;
  23312. if (this.composite) {
  23313. if (this.cMap.contains(glyphUnicode)) {
  23314. charcode = this.cMap.lookup(glyphUnicode);
  23315. }
  23316. }
  23317. // ... via toUnicode map
  23318. if (!charcode && 'toUnicode' in this) {
  23319. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  23320. }
  23321. // setting it to unicode if negative or undefined
  23322. if (charcode <= 0) {
  23323. charcode = glyphUnicode;
  23324. }
  23325. // trying to get width via charcode
  23326. width = this.widths[charcode];
  23327. if (width) {
  23328. break; // the non-zero width found
  23329. }
  23330. }
  23331. width = width || this.defaultWidth;
  23332. // Do not shadow the property here. See discussion:
  23333. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  23334. this._shadowWidth = width;
  23335. return width;
  23336. },
  23337. charToGlyph: function Font_charToGlyph(charcode) {
  23338. var fontCharCode, width, operatorListId;
  23339. var widthCode = charcode;
  23340. if (this.cMap && this.cMap.contains(charcode)) {
  23341. widthCode = this.cMap.lookup(charcode);
  23342. }
  23343. width = this.widths[widthCode];
  23344. width = isNum(width) ? width : this.defaultWidth;
  23345. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  23346. var unicode = this.toUnicode.get(charcode) || charcode;
  23347. if (typeof unicode === 'number') {
  23348. unicode = String.fromCharCode(unicode);
  23349. }
  23350. // First try the toFontChar map, if it's not there then try falling
  23351. // back to the char code.
  23352. fontCharCode = this.toFontChar[charcode] || charcode;
  23353. if (this.missingFile) {
  23354. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  23355. }
  23356. if (this.isType3Font) {
  23357. // Font char code in this case is actually a glyph name.
  23358. operatorListId = fontCharCode;
  23359. }
  23360. var accent = null;
  23361. if (this.seacMap && this.seacMap[charcode]) {
  23362. var seac = this.seacMap[charcode];
  23363. fontCharCode = seac.baseFontCharCode;
  23364. accent = {
  23365. fontChar: String.fromCharCode(seac.accentFontCharCode),
  23366. offset: seac.accentOffset
  23367. };
  23368. }
  23369. var fontChar = String.fromCharCode(fontCharCode);
  23370. var glyph = this.glyphCache[charcode];
  23371. if (!glyph ||
  23372. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  23373. operatorListId)) {
  23374. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  23375. operatorListId);
  23376. this.glyphCache[charcode] = glyph;
  23377. }
  23378. return glyph;
  23379. },
  23380. charsToGlyphs: function Font_charsToGlyphs(chars) {
  23381. var charsCache = this.charsCache;
  23382. var glyphs, glyph, charcode;
  23383. // if we translated this string before, just grab it from the cache
  23384. if (charsCache) {
  23385. glyphs = charsCache[chars];
  23386. if (glyphs) {
  23387. return glyphs;
  23388. }
  23389. }
  23390. // lazily create the translation cache
  23391. if (!charsCache) {
  23392. charsCache = this.charsCache = Object.create(null);
  23393. }
  23394. glyphs = [];
  23395. var charsCacheKey = chars;
  23396. var i = 0, ii;
  23397. if (this.cMap) {
  23398. // composite fonts have multi-byte strings convert the string from
  23399. // single-byte to multi-byte
  23400. var c = {};
  23401. while (i < chars.length) {
  23402. this.cMap.readCharCode(chars, i, c);
  23403. charcode = c.charcode;
  23404. var length = c.length;
  23405. i += length;
  23406. glyph = this.charToGlyph(charcode);
  23407. glyphs.push(glyph);
  23408. // placing null after each word break charcode (ASCII SPACE)
  23409. // Ignore occurences of 0x20 in multiple-byte codes.
  23410. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  23411. glyphs.push(null);
  23412. }
  23413. }
  23414. } else {
  23415. for (i = 0, ii = chars.length; i < ii; ++i) {
  23416. charcode = chars.charCodeAt(i);
  23417. glyph = this.charToGlyph(charcode);
  23418. glyphs.push(glyph);
  23419. if (charcode === 0x20) {
  23420. glyphs.push(null);
  23421. }
  23422. }
  23423. }
  23424. // Enter the translated string into the cache
  23425. return (charsCache[charsCacheKey] = glyphs);
  23426. }
  23427. };
  23428. return Font;
  23429. })();
  23430. var ErrorFont = (function ErrorFontClosure() {
  23431. function ErrorFont(error) {
  23432. this.error = error;
  23433. this.loadedName = 'g_font_error';
  23434. this.loading = false;
  23435. }
  23436. ErrorFont.prototype = {
  23437. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  23438. return [];
  23439. },
  23440. exportData: function ErrorFont_exportData() {
  23441. return {error: this.error};
  23442. }
  23443. };
  23444. return ErrorFont;
  23445. })();
  23446. /**
  23447. * Shared logic for building a char code to glyph id mapping for Type1 and
  23448. * simple CFF fonts. See section 9.6.6.2 of the spec.
  23449. * @param {Object} properties Font properties object.
  23450. * @param {Object} builtInEncoding The encoding contained within the actual font
  23451. * data.
  23452. * @param {Array} Array of glyph names where the index is the glyph ID.
  23453. * @returns {Object} A char code to glyph ID map.
  23454. */
  23455. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  23456. var charCodeToGlyphId = Object.create(null);
  23457. var glyphId, charCode, baseEncoding;
  23458. if (properties.baseEncodingName) {
  23459. // If a valid base encoding name was used, the mapping is initialized with
  23460. // that.
  23461. baseEncoding = Encodings[properties.baseEncodingName];
  23462. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23463. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23464. if (glyphId >= 0) {
  23465. charCodeToGlyphId[charCode] = glyphId;
  23466. } else {
  23467. charCodeToGlyphId[charCode] = 0; // notdef
  23468. }
  23469. }
  23470. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  23471. // For a symbolic font the encoding should be the fonts built-in
  23472. // encoding.
  23473. for (charCode in builtInEncoding) {
  23474. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  23475. }
  23476. } else {
  23477. // For non-symbolic fonts that don't have a base encoding the standard
  23478. // encoding should be used.
  23479. baseEncoding = Encodings.StandardEncoding;
  23480. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23481. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23482. if (glyphId >= 0) {
  23483. charCodeToGlyphId[charCode] = glyphId;
  23484. } else {
  23485. charCodeToGlyphId[charCode] = 0; // notdef
  23486. }
  23487. }
  23488. }
  23489. // Lastly, merge in the differences.
  23490. var differences = properties.differences;
  23491. if (differences) {
  23492. for (charCode in differences) {
  23493. var glyphName = differences[charCode];
  23494. glyphId = glyphNames.indexOf(glyphName);
  23495. if (glyphId >= 0) {
  23496. charCodeToGlyphId[charCode] = glyphId;
  23497. } else {
  23498. charCodeToGlyphId[charCode] = 0; // notdef
  23499. }
  23500. }
  23501. }
  23502. return charCodeToGlyphId;
  23503. }
  23504. /*
  23505. * CharStrings are encoded following the the CharString Encoding sequence
  23506. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  23507. * The value in a byte indicates a command, a number, or subsequent bytes
  23508. * that are to be interpreted in a special way.
  23509. *
  23510. * CharString Number Encoding:
  23511. * A CharString byte containing the values from 32 through 255 inclusive
  23512. * indicate an integer. These values are decoded in four ranges.
  23513. *
  23514. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  23515. * indicate the integer v - 139. Thus, the integer values from -107 through
  23516. * 107 inclusive may be encoded in single byte.
  23517. *
  23518. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  23519. * indicates an integer involving the next byte, w, according to the formula:
  23520. * [(v - 247) x 256] + w + 108
  23521. *
  23522. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  23523. * indicates an integer involving the next byte, w, according to the formula:
  23524. * -[(v - 251) * 256] - w - 108
  23525. *
  23526. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  23527. * are a two complement signed integer. The first of these bytes contains the
  23528. * highest order bits, the second byte contains the next higher order bits
  23529. * and the fourth byte contain the lowest order bits.
  23530. *
  23531. *
  23532. * CharString Command Encoding:
  23533. * CharStrings commands are encoded in 1 or 2 bytes.
  23534. *
  23535. * Single byte commands are encoded in 1 byte that contains a value between
  23536. * 0 and 31 inclusive.
  23537. * If a command byte contains the value 12, then the value in the next byte
  23538. * indicates a command. This "escape" mechanism allows many extra commands
  23539. * to be encoded and this encoding technique helps to minimize the length of
  23540. * the charStrings.
  23541. */
  23542. var Type1CharString = (function Type1CharStringClosure() {
  23543. var COMMAND_MAP = {
  23544. 'hstem': [1],
  23545. 'vstem': [3],
  23546. 'vmoveto': [4],
  23547. 'rlineto': [5],
  23548. 'hlineto': [6],
  23549. 'vlineto': [7],
  23550. 'rrcurveto': [8],
  23551. 'callsubr': [10],
  23552. 'flex': [12, 35],
  23553. 'drop' : [12, 18],
  23554. 'endchar': [14],
  23555. 'rmoveto': [21],
  23556. 'hmoveto': [22],
  23557. 'vhcurveto': [30],
  23558. 'hvcurveto': [31]
  23559. };
  23560. function Type1CharString() {
  23561. this.width = 0;
  23562. this.lsb = 0;
  23563. this.flexing = false;
  23564. this.output = [];
  23565. this.stack = [];
  23566. }
  23567. Type1CharString.prototype = {
  23568. convert: function Type1CharString_convert(encoded, subrs) {
  23569. var count = encoded.length;
  23570. var error = false;
  23571. var wx, sbx, subrNumber;
  23572. for (var i = 0; i < count; i++) {
  23573. var value = encoded[i];
  23574. if (value < 32) {
  23575. if (value === 12) {
  23576. value = (value << 8) + encoded[++i];
  23577. }
  23578. switch (value) {
  23579. case 1: // hstem
  23580. if (!HINTING_ENABLED) {
  23581. this.stack = [];
  23582. break;
  23583. }
  23584. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23585. break;
  23586. case 3: // vstem
  23587. if (!HINTING_ENABLED) {
  23588. this.stack = [];
  23589. break;
  23590. }
  23591. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23592. break;
  23593. case 4: // vmoveto
  23594. if (this.flexing) {
  23595. if (this.stack.length < 1) {
  23596. error = true;
  23597. break;
  23598. }
  23599. // Add the dx for flex and but also swap the values so they are
  23600. // the right order.
  23601. var dy = this.stack.pop();
  23602. this.stack.push(0, dy);
  23603. break;
  23604. }
  23605. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23606. break;
  23607. case 5: // rlineto
  23608. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23609. break;
  23610. case 6: // hlineto
  23611. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23612. break;
  23613. case 7: // vlineto
  23614. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23615. break;
  23616. case 8: // rrcurveto
  23617. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23618. break;
  23619. case 9: // closepath
  23620. // closepath is a Type1 command that does not take argument and is
  23621. // useless in Type2 and it can simply be ignored.
  23622. this.stack = [];
  23623. break;
  23624. case 10: // callsubr
  23625. if (this.stack.length < 1) {
  23626. error = true;
  23627. break;
  23628. }
  23629. subrNumber = this.stack.pop();
  23630. error = this.convert(subrs[subrNumber], subrs);
  23631. break;
  23632. case 11: // return
  23633. return error;
  23634. case 13: // hsbw
  23635. if (this.stack.length < 2) {
  23636. error = true;
  23637. break;
  23638. }
  23639. // To convert to type2 we have to move the width value to the
  23640. // first part of the charstring and then use hmoveto with lsb.
  23641. wx = this.stack.pop();
  23642. sbx = this.stack.pop();
  23643. this.lsb = sbx;
  23644. this.width = wx;
  23645. this.stack.push(wx, sbx);
  23646. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23647. break;
  23648. case 14: // endchar
  23649. this.output.push(COMMAND_MAP.endchar[0]);
  23650. break;
  23651. case 21: // rmoveto
  23652. if (this.flexing) {
  23653. break;
  23654. }
  23655. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23656. break;
  23657. case 22: // hmoveto
  23658. if (this.flexing) {
  23659. // Add the dy for flex.
  23660. this.stack.push(0);
  23661. break;
  23662. }
  23663. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23664. break;
  23665. case 30: // vhcurveto
  23666. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23667. break;
  23668. case 31: // hvcurveto
  23669. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23670. break;
  23671. case (12 << 8) + 0: // dotsection
  23672. // dotsection is a Type1 command to specify some hinting feature
  23673. // for dots that do not take a parameter and it can safely be
  23674. // ignored for Type2.
  23675. this.stack = [];
  23676. break;
  23677. case (12 << 8) + 1: // vstem3
  23678. if (!HINTING_ENABLED) {
  23679. this.stack = [];
  23680. break;
  23681. }
  23682. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23683. // multiple parameters, so instead of returning [vh]stem3 take a
  23684. // shortcut and return [vhstem] instead.
  23685. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23686. break;
  23687. case (12 << 8) + 2: // hstem3
  23688. if (!HINTING_ENABLED) {
  23689. this.stack = [];
  23690. break;
  23691. }
  23692. // See vstem3.
  23693. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23694. break;
  23695. case (12 << 8) + 6: // seac
  23696. // seac is like type 2's special endchar but it doesn't use the
  23697. // first argument asb, so remove it.
  23698. if (SEAC_ANALYSIS_ENABLED) {
  23699. this.seac = this.stack.splice(-4, 4);
  23700. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23701. } else {
  23702. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23703. }
  23704. break;
  23705. case (12 << 8) + 7: // sbw
  23706. if (this.stack.length < 4) {
  23707. error = true;
  23708. break;
  23709. }
  23710. // To convert to type2 we have to move the width value to the
  23711. // first part of the charstring and then use rmoveto with
  23712. // (dx, dy). The height argument will not be used for vmtx and
  23713. // vhea tables reconstruction -- ignoring it.
  23714. var wy = this.stack.pop();
  23715. wx = this.stack.pop();
  23716. var sby = this.stack.pop();
  23717. sbx = this.stack.pop();
  23718. this.lsb = sbx;
  23719. this.width = wx;
  23720. this.stack.push(wx, sbx, sby);
  23721. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23722. break;
  23723. case (12 << 8) + 12: // div
  23724. if (this.stack.length < 2) {
  23725. error = true;
  23726. break;
  23727. }
  23728. var num2 = this.stack.pop();
  23729. var num1 = this.stack.pop();
  23730. this.stack.push(num1 / num2);
  23731. break;
  23732. case (12 << 8) + 16: // callothersubr
  23733. if (this.stack.length < 2) {
  23734. error = true;
  23735. break;
  23736. }
  23737. subrNumber = this.stack.pop();
  23738. var numArgs = this.stack.pop();
  23739. if (subrNumber === 0 && numArgs === 3) {
  23740. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23741. this.stack.push(
  23742. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23743. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23744. flexArgs[4], // bcp2x
  23745. flexArgs[5], // bcp2y
  23746. flexArgs[6], // p2x
  23747. flexArgs[7], // p2y
  23748. flexArgs[8], // bcp3x
  23749. flexArgs[9], // bcp3y
  23750. flexArgs[10], // bcp4x
  23751. flexArgs[11], // bcp4y
  23752. flexArgs[12], // p3x
  23753. flexArgs[13], // p3y
  23754. flexArgs[14] // flexDepth
  23755. // 15 = finalx unused by flex
  23756. // 16 = finaly unused by flex
  23757. );
  23758. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23759. this.flexing = false;
  23760. this.stack.push(flexArgs[15], flexArgs[16]);
  23761. } else if (subrNumber === 1 && numArgs === 0) {
  23762. this.flexing = true;
  23763. }
  23764. break;
  23765. case (12 << 8) + 17: // pop
  23766. // Ignore this since it is only used with othersubr.
  23767. break;
  23768. case (12 << 8) + 33: // setcurrentpoint
  23769. // Ignore for now.
  23770. this.stack = [];
  23771. break;
  23772. default:
  23773. warn('Unknown type 1 charstring command of "' + value + '"');
  23774. break;
  23775. }
  23776. if (error) {
  23777. break;
  23778. }
  23779. continue;
  23780. } else if (value <= 246) {
  23781. value = value - 139;
  23782. } else if (value <= 250) {
  23783. value = ((value - 247) * 256) + encoded[++i] + 108;
  23784. } else if (value <= 254) {
  23785. value = -((value - 251) * 256) - encoded[++i] - 108;
  23786. } else {
  23787. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23788. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23789. }
  23790. this.stack.push(value);
  23791. }
  23792. return error;
  23793. },
  23794. executeCommand: function(howManyArgs, command, keepStack) {
  23795. var stackLength = this.stack.length;
  23796. if (howManyArgs > stackLength) {
  23797. return true;
  23798. }
  23799. var start = stackLength - howManyArgs;
  23800. for (var i = start; i < stackLength; i++) {
  23801. var value = this.stack[i];
  23802. if (value === (value | 0)) { // int
  23803. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23804. } else { // fixed point
  23805. value = (65536 * value) | 0;
  23806. this.output.push(255,
  23807. (value >> 24) & 0xFF,
  23808. (value >> 16) & 0xFF,
  23809. (value >> 8) & 0xFF,
  23810. value & 0xFF);
  23811. }
  23812. }
  23813. this.output.push.apply(this.output, command);
  23814. if (keepStack) {
  23815. this.stack.splice(start, howManyArgs);
  23816. } else {
  23817. this.stack.length = 0;
  23818. }
  23819. return false;
  23820. }
  23821. };
  23822. return Type1CharString;
  23823. })();
  23824. /*
  23825. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23826. * program. Some of its logic depends on the Type2 charstrings
  23827. * structure.
  23828. * Note: this doesn't really parse the font since that would require evaluation
  23829. * of PostScript, but it is possible in most cases to extract what we need
  23830. * without a full parse.
  23831. */
  23832. var Type1Parser = (function Type1ParserClosure() {
  23833. /*
  23834. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23835. * of Plaintext Bytes. The function took a key as a parameter which can be
  23836. * for decrypting the eexec block of for decoding charStrings.
  23837. */
  23838. var EEXEC_ENCRYPT_KEY = 55665;
  23839. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23840. function isHexDigit(code) {
  23841. return code >= 48 && code <= 57 || // '0'-'9'
  23842. code >= 65 && code <= 70 || // 'A'-'F'
  23843. code >= 97 && code <= 102; // 'a'-'f'
  23844. }
  23845. function decrypt(data, key, discardNumber) {
  23846. var r = key | 0, c1 = 52845, c2 = 22719;
  23847. var count = data.length;
  23848. var decrypted = new Uint8Array(count);
  23849. for (var i = 0; i < count; i++) {
  23850. var value = data[i];
  23851. decrypted[i] = value ^ (r >> 8);
  23852. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23853. }
  23854. return Array.prototype.slice.call(decrypted, discardNumber);
  23855. }
  23856. function decryptAscii(data, key, discardNumber) {
  23857. var r = key | 0, c1 = 52845, c2 = 22719;
  23858. var count = data.length, maybeLength = count >>> 1;
  23859. var decrypted = new Uint8Array(maybeLength);
  23860. var i, j;
  23861. for (i = 0, j = 0; i < count; i++) {
  23862. var digit1 = data[i];
  23863. if (!isHexDigit(digit1)) {
  23864. continue;
  23865. }
  23866. i++;
  23867. var digit2;
  23868. while (i < count && !isHexDigit(digit2 = data[i])) {
  23869. i++;
  23870. }
  23871. if (i < count) {
  23872. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23873. decrypted[j++] = value ^ (r >> 8);
  23874. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23875. }
  23876. }
  23877. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23878. }
  23879. function isSpecial(c) {
  23880. return c === 0x2F || // '/'
  23881. c === 0x5B || c === 0x5D || // '[', ']'
  23882. c === 0x7B || c === 0x7D || // '{', '}'
  23883. c === 0x28 || c === 0x29; // '(', ')'
  23884. }
  23885. function Type1Parser(stream, encrypted) {
  23886. if (encrypted) {
  23887. var data = stream.getBytes();
  23888. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23889. isHexDigit(data[2]) && isHexDigit(data[3]));
  23890. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23891. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23892. }
  23893. this.stream = stream;
  23894. this.nextChar();
  23895. }
  23896. Type1Parser.prototype = {
  23897. readNumberArray: function Type1Parser_readNumberArray() {
  23898. this.getToken(); // read '[' or '{' (arrays can start with either)
  23899. var array = [];
  23900. while (true) {
  23901. var token = this.getToken();
  23902. if (token === null || token === ']' || token === '}') {
  23903. break;
  23904. }
  23905. array.push(parseFloat(token || 0));
  23906. }
  23907. return array;
  23908. },
  23909. readNumber: function Type1Parser_readNumber() {
  23910. var token = this.getToken();
  23911. return parseFloat(token || 0);
  23912. },
  23913. readInt: function Type1Parser_readInt() {
  23914. // Use '| 0' to prevent setting a double into length such as the double
  23915. // does not flow into the loop variable.
  23916. var token = this.getToken();
  23917. return parseInt(token || 0, 10) | 0;
  23918. },
  23919. readBoolean: function Type1Parser_readBoolean() {
  23920. var token = this.getToken();
  23921. // Use 1 and 0 since that's what type2 charstrings use.
  23922. return token === 'true' ? 1 : 0;
  23923. },
  23924. nextChar : function Type1_nextChar() {
  23925. return (this.currentChar = this.stream.getByte());
  23926. },
  23927. getToken: function Type1Parser_getToken() {
  23928. // Eat whitespace and comments.
  23929. var comment = false;
  23930. var ch = this.currentChar;
  23931. while (true) {
  23932. if (ch === -1) {
  23933. return null;
  23934. }
  23935. if (comment) {
  23936. if (ch === 0x0A || ch === 0x0D) {
  23937. comment = false;
  23938. }
  23939. } else if (ch === 0x25) { // '%'
  23940. comment = true;
  23941. } else if (!Lexer.isSpace(ch)) {
  23942. break;
  23943. }
  23944. ch = this.nextChar();
  23945. }
  23946. if (isSpecial(ch)) {
  23947. this.nextChar();
  23948. return String.fromCharCode(ch);
  23949. }
  23950. var token = '';
  23951. do {
  23952. token += String.fromCharCode(ch);
  23953. ch = this.nextChar();
  23954. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23955. return token;
  23956. },
  23957. /*
  23958. * Returns an object containing a Subrs array and a CharStrings
  23959. * array extracted from and eexec encrypted block of data
  23960. */
  23961. extractFontProgram: function Type1Parser_extractFontProgram() {
  23962. var stream = this.stream;
  23963. var subrs = [], charstrings = [];
  23964. var program = {
  23965. subrs: [],
  23966. charstrings: [],
  23967. properties: {
  23968. 'privateData': {
  23969. 'lenIV': 4
  23970. }
  23971. }
  23972. };
  23973. var token, length, data, lenIV, encoded;
  23974. while ((token = this.getToken()) !== null) {
  23975. if (token !== '/') {
  23976. continue;
  23977. }
  23978. token = this.getToken();
  23979. switch (token) {
  23980. case 'CharStrings':
  23981. // The number immediately following CharStrings must be greater or
  23982. // equal to the number of CharStrings.
  23983. this.getToken();
  23984. this.getToken(); // read in 'dict'
  23985. this.getToken(); // read in 'dup'
  23986. this.getToken(); // read in 'begin'
  23987. while(true) {
  23988. token = this.getToken();
  23989. if (token === null || token === 'end') {
  23990. break;
  23991. }
  23992. if (token !== '/') {
  23993. continue;
  23994. }
  23995. var glyph = this.getToken();
  23996. length = this.readInt();
  23997. this.getToken(); // read in 'RD' or '-|'
  23998. data = stream.makeSubStream(stream.pos, length);
  23999. lenIV = program.properties.privateData['lenIV'];
  24000. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  24001. // Skip past the required space and binary data.
  24002. stream.skip(length);
  24003. this.nextChar();
  24004. token = this.getToken(); // read in 'ND' or '|-'
  24005. if (token === 'noaccess') {
  24006. this.getToken(); // read in 'def'
  24007. }
  24008. charstrings.push({
  24009. glyph: glyph,
  24010. encoded: encoded
  24011. });
  24012. }
  24013. break;
  24014. case 'Subrs':
  24015. var num = this.readInt();
  24016. this.getToken(); // read in 'array'
  24017. while ((token = this.getToken()) === 'dup') {
  24018. var index = this.readInt();
  24019. length = this.readInt();
  24020. this.getToken(); // read in 'RD' or '-|'
  24021. data = stream.makeSubStream(stream.pos, length);
  24022. lenIV = program.properties.privateData['lenIV'];
  24023. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  24024. // Skip past the required space and binary data.
  24025. stream.skip(length);
  24026. this.nextChar();
  24027. token = this.getToken(); // read in 'NP' or '|'
  24028. if (token === 'noaccess') {
  24029. this.getToken(); // read in 'put'
  24030. }
  24031. subrs[index] = encoded;
  24032. }
  24033. break;
  24034. case 'BlueValues':
  24035. case 'OtherBlues':
  24036. case 'FamilyBlues':
  24037. case 'FamilyOtherBlues':
  24038. var blueArray = this.readNumberArray();
  24039. // *Blue* values may contain invalid data: disables reading of
  24040. // those values when hinting is disabled.
  24041. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  24042. HINTING_ENABLED) {
  24043. program.properties.privateData[token] = blueArray;
  24044. }
  24045. break;
  24046. case 'StemSnapH':
  24047. case 'StemSnapV':
  24048. program.properties.privateData[token] = this.readNumberArray();
  24049. break;
  24050. case 'StdHW':
  24051. case 'StdVW':
  24052. program.properties.privateData[token] =
  24053. this.readNumberArray()[0];
  24054. break;
  24055. case 'BlueShift':
  24056. case 'lenIV':
  24057. case 'BlueFuzz':
  24058. case 'BlueScale':
  24059. case 'LanguageGroup':
  24060. case 'ExpansionFactor':
  24061. program.properties.privateData[token] = this.readNumber();
  24062. break;
  24063. case 'ForceBold':
  24064. program.properties.privateData[token] = this.readBoolean();
  24065. break;
  24066. }
  24067. }
  24068. for (var i = 0; i < charstrings.length; i++) {
  24069. glyph = charstrings[i].glyph;
  24070. encoded = charstrings[i].encoded;
  24071. var charString = new Type1CharString();
  24072. var error = charString.convert(encoded, subrs);
  24073. var output = charString.output;
  24074. if (error) {
  24075. // It seems when FreeType encounters an error while evaluating a glyph
  24076. // that it completely ignores the glyph so we'll mimic that behaviour
  24077. // here and put an endchar to make the validator happy.
  24078. output = [14];
  24079. }
  24080. program.charstrings.push({
  24081. glyphName: glyph,
  24082. charstring: output,
  24083. width: charString.width,
  24084. lsb: charString.lsb,
  24085. seac: charString.seac
  24086. });
  24087. }
  24088. return program;
  24089. },
  24090. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  24091. var token;
  24092. while ((token = this.getToken()) !== null) {
  24093. if (token !== '/') {
  24094. continue;
  24095. }
  24096. token = this.getToken();
  24097. switch (token) {
  24098. case 'FontMatrix':
  24099. var matrix = this.readNumberArray();
  24100. properties.fontMatrix = matrix;
  24101. break;
  24102. case 'Encoding':
  24103. var encodingArg = this.getToken();
  24104. var encoding;
  24105. if (!/^\d+$/.test(encodingArg)) {
  24106. // encoding name is specified
  24107. encoding = Encodings[encodingArg];
  24108. } else {
  24109. encoding = [];
  24110. var size = parseInt(encodingArg, 10) | 0;
  24111. this.getToken(); // read in 'array'
  24112. for (var j = 0; j < size; j++) {
  24113. token = this.getToken();
  24114. // skipping till first dup or def (e.g. ignoring for statement)
  24115. while (token !== 'dup' && token !== 'def') {
  24116. token = this.getToken();
  24117. if (token === null) {
  24118. return; // invalid header
  24119. }
  24120. }
  24121. if (token === 'def') {
  24122. break; // read all array data
  24123. }
  24124. var index = this.readInt();
  24125. this.getToken(); // read in '/'
  24126. var glyph = this.getToken();
  24127. encoding[index] = glyph;
  24128. this.getToken(); // read the in 'put'
  24129. }
  24130. }
  24131. properties.builtInEncoding = encoding;
  24132. break;
  24133. case 'FontBBox':
  24134. var fontBBox = this.readNumberArray();
  24135. // adjusting ascent/descent
  24136. properties.ascent = fontBBox[3];
  24137. properties.descent = fontBBox[1];
  24138. properties.ascentScaled = true;
  24139. break;
  24140. }
  24141. }
  24142. }
  24143. };
  24144. return Type1Parser;
  24145. })();
  24146. /**
  24147. * The CFF class takes a Type1 file and wrap it into a
  24148. * 'Compact Font Format' which itself embed Type2 charstrings.
  24149. */
  24150. var CFFStandardStrings = [
  24151. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  24152. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  24153. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  24154. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  24155. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  24156. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  24157. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  24158. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  24159. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  24160. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  24161. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  24162. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  24163. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  24164. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  24165. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  24166. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  24167. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  24168. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  24169. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  24170. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  24171. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  24172. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  24173. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  24174. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  24175. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  24176. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  24177. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  24178. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  24179. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  24180. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  24181. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  24182. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  24183. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  24184. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  24185. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  24186. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  24187. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  24188. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  24189. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  24190. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  24191. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  24192. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  24193. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  24194. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  24195. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  24196. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  24197. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  24198. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  24199. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  24200. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  24201. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  24202. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  24203. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  24204. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  24205. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  24206. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  24207. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  24208. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  24209. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  24210. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  24211. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  24212. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  24213. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  24214. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  24215. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  24216. ];
  24217. // Type1Font is also a CIDFontType0.
  24218. var Type1Font = function Type1Font(name, file, properties) {
  24219. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  24220. // Also, length1 and length2 might be off by 6 bytes as well.
  24221. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  24222. var PFB_HEADER_SIZE = 6;
  24223. var headerBlockLength = properties.length1;
  24224. var eexecBlockLength = properties.length2;
  24225. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  24226. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  24227. if (pfbHeaderPresent) {
  24228. file.skip(PFB_HEADER_SIZE);
  24229. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  24230. (pfbHeader[3] << 8) | pfbHeader[2];
  24231. }
  24232. // Get the data block containing glyphs and subrs informations
  24233. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  24234. var headerBlockParser = new Type1Parser(headerBlock);
  24235. headerBlockParser.extractFontHeader(properties);
  24236. if (pfbHeaderPresent) {
  24237. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  24238. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  24239. (pfbHeader[3] << 8) | pfbHeader[2];
  24240. }
  24241. // Decrypt the data blocks and retrieve it's content
  24242. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  24243. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  24244. var data = eexecBlockParser.extractFontProgram();
  24245. for (var info in data.properties) {
  24246. properties[info] = data.properties[info];
  24247. }
  24248. var charstrings = data.charstrings;
  24249. var type2Charstrings = this.getType2Charstrings(charstrings);
  24250. var subrs = this.getType2Subrs(data.subrs);
  24251. this.charstrings = charstrings;
  24252. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  24253. subrs, properties);
  24254. this.seacs = this.getSeacs(data.charstrings);
  24255. };
  24256. Type1Font.prototype = {
  24257. get numGlyphs() {
  24258. return this.charstrings.length + 1;
  24259. },
  24260. getCharset: function Type1Font_getCharset() {
  24261. var charset = ['.notdef'];
  24262. var charstrings = this.charstrings;
  24263. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  24264. charset.push(charstrings[glyphId].glyphName);
  24265. }
  24266. return charset;
  24267. },
  24268. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  24269. var charstrings = this.charstrings;
  24270. var glyphNames = ['.notdef'], glyphId;
  24271. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  24272. glyphNames.push(charstrings[glyphId].glyphName);
  24273. }
  24274. var encoding = properties.builtInEncoding;
  24275. if (encoding) {
  24276. var builtInEncoding = {};
  24277. for (var charCode in encoding) {
  24278. glyphId = glyphNames.indexOf(encoding[charCode]);
  24279. if (glyphId >= 0) {
  24280. builtInEncoding[charCode] = glyphId;
  24281. }
  24282. }
  24283. }
  24284. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  24285. },
  24286. getSeacs: function Type1Font_getSeacs(charstrings) {
  24287. var i, ii;
  24288. var seacMap = [];
  24289. for (i = 0, ii = charstrings.length; i < ii; i++) {
  24290. var charstring = charstrings[i];
  24291. if (charstring.seac) {
  24292. // Offset by 1 for .notdef
  24293. seacMap[i + 1] = charstring.seac;
  24294. }
  24295. }
  24296. return seacMap;
  24297. },
  24298. getType2Charstrings: function Type1Font_getType2Charstrings(
  24299. type1Charstrings) {
  24300. var type2Charstrings = [];
  24301. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  24302. type2Charstrings.push(type1Charstrings[i].charstring);
  24303. }
  24304. return type2Charstrings;
  24305. },
  24306. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  24307. var bias = 0;
  24308. var count = type1Subrs.length;
  24309. if (count < 1133) {
  24310. bias = 107;
  24311. } else if (count < 33769) {
  24312. bias = 1131;
  24313. } else {
  24314. bias = 32768;
  24315. }
  24316. // Add a bunch of empty subrs to deal with the Type2 bias
  24317. var type2Subrs = [];
  24318. var i;
  24319. for (i = 0; i < bias; i++) {
  24320. type2Subrs.push([0x0B]);
  24321. }
  24322. for (i = 0; i < count; i++) {
  24323. type2Subrs.push(type1Subrs[i]);
  24324. }
  24325. return type2Subrs;
  24326. },
  24327. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  24328. var cff = new CFF();
  24329. cff.header = new CFFHeader(1, 0, 4, 4);
  24330. cff.names = [name];
  24331. var topDict = new CFFTopDict();
  24332. // CFF strings IDs 0...390 are predefined names, so refering
  24333. // to entries in our own String INDEX starts at SID 391.
  24334. topDict.setByName('version', 391);
  24335. topDict.setByName('Notice', 392);
  24336. topDict.setByName('FullName', 393);
  24337. topDict.setByName('FamilyName', 394);
  24338. topDict.setByName('Weight', 395);
  24339. topDict.setByName('Encoding', null); // placeholder
  24340. topDict.setByName('FontMatrix', properties.fontMatrix);
  24341. topDict.setByName('FontBBox', properties.bbox);
  24342. topDict.setByName('charset', null); // placeholder
  24343. topDict.setByName('CharStrings', null); // placeholder
  24344. topDict.setByName('Private', null); // placeholder
  24345. cff.topDict = topDict;
  24346. var strings = new CFFStrings();
  24347. strings.add('Version 0.11'); // Version
  24348. strings.add('See original notice'); // Notice
  24349. strings.add(name); // FullName
  24350. strings.add(name); // FamilyName
  24351. strings.add('Medium'); // Weight
  24352. cff.strings = strings;
  24353. cff.globalSubrIndex = new CFFIndex();
  24354. var count = glyphs.length;
  24355. var charsetArray = [0];
  24356. var i, ii;
  24357. for (i = 0; i < count; i++) {
  24358. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  24359. // TODO: Insert the string and correctly map it. Previously it was
  24360. // thought mapping names that aren't in the standard strings to .notdef
  24361. // was fine, however in issue818 when mapping them all to .notdef the
  24362. // adieresis glyph no longer worked.
  24363. if (index === -1) {
  24364. index = 0;
  24365. }
  24366. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  24367. }
  24368. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  24369. var charStringsIndex = new CFFIndex();
  24370. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  24371. for (i = 0; i < count; i++) {
  24372. charStringsIndex.add(glyphs[i]);
  24373. }
  24374. cff.charStrings = charStringsIndex;
  24375. var privateDict = new CFFPrivateDict();
  24376. privateDict.setByName('Subrs', null); // placeholder
  24377. var fields = [
  24378. 'BlueValues',
  24379. 'OtherBlues',
  24380. 'FamilyBlues',
  24381. 'FamilyOtherBlues',
  24382. 'StemSnapH',
  24383. 'StemSnapV',
  24384. 'BlueShift',
  24385. 'BlueFuzz',
  24386. 'BlueScale',
  24387. 'LanguageGroup',
  24388. 'ExpansionFactor',
  24389. 'ForceBold',
  24390. 'StdHW',
  24391. 'StdVW'
  24392. ];
  24393. for (i = 0, ii = fields.length; i < ii; i++) {
  24394. var field = fields[i];
  24395. if (!properties.privateData.hasOwnProperty(field)) {
  24396. continue;
  24397. }
  24398. var value = properties.privateData[field];
  24399. if (isArray(value)) {
  24400. // All of the private dictionary array data in CFF must be stored as
  24401. // "delta-encoded" numbers.
  24402. for (var j = value.length - 1; j > 0; j--) {
  24403. value[j] -= value[j - 1]; // ... difference from previous value
  24404. }
  24405. }
  24406. privateDict.setByName(field, value);
  24407. }
  24408. cff.topDict.privateDict = privateDict;
  24409. var subrIndex = new CFFIndex();
  24410. for (i = 0, ii = subrs.length; i < ii; i++) {
  24411. subrIndex.add(subrs[i]);
  24412. }
  24413. privateDict.subrsIndex = subrIndex;
  24414. var compiler = new CFFCompiler(cff);
  24415. return compiler.compile();
  24416. }
  24417. };
  24418. var CFFFont = (function CFFFontClosure() {
  24419. function CFFFont(file, properties) {
  24420. this.properties = properties;
  24421. var parser = new CFFParser(file, properties);
  24422. this.cff = parser.parse();
  24423. var compiler = new CFFCompiler(this.cff);
  24424. this.seacs = this.cff.seacs;
  24425. try {
  24426. this.data = compiler.compile();
  24427. } catch (e) {
  24428. warn('Failed to compile font ' + properties.loadedName);
  24429. // There may have just been an issue with the compiler, set the data
  24430. // anyway and hope the font loaded.
  24431. this.data = file;
  24432. }
  24433. }
  24434. CFFFont.prototype = {
  24435. get numGlyphs() {
  24436. return this.cff.charStrings.count;
  24437. },
  24438. getCharset: function CFFFont_getCharset() {
  24439. return this.cff.charset.charset;
  24440. },
  24441. getGlyphMapping: function CFFFont_getGlyphMapping() {
  24442. var cff = this.cff;
  24443. var properties = this.properties;
  24444. var charsets = cff.charset.charset;
  24445. var charCodeToGlyphId;
  24446. var glyphId;
  24447. if (properties.composite) {
  24448. charCodeToGlyphId = Object.create(null);
  24449. if (cff.isCIDFont) {
  24450. // If the font is actually a CID font then we should use the charset
  24451. // to map CIDs to GIDs.
  24452. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  24453. var cid = charsets[glyphId];
  24454. var charCode = properties.cMap.charCodeOf(cid);
  24455. charCodeToGlyphId[charCode] = glyphId;
  24456. }
  24457. } else {
  24458. // If it is NOT actually a CID font then CIDs should be mapped
  24459. // directly to GIDs.
  24460. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  24461. charCodeToGlyphId[glyphId] = glyphId;
  24462. }
  24463. }
  24464. return charCodeToGlyphId;
  24465. }
  24466. var encoding = cff.encoding ? cff.encoding.encoding : null;
  24467. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  24468. return charCodeToGlyphId;
  24469. }
  24470. };
  24471. return CFFFont;
  24472. })();
  24473. var CFFParser = (function CFFParserClosure() {
  24474. var CharstringValidationData = [
  24475. null,
  24476. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  24477. null,
  24478. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  24479. { id: 'vmoveto', min: 1, stackClearing: true },
  24480. { id: 'rlineto', min: 2, resetStack: true },
  24481. { id: 'hlineto', min: 1, resetStack: true },
  24482. { id: 'vlineto', min: 1, resetStack: true },
  24483. { id: 'rrcurveto', min: 6, resetStack: true },
  24484. null,
  24485. { id: 'callsubr', min: 1, undefStack: true },
  24486. { id: 'return', min: 0, undefStack: true },
  24487. null, // 12
  24488. null,
  24489. { id: 'endchar', min: 0, stackClearing: true },
  24490. null,
  24491. null,
  24492. null,
  24493. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  24494. { id: 'hintmask', min: 0, stackClearing: true },
  24495. { id: 'cntrmask', min: 0, stackClearing: true },
  24496. { id: 'rmoveto', min: 2, stackClearing: true },
  24497. { id: 'hmoveto', min: 1, stackClearing: true },
  24498. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  24499. { id: 'rcurveline', min: 8, resetStack: true },
  24500. { id: 'rlinecurve', min: 8, resetStack: true },
  24501. { id: 'vvcurveto', min: 4, resetStack: true },
  24502. { id: 'hhcurveto', min: 4, resetStack: true },
  24503. null, // shortint
  24504. { id: 'callgsubr', min: 1, undefStack: true },
  24505. { id: 'vhcurveto', min: 4, resetStack: true },
  24506. { id: 'hvcurveto', min: 4, resetStack: true }
  24507. ];
  24508. var CharstringValidationData12 = [
  24509. null,
  24510. null,
  24511. null,
  24512. { id: 'and', min: 2, stackDelta: -1 },
  24513. { id: 'or', min: 2, stackDelta: -1 },
  24514. { id: 'not', min: 1, stackDelta: 0 },
  24515. null,
  24516. null,
  24517. null,
  24518. { id: 'abs', min: 1, stackDelta: 0 },
  24519. { id: 'add', min: 2, stackDelta: -1,
  24520. stackFn: function stack_div(stack, index) {
  24521. stack[index - 2] = stack[index - 2] + stack[index - 1];
  24522. }
  24523. },
  24524. { id: 'sub', min: 2, stackDelta: -1,
  24525. stackFn: function stack_div(stack, index) {
  24526. stack[index - 2] = stack[index - 2] - stack[index - 1];
  24527. }
  24528. },
  24529. { id: 'div', min: 2, stackDelta: -1,
  24530. stackFn: function stack_div(stack, index) {
  24531. stack[index - 2] = stack[index - 2] / stack[index - 1];
  24532. }
  24533. },
  24534. null,
  24535. { id: 'neg', min: 1, stackDelta: 0,
  24536. stackFn: function stack_div(stack, index) {
  24537. stack[index - 1] = -stack[index - 1];
  24538. }
  24539. },
  24540. { id: 'eq', min: 2, stackDelta: -1 },
  24541. null,
  24542. null,
  24543. { id: 'drop', min: 1, stackDelta: -1 },
  24544. null,
  24545. { id: 'put', min: 2, stackDelta: -2 },
  24546. { id: 'get', min: 1, stackDelta: 0 },
  24547. { id: 'ifelse', min: 4, stackDelta: -3 },
  24548. { id: 'random', min: 0, stackDelta: 1 },
  24549. { id: 'mul', min: 2, stackDelta: -1,
  24550. stackFn: function stack_div(stack, index) {
  24551. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24552. }
  24553. },
  24554. null,
  24555. { id: 'sqrt', min: 1, stackDelta: 0 },
  24556. { id: 'dup', min: 1, stackDelta: 1 },
  24557. { id: 'exch', min: 2, stackDelta: 0 },
  24558. { id: 'index', min: 2, stackDelta: 0 },
  24559. { id: 'roll', min: 3, stackDelta: -2 },
  24560. null,
  24561. null,
  24562. null,
  24563. { id: 'hflex', min: 7, resetStack: true },
  24564. { id: 'flex', min: 13, resetStack: true },
  24565. { id: 'hflex1', min: 9, resetStack: true },
  24566. { id: 'flex1', min: 11, resetStack: true }
  24567. ];
  24568. function CFFParser(file, properties) {
  24569. this.bytes = file.getBytes();
  24570. this.properties = properties;
  24571. }
  24572. CFFParser.prototype = {
  24573. parse: function CFFParser_parse() {
  24574. var properties = this.properties;
  24575. var cff = new CFF();
  24576. this.cff = cff;
  24577. // The first five sections must be in order, all the others are reached
  24578. // via offsets contained in one of the below.
  24579. var header = this.parseHeader();
  24580. var nameIndex = this.parseIndex(header.endPos);
  24581. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24582. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24583. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24584. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24585. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24586. cff.header = header.obj;
  24587. cff.names = this.parseNameIndex(nameIndex.obj);
  24588. cff.strings = this.parseStringIndex(stringIndex.obj);
  24589. cff.topDict = topDict;
  24590. cff.globalSubrIndex = globalSubrIndex.obj;
  24591. this.parsePrivateDict(cff.topDict);
  24592. cff.isCIDFont = topDict.hasName('ROS');
  24593. var charStringOffset = topDict.getByName('CharStrings');
  24594. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24595. cff.charStrings = charStringsAndSeacs.charStrings;
  24596. cff.seacs = charStringsAndSeacs.seacs;
  24597. cff.widths = charStringsAndSeacs.widths;
  24598. var fontMatrix = topDict.getByName('FontMatrix');
  24599. if (fontMatrix) {
  24600. properties.fontMatrix = fontMatrix;
  24601. }
  24602. var fontBBox = topDict.getByName('FontBBox');
  24603. if (fontBBox) {
  24604. // adjusting ascent/descent
  24605. properties.ascent = fontBBox[3];
  24606. properties.descent = fontBBox[1];
  24607. properties.ascentScaled = true;
  24608. }
  24609. var charset, encoding;
  24610. if (cff.isCIDFont) {
  24611. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24612. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24613. var dictRaw = fdArrayIndex.get(i);
  24614. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24615. cff.strings);
  24616. this.parsePrivateDict(fontDict);
  24617. cff.fdArray.push(fontDict);
  24618. }
  24619. // cid fonts don't have an encoding
  24620. encoding = null;
  24621. charset = this.parseCharsets(topDict.getByName('charset'),
  24622. cff.charStrings.count, cff.strings, true);
  24623. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24624. cff.charStrings.count);
  24625. } else {
  24626. charset = this.parseCharsets(topDict.getByName('charset'),
  24627. cff.charStrings.count, cff.strings, false);
  24628. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24629. properties,
  24630. cff.strings, charset.charset);
  24631. }
  24632. cff.charset = charset;
  24633. cff.encoding = encoding;
  24634. return cff;
  24635. },
  24636. parseHeader: function CFFParser_parseHeader() {
  24637. var bytes = this.bytes;
  24638. var bytesLength = bytes.length;
  24639. var offset = 0;
  24640. // Prevent an infinite loop, by checking that the offset is within the
  24641. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24642. while (offset < bytesLength && bytes[offset] !== 1) {
  24643. ++offset;
  24644. }
  24645. if (offset >= bytesLength) {
  24646. error('Invalid CFF header');
  24647. } else if (offset !== 0) {
  24648. info('cff data is shifted');
  24649. bytes = bytes.subarray(offset);
  24650. this.bytes = bytes;
  24651. }
  24652. var major = bytes[0];
  24653. var minor = bytes[1];
  24654. var hdrSize = bytes[2];
  24655. var offSize = bytes[3];
  24656. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24657. return { obj: header, endPos: hdrSize };
  24658. },
  24659. parseDict: function CFFParser_parseDict(dict) {
  24660. var pos = 0;
  24661. function parseOperand() {
  24662. var value = dict[pos++];
  24663. if (value === 30) {
  24664. return parseFloatOperand(pos);
  24665. } else if (value === 28) {
  24666. value = dict[pos++];
  24667. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24668. return value;
  24669. } else if (value === 29) {
  24670. value = dict[pos++];
  24671. value = (value << 8) | dict[pos++];
  24672. value = (value << 8) | dict[pos++];
  24673. value = (value << 8) | dict[pos++];
  24674. return value;
  24675. } else if (value >= 32 && value <= 246) {
  24676. return value - 139;
  24677. } else if (value >= 247 && value <= 250) {
  24678. return ((value - 247) * 256) + dict[pos++] + 108;
  24679. } else if (value >= 251 && value <= 254) {
  24680. return -((value - 251) * 256) - dict[pos++] - 108;
  24681. } else {
  24682. error('255 is not a valid DICT command');
  24683. }
  24684. return -1;
  24685. }
  24686. function parseFloatOperand() {
  24687. var str = '';
  24688. var eof = 15;
  24689. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24690. '9', '.', 'E', 'E-', null, '-'];
  24691. var length = dict.length;
  24692. while (pos < length) {
  24693. var b = dict[pos++];
  24694. var b1 = b >> 4;
  24695. var b2 = b & 15;
  24696. if (b1 === eof) {
  24697. break;
  24698. }
  24699. str += lookup[b1];
  24700. if (b2 === eof) {
  24701. break;
  24702. }
  24703. str += lookup[b2];
  24704. }
  24705. return parseFloat(str);
  24706. }
  24707. var operands = [];
  24708. var entries = [];
  24709. pos = 0;
  24710. var end = dict.length;
  24711. while (pos < end) {
  24712. var b = dict[pos];
  24713. if (b <= 21) {
  24714. if (b === 12) {
  24715. b = (b << 8) | dict[++pos];
  24716. }
  24717. entries.push([b, operands]);
  24718. operands = [];
  24719. ++pos;
  24720. } else {
  24721. operands.push(parseOperand());
  24722. }
  24723. }
  24724. return entries;
  24725. },
  24726. parseIndex: function CFFParser_parseIndex(pos) {
  24727. var cffIndex = new CFFIndex();
  24728. var bytes = this.bytes;
  24729. var count = (bytes[pos++] << 8) | bytes[pos++];
  24730. var offsets = [];
  24731. var end = pos;
  24732. var i, ii;
  24733. if (count !== 0) {
  24734. var offsetSize = bytes[pos++];
  24735. // add 1 for offset to determine size of last object
  24736. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24737. for (i = 0, ii = count + 1; i < ii; ++i) {
  24738. var offset = 0;
  24739. for (var j = 0; j < offsetSize; ++j) {
  24740. offset <<= 8;
  24741. offset += bytes[pos++];
  24742. }
  24743. offsets.push(startPos + offset);
  24744. }
  24745. end = offsets[count];
  24746. }
  24747. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24748. var offsetStart = offsets[i];
  24749. var offsetEnd = offsets[i + 1];
  24750. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24751. }
  24752. return {obj: cffIndex, endPos: end};
  24753. },
  24754. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24755. var names = [];
  24756. for (var i = 0, ii = index.count; i < ii; ++i) {
  24757. var name = index.get(i);
  24758. // OTS doesn't allow names to be over 127 characters.
  24759. var length = Math.min(name.length, 127);
  24760. var data = [];
  24761. // OTS also only permits certain characters in the name.
  24762. for (var j = 0; j < length; ++j) {
  24763. var c = name[j];
  24764. if (j === 0 && c === 0) {
  24765. data[j] = c;
  24766. continue;
  24767. }
  24768. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24769. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24770. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24771. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24772. data[j] = 95;
  24773. continue;
  24774. }
  24775. data[j] = c;
  24776. }
  24777. names.push(bytesToString(data));
  24778. }
  24779. return names;
  24780. },
  24781. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24782. var strings = new CFFStrings();
  24783. for (var i = 0, ii = index.count; i < ii; ++i) {
  24784. var data = index.get(i);
  24785. strings.add(bytesToString(data));
  24786. }
  24787. return strings;
  24788. },
  24789. createDict: function CFFParser_createDict(Type, dict, strings) {
  24790. var cffDict = new Type(strings);
  24791. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24792. var pair = dict[i];
  24793. var key = pair[0];
  24794. var value = pair[1];
  24795. cffDict.setByKey(key, value);
  24796. }
  24797. return cffDict;
  24798. },
  24799. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24800. var charStrings = this.parseIndex(charStringOffset).obj;
  24801. var seacs = [];
  24802. var widths = [];
  24803. var count = charStrings.count;
  24804. for (var i = 0; i < count; i++) {
  24805. var charstring = charStrings.get(i);
  24806. var stackSize = 0;
  24807. var stack = [];
  24808. var undefStack = true;
  24809. var hints = 0;
  24810. var valid = true;
  24811. var data = charstring;
  24812. var length = data.length;
  24813. var firstStackClearing = true;
  24814. for (var j = 0; j < length;) {
  24815. var value = data[j++];
  24816. var validationCommand = null;
  24817. if (value === 12) {
  24818. var q = data[j++];
  24819. if (q === 0) {
  24820. // The CFF specification state that the 'dotsection' command
  24821. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24822. // charstrings processors should support them. Unfortunately
  24823. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24824. // is replaced by a useless (0, hmoveto).
  24825. data[j - 2] = 139;
  24826. data[j - 1] = 22;
  24827. stackSize = 0;
  24828. } else {
  24829. validationCommand = CharstringValidationData12[q];
  24830. }
  24831. } else if (value === 28) { // number (16 bit)
  24832. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24833. j += 2;
  24834. stackSize++;
  24835. } else if (value === 14) {
  24836. if (stackSize >= 4) {
  24837. stackSize -= 4;
  24838. if (SEAC_ANALYSIS_ENABLED) {
  24839. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24840. valid = false;
  24841. }
  24842. }
  24843. validationCommand = CharstringValidationData[value];
  24844. } else if (value >= 32 && value <= 246) { // number
  24845. stack[stackSize] = value - 139;
  24846. stackSize++;
  24847. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24848. stack[stackSize] = (value < 251 ?
  24849. ((value - 247) << 8) + data[j] + 108 :
  24850. -((value - 251) << 8) - data[j] - 108);
  24851. j++;
  24852. stackSize++;
  24853. } else if (value === 255) { // number (32 bit)
  24854. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24855. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24856. j += 4;
  24857. stackSize++;
  24858. } else if (value === 19 || value === 20) {
  24859. hints += stackSize >> 1;
  24860. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24861. stackSize %= 2;
  24862. validationCommand = CharstringValidationData[value];
  24863. } else {
  24864. validationCommand = CharstringValidationData[value];
  24865. }
  24866. if (validationCommand) {
  24867. if (validationCommand.stem) {
  24868. hints += stackSize >> 1;
  24869. }
  24870. if ('min' in validationCommand) {
  24871. if (!undefStack && stackSize < validationCommand.min) {
  24872. warn('Not enough parameters for ' + validationCommand.id +
  24873. '; actual: ' + stackSize +
  24874. ', expected: ' + validationCommand.min);
  24875. valid = false;
  24876. break;
  24877. }
  24878. }
  24879. if (firstStackClearing && validationCommand.stackClearing) {
  24880. firstStackClearing = false;
  24881. // the optional character width can be found before the first
  24882. // stack-clearing command arguments
  24883. stackSize -= validationCommand.min;
  24884. if (stackSize >= 2 && validationCommand.stem) {
  24885. // there are even amount of arguments for stem commands
  24886. stackSize %= 2;
  24887. } else if (stackSize > 1) {
  24888. warn('Found too many parameters for stack-clearing command');
  24889. }
  24890. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24891. widths[i] = stack[stackSize - 1];
  24892. }
  24893. }
  24894. if ('stackDelta' in validationCommand) {
  24895. if ('stackFn' in validationCommand) {
  24896. validationCommand.stackFn(stack, stackSize);
  24897. }
  24898. stackSize += validationCommand.stackDelta;
  24899. } else if (validationCommand.stackClearing) {
  24900. stackSize = 0;
  24901. } else if (validationCommand.resetStack) {
  24902. stackSize = 0;
  24903. undefStack = false;
  24904. } else if (validationCommand.undefStack) {
  24905. stackSize = 0;
  24906. undefStack = true;
  24907. firstStackClearing = false;
  24908. }
  24909. }
  24910. }
  24911. if (!valid) {
  24912. // resetting invalid charstring to single 'endchar'
  24913. charStrings.set(i, new Uint8Array([14]));
  24914. }
  24915. }
  24916. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24917. },
  24918. emptyPrivateDictionary:
  24919. function CFFParser_emptyPrivateDictionary(parentDict) {
  24920. var privateDict = this.createDict(CFFPrivateDict, [],
  24921. parentDict.strings);
  24922. parentDict.setByKey(18, [0, 0]);
  24923. parentDict.privateDict = privateDict;
  24924. },
  24925. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24926. // no private dict, do nothing
  24927. if (!parentDict.hasName('Private')) {
  24928. this.emptyPrivateDictionary(parentDict);
  24929. return;
  24930. }
  24931. var privateOffset = parentDict.getByName('Private');
  24932. // make sure the params are formatted correctly
  24933. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24934. parentDict.removeByName('Private');
  24935. return;
  24936. }
  24937. var size = privateOffset[0];
  24938. var offset = privateOffset[1];
  24939. // remove empty dicts or ones that refer to invalid location
  24940. if (size === 0 || offset >= this.bytes.length) {
  24941. this.emptyPrivateDictionary(parentDict);
  24942. return;
  24943. }
  24944. var privateDictEnd = offset + size;
  24945. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24946. var dict = this.parseDict(dictData);
  24947. var privateDict = this.createDict(CFFPrivateDict, dict,
  24948. parentDict.strings);
  24949. parentDict.privateDict = privateDict;
  24950. // Parse the Subrs index also since it's relative to the private dict.
  24951. if (!privateDict.getByName('Subrs')) {
  24952. return;
  24953. }
  24954. var subrsOffset = privateDict.getByName('Subrs');
  24955. var relativeOffset = offset + subrsOffset;
  24956. // Validate the offset.
  24957. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24958. this.emptyPrivateDictionary(parentDict);
  24959. return;
  24960. }
  24961. var subrsIndex = this.parseIndex(relativeOffset);
  24962. privateDict.subrsIndex = subrsIndex.obj;
  24963. },
  24964. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24965. if (pos === 0) {
  24966. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24967. ISOAdobeCharset);
  24968. } else if (pos === 1) {
  24969. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24970. ExpertCharset);
  24971. } else if (pos === 2) {
  24972. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24973. ExpertSubsetCharset);
  24974. }
  24975. var bytes = this.bytes;
  24976. var start = pos;
  24977. var format = bytes[pos++];
  24978. var charset = ['.notdef'];
  24979. var id, count, i;
  24980. // subtract 1 for the .notdef glyph
  24981. length -= 1;
  24982. switch (format) {
  24983. case 0:
  24984. for (i = 0; i < length; i++) {
  24985. id = (bytes[pos++] << 8) | bytes[pos++];
  24986. charset.push(cid ? id : strings.get(id));
  24987. }
  24988. break;
  24989. case 1:
  24990. while (charset.length <= length) {
  24991. id = (bytes[pos++] << 8) | bytes[pos++];
  24992. count = bytes[pos++];
  24993. for (i = 0; i <= count; i++) {
  24994. charset.push(cid ? id++ : strings.get(id++));
  24995. }
  24996. }
  24997. break;
  24998. case 2:
  24999. while (charset.length <= length) {
  25000. id = (bytes[pos++] << 8) | bytes[pos++];
  25001. count = (bytes[pos++] << 8) | bytes[pos++];
  25002. for (i = 0; i <= count; i++) {
  25003. charset.push(cid ? id++ : strings.get(id++));
  25004. }
  25005. }
  25006. break;
  25007. default:
  25008. error('Unknown charset format');
  25009. }
  25010. // Raw won't be needed if we actually compile the charset.
  25011. var end = pos;
  25012. var raw = bytes.subarray(start, end);
  25013. return new CFFCharset(false, format, charset, raw);
  25014. },
  25015. parseEncoding: function CFFParser_parseEncoding(pos,
  25016. properties,
  25017. strings,
  25018. charset) {
  25019. var encoding = {};
  25020. var bytes = this.bytes;
  25021. var predefined = false;
  25022. var hasSupplement = false;
  25023. var format, i, ii;
  25024. var raw = null;
  25025. function readSupplement() {
  25026. var supplementsCount = bytes[pos++];
  25027. for (i = 0; i < supplementsCount; i++) {
  25028. var code = bytes[pos++];
  25029. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  25030. encoding[code] = charset.indexOf(strings.get(sid));
  25031. }
  25032. }
  25033. if (pos === 0 || pos === 1) {
  25034. predefined = true;
  25035. format = pos;
  25036. var baseEncoding = pos ? Encodings.ExpertEncoding :
  25037. Encodings.StandardEncoding;
  25038. for (i = 0, ii = charset.length; i < ii; i++) {
  25039. var index = baseEncoding.indexOf(charset[i]);
  25040. if (index !== -1) {
  25041. encoding[index] = i;
  25042. }
  25043. }
  25044. } else {
  25045. var dataStart = pos;
  25046. format = bytes[pos++];
  25047. switch (format & 0x7f) {
  25048. case 0:
  25049. var glyphsCount = bytes[pos++];
  25050. for (i = 1; i <= glyphsCount; i++) {
  25051. encoding[bytes[pos++]] = i;
  25052. }
  25053. break;
  25054. case 1:
  25055. var rangesCount = bytes[pos++];
  25056. var gid = 1;
  25057. for (i = 0; i < rangesCount; i++) {
  25058. var start = bytes[pos++];
  25059. var left = bytes[pos++];
  25060. for (var j = start; j <= start + left; j++) {
  25061. encoding[j] = gid++;
  25062. }
  25063. }
  25064. break;
  25065. default:
  25066. error('Unknow encoding format: ' + format + ' in CFF');
  25067. break;
  25068. }
  25069. var dataEnd = pos;
  25070. if (format & 0x80) {
  25071. // The font sanitizer does not support CFF encoding with a
  25072. // supplement, since the encoding is not really used to map
  25073. // between gid to glyph, let's overwrite what is declared in
  25074. // the top dictionary to let the sanitizer think the font use
  25075. // StandardEncoding, that's a lie but that's ok.
  25076. bytes[dataStart] &= 0x7f;
  25077. readSupplement();
  25078. hasSupplement = true;
  25079. }
  25080. raw = bytes.subarray(dataStart, dataEnd);
  25081. }
  25082. format = format & 0x7f;
  25083. return new CFFEncoding(predefined, format, encoding, raw);
  25084. },
  25085. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  25086. var start = pos;
  25087. var bytes = this.bytes;
  25088. var format = bytes[pos++];
  25089. var fdSelect = [];
  25090. var i;
  25091. switch (format) {
  25092. case 0:
  25093. for (i = 0; i < length; ++i) {
  25094. var id = bytes[pos++];
  25095. fdSelect.push(id);
  25096. }
  25097. break;
  25098. case 3:
  25099. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  25100. for (i = 0; i < rangesCount; ++i) {
  25101. var first = (bytes[pos++] << 8) | bytes[pos++];
  25102. var fdIndex = bytes[pos++];
  25103. var next = (bytes[pos] << 8) | bytes[pos + 1];
  25104. for (var j = first; j < next; ++j) {
  25105. fdSelect.push(fdIndex);
  25106. }
  25107. }
  25108. // Advance past the sentinel(next).
  25109. pos += 2;
  25110. break;
  25111. default:
  25112. error('Unknown fdselect format ' + format);
  25113. break;
  25114. }
  25115. var end = pos;
  25116. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  25117. }
  25118. };
  25119. return CFFParser;
  25120. })();
  25121. // Compact Font Format
  25122. var CFF = (function CFFClosure() {
  25123. function CFF() {
  25124. this.header = null;
  25125. this.names = [];
  25126. this.topDict = null;
  25127. this.strings = new CFFStrings();
  25128. this.globalSubrIndex = null;
  25129. // The following could really be per font, but since we only have one font
  25130. // store them here.
  25131. this.encoding = null;
  25132. this.charset = null;
  25133. this.charStrings = null;
  25134. this.fdArray = [];
  25135. this.fdSelect = null;
  25136. this.isCIDFont = false;
  25137. }
  25138. return CFF;
  25139. })();
  25140. var CFFHeader = (function CFFHeaderClosure() {
  25141. function CFFHeader(major, minor, hdrSize, offSize) {
  25142. this.major = major;
  25143. this.minor = minor;
  25144. this.hdrSize = hdrSize;
  25145. this.offSize = offSize;
  25146. }
  25147. return CFFHeader;
  25148. })();
  25149. var CFFStrings = (function CFFStringsClosure() {
  25150. function CFFStrings() {
  25151. this.strings = [];
  25152. }
  25153. CFFStrings.prototype = {
  25154. get: function CFFStrings_get(index) {
  25155. if (index >= 0 && index <= 390) {
  25156. return CFFStandardStrings[index];
  25157. }
  25158. if (index - 391 <= this.strings.length) {
  25159. return this.strings[index - 391];
  25160. }
  25161. return CFFStandardStrings[0];
  25162. },
  25163. add: function CFFStrings_add(value) {
  25164. this.strings.push(value);
  25165. },
  25166. get count() {
  25167. return this.strings.length;
  25168. }
  25169. };
  25170. return CFFStrings;
  25171. })();
  25172. var CFFIndex = (function CFFIndexClosure() {
  25173. function CFFIndex() {
  25174. this.objects = [];
  25175. this.length = 0;
  25176. }
  25177. CFFIndex.prototype = {
  25178. add: function CFFIndex_add(data) {
  25179. this.length += data.length;
  25180. this.objects.push(data);
  25181. },
  25182. set: function CFFIndex_set(index, data) {
  25183. this.length += data.length - this.objects[index].length;
  25184. this.objects[index] = data;
  25185. },
  25186. get: function CFFIndex_get(index) {
  25187. return this.objects[index];
  25188. },
  25189. get count() {
  25190. return this.objects.length;
  25191. }
  25192. };
  25193. return CFFIndex;
  25194. })();
  25195. var CFFDict = (function CFFDictClosure() {
  25196. function CFFDict(tables, strings) {
  25197. this.keyToNameMap = tables.keyToNameMap;
  25198. this.nameToKeyMap = tables.nameToKeyMap;
  25199. this.defaults = tables.defaults;
  25200. this.types = tables.types;
  25201. this.opcodes = tables.opcodes;
  25202. this.order = tables.order;
  25203. this.strings = strings;
  25204. this.values = {};
  25205. }
  25206. CFFDict.prototype = {
  25207. // value should always be an array
  25208. setByKey: function CFFDict_setByKey(key, value) {
  25209. if (!(key in this.keyToNameMap)) {
  25210. return false;
  25211. }
  25212. // ignore empty values
  25213. if (value.length === 0) {
  25214. return true;
  25215. }
  25216. var type = this.types[key];
  25217. // remove the array wrapping these types of values
  25218. if (type === 'num' || type === 'sid' || type === 'offset') {
  25219. value = value[0];
  25220. }
  25221. this.values[key] = value;
  25222. return true;
  25223. },
  25224. setByName: function CFFDict_setByName(name, value) {
  25225. if (!(name in this.nameToKeyMap)) {
  25226. error('Invalid dictionary name "' + name + '"');
  25227. }
  25228. this.values[this.nameToKeyMap[name]] = value;
  25229. },
  25230. hasName: function CFFDict_hasName(name) {
  25231. return this.nameToKeyMap[name] in this.values;
  25232. },
  25233. getByName: function CFFDict_getByName(name) {
  25234. if (!(name in this.nameToKeyMap)) {
  25235. error('Invalid dictionary name "' + name + '"');
  25236. }
  25237. var key = this.nameToKeyMap[name];
  25238. if (!(key in this.values)) {
  25239. return this.defaults[key];
  25240. }
  25241. return this.values[key];
  25242. },
  25243. removeByName: function CFFDict_removeByName(name) {
  25244. delete this.values[this.nameToKeyMap[name]];
  25245. }
  25246. };
  25247. CFFDict.createTables = function CFFDict_createTables(layout) {
  25248. var tables = {
  25249. keyToNameMap: {},
  25250. nameToKeyMap: {},
  25251. defaults: {},
  25252. types: {},
  25253. opcodes: {},
  25254. order: []
  25255. };
  25256. for (var i = 0, ii = layout.length; i < ii; ++i) {
  25257. var entry = layout[i];
  25258. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  25259. tables.keyToNameMap[key] = entry[1];
  25260. tables.nameToKeyMap[entry[1]] = key;
  25261. tables.types[key] = entry[2];
  25262. tables.defaults[key] = entry[3];
  25263. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  25264. tables.order.push(key);
  25265. }
  25266. return tables;
  25267. };
  25268. return CFFDict;
  25269. })();
  25270. var CFFTopDict = (function CFFTopDictClosure() {
  25271. var layout = [
  25272. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  25273. [[12, 20], 'SyntheticBase', 'num', null],
  25274. [0, 'version', 'sid', null],
  25275. [1, 'Notice', 'sid', null],
  25276. [[12, 0], 'Copyright', 'sid', null],
  25277. [2, 'FullName', 'sid', null],
  25278. [3, 'FamilyName', 'sid', null],
  25279. [4, 'Weight', 'sid', null],
  25280. [[12, 1], 'isFixedPitch', 'num', 0],
  25281. [[12, 2], 'ItalicAngle', 'num', 0],
  25282. [[12, 3], 'UnderlinePosition', 'num', -100],
  25283. [[12, 4], 'UnderlineThickness', 'num', 50],
  25284. [[12, 5], 'PaintType', 'num', 0],
  25285. [[12, 6], 'CharstringType', 'num', 2],
  25286. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  25287. [0.001, 0, 0, 0.001, 0, 0]],
  25288. [13, 'UniqueID', 'num', null],
  25289. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  25290. [[12, 8], 'StrokeWidth', 'num', 0],
  25291. [14, 'XUID', 'array', null],
  25292. [15, 'charset', 'offset', 0],
  25293. [16, 'Encoding', 'offset', 0],
  25294. [17, 'CharStrings', 'offset', 0],
  25295. [18, 'Private', ['offset', 'offset'], null],
  25296. [[12, 21], 'PostScript', 'sid', null],
  25297. [[12, 22], 'BaseFontName', 'sid', null],
  25298. [[12, 23], 'BaseFontBlend', 'delta', null],
  25299. [[12, 31], 'CIDFontVersion', 'num', 0],
  25300. [[12, 32], 'CIDFontRevision', 'num', 0],
  25301. [[12, 33], 'CIDFontType', 'num', 0],
  25302. [[12, 34], 'CIDCount', 'num', 8720],
  25303. [[12, 35], 'UIDBase', 'num', null],
  25304. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  25305. // before FDArray.
  25306. [[12, 37], 'FDSelect', 'offset', null],
  25307. [[12, 36], 'FDArray', 'offset', null],
  25308. [[12, 38], 'FontName', 'sid', null]
  25309. ];
  25310. var tables = null;
  25311. function CFFTopDict(strings) {
  25312. if (tables === null) {
  25313. tables = CFFDict.createTables(layout);
  25314. }
  25315. CFFDict.call(this, tables, strings);
  25316. this.privateDict = null;
  25317. }
  25318. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  25319. return CFFTopDict;
  25320. })();
  25321. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  25322. var layout = [
  25323. [6, 'BlueValues', 'delta', null],
  25324. [7, 'OtherBlues', 'delta', null],
  25325. [8, 'FamilyBlues', 'delta', null],
  25326. [9, 'FamilyOtherBlues', 'delta', null],
  25327. [[12, 9], 'BlueScale', 'num', 0.039625],
  25328. [[12, 10], 'BlueShift', 'num', 7],
  25329. [[12, 11], 'BlueFuzz', 'num', 1],
  25330. [10, 'StdHW', 'num', null],
  25331. [11, 'StdVW', 'num', null],
  25332. [[12, 12], 'StemSnapH', 'delta', null],
  25333. [[12, 13], 'StemSnapV', 'delta', null],
  25334. [[12, 14], 'ForceBold', 'num', 0],
  25335. [[12, 17], 'LanguageGroup', 'num', 0],
  25336. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  25337. [[12, 19], 'initialRandomSeed', 'num', 0],
  25338. [20, 'defaultWidthX', 'num', 0],
  25339. [21, 'nominalWidthX', 'num', 0],
  25340. [19, 'Subrs', 'offset', null]
  25341. ];
  25342. var tables = null;
  25343. function CFFPrivateDict(strings) {
  25344. if (tables === null) {
  25345. tables = CFFDict.createTables(layout);
  25346. }
  25347. CFFDict.call(this, tables, strings);
  25348. this.subrsIndex = null;
  25349. }
  25350. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  25351. return CFFPrivateDict;
  25352. })();
  25353. var CFFCharsetPredefinedTypes = {
  25354. ISO_ADOBE: 0,
  25355. EXPERT: 1,
  25356. EXPERT_SUBSET: 2
  25357. };
  25358. var CFFCharset = (function CFFCharsetClosure() {
  25359. function CFFCharset(predefined, format, charset, raw) {
  25360. this.predefined = predefined;
  25361. this.format = format;
  25362. this.charset = charset;
  25363. this.raw = raw;
  25364. }
  25365. return CFFCharset;
  25366. })();
  25367. var CFFEncoding = (function CFFEncodingClosure() {
  25368. function CFFEncoding(predefined, format, encoding, raw) {
  25369. this.predefined = predefined;
  25370. this.format = format;
  25371. this.encoding = encoding;
  25372. this.raw = raw;
  25373. }
  25374. return CFFEncoding;
  25375. })();
  25376. var CFFFDSelect = (function CFFFDSelectClosure() {
  25377. function CFFFDSelect(fdSelect, raw) {
  25378. this.fdSelect = fdSelect;
  25379. this.raw = raw;
  25380. }
  25381. return CFFFDSelect;
  25382. })();
  25383. // Helper class to keep track of where an offset is within the data and helps
  25384. // filling in that offset once it's known.
  25385. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  25386. function CFFOffsetTracker() {
  25387. this.offsets = {};
  25388. }
  25389. CFFOffsetTracker.prototype = {
  25390. isTracking: function CFFOffsetTracker_isTracking(key) {
  25391. return key in this.offsets;
  25392. },
  25393. track: function CFFOffsetTracker_track(key, location) {
  25394. if (key in this.offsets) {
  25395. error('Already tracking location of ' + key);
  25396. }
  25397. this.offsets[key] = location;
  25398. },
  25399. offset: function CFFOffsetTracker_offset(value) {
  25400. for (var key in this.offsets) {
  25401. this.offsets[key] += value;
  25402. }
  25403. },
  25404. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  25405. values,
  25406. output) {
  25407. if (!(key in this.offsets)) {
  25408. error('Not tracking location of ' + key);
  25409. }
  25410. var data = output.data;
  25411. var dataOffset = this.offsets[key];
  25412. var size = 5;
  25413. for (var i = 0, ii = values.length; i < ii; ++i) {
  25414. var offset0 = i * size + dataOffset;
  25415. var offset1 = offset0 + 1;
  25416. var offset2 = offset0 + 2;
  25417. var offset3 = offset0 + 3;
  25418. var offset4 = offset0 + 4;
  25419. // It's easy to screw up offsets so perform this sanity check.
  25420. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  25421. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  25422. error('writing to an offset that is not empty');
  25423. }
  25424. var value = values[i];
  25425. data[offset0] = 0x1d;
  25426. data[offset1] = (value >> 24) & 0xFF;
  25427. data[offset2] = (value >> 16) & 0xFF;
  25428. data[offset3] = (value >> 8) & 0xFF;
  25429. data[offset4] = value & 0xFF;
  25430. }
  25431. }
  25432. };
  25433. return CFFOffsetTracker;
  25434. })();
  25435. // Takes a CFF and converts it to the binary representation.
  25436. var CFFCompiler = (function CFFCompilerClosure() {
  25437. function CFFCompiler(cff) {
  25438. this.cff = cff;
  25439. }
  25440. CFFCompiler.prototype = {
  25441. compile: function CFFCompiler_compile() {
  25442. var cff = this.cff;
  25443. var output = {
  25444. data: [],
  25445. length: 0,
  25446. add: function CFFCompiler_add(data) {
  25447. this.data = this.data.concat(data);
  25448. this.length = this.data.length;
  25449. }
  25450. };
  25451. // Compile the five entries that must be in order.
  25452. var header = this.compileHeader(cff.header);
  25453. output.add(header);
  25454. var nameIndex = this.compileNameIndex(cff.names);
  25455. output.add(nameIndex);
  25456. if (cff.isCIDFont) {
  25457. // The spec is unclear on how font matrices should relate to each other
  25458. // when there is one in the main top dict and the sub top dicts.
  25459. // Windows handles this differently than linux and osx so we have to
  25460. // normalize to work on all.
  25461. // Rules based off of some mailing list discussions:
  25462. // - If main font has a matrix and subfont doesn't, use the main matrix.
  25463. // - If no main font matrix and there is a subfont matrix, use the
  25464. // subfont matrix.
  25465. // - If both have matrices, concat together.
  25466. // - If neither have matrices, use default.
  25467. // To make this work on all platforms we move the top matrix into each
  25468. // sub top dict and concat if necessary.
  25469. if (cff.topDict.hasName('FontMatrix')) {
  25470. var base = cff.topDict.getByName('FontMatrix');
  25471. cff.topDict.removeByName('FontMatrix');
  25472. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  25473. var subDict = cff.fdArray[i];
  25474. var matrix = base.slice(0);
  25475. if (subDict.hasName('FontMatrix')) {
  25476. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  25477. }
  25478. subDict.setByName('FontMatrix', matrix);
  25479. }
  25480. }
  25481. }
  25482. var compiled = this.compileTopDicts([cff.topDict],
  25483. output.length,
  25484. cff.isCIDFont);
  25485. output.add(compiled.output);
  25486. var topDictTracker = compiled.trackers[0];
  25487. var stringIndex = this.compileStringIndex(cff.strings.strings);
  25488. output.add(stringIndex);
  25489. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  25490. output.add(globalSubrIndex);
  25491. // Now start on the other entries that have no specfic order.
  25492. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  25493. if (cff.encoding.predefined) {
  25494. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  25495. output);
  25496. } else {
  25497. var encoding = this.compileEncoding(cff.encoding);
  25498. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  25499. output.add(encoding);
  25500. }
  25501. }
  25502. if (cff.charset && cff.topDict.hasName('charset')) {
  25503. if (cff.charset.predefined) {
  25504. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  25505. output);
  25506. } else {
  25507. var charset = this.compileCharset(cff.charset);
  25508. topDictTracker.setEntryLocation('charset', [output.length], output);
  25509. output.add(charset);
  25510. }
  25511. }
  25512. var charStrings = this.compileCharStrings(cff.charStrings);
  25513. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  25514. output.add(charStrings);
  25515. if (cff.isCIDFont) {
  25516. // For some reason FDSelect must be in front of FDArray on windows. OSX
  25517. // and linux don't seem to care.
  25518. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  25519. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  25520. output.add(fdSelect);
  25521. // It is unclear if the sub font dictionary can have CID related
  25522. // dictionary keys, but the sanitizer doesn't like them so remove them.
  25523. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  25524. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  25525. output.add(compiled.output);
  25526. var fontDictTrackers = compiled.trackers;
  25527. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  25528. }
  25529. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  25530. // If the font data ends with INDEX whose object data is zero-length,
  25531. // the sanitizer will bail out. Add a dummy byte to avoid that.
  25532. output.add([0]);
  25533. return output.data;
  25534. },
  25535. encodeNumber: function CFFCompiler_encodeNumber(value) {
  25536. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  25537. return this.encodeInteger(value);
  25538. } else {
  25539. return this.encodeFloat(value);
  25540. }
  25541. },
  25542. encodeFloat: function CFFCompiler_encodeFloat(num) {
  25543. var value = num.toString();
  25544. // rounding inaccurate doubles
  25545. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  25546. if (m) {
  25547. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  25548. value = (Math.round(num * epsilon) / epsilon).toString();
  25549. }
  25550. var nibbles = '';
  25551. var i, ii;
  25552. for (i = 0, ii = value.length; i < ii; ++i) {
  25553. var a = value[i];
  25554. if (a === 'e') {
  25555. nibbles += value[++i] === '-' ? 'c' : 'b';
  25556. } else if (a === '.') {
  25557. nibbles += 'a';
  25558. } else if (a === '-') {
  25559. nibbles += 'e';
  25560. } else {
  25561. nibbles += a;
  25562. }
  25563. }
  25564. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25565. var out = [30];
  25566. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25567. out.push(parseInt(nibbles.substr(i, 2), 16));
  25568. }
  25569. return out;
  25570. },
  25571. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25572. var code;
  25573. if (value >= -107 && value <= 107) {
  25574. code = [value + 139];
  25575. } else if (value >= 108 && value <= 1131) {
  25576. value = [value - 108];
  25577. code = [(value >> 8) + 247, value & 0xFF];
  25578. } else if (value >= -1131 && value <= -108) {
  25579. value = -value - 108;
  25580. code = [(value >> 8) + 251, value & 0xFF];
  25581. } else if (value >= -32768 && value <= 32767) {
  25582. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25583. } else {
  25584. code = [0x1d,
  25585. (value >> 24) & 0xFF,
  25586. (value >> 16) & 0xFF,
  25587. (value >> 8) & 0xFF,
  25588. value & 0xFF];
  25589. }
  25590. return code;
  25591. },
  25592. compileHeader: function CFFCompiler_compileHeader(header) {
  25593. return [
  25594. header.major,
  25595. header.minor,
  25596. header.hdrSize,
  25597. header.offSize
  25598. ];
  25599. },
  25600. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25601. var nameIndex = new CFFIndex();
  25602. for (var i = 0, ii = names.length; i < ii; ++i) {
  25603. nameIndex.add(stringToBytes(names[i]));
  25604. }
  25605. return this.compileIndex(nameIndex);
  25606. },
  25607. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25608. length,
  25609. removeCidKeys) {
  25610. var fontDictTrackers = [];
  25611. var fdArrayIndex = new CFFIndex();
  25612. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25613. var fontDict = dicts[i];
  25614. if (removeCidKeys) {
  25615. fontDict.removeByName('CIDFontVersion');
  25616. fontDict.removeByName('CIDFontRevision');
  25617. fontDict.removeByName('CIDFontType');
  25618. fontDict.removeByName('CIDCount');
  25619. fontDict.removeByName('UIDBase');
  25620. }
  25621. var fontDictTracker = new CFFOffsetTracker();
  25622. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25623. fontDictTrackers.push(fontDictTracker);
  25624. fdArrayIndex.add(fontDictData);
  25625. fontDictTracker.offset(length);
  25626. }
  25627. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25628. return {
  25629. trackers: fontDictTrackers,
  25630. output: fdArrayIndex
  25631. };
  25632. },
  25633. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25634. trackers,
  25635. output) {
  25636. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25637. var fontDict = dicts[i];
  25638. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25639. 'There must be an private dictionary.');
  25640. var privateDict = fontDict.privateDict;
  25641. var privateDictTracker = new CFFOffsetTracker();
  25642. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25643. var outputLength = output.length;
  25644. privateDictTracker.offset(outputLength);
  25645. if (!privateDictData.length) {
  25646. // The private dictionary was empty, set the output length to zero to
  25647. // ensure the offset length isn't out of bounds in the eyes of the
  25648. // sanitizer.
  25649. outputLength = 0;
  25650. }
  25651. trackers[i].setEntryLocation('Private',
  25652. [privateDictData.length, outputLength],
  25653. output);
  25654. output.add(privateDictData);
  25655. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25656. var subrs = this.compileIndex(privateDict.subrsIndex);
  25657. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25658. output);
  25659. output.add(subrs);
  25660. }
  25661. }
  25662. },
  25663. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25664. var out = [];
  25665. // The dictionary keys must be in a certain order.
  25666. var order = dict.order;
  25667. for (var i = 0; i < order.length; ++i) {
  25668. var key = order[i];
  25669. if (!(key in dict.values)) {
  25670. continue;
  25671. }
  25672. var values = dict.values[key];
  25673. var types = dict.types[key];
  25674. if (!isArray(types)) {
  25675. types = [types];
  25676. }
  25677. if (!isArray(values)) {
  25678. values = [values];
  25679. }
  25680. // Remove any empty dict values.
  25681. if (values.length === 0) {
  25682. continue;
  25683. }
  25684. for (var j = 0, jj = types.length; j < jj; ++j) {
  25685. var type = types[j];
  25686. var value = values[j];
  25687. switch (type) {
  25688. case 'num':
  25689. case 'sid':
  25690. out = out.concat(this.encodeNumber(value));
  25691. break;
  25692. case 'offset':
  25693. // For offsets we just insert a 32bit integer so we don't have to
  25694. // deal with figuring out the length of the offset when it gets
  25695. // replaced later on by the compiler.
  25696. var name = dict.keyToNameMap[key];
  25697. // Some offsets have the offset and the length, so just record the
  25698. // position of the first one.
  25699. if (!offsetTracker.isTracking(name)) {
  25700. offsetTracker.track(name, out.length);
  25701. }
  25702. out = out.concat([0x1d, 0, 0, 0, 0]);
  25703. break;
  25704. case 'array':
  25705. case 'delta':
  25706. out = out.concat(this.encodeNumber(value));
  25707. for (var k = 1, kk = values.length; k < kk; ++k) {
  25708. out = out.concat(this.encodeNumber(values[k]));
  25709. }
  25710. break;
  25711. default:
  25712. error('Unknown data type of ' + type);
  25713. break;
  25714. }
  25715. }
  25716. out = out.concat(dict.opcodes[key]);
  25717. }
  25718. return out;
  25719. },
  25720. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25721. var stringIndex = new CFFIndex();
  25722. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25723. stringIndex.add(stringToBytes(strings[i]));
  25724. }
  25725. return this.compileIndex(stringIndex);
  25726. },
  25727. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25728. var globalSubrIndex = this.cff.globalSubrIndex;
  25729. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25730. },
  25731. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25732. return this.compileIndex(charStrings);
  25733. },
  25734. compileCharset: function CFFCompiler_compileCharset(charset) {
  25735. return this.compileTypedArray(charset.raw);
  25736. },
  25737. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25738. return this.compileTypedArray(encoding.raw);
  25739. },
  25740. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25741. return this.compileTypedArray(fdSelect);
  25742. },
  25743. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25744. var out = [];
  25745. for (var i = 0, ii = data.length; i < ii; ++i) {
  25746. out[i] = data[i];
  25747. }
  25748. return out;
  25749. },
  25750. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25751. trackers = trackers || [];
  25752. var objects = index.objects;
  25753. // First 2 bytes contains the number of objects contained into this index
  25754. var count = objects.length;
  25755. // If there is no object, just create an index. This technically
  25756. // should just be [0, 0] but OTS has an issue with that.
  25757. if (count === 0) {
  25758. return [0, 0, 0];
  25759. }
  25760. var data = [(count >> 8) & 0xFF, count & 0xff];
  25761. var lastOffset = 1, i;
  25762. for (i = 0; i < count; ++i) {
  25763. lastOffset += objects[i].length;
  25764. }
  25765. var offsetSize;
  25766. if (lastOffset < 0x100) {
  25767. offsetSize = 1;
  25768. } else if (lastOffset < 0x10000) {
  25769. offsetSize = 2;
  25770. } else if (lastOffset < 0x1000000) {
  25771. offsetSize = 3;
  25772. } else {
  25773. offsetSize = 4;
  25774. }
  25775. // Next byte contains the offset size use to reference object in the file
  25776. data.push(offsetSize);
  25777. // Add another offset after this one because we need a new offset
  25778. var relativeOffset = 1;
  25779. for (i = 0; i < count + 1; i++) {
  25780. if (offsetSize === 1) {
  25781. data.push(relativeOffset & 0xFF);
  25782. } else if (offsetSize === 2) {
  25783. data.push((relativeOffset >> 8) & 0xFF,
  25784. relativeOffset & 0xFF);
  25785. } else if (offsetSize === 3) {
  25786. data.push((relativeOffset >> 16) & 0xFF,
  25787. (relativeOffset >> 8) & 0xFF,
  25788. relativeOffset & 0xFF);
  25789. } else {
  25790. data.push((relativeOffset >>> 24) & 0xFF,
  25791. (relativeOffset >> 16) & 0xFF,
  25792. (relativeOffset >> 8) & 0xFF,
  25793. relativeOffset & 0xFF);
  25794. }
  25795. if (objects[i]) {
  25796. relativeOffset += objects[i].length;
  25797. }
  25798. }
  25799. for (i = 0; i < count; i++) {
  25800. // Notify the tracker where the object will be offset in the data.
  25801. if (trackers[i]) {
  25802. trackers[i].offset(data.length);
  25803. }
  25804. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25805. data.push(objects[i][j]);
  25806. }
  25807. }
  25808. return data;
  25809. }
  25810. };
  25811. return CFFCompiler;
  25812. })();
  25813. // Workaround for seac on Windows.
  25814. (function checkSeacSupport() {
  25815. if (/Windows/.test(navigator.userAgent)) {
  25816. SEAC_ANALYSIS_ENABLED = true;
  25817. }
  25818. })();
  25819. // Workaround for Private Use Area characters in Chrome on Windows
  25820. // http://code.google.com/p/chromium/issues/detail?id=122465
  25821. // https://github.com/mozilla/pdf.js/issues/1689
  25822. (function checkChromeWindows() {
  25823. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25824. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25825. }
  25826. })();
  25827. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25828. function getLong(data, offset) {
  25829. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25830. (data[offset + 2] << 8) | data[offset + 3];
  25831. }
  25832. function getUshort(data, offset) {
  25833. return (data[offset] << 8) | data[offset + 1];
  25834. }
  25835. function parseCmap(data, start, end) {
  25836. var offset = (getUshort(data, start + 2) === 1 ?
  25837. getLong(data, start + 8) : getLong(data, start + 16));
  25838. var format = getUshort(data, start + offset);
  25839. var length, ranges, p, i;
  25840. if (format === 4) {
  25841. length = getUshort(data, start + offset + 2);
  25842. var segCount = getUshort(data, start + offset + 6) >> 1;
  25843. p = start + offset + 14;
  25844. ranges = [];
  25845. for (i = 0; i < segCount; i++, p += 2) {
  25846. ranges[i] = {end: getUshort(data, p)};
  25847. }
  25848. p += 2;
  25849. for (i = 0; i < segCount; i++, p += 2) {
  25850. ranges[i].start = getUshort(data, p);
  25851. }
  25852. for (i = 0; i < segCount; i++, p += 2) {
  25853. ranges[i].idDelta = getUshort(data, p);
  25854. }
  25855. for (i = 0; i < segCount; i++, p += 2) {
  25856. var idOffset = getUshort(data, p);
  25857. if (idOffset === 0) {
  25858. continue;
  25859. }
  25860. ranges[i].ids = [];
  25861. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25862. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25863. idOffset += 2;
  25864. }
  25865. }
  25866. return ranges;
  25867. } else if (format === 12) {
  25868. length = getLong(data, start + offset + 4);
  25869. var groups = getLong(data, start + offset + 12);
  25870. p = start + offset + 16;
  25871. ranges = [];
  25872. for (i = 0; i < groups; i++) {
  25873. ranges.push({
  25874. start: getLong(data, p),
  25875. end: getLong(data, p + 4),
  25876. idDelta: getLong(data, p + 8) - getLong(data, p)
  25877. });
  25878. p += 12;
  25879. }
  25880. return ranges;
  25881. }
  25882. error('not supported cmap: ' + format);
  25883. }
  25884. function parseCff(data, start, end) {
  25885. var properties = {};
  25886. var parser = new CFFParser(new Stream(data, start, end - start),
  25887. properties);
  25888. var cff = parser.parse();
  25889. return {
  25890. glyphs: cff.charStrings.objects,
  25891. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25892. cff.topDict.privateDict.subrsIndex.objects),
  25893. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25894. };
  25895. }
  25896. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25897. var itemSize, itemDecode;
  25898. if (isGlyphLocationsLong) {
  25899. itemSize = 4;
  25900. itemDecode = function fontItemDecodeLong(data, offset) {
  25901. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25902. (data[offset + 2] << 8) | data[offset + 3];
  25903. };
  25904. } else {
  25905. itemSize = 2;
  25906. itemDecode = function fontItemDecode(data, offset) {
  25907. return (data[offset] << 9) | (data[offset + 1] << 1);
  25908. };
  25909. }
  25910. var glyphs = [];
  25911. var startOffset = itemDecode(loca, 0);
  25912. for (var j = itemSize; j < loca.length; j += itemSize) {
  25913. var endOffset = itemDecode(loca, j);
  25914. glyphs.push(glyf.subarray(startOffset, endOffset));
  25915. startOffset = endOffset;
  25916. }
  25917. return glyphs;
  25918. }
  25919. function lookupCmap(ranges, unicode) {
  25920. var code = unicode.charCodeAt(0);
  25921. var l = 0, r = ranges.length - 1;
  25922. while (l < r) {
  25923. var c = (l + r + 1) >> 1;
  25924. if (code < ranges[c].start) {
  25925. r = c - 1;
  25926. } else {
  25927. l = c;
  25928. }
  25929. }
  25930. if (ranges[l].start <= code && code <= ranges[l].end) {
  25931. return (ranges[l].idDelta + (ranges[l].ids ?
  25932. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25933. }
  25934. return 0;
  25935. }
  25936. function compileGlyf(code, cmds, font) {
  25937. function moveTo(x, y) {
  25938. cmds.push({cmd: 'moveTo', args: [x, y]});
  25939. }
  25940. function lineTo(x, y) {
  25941. cmds.push({cmd: 'lineTo', args: [x, y]});
  25942. }
  25943. function quadraticCurveTo(xa, ya, x, y) {
  25944. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25945. }
  25946. var i = 0;
  25947. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25948. var flags;
  25949. var x = 0, y = 0;
  25950. i += 10;
  25951. if (numberOfContours < 0) {
  25952. // composite glyph
  25953. do {
  25954. flags = (code[i] << 8) | code[i + 1];
  25955. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25956. i += 4;
  25957. var arg1, arg2;
  25958. if ((flags & 0x01)) {
  25959. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25960. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25961. i += 4;
  25962. } else {
  25963. arg1 = code[i++]; arg2 = code[i++];
  25964. }
  25965. if ((flags & 0x02)) {
  25966. x = arg1;
  25967. y = arg2;
  25968. } else {
  25969. x = 0; y = 0; // TODO "they are points" ?
  25970. }
  25971. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25972. if ((flags & 0x08)) {
  25973. scaleX =
  25974. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25975. i += 2;
  25976. } else if ((flags & 0x40)) {
  25977. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25978. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25979. i += 4;
  25980. } else if ((flags & 0x80)) {
  25981. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25982. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25983. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25984. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25985. i += 8;
  25986. }
  25987. var subglyph = font.glyphs[glyphIndex];
  25988. if (subglyph) {
  25989. cmds.push({cmd: 'save'});
  25990. cmds.push({cmd: 'transform',
  25991. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25992. compileGlyf(subglyph, cmds, font);
  25993. cmds.push({cmd: 'restore'});
  25994. }
  25995. } while ((flags & 0x20));
  25996. } else {
  25997. // simple glyph
  25998. var endPtsOfContours = [];
  25999. var j, jj;
  26000. for (j = 0; j < numberOfContours; j++) {
  26001. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26002. i += 2;
  26003. }
  26004. var instructionLength = (code[i] << 8) | code[i + 1];
  26005. i += 2 + instructionLength; // skipping the instructions
  26006. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26007. var points = [];
  26008. while (points.length < numberOfPoints) {
  26009. flags = code[i++];
  26010. var repeat = 1;
  26011. if ((flags & 0x08)) {
  26012. repeat += code[i++];
  26013. }
  26014. while (repeat-- > 0) {
  26015. points.push({flags: flags});
  26016. }
  26017. }
  26018. for (j = 0; j < numberOfPoints; j++) {
  26019. switch (points[j].flags & 0x12) {
  26020. case 0x00:
  26021. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26022. i += 2;
  26023. break;
  26024. case 0x02:
  26025. x -= code[i++];
  26026. break;
  26027. case 0x12:
  26028. x += code[i++];
  26029. break;
  26030. }
  26031. points[j].x = x;
  26032. }
  26033. for (j = 0; j < numberOfPoints; j++) {
  26034. switch (points[j].flags & 0x24) {
  26035. case 0x00:
  26036. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26037. i += 2;
  26038. break;
  26039. case 0x04:
  26040. y -= code[i++];
  26041. break;
  26042. case 0x24:
  26043. y += code[i++];
  26044. break;
  26045. }
  26046. points[j].y = y;
  26047. }
  26048. var startPoint = 0;
  26049. for (i = 0; i < numberOfContours; i++) {
  26050. var endPoint = endPtsOfContours[i];
  26051. // contours might have implicit points, which is located in the middle
  26052. // between two neighboring off-curve points
  26053. var contour = points.slice(startPoint, endPoint + 1);
  26054. if ((contour[0].flags & 1)) {
  26055. contour.push(contour[0]); // using start point at the contour end
  26056. } else if ((contour[contour.length - 1].flags & 1)) {
  26057. // first is off-curve point, trying to use one from the end
  26058. contour.unshift(contour[contour.length - 1]);
  26059. } else {
  26060. // start and end are off-curve points, creating implicit one
  26061. var p = {
  26062. flags: 1,
  26063. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26064. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26065. };
  26066. contour.unshift(p);
  26067. contour.push(p);
  26068. }
  26069. moveTo(contour[0].x, contour[0].y);
  26070. for (j = 1, jj = contour.length; j < jj; j++) {
  26071. if ((contour[j].flags & 1)) {
  26072. lineTo(contour[j].x, contour[j].y);
  26073. } else if ((contour[j + 1].flags & 1)){
  26074. quadraticCurveTo(contour[j].x, contour[j].y,
  26075. contour[j + 1].x, contour[j + 1].y);
  26076. j++;
  26077. } else {
  26078. quadraticCurveTo(contour[j].x, contour[j].y,
  26079. (contour[j].x + contour[j + 1].x) / 2,
  26080. (contour[j].y + contour[j + 1].y) / 2);
  26081. }
  26082. }
  26083. startPoint = endPoint + 1;
  26084. }
  26085. }
  26086. }
  26087. function compileCharString(code, cmds, font) {
  26088. var stack = [];
  26089. var x = 0, y = 0;
  26090. var stems = 0;
  26091. function moveTo(x, y) {
  26092. cmds.push({cmd: 'moveTo', args: [x, y]});
  26093. }
  26094. function lineTo(x, y) {
  26095. cmds.push({cmd: 'lineTo', args: [x, y]});
  26096. }
  26097. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26098. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26099. }
  26100. function parse(code) {
  26101. var i = 0;
  26102. while (i < code.length) {
  26103. var stackClean = false;
  26104. var v = code[i++];
  26105. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26106. switch (v) {
  26107. case 1: // hstem
  26108. stems += stack.length >> 1;
  26109. stackClean = true;
  26110. break;
  26111. case 3: // vstem
  26112. stems += stack.length >> 1;
  26113. stackClean = true;
  26114. break;
  26115. case 4: // vmoveto
  26116. y += stack.pop();
  26117. moveTo(x, y);
  26118. stackClean = true;
  26119. break;
  26120. case 5: // rlineto
  26121. while (stack.length > 0) {
  26122. x += stack.shift();
  26123. y += stack.shift();
  26124. lineTo(x, y);
  26125. }
  26126. break;
  26127. case 6: // hlineto
  26128. while (stack.length > 0) {
  26129. x += stack.shift();
  26130. lineTo(x, y);
  26131. if (stack.length === 0) {
  26132. break;
  26133. }
  26134. y += stack.shift();
  26135. lineTo(x, y);
  26136. }
  26137. break;
  26138. case 7: // vlineto
  26139. while (stack.length > 0) {
  26140. y += stack.shift();
  26141. lineTo(x, y);
  26142. if (stack.length === 0) {
  26143. break;
  26144. }
  26145. x += stack.shift();
  26146. lineTo(x, y);
  26147. }
  26148. break;
  26149. case 8: // rrcurveto
  26150. while (stack.length > 0) {
  26151. xa = x + stack.shift(); ya = y + stack.shift();
  26152. xb = xa + stack.shift(); yb = ya + stack.shift();
  26153. x = xb + stack.shift(); y = yb + stack.shift();
  26154. bezierCurveTo(xa, ya, xb, yb, x, y);
  26155. }
  26156. break;
  26157. case 10: // callsubr
  26158. n = stack.pop() + font.subrsBias;
  26159. subrCode = font.subrs[n];
  26160. if (subrCode) {
  26161. parse(subrCode);
  26162. }
  26163. break;
  26164. case 11: // return
  26165. return;
  26166. case 12:
  26167. v = code[i++];
  26168. switch (v) {
  26169. case 34: // flex
  26170. xa = x + stack.shift();
  26171. xb = xa + stack.shift(); y1 = y + stack.shift();
  26172. x = xb + stack.shift();
  26173. bezierCurveTo(xa, y, xb, y1, x, y1);
  26174. xa = x + stack.shift();
  26175. xb = xa + stack.shift();
  26176. x = xb + stack.shift();
  26177. bezierCurveTo(xa, y1, xb, y, x, y);
  26178. break;
  26179. case 35: // flex
  26180. xa = x + stack.shift(); ya = y + stack.shift();
  26181. xb = xa + stack.shift(); yb = ya + stack.shift();
  26182. x = xb + stack.shift(); y = yb + stack.shift();
  26183. bezierCurveTo(xa, ya, xb, yb, x, y);
  26184. xa = x + stack.shift(); ya = y + stack.shift();
  26185. xb = xa + stack.shift(); yb = ya + stack.shift();
  26186. x = xb + stack.shift(); y = yb + stack.shift();
  26187. bezierCurveTo(xa, ya, xb, yb, x, y);
  26188. stack.pop(); // fd
  26189. break;
  26190. case 36: // hflex1
  26191. xa = x + stack.shift(); y1 = y + stack.shift();
  26192. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26193. x = xb + stack.shift();
  26194. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26195. xa = x + stack.shift();
  26196. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26197. x = xb + stack.shift();
  26198. bezierCurveTo(xa, y2, xb, y3, x, y);
  26199. break;
  26200. case 37: // flex1
  26201. var x0 = x, y0 = y;
  26202. xa = x + stack.shift(); ya = y + stack.shift();
  26203. xb = xa + stack.shift(); yb = ya + stack.shift();
  26204. x = xb + stack.shift(); y = yb + stack.shift();
  26205. bezierCurveTo(xa, ya, xb, yb, x, y);
  26206. xa = x + stack.shift(); ya = y + stack.shift();
  26207. xb = xa + stack.shift(); yb = ya + stack.shift();
  26208. x = xb; y = yb;
  26209. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26210. x += stack.shift();
  26211. } else {
  26212. y += stack.shift();
  26213. }
  26214. bezierCurveTo(xa, ya, xb, yb, x, y);
  26215. break;
  26216. default:
  26217. error('unknown operator: 12 ' + v);
  26218. }
  26219. break;
  26220. case 14: // endchar
  26221. if (stack.length >= 4) {
  26222. var achar = stack.pop();
  26223. var bchar = stack.pop();
  26224. y = stack.pop();
  26225. x = stack.pop();
  26226. cmds.push({cmd: 'save'});
  26227. cmds.push({cmd: 'translate', args: [x, y]});
  26228. var gid = lookupCmap(font.cmap, String.fromCharCode(
  26229. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  26230. compileCharString(font.glyphs[gid], cmds, font);
  26231. cmds.push({cmd: 'restore'});
  26232. gid = lookupCmap(font.cmap, String.fromCharCode(
  26233. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  26234. compileCharString(font.glyphs[gid], cmds, font);
  26235. }
  26236. return;
  26237. case 18: // hstemhm
  26238. stems += stack.length >> 1;
  26239. stackClean = true;
  26240. break;
  26241. case 19: // hintmask
  26242. stems += stack.length >> 1;
  26243. i += (stems + 7) >> 3;
  26244. stackClean = true;
  26245. break;
  26246. case 20: // cntrmask
  26247. stems += stack.length >> 1;
  26248. i += (stems + 7) >> 3;
  26249. stackClean = true;
  26250. break;
  26251. case 21: // rmoveto
  26252. y += stack.pop();
  26253. x += stack.pop();
  26254. moveTo(x, y);
  26255. stackClean = true;
  26256. break;
  26257. case 22: // hmoveto
  26258. x += stack.pop();
  26259. moveTo(x, y);
  26260. stackClean = true;
  26261. break;
  26262. case 23: // vstemhm
  26263. stems += stack.length >> 1;
  26264. stackClean = true;
  26265. break;
  26266. case 24: // rcurveline
  26267. while (stack.length > 2) {
  26268. xa = x + stack.shift(); ya = y + stack.shift();
  26269. xb = xa + stack.shift(); yb = ya + stack.shift();
  26270. x = xb + stack.shift(); y = yb + stack.shift();
  26271. bezierCurveTo(xa, ya, xb, yb, x, y);
  26272. }
  26273. x += stack.shift();
  26274. y += stack.shift();
  26275. lineTo(x, y);
  26276. break;
  26277. case 25: // rlinecurve
  26278. while (stack.length > 6) {
  26279. x += stack.shift();
  26280. y += stack.shift();
  26281. lineTo(x, y);
  26282. }
  26283. xa = x + stack.shift(); ya = y + stack.shift();
  26284. xb = xa + stack.shift(); yb = ya + stack.shift();
  26285. x = xb + stack.shift(); y = yb + stack.shift();
  26286. bezierCurveTo(xa, ya, xb, yb, x, y);
  26287. break;
  26288. case 26: // vvcurveto
  26289. if (stack.length % 2) {
  26290. x += stack.shift();
  26291. }
  26292. while (stack.length > 0) {
  26293. xa = x; ya = y + stack.shift();
  26294. xb = xa + stack.shift(); yb = ya + stack.shift();
  26295. x = xb; y = yb + stack.shift();
  26296. bezierCurveTo(xa, ya, xb, yb, x, y);
  26297. }
  26298. break;
  26299. case 27: // hhcurveto
  26300. if (stack.length % 2) {
  26301. y += stack.shift();
  26302. }
  26303. while (stack.length > 0) {
  26304. xa = x + stack.shift(); ya = y;
  26305. xb = xa + stack.shift(); yb = ya + stack.shift();
  26306. x = xb + stack.shift(); y = yb;
  26307. bezierCurveTo(xa, ya, xb, yb, x, y);
  26308. }
  26309. break;
  26310. case 28:
  26311. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  26312. i += 2;
  26313. break;
  26314. case 29: // callgsubr
  26315. n = stack.pop() + font.gsubrsBias;
  26316. subrCode = font.gsubrs[n];
  26317. if (subrCode) {
  26318. parse(subrCode);
  26319. }
  26320. break;
  26321. case 30: // vhcurveto
  26322. while (stack.length > 0) {
  26323. xa = x; ya = y + stack.shift();
  26324. xb = xa + stack.shift(); yb = ya + stack.shift();
  26325. x = xb + stack.shift();
  26326. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26327. bezierCurveTo(xa, ya, xb, yb, x, y);
  26328. if (stack.length === 0) {
  26329. break;
  26330. }
  26331. xa = x + stack.shift(); ya = y;
  26332. xb = xa + stack.shift(); yb = ya + stack.shift();
  26333. y = yb + stack.shift();
  26334. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26335. bezierCurveTo(xa, ya, xb, yb, x, y);
  26336. }
  26337. break;
  26338. case 31: // hvcurveto
  26339. while (stack.length > 0) {
  26340. xa = x + stack.shift(); ya = y;
  26341. xb = xa + stack.shift(); yb = ya + stack.shift();
  26342. y = yb + stack.shift();
  26343. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26344. bezierCurveTo(xa, ya, xb, yb, x, y);
  26345. if (stack.length === 0) {
  26346. break;
  26347. }
  26348. xa = x; ya = y + stack.shift();
  26349. xb = xa + stack.shift(); yb = ya + stack.shift();
  26350. x = xb + stack.shift();
  26351. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26352. bezierCurveTo(xa, ya, xb, yb, x, y);
  26353. }
  26354. break;
  26355. default:
  26356. if (v < 32) {
  26357. error('unknown operator: ' + v);
  26358. }
  26359. if (v < 247) {
  26360. stack.push(v - 139);
  26361. } else if (v < 251) {
  26362. stack.push((v - 247) * 256 + code[i++] + 108);
  26363. } else if (v < 255) {
  26364. stack.push(-(v - 251) * 256 - code[i++] - 108);
  26365. } else {
  26366. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  26367. (code[i + 2] << 8) | code[i + 3]) / 65536);
  26368. i += 4;
  26369. }
  26370. break;
  26371. }
  26372. if (stackClean) {
  26373. stack.length = 0;
  26374. }
  26375. }
  26376. }
  26377. parse(code);
  26378. }
  26379. var noop = '';
  26380. function CompiledFont(fontMatrix) {
  26381. this.compiledGlyphs = {};
  26382. this.fontMatrix = fontMatrix;
  26383. }
  26384. CompiledFont.prototype = {
  26385. getPathJs: function (unicode) {
  26386. var gid = lookupCmap(this.cmap, unicode);
  26387. var fn = this.compiledGlyphs[gid];
  26388. if (!fn) {
  26389. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  26390. }
  26391. return fn;
  26392. },
  26393. compileGlyph: function (code) {
  26394. if (!code || code.length === 0 || code[0] === 14) {
  26395. return noop;
  26396. }
  26397. var cmds = [];
  26398. cmds.push({cmd: 'save'});
  26399. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  26400. cmds.push({cmd: 'scale', args: ['size', '-size']});
  26401. this.compileGlyphImpl(code, cmds);
  26402. cmds.push({cmd: 'restore'});
  26403. return cmds;
  26404. },
  26405. compileGlyphImpl: function () {
  26406. error('Children classes should implement this.');
  26407. },
  26408. hasBuiltPath: function (unicode) {
  26409. var gid = lookupCmap(this.cmap, unicode);
  26410. return gid in this.compiledGlyphs;
  26411. }
  26412. };
  26413. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26414. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26415. CompiledFont.call(this, fontMatrix);
  26416. this.glyphs = glyphs;
  26417. this.cmap = cmap;
  26418. this.compiledGlyphs = [];
  26419. }
  26420. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26421. compileGlyphImpl: function (code, cmds) {
  26422. compileGlyf(code, cmds, this);
  26423. }
  26424. });
  26425. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26426. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26427. CompiledFont.call(this, fontMatrix);
  26428. this.glyphs = cffInfo.glyphs;
  26429. this.gsubrs = cffInfo.gsubrs || [];
  26430. this.subrs = cffInfo.subrs || [];
  26431. this.cmap = cmap;
  26432. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26433. this.compiledGlyphs = [];
  26434. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26435. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26436. this.subrsBias = (this.subrs.length < 1240 ?
  26437. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26438. }
  26439. Util.inherit(Type2Compiled, CompiledFont, {
  26440. compileGlyphImpl: function (code, cmds) {
  26441. compileCharString(code, cmds, this);
  26442. }
  26443. });
  26444. return {
  26445. create: function FontRendererFactory_create(font) {
  26446. var data = new Uint8Array(font.data);
  26447. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26448. var numTables = getUshort(data, 4);
  26449. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26450. var tag = bytesToString(data.subarray(p, p + 4));
  26451. var offset = getLong(data, p + 8);
  26452. var length = getLong(data, p + 12);
  26453. switch (tag) {
  26454. case 'cmap':
  26455. cmap = parseCmap(data, offset, offset + length);
  26456. break;
  26457. case 'glyf':
  26458. glyf = data.subarray(offset, offset + length);
  26459. break;
  26460. case 'loca':
  26461. loca = data.subarray(offset, offset + length);
  26462. break;
  26463. case 'head':
  26464. unitsPerEm = getUshort(data, offset + 18);
  26465. indexToLocFormat = getUshort(data, offset + 50);
  26466. break;
  26467. case 'CFF ':
  26468. cff = parseCff(data, offset, offset + length);
  26469. break;
  26470. }
  26471. }
  26472. if (glyf) {
  26473. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26474. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26475. return new TrueTypeCompiled(
  26476. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26477. } else {
  26478. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26479. }
  26480. }
  26481. };
  26482. })();
  26483. var GlyphsUnicode = {
  26484. A: 0x0041,
  26485. AE: 0x00C6,
  26486. AEacute: 0x01FC,
  26487. AEmacron: 0x01E2,
  26488. AEsmall: 0xF7E6,
  26489. Aacute: 0x00C1,
  26490. Aacutesmall: 0xF7E1,
  26491. Abreve: 0x0102,
  26492. Abreveacute: 0x1EAE,
  26493. Abrevecyrillic: 0x04D0,
  26494. Abrevedotbelow: 0x1EB6,
  26495. Abrevegrave: 0x1EB0,
  26496. Abrevehookabove: 0x1EB2,
  26497. Abrevetilde: 0x1EB4,
  26498. Acaron: 0x01CD,
  26499. Acircle: 0x24B6,
  26500. Acircumflex: 0x00C2,
  26501. Acircumflexacute: 0x1EA4,
  26502. Acircumflexdotbelow: 0x1EAC,
  26503. Acircumflexgrave: 0x1EA6,
  26504. Acircumflexhookabove: 0x1EA8,
  26505. Acircumflexsmall: 0xF7E2,
  26506. Acircumflextilde: 0x1EAA,
  26507. Acute: 0xF6C9,
  26508. Acutesmall: 0xF7B4,
  26509. Acyrillic: 0x0410,
  26510. Adblgrave: 0x0200,
  26511. Adieresis: 0x00C4,
  26512. Adieresiscyrillic: 0x04D2,
  26513. Adieresismacron: 0x01DE,
  26514. Adieresissmall: 0xF7E4,
  26515. Adotbelow: 0x1EA0,
  26516. Adotmacron: 0x01E0,
  26517. Agrave: 0x00C0,
  26518. Agravesmall: 0xF7E0,
  26519. Ahookabove: 0x1EA2,
  26520. Aiecyrillic: 0x04D4,
  26521. Ainvertedbreve: 0x0202,
  26522. Alpha: 0x0391,
  26523. Alphatonos: 0x0386,
  26524. Amacron: 0x0100,
  26525. Amonospace: 0xFF21,
  26526. Aogonek: 0x0104,
  26527. Aring: 0x00C5,
  26528. Aringacute: 0x01FA,
  26529. Aringbelow: 0x1E00,
  26530. Aringsmall: 0xF7E5,
  26531. Asmall: 0xF761,
  26532. Atilde: 0x00C3,
  26533. Atildesmall: 0xF7E3,
  26534. Aybarmenian: 0x0531,
  26535. B: 0x0042,
  26536. Bcircle: 0x24B7,
  26537. Bdotaccent: 0x1E02,
  26538. Bdotbelow: 0x1E04,
  26539. Becyrillic: 0x0411,
  26540. Benarmenian: 0x0532,
  26541. Beta: 0x0392,
  26542. Bhook: 0x0181,
  26543. Blinebelow: 0x1E06,
  26544. Bmonospace: 0xFF22,
  26545. Brevesmall: 0xF6F4,
  26546. Bsmall: 0xF762,
  26547. Btopbar: 0x0182,
  26548. C: 0x0043,
  26549. Caarmenian: 0x053E,
  26550. Cacute: 0x0106,
  26551. Caron: 0xF6CA,
  26552. Caronsmall: 0xF6F5,
  26553. Ccaron: 0x010C,
  26554. Ccedilla: 0x00C7,
  26555. Ccedillaacute: 0x1E08,
  26556. Ccedillasmall: 0xF7E7,
  26557. Ccircle: 0x24B8,
  26558. Ccircumflex: 0x0108,
  26559. Cdot: 0x010A,
  26560. Cdotaccent: 0x010A,
  26561. Cedillasmall: 0xF7B8,
  26562. Chaarmenian: 0x0549,
  26563. Cheabkhasiancyrillic: 0x04BC,
  26564. Checyrillic: 0x0427,
  26565. Chedescenderabkhasiancyrillic: 0x04BE,
  26566. Chedescendercyrillic: 0x04B6,
  26567. Chedieresiscyrillic: 0x04F4,
  26568. Cheharmenian: 0x0543,
  26569. Chekhakassiancyrillic: 0x04CB,
  26570. Cheverticalstrokecyrillic: 0x04B8,
  26571. Chi: 0x03A7,
  26572. Chook: 0x0187,
  26573. Circumflexsmall: 0xF6F6,
  26574. Cmonospace: 0xFF23,
  26575. Coarmenian: 0x0551,
  26576. Csmall: 0xF763,
  26577. D: 0x0044,
  26578. DZ: 0x01F1,
  26579. DZcaron: 0x01C4,
  26580. Daarmenian: 0x0534,
  26581. Dafrican: 0x0189,
  26582. Dcaron: 0x010E,
  26583. Dcedilla: 0x1E10,
  26584. Dcircle: 0x24B9,
  26585. Dcircumflexbelow: 0x1E12,
  26586. Dcroat: 0x0110,
  26587. Ddotaccent: 0x1E0A,
  26588. Ddotbelow: 0x1E0C,
  26589. Decyrillic: 0x0414,
  26590. Deicoptic: 0x03EE,
  26591. Delta: 0x2206,
  26592. Deltagreek: 0x0394,
  26593. Dhook: 0x018A,
  26594. Dieresis: 0xF6CB,
  26595. DieresisAcute: 0xF6CC,
  26596. DieresisGrave: 0xF6CD,
  26597. Dieresissmall: 0xF7A8,
  26598. Digammagreek: 0x03DC,
  26599. Djecyrillic: 0x0402,
  26600. Dlinebelow: 0x1E0E,
  26601. Dmonospace: 0xFF24,
  26602. Dotaccentsmall: 0xF6F7,
  26603. Dslash: 0x0110,
  26604. Dsmall: 0xF764,
  26605. Dtopbar: 0x018B,
  26606. Dz: 0x01F2,
  26607. Dzcaron: 0x01C5,
  26608. Dzeabkhasiancyrillic: 0x04E0,
  26609. Dzecyrillic: 0x0405,
  26610. Dzhecyrillic: 0x040F,
  26611. E: 0x0045,
  26612. Eacute: 0x00C9,
  26613. Eacutesmall: 0xF7E9,
  26614. Ebreve: 0x0114,
  26615. Ecaron: 0x011A,
  26616. Ecedillabreve: 0x1E1C,
  26617. Echarmenian: 0x0535,
  26618. Ecircle: 0x24BA,
  26619. Ecircumflex: 0x00CA,
  26620. Ecircumflexacute: 0x1EBE,
  26621. Ecircumflexbelow: 0x1E18,
  26622. Ecircumflexdotbelow: 0x1EC6,
  26623. Ecircumflexgrave: 0x1EC0,
  26624. Ecircumflexhookabove: 0x1EC2,
  26625. Ecircumflexsmall: 0xF7EA,
  26626. Ecircumflextilde: 0x1EC4,
  26627. Ecyrillic: 0x0404,
  26628. Edblgrave: 0x0204,
  26629. Edieresis: 0x00CB,
  26630. Edieresissmall: 0xF7EB,
  26631. Edot: 0x0116,
  26632. Edotaccent: 0x0116,
  26633. Edotbelow: 0x1EB8,
  26634. Efcyrillic: 0x0424,
  26635. Egrave: 0x00C8,
  26636. Egravesmall: 0xF7E8,
  26637. Eharmenian: 0x0537,
  26638. Ehookabove: 0x1EBA,
  26639. Eightroman: 0x2167,
  26640. Einvertedbreve: 0x0206,
  26641. Eiotifiedcyrillic: 0x0464,
  26642. Elcyrillic: 0x041B,
  26643. Elevenroman: 0x216A,
  26644. Emacron: 0x0112,
  26645. Emacronacute: 0x1E16,
  26646. Emacrongrave: 0x1E14,
  26647. Emcyrillic: 0x041C,
  26648. Emonospace: 0xFF25,
  26649. Encyrillic: 0x041D,
  26650. Endescendercyrillic: 0x04A2,
  26651. Eng: 0x014A,
  26652. Enghecyrillic: 0x04A4,
  26653. Enhookcyrillic: 0x04C7,
  26654. Eogonek: 0x0118,
  26655. Eopen: 0x0190,
  26656. Epsilon: 0x0395,
  26657. Epsilontonos: 0x0388,
  26658. Ercyrillic: 0x0420,
  26659. Ereversed: 0x018E,
  26660. Ereversedcyrillic: 0x042D,
  26661. Escyrillic: 0x0421,
  26662. Esdescendercyrillic: 0x04AA,
  26663. Esh: 0x01A9,
  26664. Esmall: 0xF765,
  26665. Eta: 0x0397,
  26666. Etarmenian: 0x0538,
  26667. Etatonos: 0x0389,
  26668. Eth: 0x00D0,
  26669. Ethsmall: 0xF7F0,
  26670. Etilde: 0x1EBC,
  26671. Etildebelow: 0x1E1A,
  26672. Euro: 0x20AC,
  26673. Ezh: 0x01B7,
  26674. Ezhcaron: 0x01EE,
  26675. Ezhreversed: 0x01B8,
  26676. F: 0x0046,
  26677. Fcircle: 0x24BB,
  26678. Fdotaccent: 0x1E1E,
  26679. Feharmenian: 0x0556,
  26680. Feicoptic: 0x03E4,
  26681. Fhook: 0x0191,
  26682. Fitacyrillic: 0x0472,
  26683. Fiveroman: 0x2164,
  26684. Fmonospace: 0xFF26,
  26685. Fourroman: 0x2163,
  26686. Fsmall: 0xF766,
  26687. G: 0x0047,
  26688. GBsquare: 0x3387,
  26689. Gacute: 0x01F4,
  26690. Gamma: 0x0393,
  26691. Gammaafrican: 0x0194,
  26692. Gangiacoptic: 0x03EA,
  26693. Gbreve: 0x011E,
  26694. Gcaron: 0x01E6,
  26695. Gcedilla: 0x0122,
  26696. Gcircle: 0x24BC,
  26697. Gcircumflex: 0x011C,
  26698. Gcommaaccent: 0x0122,
  26699. Gdot: 0x0120,
  26700. Gdotaccent: 0x0120,
  26701. Gecyrillic: 0x0413,
  26702. Ghadarmenian: 0x0542,
  26703. Ghemiddlehookcyrillic: 0x0494,
  26704. Ghestrokecyrillic: 0x0492,
  26705. Gheupturncyrillic: 0x0490,
  26706. Ghook: 0x0193,
  26707. Gimarmenian: 0x0533,
  26708. Gjecyrillic: 0x0403,
  26709. Gmacron: 0x1E20,
  26710. Gmonospace: 0xFF27,
  26711. Grave: 0xF6CE,
  26712. Gravesmall: 0xF760,
  26713. Gsmall: 0xF767,
  26714. Gsmallhook: 0x029B,
  26715. Gstroke: 0x01E4,
  26716. H: 0x0048,
  26717. H18533: 0x25CF,
  26718. H18543: 0x25AA,
  26719. H18551: 0x25AB,
  26720. H22073: 0x25A1,
  26721. HPsquare: 0x33CB,
  26722. Haabkhasiancyrillic: 0x04A8,
  26723. Hadescendercyrillic: 0x04B2,
  26724. Hardsigncyrillic: 0x042A,
  26725. Hbar: 0x0126,
  26726. Hbrevebelow: 0x1E2A,
  26727. Hcedilla: 0x1E28,
  26728. Hcircle: 0x24BD,
  26729. Hcircumflex: 0x0124,
  26730. Hdieresis: 0x1E26,
  26731. Hdotaccent: 0x1E22,
  26732. Hdotbelow: 0x1E24,
  26733. Hmonospace: 0xFF28,
  26734. Hoarmenian: 0x0540,
  26735. Horicoptic: 0x03E8,
  26736. Hsmall: 0xF768,
  26737. Hungarumlaut: 0xF6CF,
  26738. Hungarumlautsmall: 0xF6F8,
  26739. Hzsquare: 0x3390,
  26740. I: 0x0049,
  26741. IAcyrillic: 0x042F,
  26742. IJ: 0x0132,
  26743. IUcyrillic: 0x042E,
  26744. Iacute: 0x00CD,
  26745. Iacutesmall: 0xF7ED,
  26746. Ibreve: 0x012C,
  26747. Icaron: 0x01CF,
  26748. Icircle: 0x24BE,
  26749. Icircumflex: 0x00CE,
  26750. Icircumflexsmall: 0xF7EE,
  26751. Icyrillic: 0x0406,
  26752. Idblgrave: 0x0208,
  26753. Idieresis: 0x00CF,
  26754. Idieresisacute: 0x1E2E,
  26755. Idieresiscyrillic: 0x04E4,
  26756. Idieresissmall: 0xF7EF,
  26757. Idot: 0x0130,
  26758. Idotaccent: 0x0130,
  26759. Idotbelow: 0x1ECA,
  26760. Iebrevecyrillic: 0x04D6,
  26761. Iecyrillic: 0x0415,
  26762. Ifraktur: 0x2111,
  26763. Igrave: 0x00CC,
  26764. Igravesmall: 0xF7EC,
  26765. Ihookabove: 0x1EC8,
  26766. Iicyrillic: 0x0418,
  26767. Iinvertedbreve: 0x020A,
  26768. Iishortcyrillic: 0x0419,
  26769. Imacron: 0x012A,
  26770. Imacroncyrillic: 0x04E2,
  26771. Imonospace: 0xFF29,
  26772. Iniarmenian: 0x053B,
  26773. Iocyrillic: 0x0401,
  26774. Iogonek: 0x012E,
  26775. Iota: 0x0399,
  26776. Iotaafrican: 0x0196,
  26777. Iotadieresis: 0x03AA,
  26778. Iotatonos: 0x038A,
  26779. Ismall: 0xF769,
  26780. Istroke: 0x0197,
  26781. Itilde: 0x0128,
  26782. Itildebelow: 0x1E2C,
  26783. Izhitsacyrillic: 0x0474,
  26784. Izhitsadblgravecyrillic: 0x0476,
  26785. J: 0x004A,
  26786. Jaarmenian: 0x0541,
  26787. Jcircle: 0x24BF,
  26788. Jcircumflex: 0x0134,
  26789. Jecyrillic: 0x0408,
  26790. Jheharmenian: 0x054B,
  26791. Jmonospace: 0xFF2A,
  26792. Jsmall: 0xF76A,
  26793. K: 0x004B,
  26794. KBsquare: 0x3385,
  26795. KKsquare: 0x33CD,
  26796. Kabashkircyrillic: 0x04A0,
  26797. Kacute: 0x1E30,
  26798. Kacyrillic: 0x041A,
  26799. Kadescendercyrillic: 0x049A,
  26800. Kahookcyrillic: 0x04C3,
  26801. Kappa: 0x039A,
  26802. Kastrokecyrillic: 0x049E,
  26803. Kaverticalstrokecyrillic: 0x049C,
  26804. Kcaron: 0x01E8,
  26805. Kcedilla: 0x0136,
  26806. Kcircle: 0x24C0,
  26807. Kcommaaccent: 0x0136,
  26808. Kdotbelow: 0x1E32,
  26809. Keharmenian: 0x0554,
  26810. Kenarmenian: 0x053F,
  26811. Khacyrillic: 0x0425,
  26812. Kheicoptic: 0x03E6,
  26813. Khook: 0x0198,
  26814. Kjecyrillic: 0x040C,
  26815. Klinebelow: 0x1E34,
  26816. Kmonospace: 0xFF2B,
  26817. Koppacyrillic: 0x0480,
  26818. Koppagreek: 0x03DE,
  26819. Ksicyrillic: 0x046E,
  26820. Ksmall: 0xF76B,
  26821. L: 0x004C,
  26822. LJ: 0x01C7,
  26823. LL: 0xF6BF,
  26824. Lacute: 0x0139,
  26825. Lambda: 0x039B,
  26826. Lcaron: 0x013D,
  26827. Lcedilla: 0x013B,
  26828. Lcircle: 0x24C1,
  26829. Lcircumflexbelow: 0x1E3C,
  26830. Lcommaaccent: 0x013B,
  26831. Ldot: 0x013F,
  26832. Ldotaccent: 0x013F,
  26833. Ldotbelow: 0x1E36,
  26834. Ldotbelowmacron: 0x1E38,
  26835. Liwnarmenian: 0x053C,
  26836. Lj: 0x01C8,
  26837. Ljecyrillic: 0x0409,
  26838. Llinebelow: 0x1E3A,
  26839. Lmonospace: 0xFF2C,
  26840. Lslash: 0x0141,
  26841. Lslashsmall: 0xF6F9,
  26842. Lsmall: 0xF76C,
  26843. M: 0x004D,
  26844. MBsquare: 0x3386,
  26845. Macron: 0xF6D0,
  26846. Macronsmall: 0xF7AF,
  26847. Macute: 0x1E3E,
  26848. Mcircle: 0x24C2,
  26849. Mdotaccent: 0x1E40,
  26850. Mdotbelow: 0x1E42,
  26851. Menarmenian: 0x0544,
  26852. Mmonospace: 0xFF2D,
  26853. Msmall: 0xF76D,
  26854. Mturned: 0x019C,
  26855. Mu: 0x039C,
  26856. N: 0x004E,
  26857. NJ: 0x01CA,
  26858. Nacute: 0x0143,
  26859. Ncaron: 0x0147,
  26860. Ncedilla: 0x0145,
  26861. Ncircle: 0x24C3,
  26862. Ncircumflexbelow: 0x1E4A,
  26863. Ncommaaccent: 0x0145,
  26864. Ndotaccent: 0x1E44,
  26865. Ndotbelow: 0x1E46,
  26866. Nhookleft: 0x019D,
  26867. Nineroman: 0x2168,
  26868. Nj: 0x01CB,
  26869. Njecyrillic: 0x040A,
  26870. Nlinebelow: 0x1E48,
  26871. Nmonospace: 0xFF2E,
  26872. Nowarmenian: 0x0546,
  26873. Nsmall: 0xF76E,
  26874. Ntilde: 0x00D1,
  26875. Ntildesmall: 0xF7F1,
  26876. Nu: 0x039D,
  26877. O: 0x004F,
  26878. OE: 0x0152,
  26879. OEsmall: 0xF6FA,
  26880. Oacute: 0x00D3,
  26881. Oacutesmall: 0xF7F3,
  26882. Obarredcyrillic: 0x04E8,
  26883. Obarreddieresiscyrillic: 0x04EA,
  26884. Obreve: 0x014E,
  26885. Ocaron: 0x01D1,
  26886. Ocenteredtilde: 0x019F,
  26887. Ocircle: 0x24C4,
  26888. Ocircumflex: 0x00D4,
  26889. Ocircumflexacute: 0x1ED0,
  26890. Ocircumflexdotbelow: 0x1ED8,
  26891. Ocircumflexgrave: 0x1ED2,
  26892. Ocircumflexhookabove: 0x1ED4,
  26893. Ocircumflexsmall: 0xF7F4,
  26894. Ocircumflextilde: 0x1ED6,
  26895. Ocyrillic: 0x041E,
  26896. Odblacute: 0x0150,
  26897. Odblgrave: 0x020C,
  26898. Odieresis: 0x00D6,
  26899. Odieresiscyrillic: 0x04E6,
  26900. Odieresissmall: 0xF7F6,
  26901. Odotbelow: 0x1ECC,
  26902. Ogoneksmall: 0xF6FB,
  26903. Ograve: 0x00D2,
  26904. Ogravesmall: 0xF7F2,
  26905. Oharmenian: 0x0555,
  26906. Ohm: 0x2126,
  26907. Ohookabove: 0x1ECE,
  26908. Ohorn: 0x01A0,
  26909. Ohornacute: 0x1EDA,
  26910. Ohorndotbelow: 0x1EE2,
  26911. Ohorngrave: 0x1EDC,
  26912. Ohornhookabove: 0x1EDE,
  26913. Ohorntilde: 0x1EE0,
  26914. Ohungarumlaut: 0x0150,
  26915. Oi: 0x01A2,
  26916. Oinvertedbreve: 0x020E,
  26917. Omacron: 0x014C,
  26918. Omacronacute: 0x1E52,
  26919. Omacrongrave: 0x1E50,
  26920. Omega: 0x2126,
  26921. Omegacyrillic: 0x0460,
  26922. Omegagreek: 0x03A9,
  26923. Omegaroundcyrillic: 0x047A,
  26924. Omegatitlocyrillic: 0x047C,
  26925. Omegatonos: 0x038F,
  26926. Omicron: 0x039F,
  26927. Omicrontonos: 0x038C,
  26928. Omonospace: 0xFF2F,
  26929. Oneroman: 0x2160,
  26930. Oogonek: 0x01EA,
  26931. Oogonekmacron: 0x01EC,
  26932. Oopen: 0x0186,
  26933. Oslash: 0x00D8,
  26934. Oslashacute: 0x01FE,
  26935. Oslashsmall: 0xF7F8,
  26936. Osmall: 0xF76F,
  26937. Ostrokeacute: 0x01FE,
  26938. Otcyrillic: 0x047E,
  26939. Otilde: 0x00D5,
  26940. Otildeacute: 0x1E4C,
  26941. Otildedieresis: 0x1E4E,
  26942. Otildesmall: 0xF7F5,
  26943. P: 0x0050,
  26944. Pacute: 0x1E54,
  26945. Pcircle: 0x24C5,
  26946. Pdotaccent: 0x1E56,
  26947. Pecyrillic: 0x041F,
  26948. Peharmenian: 0x054A,
  26949. Pemiddlehookcyrillic: 0x04A6,
  26950. Phi: 0x03A6,
  26951. Phook: 0x01A4,
  26952. Pi: 0x03A0,
  26953. Piwrarmenian: 0x0553,
  26954. Pmonospace: 0xFF30,
  26955. Psi: 0x03A8,
  26956. Psicyrillic: 0x0470,
  26957. Psmall: 0xF770,
  26958. Q: 0x0051,
  26959. Qcircle: 0x24C6,
  26960. Qmonospace: 0xFF31,
  26961. Qsmall: 0xF771,
  26962. R: 0x0052,
  26963. Raarmenian: 0x054C,
  26964. Racute: 0x0154,
  26965. Rcaron: 0x0158,
  26966. Rcedilla: 0x0156,
  26967. Rcircle: 0x24C7,
  26968. Rcommaaccent: 0x0156,
  26969. Rdblgrave: 0x0210,
  26970. Rdotaccent: 0x1E58,
  26971. Rdotbelow: 0x1E5A,
  26972. Rdotbelowmacron: 0x1E5C,
  26973. Reharmenian: 0x0550,
  26974. Rfraktur: 0x211C,
  26975. Rho: 0x03A1,
  26976. Ringsmall: 0xF6FC,
  26977. Rinvertedbreve: 0x0212,
  26978. Rlinebelow: 0x1E5E,
  26979. Rmonospace: 0xFF32,
  26980. Rsmall: 0xF772,
  26981. Rsmallinverted: 0x0281,
  26982. Rsmallinvertedsuperior: 0x02B6,
  26983. S: 0x0053,
  26984. SF010000: 0x250C,
  26985. SF020000: 0x2514,
  26986. SF030000: 0x2510,
  26987. SF040000: 0x2518,
  26988. SF050000: 0x253C,
  26989. SF060000: 0x252C,
  26990. SF070000: 0x2534,
  26991. SF080000: 0x251C,
  26992. SF090000: 0x2524,
  26993. SF100000: 0x2500,
  26994. SF110000: 0x2502,
  26995. SF190000: 0x2561,
  26996. SF200000: 0x2562,
  26997. SF210000: 0x2556,
  26998. SF220000: 0x2555,
  26999. SF230000: 0x2563,
  27000. SF240000: 0x2551,
  27001. SF250000: 0x2557,
  27002. SF260000: 0x255D,
  27003. SF270000: 0x255C,
  27004. SF280000: 0x255B,
  27005. SF360000: 0x255E,
  27006. SF370000: 0x255F,
  27007. SF380000: 0x255A,
  27008. SF390000: 0x2554,
  27009. SF400000: 0x2569,
  27010. SF410000: 0x2566,
  27011. SF420000: 0x2560,
  27012. SF430000: 0x2550,
  27013. SF440000: 0x256C,
  27014. SF450000: 0x2567,
  27015. SF460000: 0x2568,
  27016. SF470000: 0x2564,
  27017. SF480000: 0x2565,
  27018. SF490000: 0x2559,
  27019. SF500000: 0x2558,
  27020. SF510000: 0x2552,
  27021. SF520000: 0x2553,
  27022. SF530000: 0x256B,
  27023. SF540000: 0x256A,
  27024. Sacute: 0x015A,
  27025. Sacutedotaccent: 0x1E64,
  27026. Sampigreek: 0x03E0,
  27027. Scaron: 0x0160,
  27028. Scarondotaccent: 0x1E66,
  27029. Scaronsmall: 0xF6FD,
  27030. Scedilla: 0x015E,
  27031. Schwa: 0x018F,
  27032. Schwacyrillic: 0x04D8,
  27033. Schwadieresiscyrillic: 0x04DA,
  27034. Scircle: 0x24C8,
  27035. Scircumflex: 0x015C,
  27036. Scommaaccent: 0x0218,
  27037. Sdotaccent: 0x1E60,
  27038. Sdotbelow: 0x1E62,
  27039. Sdotbelowdotaccent: 0x1E68,
  27040. Seharmenian: 0x054D,
  27041. Sevenroman: 0x2166,
  27042. Shaarmenian: 0x0547,
  27043. Shacyrillic: 0x0428,
  27044. Shchacyrillic: 0x0429,
  27045. Sheicoptic: 0x03E2,
  27046. Shhacyrillic: 0x04BA,
  27047. Shimacoptic: 0x03EC,
  27048. Sigma: 0x03A3,
  27049. Sixroman: 0x2165,
  27050. Smonospace: 0xFF33,
  27051. Softsigncyrillic: 0x042C,
  27052. Ssmall: 0xF773,
  27053. Stigmagreek: 0x03DA,
  27054. T: 0x0054,
  27055. Tau: 0x03A4,
  27056. Tbar: 0x0166,
  27057. Tcaron: 0x0164,
  27058. Tcedilla: 0x0162,
  27059. Tcircle: 0x24C9,
  27060. Tcircumflexbelow: 0x1E70,
  27061. Tcommaaccent: 0x0162,
  27062. Tdotaccent: 0x1E6A,
  27063. Tdotbelow: 0x1E6C,
  27064. Tecyrillic: 0x0422,
  27065. Tedescendercyrillic: 0x04AC,
  27066. Tenroman: 0x2169,
  27067. Tetsecyrillic: 0x04B4,
  27068. Theta: 0x0398,
  27069. Thook: 0x01AC,
  27070. Thorn: 0x00DE,
  27071. Thornsmall: 0xF7FE,
  27072. Threeroman: 0x2162,
  27073. Tildesmall: 0xF6FE,
  27074. Tiwnarmenian: 0x054F,
  27075. Tlinebelow: 0x1E6E,
  27076. Tmonospace: 0xFF34,
  27077. Toarmenian: 0x0539,
  27078. Tonefive: 0x01BC,
  27079. Tonesix: 0x0184,
  27080. Tonetwo: 0x01A7,
  27081. Tretroflexhook: 0x01AE,
  27082. Tsecyrillic: 0x0426,
  27083. Tshecyrillic: 0x040B,
  27084. Tsmall: 0xF774,
  27085. Twelveroman: 0x216B,
  27086. Tworoman: 0x2161,
  27087. U: 0x0055,
  27088. Uacute: 0x00DA,
  27089. Uacutesmall: 0xF7FA,
  27090. Ubreve: 0x016C,
  27091. Ucaron: 0x01D3,
  27092. Ucircle: 0x24CA,
  27093. Ucircumflex: 0x00DB,
  27094. Ucircumflexbelow: 0x1E76,
  27095. Ucircumflexsmall: 0xF7FB,
  27096. Ucyrillic: 0x0423,
  27097. Udblacute: 0x0170,
  27098. Udblgrave: 0x0214,
  27099. Udieresis: 0x00DC,
  27100. Udieresisacute: 0x01D7,
  27101. Udieresisbelow: 0x1E72,
  27102. Udieresiscaron: 0x01D9,
  27103. Udieresiscyrillic: 0x04F0,
  27104. Udieresisgrave: 0x01DB,
  27105. Udieresismacron: 0x01D5,
  27106. Udieresissmall: 0xF7FC,
  27107. Udotbelow: 0x1EE4,
  27108. Ugrave: 0x00D9,
  27109. Ugravesmall: 0xF7F9,
  27110. Uhookabove: 0x1EE6,
  27111. Uhorn: 0x01AF,
  27112. Uhornacute: 0x1EE8,
  27113. Uhorndotbelow: 0x1EF0,
  27114. Uhorngrave: 0x1EEA,
  27115. Uhornhookabove: 0x1EEC,
  27116. Uhorntilde: 0x1EEE,
  27117. Uhungarumlaut: 0x0170,
  27118. Uhungarumlautcyrillic: 0x04F2,
  27119. Uinvertedbreve: 0x0216,
  27120. Ukcyrillic: 0x0478,
  27121. Umacron: 0x016A,
  27122. Umacroncyrillic: 0x04EE,
  27123. Umacrondieresis: 0x1E7A,
  27124. Umonospace: 0xFF35,
  27125. Uogonek: 0x0172,
  27126. Upsilon: 0x03A5,
  27127. Upsilon1: 0x03D2,
  27128. Upsilonacutehooksymbolgreek: 0x03D3,
  27129. Upsilonafrican: 0x01B1,
  27130. Upsilondieresis: 0x03AB,
  27131. Upsilondieresishooksymbolgreek: 0x03D4,
  27132. Upsilonhooksymbol: 0x03D2,
  27133. Upsilontonos: 0x038E,
  27134. Uring: 0x016E,
  27135. Ushortcyrillic: 0x040E,
  27136. Usmall: 0xF775,
  27137. Ustraightcyrillic: 0x04AE,
  27138. Ustraightstrokecyrillic: 0x04B0,
  27139. Utilde: 0x0168,
  27140. Utildeacute: 0x1E78,
  27141. Utildebelow: 0x1E74,
  27142. V: 0x0056,
  27143. Vcircle: 0x24CB,
  27144. Vdotbelow: 0x1E7E,
  27145. Vecyrillic: 0x0412,
  27146. Vewarmenian: 0x054E,
  27147. Vhook: 0x01B2,
  27148. Vmonospace: 0xFF36,
  27149. Voarmenian: 0x0548,
  27150. Vsmall: 0xF776,
  27151. Vtilde: 0x1E7C,
  27152. W: 0x0057,
  27153. Wacute: 0x1E82,
  27154. Wcircle: 0x24CC,
  27155. Wcircumflex: 0x0174,
  27156. Wdieresis: 0x1E84,
  27157. Wdotaccent: 0x1E86,
  27158. Wdotbelow: 0x1E88,
  27159. Wgrave: 0x1E80,
  27160. Wmonospace: 0xFF37,
  27161. Wsmall: 0xF777,
  27162. X: 0x0058,
  27163. Xcircle: 0x24CD,
  27164. Xdieresis: 0x1E8C,
  27165. Xdotaccent: 0x1E8A,
  27166. Xeharmenian: 0x053D,
  27167. Xi: 0x039E,
  27168. Xmonospace: 0xFF38,
  27169. Xsmall: 0xF778,
  27170. Y: 0x0059,
  27171. Yacute: 0x00DD,
  27172. Yacutesmall: 0xF7FD,
  27173. Yatcyrillic: 0x0462,
  27174. Ycircle: 0x24CE,
  27175. Ycircumflex: 0x0176,
  27176. Ydieresis: 0x0178,
  27177. Ydieresissmall: 0xF7FF,
  27178. Ydotaccent: 0x1E8E,
  27179. Ydotbelow: 0x1EF4,
  27180. Yericyrillic: 0x042B,
  27181. Yerudieresiscyrillic: 0x04F8,
  27182. Ygrave: 0x1EF2,
  27183. Yhook: 0x01B3,
  27184. Yhookabove: 0x1EF6,
  27185. Yiarmenian: 0x0545,
  27186. Yicyrillic: 0x0407,
  27187. Yiwnarmenian: 0x0552,
  27188. Ymonospace: 0xFF39,
  27189. Ysmall: 0xF779,
  27190. Ytilde: 0x1EF8,
  27191. Yusbigcyrillic: 0x046A,
  27192. Yusbigiotifiedcyrillic: 0x046C,
  27193. Yuslittlecyrillic: 0x0466,
  27194. Yuslittleiotifiedcyrillic: 0x0468,
  27195. Z: 0x005A,
  27196. Zaarmenian: 0x0536,
  27197. Zacute: 0x0179,
  27198. Zcaron: 0x017D,
  27199. Zcaronsmall: 0xF6FF,
  27200. Zcircle: 0x24CF,
  27201. Zcircumflex: 0x1E90,
  27202. Zdot: 0x017B,
  27203. Zdotaccent: 0x017B,
  27204. Zdotbelow: 0x1E92,
  27205. Zecyrillic: 0x0417,
  27206. Zedescendercyrillic: 0x0498,
  27207. Zedieresiscyrillic: 0x04DE,
  27208. Zeta: 0x0396,
  27209. Zhearmenian: 0x053A,
  27210. Zhebrevecyrillic: 0x04C1,
  27211. Zhecyrillic: 0x0416,
  27212. Zhedescendercyrillic: 0x0496,
  27213. Zhedieresiscyrillic: 0x04DC,
  27214. Zlinebelow: 0x1E94,
  27215. Zmonospace: 0xFF3A,
  27216. Zsmall: 0xF77A,
  27217. Zstroke: 0x01B5,
  27218. a: 0x0061,
  27219. aabengali: 0x0986,
  27220. aacute: 0x00E1,
  27221. aadeva: 0x0906,
  27222. aagujarati: 0x0A86,
  27223. aagurmukhi: 0x0A06,
  27224. aamatragurmukhi: 0x0A3E,
  27225. aarusquare: 0x3303,
  27226. aavowelsignbengali: 0x09BE,
  27227. aavowelsigndeva: 0x093E,
  27228. aavowelsigngujarati: 0x0ABE,
  27229. abbreviationmarkarmenian: 0x055F,
  27230. abbreviationsigndeva: 0x0970,
  27231. abengali: 0x0985,
  27232. abopomofo: 0x311A,
  27233. abreve: 0x0103,
  27234. abreveacute: 0x1EAF,
  27235. abrevecyrillic: 0x04D1,
  27236. abrevedotbelow: 0x1EB7,
  27237. abrevegrave: 0x1EB1,
  27238. abrevehookabove: 0x1EB3,
  27239. abrevetilde: 0x1EB5,
  27240. acaron: 0x01CE,
  27241. acircle: 0x24D0,
  27242. acircumflex: 0x00E2,
  27243. acircumflexacute: 0x1EA5,
  27244. acircumflexdotbelow: 0x1EAD,
  27245. acircumflexgrave: 0x1EA7,
  27246. acircumflexhookabove: 0x1EA9,
  27247. acircumflextilde: 0x1EAB,
  27248. acute: 0x00B4,
  27249. acutebelowcmb: 0x0317,
  27250. acutecmb: 0x0301,
  27251. acutecomb: 0x0301,
  27252. acutedeva: 0x0954,
  27253. acutelowmod: 0x02CF,
  27254. acutetonecmb: 0x0341,
  27255. acyrillic: 0x0430,
  27256. adblgrave: 0x0201,
  27257. addakgurmukhi: 0x0A71,
  27258. adeva: 0x0905,
  27259. adieresis: 0x00E4,
  27260. adieresiscyrillic: 0x04D3,
  27261. adieresismacron: 0x01DF,
  27262. adotbelow: 0x1EA1,
  27263. adotmacron: 0x01E1,
  27264. ae: 0x00E6,
  27265. aeacute: 0x01FD,
  27266. aekorean: 0x3150,
  27267. aemacron: 0x01E3,
  27268. afii00208: 0x2015,
  27269. afii08941: 0x20A4,
  27270. afii10017: 0x0410,
  27271. afii10018: 0x0411,
  27272. afii10019: 0x0412,
  27273. afii10020: 0x0413,
  27274. afii10021: 0x0414,
  27275. afii10022: 0x0415,
  27276. afii10023: 0x0401,
  27277. afii10024: 0x0416,
  27278. afii10025: 0x0417,
  27279. afii10026: 0x0418,
  27280. afii10027: 0x0419,
  27281. afii10028: 0x041A,
  27282. afii10029: 0x041B,
  27283. afii10030: 0x041C,
  27284. afii10031: 0x041D,
  27285. afii10032: 0x041E,
  27286. afii10033: 0x041F,
  27287. afii10034: 0x0420,
  27288. afii10035: 0x0421,
  27289. afii10036: 0x0422,
  27290. afii10037: 0x0423,
  27291. afii10038: 0x0424,
  27292. afii10039: 0x0425,
  27293. afii10040: 0x0426,
  27294. afii10041: 0x0427,
  27295. afii10042: 0x0428,
  27296. afii10043: 0x0429,
  27297. afii10044: 0x042A,
  27298. afii10045: 0x042B,
  27299. afii10046: 0x042C,
  27300. afii10047: 0x042D,
  27301. afii10048: 0x042E,
  27302. afii10049: 0x042F,
  27303. afii10050: 0x0490,
  27304. afii10051: 0x0402,
  27305. afii10052: 0x0403,
  27306. afii10053: 0x0404,
  27307. afii10054: 0x0405,
  27308. afii10055: 0x0406,
  27309. afii10056: 0x0407,
  27310. afii10057: 0x0408,
  27311. afii10058: 0x0409,
  27312. afii10059: 0x040A,
  27313. afii10060: 0x040B,
  27314. afii10061: 0x040C,
  27315. afii10062: 0x040E,
  27316. afii10063: 0xF6C4,
  27317. afii10064: 0xF6C5,
  27318. afii10065: 0x0430,
  27319. afii10066: 0x0431,
  27320. afii10067: 0x0432,
  27321. afii10068: 0x0433,
  27322. afii10069: 0x0434,
  27323. afii10070: 0x0435,
  27324. afii10071: 0x0451,
  27325. afii10072: 0x0436,
  27326. afii10073: 0x0437,
  27327. afii10074: 0x0438,
  27328. afii10075: 0x0439,
  27329. afii10076: 0x043A,
  27330. afii10077: 0x043B,
  27331. afii10078: 0x043C,
  27332. afii10079: 0x043D,
  27333. afii10080: 0x043E,
  27334. afii10081: 0x043F,
  27335. afii10082: 0x0440,
  27336. afii10083: 0x0441,
  27337. afii10084: 0x0442,
  27338. afii10085: 0x0443,
  27339. afii10086: 0x0444,
  27340. afii10087: 0x0445,
  27341. afii10088: 0x0446,
  27342. afii10089: 0x0447,
  27343. afii10090: 0x0448,
  27344. afii10091: 0x0449,
  27345. afii10092: 0x044A,
  27346. afii10093: 0x044B,
  27347. afii10094: 0x044C,
  27348. afii10095: 0x044D,
  27349. afii10096: 0x044E,
  27350. afii10097: 0x044F,
  27351. afii10098: 0x0491,
  27352. afii10099: 0x0452,
  27353. afii10100: 0x0453,
  27354. afii10101: 0x0454,
  27355. afii10102: 0x0455,
  27356. afii10103: 0x0456,
  27357. afii10104: 0x0457,
  27358. afii10105: 0x0458,
  27359. afii10106: 0x0459,
  27360. afii10107: 0x045A,
  27361. afii10108: 0x045B,
  27362. afii10109: 0x045C,
  27363. afii10110: 0x045E,
  27364. afii10145: 0x040F,
  27365. afii10146: 0x0462,
  27366. afii10147: 0x0472,
  27367. afii10148: 0x0474,
  27368. afii10192: 0xF6C6,
  27369. afii10193: 0x045F,
  27370. afii10194: 0x0463,
  27371. afii10195: 0x0473,
  27372. afii10196: 0x0475,
  27373. afii10831: 0xF6C7,
  27374. afii10832: 0xF6C8,
  27375. afii10846: 0x04D9,
  27376. afii299: 0x200E,
  27377. afii300: 0x200F,
  27378. afii301: 0x200D,
  27379. afii57381: 0x066A,
  27380. afii57388: 0x060C,
  27381. afii57392: 0x0660,
  27382. afii57393: 0x0661,
  27383. afii57394: 0x0662,
  27384. afii57395: 0x0663,
  27385. afii57396: 0x0664,
  27386. afii57397: 0x0665,
  27387. afii57398: 0x0666,
  27388. afii57399: 0x0667,
  27389. afii57400: 0x0668,
  27390. afii57401: 0x0669,
  27391. afii57403: 0x061B,
  27392. afii57407: 0x061F,
  27393. afii57409: 0x0621,
  27394. afii57410: 0x0622,
  27395. afii57411: 0x0623,
  27396. afii57412: 0x0624,
  27397. afii57413: 0x0625,
  27398. afii57414: 0x0626,
  27399. afii57415: 0x0627,
  27400. afii57416: 0x0628,
  27401. afii57417: 0x0629,
  27402. afii57418: 0x062A,
  27403. afii57419: 0x062B,
  27404. afii57420: 0x062C,
  27405. afii57421: 0x062D,
  27406. afii57422: 0x062E,
  27407. afii57423: 0x062F,
  27408. afii57424: 0x0630,
  27409. afii57425: 0x0631,
  27410. afii57426: 0x0632,
  27411. afii57427: 0x0633,
  27412. afii57428: 0x0634,
  27413. afii57429: 0x0635,
  27414. afii57430: 0x0636,
  27415. afii57431: 0x0637,
  27416. afii57432: 0x0638,
  27417. afii57433: 0x0639,
  27418. afii57434: 0x063A,
  27419. afii57440: 0x0640,
  27420. afii57441: 0x0641,
  27421. afii57442: 0x0642,
  27422. afii57443: 0x0643,
  27423. afii57444: 0x0644,
  27424. afii57445: 0x0645,
  27425. afii57446: 0x0646,
  27426. afii57448: 0x0648,
  27427. afii57449: 0x0649,
  27428. afii57450: 0x064A,
  27429. afii57451: 0x064B,
  27430. afii57452: 0x064C,
  27431. afii57453: 0x064D,
  27432. afii57454: 0x064E,
  27433. afii57455: 0x064F,
  27434. afii57456: 0x0650,
  27435. afii57457: 0x0651,
  27436. afii57458: 0x0652,
  27437. afii57470: 0x0647,
  27438. afii57505: 0x06A4,
  27439. afii57506: 0x067E,
  27440. afii57507: 0x0686,
  27441. afii57508: 0x0698,
  27442. afii57509: 0x06AF,
  27443. afii57511: 0x0679,
  27444. afii57512: 0x0688,
  27445. afii57513: 0x0691,
  27446. afii57514: 0x06BA,
  27447. afii57519: 0x06D2,
  27448. afii57534: 0x06D5,
  27449. afii57636: 0x20AA,
  27450. afii57645: 0x05BE,
  27451. afii57658: 0x05C3,
  27452. afii57664: 0x05D0,
  27453. afii57665: 0x05D1,
  27454. afii57666: 0x05D2,
  27455. afii57667: 0x05D3,
  27456. afii57668: 0x05D4,
  27457. afii57669: 0x05D5,
  27458. afii57670: 0x05D6,
  27459. afii57671: 0x05D7,
  27460. afii57672: 0x05D8,
  27461. afii57673: 0x05D9,
  27462. afii57674: 0x05DA,
  27463. afii57675: 0x05DB,
  27464. afii57676: 0x05DC,
  27465. afii57677: 0x05DD,
  27466. afii57678: 0x05DE,
  27467. afii57679: 0x05DF,
  27468. afii57680: 0x05E0,
  27469. afii57681: 0x05E1,
  27470. afii57682: 0x05E2,
  27471. afii57683: 0x05E3,
  27472. afii57684: 0x05E4,
  27473. afii57685: 0x05E5,
  27474. afii57686: 0x05E6,
  27475. afii57687: 0x05E7,
  27476. afii57688: 0x05E8,
  27477. afii57689: 0x05E9,
  27478. afii57690: 0x05EA,
  27479. afii57694: 0xFB2A,
  27480. afii57695: 0xFB2B,
  27481. afii57700: 0xFB4B,
  27482. afii57705: 0xFB1F,
  27483. afii57716: 0x05F0,
  27484. afii57717: 0x05F1,
  27485. afii57718: 0x05F2,
  27486. afii57723: 0xFB35,
  27487. afii57793: 0x05B4,
  27488. afii57794: 0x05B5,
  27489. afii57795: 0x05B6,
  27490. afii57796: 0x05BB,
  27491. afii57797: 0x05B8,
  27492. afii57798: 0x05B7,
  27493. afii57799: 0x05B0,
  27494. afii57800: 0x05B2,
  27495. afii57801: 0x05B1,
  27496. afii57802: 0x05B3,
  27497. afii57803: 0x05C2,
  27498. afii57804: 0x05C1,
  27499. afii57806: 0x05B9,
  27500. afii57807: 0x05BC,
  27501. afii57839: 0x05BD,
  27502. afii57841: 0x05BF,
  27503. afii57842: 0x05C0,
  27504. afii57929: 0x02BC,
  27505. afii61248: 0x2105,
  27506. afii61289: 0x2113,
  27507. afii61352: 0x2116,
  27508. afii61573: 0x202C,
  27509. afii61574: 0x202D,
  27510. afii61575: 0x202E,
  27511. afii61664: 0x200C,
  27512. afii63167: 0x066D,
  27513. afii64937: 0x02BD,
  27514. agrave: 0x00E0,
  27515. agujarati: 0x0A85,
  27516. agurmukhi: 0x0A05,
  27517. ahiragana: 0x3042,
  27518. ahookabove: 0x1EA3,
  27519. aibengali: 0x0990,
  27520. aibopomofo: 0x311E,
  27521. aideva: 0x0910,
  27522. aiecyrillic: 0x04D5,
  27523. aigujarati: 0x0A90,
  27524. aigurmukhi: 0x0A10,
  27525. aimatragurmukhi: 0x0A48,
  27526. ainarabic: 0x0639,
  27527. ainfinalarabic: 0xFECA,
  27528. aininitialarabic: 0xFECB,
  27529. ainmedialarabic: 0xFECC,
  27530. ainvertedbreve: 0x0203,
  27531. aivowelsignbengali: 0x09C8,
  27532. aivowelsigndeva: 0x0948,
  27533. aivowelsigngujarati: 0x0AC8,
  27534. akatakana: 0x30A2,
  27535. akatakanahalfwidth: 0xFF71,
  27536. akorean: 0x314F,
  27537. alef: 0x05D0,
  27538. alefarabic: 0x0627,
  27539. alefdageshhebrew: 0xFB30,
  27540. aleffinalarabic: 0xFE8E,
  27541. alefhamzaabovearabic: 0x0623,
  27542. alefhamzaabovefinalarabic: 0xFE84,
  27543. alefhamzabelowarabic: 0x0625,
  27544. alefhamzabelowfinalarabic: 0xFE88,
  27545. alefhebrew: 0x05D0,
  27546. aleflamedhebrew: 0xFB4F,
  27547. alefmaddaabovearabic: 0x0622,
  27548. alefmaddaabovefinalarabic: 0xFE82,
  27549. alefmaksuraarabic: 0x0649,
  27550. alefmaksurafinalarabic: 0xFEF0,
  27551. alefmaksurainitialarabic: 0xFEF3,
  27552. alefmaksuramedialarabic: 0xFEF4,
  27553. alefpatahhebrew: 0xFB2E,
  27554. alefqamatshebrew: 0xFB2F,
  27555. aleph: 0x2135,
  27556. allequal: 0x224C,
  27557. alpha: 0x03B1,
  27558. alphatonos: 0x03AC,
  27559. amacron: 0x0101,
  27560. amonospace: 0xFF41,
  27561. ampersand: 0x0026,
  27562. ampersandmonospace: 0xFF06,
  27563. ampersandsmall: 0xF726,
  27564. amsquare: 0x33C2,
  27565. anbopomofo: 0x3122,
  27566. angbopomofo: 0x3124,
  27567. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27568. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27569. angkhankhuthai: 0x0E5A,
  27570. angle: 0x2220,
  27571. anglebracketleft: 0x3008,
  27572. anglebracketleftvertical: 0xFE3F,
  27573. anglebracketright: 0x3009,
  27574. anglebracketrightvertical: 0xFE40,
  27575. angleleft: 0x2329,
  27576. angleright: 0x232A,
  27577. angstrom: 0x212B,
  27578. anoteleia: 0x0387,
  27579. anudattadeva: 0x0952,
  27580. anusvarabengali: 0x0982,
  27581. anusvaradeva: 0x0902,
  27582. anusvaragujarati: 0x0A82,
  27583. aogonek: 0x0105,
  27584. apaatosquare: 0x3300,
  27585. aparen: 0x249C,
  27586. apostrophearmenian: 0x055A,
  27587. apostrophemod: 0x02BC,
  27588. apple: 0xF8FF,
  27589. approaches: 0x2250,
  27590. approxequal: 0x2248,
  27591. approxequalorimage: 0x2252,
  27592. approximatelyequal: 0x2245,
  27593. araeaekorean: 0x318E,
  27594. araeakorean: 0x318D,
  27595. arc: 0x2312,
  27596. arighthalfring: 0x1E9A,
  27597. aring: 0x00E5,
  27598. aringacute: 0x01FB,
  27599. aringbelow: 0x1E01,
  27600. arrowboth: 0x2194,
  27601. arrowdashdown: 0x21E3,
  27602. arrowdashleft: 0x21E0,
  27603. arrowdashright: 0x21E2,
  27604. arrowdashup: 0x21E1,
  27605. arrowdblboth: 0x21D4,
  27606. arrowdbldown: 0x21D3,
  27607. arrowdblleft: 0x21D0,
  27608. arrowdblright: 0x21D2,
  27609. arrowdblup: 0x21D1,
  27610. arrowdown: 0x2193,
  27611. arrowdownleft: 0x2199,
  27612. arrowdownright: 0x2198,
  27613. arrowdownwhite: 0x21E9,
  27614. arrowheaddownmod: 0x02C5,
  27615. arrowheadleftmod: 0x02C2,
  27616. arrowheadrightmod: 0x02C3,
  27617. arrowheadupmod: 0x02C4,
  27618. arrowhorizex: 0xF8E7,
  27619. arrowleft: 0x2190,
  27620. arrowleftdbl: 0x21D0,
  27621. arrowleftdblstroke: 0x21CD,
  27622. arrowleftoverright: 0x21C6,
  27623. arrowleftwhite: 0x21E6,
  27624. arrowright: 0x2192,
  27625. arrowrightdblstroke: 0x21CF,
  27626. arrowrightheavy: 0x279E,
  27627. arrowrightoverleft: 0x21C4,
  27628. arrowrightwhite: 0x21E8,
  27629. arrowtableft: 0x21E4,
  27630. arrowtabright: 0x21E5,
  27631. arrowup: 0x2191,
  27632. arrowupdn: 0x2195,
  27633. arrowupdnbse: 0x21A8,
  27634. arrowupdownbase: 0x21A8,
  27635. arrowupleft: 0x2196,
  27636. arrowupleftofdown: 0x21C5,
  27637. arrowupright: 0x2197,
  27638. arrowupwhite: 0x21E7,
  27639. arrowvertex: 0xF8E6,
  27640. asciicircum: 0x005E,
  27641. asciicircummonospace: 0xFF3E,
  27642. asciitilde: 0x007E,
  27643. asciitildemonospace: 0xFF5E,
  27644. ascript: 0x0251,
  27645. ascriptturned: 0x0252,
  27646. asmallhiragana: 0x3041,
  27647. asmallkatakana: 0x30A1,
  27648. asmallkatakanahalfwidth: 0xFF67,
  27649. asterisk: 0x002A,
  27650. asteriskaltonearabic: 0x066D,
  27651. asteriskarabic: 0x066D,
  27652. asteriskmath: 0x2217,
  27653. asteriskmonospace: 0xFF0A,
  27654. asterisksmall: 0xFE61,
  27655. asterism: 0x2042,
  27656. asuperior: 0xF6E9,
  27657. asymptoticallyequal: 0x2243,
  27658. at: 0x0040,
  27659. atilde: 0x00E3,
  27660. atmonospace: 0xFF20,
  27661. atsmall: 0xFE6B,
  27662. aturned: 0x0250,
  27663. aubengali: 0x0994,
  27664. aubopomofo: 0x3120,
  27665. audeva: 0x0914,
  27666. augujarati: 0x0A94,
  27667. augurmukhi: 0x0A14,
  27668. aulengthmarkbengali: 0x09D7,
  27669. aumatragurmukhi: 0x0A4C,
  27670. auvowelsignbengali: 0x09CC,
  27671. auvowelsigndeva: 0x094C,
  27672. auvowelsigngujarati: 0x0ACC,
  27673. avagrahadeva: 0x093D,
  27674. aybarmenian: 0x0561,
  27675. ayin: 0x05E2,
  27676. ayinaltonehebrew: 0xFB20,
  27677. ayinhebrew: 0x05E2,
  27678. b: 0x0062,
  27679. babengali: 0x09AC,
  27680. backslash: 0x005C,
  27681. backslashmonospace: 0xFF3C,
  27682. badeva: 0x092C,
  27683. bagujarati: 0x0AAC,
  27684. bagurmukhi: 0x0A2C,
  27685. bahiragana: 0x3070,
  27686. bahtthai: 0x0E3F,
  27687. bakatakana: 0x30D0,
  27688. bar: 0x007C,
  27689. barmonospace: 0xFF5C,
  27690. bbopomofo: 0x3105,
  27691. bcircle: 0x24D1,
  27692. bdotaccent: 0x1E03,
  27693. bdotbelow: 0x1E05,
  27694. beamedsixteenthnotes: 0x266C,
  27695. because: 0x2235,
  27696. becyrillic: 0x0431,
  27697. beharabic: 0x0628,
  27698. behfinalarabic: 0xFE90,
  27699. behinitialarabic: 0xFE91,
  27700. behiragana: 0x3079,
  27701. behmedialarabic: 0xFE92,
  27702. behmeeminitialarabic: 0xFC9F,
  27703. behmeemisolatedarabic: 0xFC08,
  27704. behnoonfinalarabic: 0xFC6D,
  27705. bekatakana: 0x30D9,
  27706. benarmenian: 0x0562,
  27707. bet: 0x05D1,
  27708. beta: 0x03B2,
  27709. betasymbolgreek: 0x03D0,
  27710. betdagesh: 0xFB31,
  27711. betdageshhebrew: 0xFB31,
  27712. bethebrew: 0x05D1,
  27713. betrafehebrew: 0xFB4C,
  27714. bhabengali: 0x09AD,
  27715. bhadeva: 0x092D,
  27716. bhagujarati: 0x0AAD,
  27717. bhagurmukhi: 0x0A2D,
  27718. bhook: 0x0253,
  27719. bihiragana: 0x3073,
  27720. bikatakana: 0x30D3,
  27721. bilabialclick: 0x0298,
  27722. bindigurmukhi: 0x0A02,
  27723. birusquare: 0x3331,
  27724. blackcircle: 0x25CF,
  27725. blackdiamond: 0x25C6,
  27726. blackdownpointingtriangle: 0x25BC,
  27727. blackleftpointingpointer: 0x25C4,
  27728. blackleftpointingtriangle: 0x25C0,
  27729. blacklenticularbracketleft: 0x3010,
  27730. blacklenticularbracketleftvertical: 0xFE3B,
  27731. blacklenticularbracketright: 0x3011,
  27732. blacklenticularbracketrightvertical: 0xFE3C,
  27733. blacklowerlefttriangle: 0x25E3,
  27734. blacklowerrighttriangle: 0x25E2,
  27735. blackrectangle: 0x25AC,
  27736. blackrightpointingpointer: 0x25BA,
  27737. blackrightpointingtriangle: 0x25B6,
  27738. blacksmallsquare: 0x25AA,
  27739. blacksmilingface: 0x263B,
  27740. blacksquare: 0x25A0,
  27741. blackstar: 0x2605,
  27742. blackupperlefttriangle: 0x25E4,
  27743. blackupperrighttriangle: 0x25E5,
  27744. blackuppointingsmalltriangle: 0x25B4,
  27745. blackuppointingtriangle: 0x25B2,
  27746. blank: 0x2423,
  27747. blinebelow: 0x1E07,
  27748. block: 0x2588,
  27749. bmonospace: 0xFF42,
  27750. bobaimaithai: 0x0E1A,
  27751. bohiragana: 0x307C,
  27752. bokatakana: 0x30DC,
  27753. bparen: 0x249D,
  27754. bqsquare: 0x33C3,
  27755. braceex: 0xF8F4,
  27756. braceleft: 0x007B,
  27757. braceleftbt: 0xF8F3,
  27758. braceleftmid: 0xF8F2,
  27759. braceleftmonospace: 0xFF5B,
  27760. braceleftsmall: 0xFE5B,
  27761. bracelefttp: 0xF8F1,
  27762. braceleftvertical: 0xFE37,
  27763. braceright: 0x007D,
  27764. bracerightbt: 0xF8FE,
  27765. bracerightmid: 0xF8FD,
  27766. bracerightmonospace: 0xFF5D,
  27767. bracerightsmall: 0xFE5C,
  27768. bracerighttp: 0xF8FC,
  27769. bracerightvertical: 0xFE38,
  27770. bracketleft: 0x005B,
  27771. bracketleftbt: 0xF8F0,
  27772. bracketleftex: 0xF8EF,
  27773. bracketleftmonospace: 0xFF3B,
  27774. bracketlefttp: 0xF8EE,
  27775. bracketright: 0x005D,
  27776. bracketrightbt: 0xF8FB,
  27777. bracketrightex: 0xF8FA,
  27778. bracketrightmonospace: 0xFF3D,
  27779. bracketrighttp: 0xF8F9,
  27780. breve: 0x02D8,
  27781. brevebelowcmb: 0x032E,
  27782. brevecmb: 0x0306,
  27783. breveinvertedbelowcmb: 0x032F,
  27784. breveinvertedcmb: 0x0311,
  27785. breveinverteddoublecmb: 0x0361,
  27786. bridgebelowcmb: 0x032A,
  27787. bridgeinvertedbelowcmb: 0x033A,
  27788. brokenbar: 0x00A6,
  27789. bstroke: 0x0180,
  27790. bsuperior: 0xF6EA,
  27791. btopbar: 0x0183,
  27792. buhiragana: 0x3076,
  27793. bukatakana: 0x30D6,
  27794. bullet: 0x2022,
  27795. bulletinverse: 0x25D8,
  27796. bulletoperator: 0x2219,
  27797. bullseye: 0x25CE,
  27798. c: 0x0063,
  27799. caarmenian: 0x056E,
  27800. cabengali: 0x099A,
  27801. cacute: 0x0107,
  27802. cadeva: 0x091A,
  27803. cagujarati: 0x0A9A,
  27804. cagurmukhi: 0x0A1A,
  27805. calsquare: 0x3388,
  27806. candrabindubengali: 0x0981,
  27807. candrabinducmb: 0x0310,
  27808. candrabindudeva: 0x0901,
  27809. candrabindugujarati: 0x0A81,
  27810. capslock: 0x21EA,
  27811. careof: 0x2105,
  27812. caron: 0x02C7,
  27813. caronbelowcmb: 0x032C,
  27814. caroncmb: 0x030C,
  27815. carriagereturn: 0x21B5,
  27816. cbopomofo: 0x3118,
  27817. ccaron: 0x010D,
  27818. ccedilla: 0x00E7,
  27819. ccedillaacute: 0x1E09,
  27820. ccircle: 0x24D2,
  27821. ccircumflex: 0x0109,
  27822. ccurl: 0x0255,
  27823. cdot: 0x010B,
  27824. cdotaccent: 0x010B,
  27825. cdsquare: 0x33C5,
  27826. cedilla: 0x00B8,
  27827. cedillacmb: 0x0327,
  27828. cent: 0x00A2,
  27829. centigrade: 0x2103,
  27830. centinferior: 0xF6DF,
  27831. centmonospace: 0xFFE0,
  27832. centoldstyle: 0xF7A2,
  27833. centsuperior: 0xF6E0,
  27834. chaarmenian: 0x0579,
  27835. chabengali: 0x099B,
  27836. chadeva: 0x091B,
  27837. chagujarati: 0x0A9B,
  27838. chagurmukhi: 0x0A1B,
  27839. chbopomofo: 0x3114,
  27840. cheabkhasiancyrillic: 0x04BD,
  27841. checkmark: 0x2713,
  27842. checyrillic: 0x0447,
  27843. chedescenderabkhasiancyrillic: 0x04BF,
  27844. chedescendercyrillic: 0x04B7,
  27845. chedieresiscyrillic: 0x04F5,
  27846. cheharmenian: 0x0573,
  27847. chekhakassiancyrillic: 0x04CC,
  27848. cheverticalstrokecyrillic: 0x04B9,
  27849. chi: 0x03C7,
  27850. chieuchacirclekorean: 0x3277,
  27851. chieuchaparenkorean: 0x3217,
  27852. chieuchcirclekorean: 0x3269,
  27853. chieuchkorean: 0x314A,
  27854. chieuchparenkorean: 0x3209,
  27855. chochangthai: 0x0E0A,
  27856. chochanthai: 0x0E08,
  27857. chochingthai: 0x0E09,
  27858. chochoethai: 0x0E0C,
  27859. chook: 0x0188,
  27860. cieucacirclekorean: 0x3276,
  27861. cieucaparenkorean: 0x3216,
  27862. cieuccirclekorean: 0x3268,
  27863. cieuckorean: 0x3148,
  27864. cieucparenkorean: 0x3208,
  27865. cieucuparenkorean: 0x321C,
  27866. circle: 0x25CB,
  27867. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27868. circlemultiply: 0x2297,
  27869. circleot: 0x2299,
  27870. circleplus: 0x2295,
  27871. circlepostalmark: 0x3036,
  27872. circlewithlefthalfblack: 0x25D0,
  27873. circlewithrighthalfblack: 0x25D1,
  27874. circumflex: 0x02C6,
  27875. circumflexbelowcmb: 0x032D,
  27876. circumflexcmb: 0x0302,
  27877. clear: 0x2327,
  27878. clickalveolar: 0x01C2,
  27879. clickdental: 0x01C0,
  27880. clicklateral: 0x01C1,
  27881. clickretroflex: 0x01C3,
  27882. club: 0x2663,
  27883. clubsuitblack: 0x2663,
  27884. clubsuitwhite: 0x2667,
  27885. cmcubedsquare: 0x33A4,
  27886. cmonospace: 0xFF43,
  27887. cmsquaredsquare: 0x33A0,
  27888. coarmenian: 0x0581,
  27889. colon: 0x003A,
  27890. colonmonetary: 0x20A1,
  27891. colonmonospace: 0xFF1A,
  27892. colonsign: 0x20A1,
  27893. colonsmall: 0xFE55,
  27894. colontriangularhalfmod: 0x02D1,
  27895. colontriangularmod: 0x02D0,
  27896. comma: 0x002C,
  27897. commaabovecmb: 0x0313,
  27898. commaaboverightcmb: 0x0315,
  27899. commaaccent: 0xF6C3,
  27900. commaarabic: 0x060C,
  27901. commaarmenian: 0x055D,
  27902. commainferior: 0xF6E1,
  27903. commamonospace: 0xFF0C,
  27904. commareversedabovecmb: 0x0314,
  27905. commareversedmod: 0x02BD,
  27906. commasmall: 0xFE50,
  27907. commasuperior: 0xF6E2,
  27908. commaturnedabovecmb: 0x0312,
  27909. commaturnedmod: 0x02BB,
  27910. compass: 0x263C,
  27911. congruent: 0x2245,
  27912. contourintegral: 0x222E,
  27913. control: 0x2303,
  27914. controlACK: 0x0006,
  27915. controlBEL: 0x0007,
  27916. controlBS: 0x0008,
  27917. controlCAN: 0x0018,
  27918. controlCR: 0x000D,
  27919. controlDC1: 0x0011,
  27920. controlDC2: 0x0012,
  27921. controlDC3: 0x0013,
  27922. controlDC4: 0x0014,
  27923. controlDEL: 0x007F,
  27924. controlDLE: 0x0010,
  27925. controlEM: 0x0019,
  27926. controlENQ: 0x0005,
  27927. controlEOT: 0x0004,
  27928. controlESC: 0x001B,
  27929. controlETB: 0x0017,
  27930. controlETX: 0x0003,
  27931. controlFF: 0x000C,
  27932. controlFS: 0x001C,
  27933. controlGS: 0x001D,
  27934. controlHT: 0x0009,
  27935. controlLF: 0x000A,
  27936. controlNAK: 0x0015,
  27937. controlRS: 0x001E,
  27938. controlSI: 0x000F,
  27939. controlSO: 0x000E,
  27940. controlSOT: 0x0002,
  27941. controlSTX: 0x0001,
  27942. controlSUB: 0x001A,
  27943. controlSYN: 0x0016,
  27944. controlUS: 0x001F,
  27945. controlVT: 0x000B,
  27946. copyright: 0x00A9,
  27947. copyrightsans: 0xF8E9,
  27948. copyrightserif: 0xF6D9,
  27949. cornerbracketleft: 0x300C,
  27950. cornerbracketlefthalfwidth: 0xFF62,
  27951. cornerbracketleftvertical: 0xFE41,
  27952. cornerbracketright: 0x300D,
  27953. cornerbracketrighthalfwidth: 0xFF63,
  27954. cornerbracketrightvertical: 0xFE42,
  27955. corporationsquare: 0x337F,
  27956. cosquare: 0x33C7,
  27957. coverkgsquare: 0x33C6,
  27958. cparen: 0x249E,
  27959. cruzeiro: 0x20A2,
  27960. cstretched: 0x0297,
  27961. curlyand: 0x22CF,
  27962. curlyor: 0x22CE,
  27963. currency: 0x00A4,
  27964. cyrBreve: 0xF6D1,
  27965. cyrFlex: 0xF6D2,
  27966. cyrbreve: 0xF6D4,
  27967. cyrflex: 0xF6D5,
  27968. d: 0x0064,
  27969. daarmenian: 0x0564,
  27970. dabengali: 0x09A6,
  27971. dadarabic: 0x0636,
  27972. dadeva: 0x0926,
  27973. dadfinalarabic: 0xFEBE,
  27974. dadinitialarabic: 0xFEBF,
  27975. dadmedialarabic: 0xFEC0,
  27976. dagesh: 0x05BC,
  27977. dageshhebrew: 0x05BC,
  27978. dagger: 0x2020,
  27979. daggerdbl: 0x2021,
  27980. dagujarati: 0x0AA6,
  27981. dagurmukhi: 0x0A26,
  27982. dahiragana: 0x3060,
  27983. dakatakana: 0x30C0,
  27984. dalarabic: 0x062F,
  27985. dalet: 0x05D3,
  27986. daletdagesh: 0xFB33,
  27987. daletdageshhebrew: 0xFB33,
  27988. dalethebrew: 0x05D3,
  27989. dalfinalarabic: 0xFEAA,
  27990. dammaarabic: 0x064F,
  27991. dammalowarabic: 0x064F,
  27992. dammatanaltonearabic: 0x064C,
  27993. dammatanarabic: 0x064C,
  27994. danda: 0x0964,
  27995. dargahebrew: 0x05A7,
  27996. dargalefthebrew: 0x05A7,
  27997. dasiapneumatacyrilliccmb: 0x0485,
  27998. dblGrave: 0xF6D3,
  27999. dblanglebracketleft: 0x300A,
  28000. dblanglebracketleftvertical: 0xFE3D,
  28001. dblanglebracketright: 0x300B,
  28002. dblanglebracketrightvertical: 0xFE3E,
  28003. dblarchinvertedbelowcmb: 0x032B,
  28004. dblarrowleft: 0x21D4,
  28005. dblarrowright: 0x21D2,
  28006. dbldanda: 0x0965,
  28007. dblgrave: 0xF6D6,
  28008. dblgravecmb: 0x030F,
  28009. dblintegral: 0x222C,
  28010. dbllowline: 0x2017,
  28011. dbllowlinecmb: 0x0333,
  28012. dbloverlinecmb: 0x033F,
  28013. dblprimemod: 0x02BA,
  28014. dblverticalbar: 0x2016,
  28015. dblverticallineabovecmb: 0x030E,
  28016. dbopomofo: 0x3109,
  28017. dbsquare: 0x33C8,
  28018. dcaron: 0x010F,
  28019. dcedilla: 0x1E11,
  28020. dcircle: 0x24D3,
  28021. dcircumflexbelow: 0x1E13,
  28022. dcroat: 0x0111,
  28023. ddabengali: 0x09A1,
  28024. ddadeva: 0x0921,
  28025. ddagujarati: 0x0AA1,
  28026. ddagurmukhi: 0x0A21,
  28027. ddalarabic: 0x0688,
  28028. ddalfinalarabic: 0xFB89,
  28029. dddhadeva: 0x095C,
  28030. ddhabengali: 0x09A2,
  28031. ddhadeva: 0x0922,
  28032. ddhagujarati: 0x0AA2,
  28033. ddhagurmukhi: 0x0A22,
  28034. ddotaccent: 0x1E0B,
  28035. ddotbelow: 0x1E0D,
  28036. decimalseparatorarabic: 0x066B,
  28037. decimalseparatorpersian: 0x066B,
  28038. decyrillic: 0x0434,
  28039. degree: 0x00B0,
  28040. dehihebrew: 0x05AD,
  28041. dehiragana: 0x3067,
  28042. deicoptic: 0x03EF,
  28043. dekatakana: 0x30C7,
  28044. deleteleft: 0x232B,
  28045. deleteright: 0x2326,
  28046. delta: 0x03B4,
  28047. deltaturned: 0x018D,
  28048. denominatorminusonenumeratorbengali: 0x09F8,
  28049. dezh: 0x02A4,
  28050. dhabengali: 0x09A7,
  28051. dhadeva: 0x0927,
  28052. dhagujarati: 0x0AA7,
  28053. dhagurmukhi: 0x0A27,
  28054. dhook: 0x0257,
  28055. dialytikatonos: 0x0385,
  28056. dialytikatonoscmb: 0x0344,
  28057. diamond: 0x2666,
  28058. diamondsuitwhite: 0x2662,
  28059. dieresis: 0x00A8,
  28060. dieresisacute: 0xF6D7,
  28061. dieresisbelowcmb: 0x0324,
  28062. dieresiscmb: 0x0308,
  28063. dieresisgrave: 0xF6D8,
  28064. dieresistonos: 0x0385,
  28065. dihiragana: 0x3062,
  28066. dikatakana: 0x30C2,
  28067. dittomark: 0x3003,
  28068. divide: 0x00F7,
  28069. divides: 0x2223,
  28070. divisionslash: 0x2215,
  28071. djecyrillic: 0x0452,
  28072. dkshade: 0x2593,
  28073. dlinebelow: 0x1E0F,
  28074. dlsquare: 0x3397,
  28075. dmacron: 0x0111,
  28076. dmonospace: 0xFF44,
  28077. dnblock: 0x2584,
  28078. dochadathai: 0x0E0E,
  28079. dodekthai: 0x0E14,
  28080. dohiragana: 0x3069,
  28081. dokatakana: 0x30C9,
  28082. dollar: 0x0024,
  28083. dollarinferior: 0xF6E3,
  28084. dollarmonospace: 0xFF04,
  28085. dollaroldstyle: 0xF724,
  28086. dollarsmall: 0xFE69,
  28087. dollarsuperior: 0xF6E4,
  28088. dong: 0x20AB,
  28089. dorusquare: 0x3326,
  28090. dotaccent: 0x02D9,
  28091. dotaccentcmb: 0x0307,
  28092. dotbelowcmb: 0x0323,
  28093. dotbelowcomb: 0x0323,
  28094. dotkatakana: 0x30FB,
  28095. dotlessi: 0x0131,
  28096. dotlessj: 0xF6BE,
  28097. dotlessjstrokehook: 0x0284,
  28098. dotmath: 0x22C5,
  28099. dottedcircle: 0x25CC,
  28100. doubleyodpatah: 0xFB1F,
  28101. doubleyodpatahhebrew: 0xFB1F,
  28102. downtackbelowcmb: 0x031E,
  28103. downtackmod: 0x02D5,
  28104. dparen: 0x249F,
  28105. dsuperior: 0xF6EB,
  28106. dtail: 0x0256,
  28107. dtopbar: 0x018C,
  28108. duhiragana: 0x3065,
  28109. dukatakana: 0x30C5,
  28110. dz: 0x01F3,
  28111. dzaltone: 0x02A3,
  28112. dzcaron: 0x01C6,
  28113. dzcurl: 0x02A5,
  28114. dzeabkhasiancyrillic: 0x04E1,
  28115. dzecyrillic: 0x0455,
  28116. dzhecyrillic: 0x045F,
  28117. e: 0x0065,
  28118. eacute: 0x00E9,
  28119. earth: 0x2641,
  28120. ebengali: 0x098F,
  28121. ebopomofo: 0x311C,
  28122. ebreve: 0x0115,
  28123. ecandradeva: 0x090D,
  28124. ecandragujarati: 0x0A8D,
  28125. ecandravowelsigndeva: 0x0945,
  28126. ecandravowelsigngujarati: 0x0AC5,
  28127. ecaron: 0x011B,
  28128. ecedillabreve: 0x1E1D,
  28129. echarmenian: 0x0565,
  28130. echyiwnarmenian: 0x0587,
  28131. ecircle: 0x24D4,
  28132. ecircumflex: 0x00EA,
  28133. ecircumflexacute: 0x1EBF,
  28134. ecircumflexbelow: 0x1E19,
  28135. ecircumflexdotbelow: 0x1EC7,
  28136. ecircumflexgrave: 0x1EC1,
  28137. ecircumflexhookabove: 0x1EC3,
  28138. ecircumflextilde: 0x1EC5,
  28139. ecyrillic: 0x0454,
  28140. edblgrave: 0x0205,
  28141. edeva: 0x090F,
  28142. edieresis: 0x00EB,
  28143. edot: 0x0117,
  28144. edotaccent: 0x0117,
  28145. edotbelow: 0x1EB9,
  28146. eegurmukhi: 0x0A0F,
  28147. eematragurmukhi: 0x0A47,
  28148. efcyrillic: 0x0444,
  28149. egrave: 0x00E8,
  28150. egujarati: 0x0A8F,
  28151. eharmenian: 0x0567,
  28152. ehbopomofo: 0x311D,
  28153. ehiragana: 0x3048,
  28154. ehookabove: 0x1EBB,
  28155. eibopomofo: 0x311F,
  28156. eight: 0x0038,
  28157. eightarabic: 0x0668,
  28158. eightbengali: 0x09EE,
  28159. eightcircle: 0x2467,
  28160. eightcircleinversesansserif: 0x2791,
  28161. eightdeva: 0x096E,
  28162. eighteencircle: 0x2471,
  28163. eighteenparen: 0x2485,
  28164. eighteenperiod: 0x2499,
  28165. eightgujarati: 0x0AEE,
  28166. eightgurmukhi: 0x0A6E,
  28167. eighthackarabic: 0x0668,
  28168. eighthangzhou: 0x3028,
  28169. eighthnotebeamed: 0x266B,
  28170. eightideographicparen: 0x3227,
  28171. eightinferior: 0x2088,
  28172. eightmonospace: 0xFF18,
  28173. eightoldstyle: 0xF738,
  28174. eightparen: 0x247B,
  28175. eightperiod: 0x248F,
  28176. eightpersian: 0x06F8,
  28177. eightroman: 0x2177,
  28178. eightsuperior: 0x2078,
  28179. eightthai: 0x0E58,
  28180. einvertedbreve: 0x0207,
  28181. eiotifiedcyrillic: 0x0465,
  28182. ekatakana: 0x30A8,
  28183. ekatakanahalfwidth: 0xFF74,
  28184. ekonkargurmukhi: 0x0A74,
  28185. ekorean: 0x3154,
  28186. elcyrillic: 0x043B,
  28187. element: 0x2208,
  28188. elevencircle: 0x246A,
  28189. elevenparen: 0x247E,
  28190. elevenperiod: 0x2492,
  28191. elevenroman: 0x217A,
  28192. ellipsis: 0x2026,
  28193. ellipsisvertical: 0x22EE,
  28194. emacron: 0x0113,
  28195. emacronacute: 0x1E17,
  28196. emacrongrave: 0x1E15,
  28197. emcyrillic: 0x043C,
  28198. emdash: 0x2014,
  28199. emdashvertical: 0xFE31,
  28200. emonospace: 0xFF45,
  28201. emphasismarkarmenian: 0x055B,
  28202. emptyset: 0x2205,
  28203. enbopomofo: 0x3123,
  28204. encyrillic: 0x043D,
  28205. endash: 0x2013,
  28206. endashvertical: 0xFE32,
  28207. endescendercyrillic: 0x04A3,
  28208. eng: 0x014B,
  28209. engbopomofo: 0x3125,
  28210. enghecyrillic: 0x04A5,
  28211. enhookcyrillic: 0x04C8,
  28212. enspace: 0x2002,
  28213. eogonek: 0x0119,
  28214. eokorean: 0x3153,
  28215. eopen: 0x025B,
  28216. eopenclosed: 0x029A,
  28217. eopenreversed: 0x025C,
  28218. eopenreversedclosed: 0x025E,
  28219. eopenreversedhook: 0x025D,
  28220. eparen: 0x24A0,
  28221. epsilon: 0x03B5,
  28222. epsilontonos: 0x03AD,
  28223. equal: 0x003D,
  28224. equalmonospace: 0xFF1D,
  28225. equalsmall: 0xFE66,
  28226. equalsuperior: 0x207C,
  28227. equivalence: 0x2261,
  28228. erbopomofo: 0x3126,
  28229. ercyrillic: 0x0440,
  28230. ereversed: 0x0258,
  28231. ereversedcyrillic: 0x044D,
  28232. escyrillic: 0x0441,
  28233. esdescendercyrillic: 0x04AB,
  28234. esh: 0x0283,
  28235. eshcurl: 0x0286,
  28236. eshortdeva: 0x090E,
  28237. eshortvowelsigndeva: 0x0946,
  28238. eshreversedloop: 0x01AA,
  28239. eshsquatreversed: 0x0285,
  28240. esmallhiragana: 0x3047,
  28241. esmallkatakana: 0x30A7,
  28242. esmallkatakanahalfwidth: 0xFF6A,
  28243. estimated: 0x212E,
  28244. esuperior: 0xF6EC,
  28245. eta: 0x03B7,
  28246. etarmenian: 0x0568,
  28247. etatonos: 0x03AE,
  28248. eth: 0x00F0,
  28249. etilde: 0x1EBD,
  28250. etildebelow: 0x1E1B,
  28251. etnahtafoukhhebrew: 0x0591,
  28252. etnahtafoukhlefthebrew: 0x0591,
  28253. etnahtahebrew: 0x0591,
  28254. etnahtalefthebrew: 0x0591,
  28255. eturned: 0x01DD,
  28256. eukorean: 0x3161,
  28257. euro: 0x20AC,
  28258. evowelsignbengali: 0x09C7,
  28259. evowelsigndeva: 0x0947,
  28260. evowelsigngujarati: 0x0AC7,
  28261. exclam: 0x0021,
  28262. exclamarmenian: 0x055C,
  28263. exclamdbl: 0x203C,
  28264. exclamdown: 0x00A1,
  28265. exclamdownsmall: 0xF7A1,
  28266. exclammonospace: 0xFF01,
  28267. exclamsmall: 0xF721,
  28268. existential: 0x2203,
  28269. ezh: 0x0292,
  28270. ezhcaron: 0x01EF,
  28271. ezhcurl: 0x0293,
  28272. ezhreversed: 0x01B9,
  28273. ezhtail: 0x01BA,
  28274. f: 0x0066,
  28275. fadeva: 0x095E,
  28276. fagurmukhi: 0x0A5E,
  28277. fahrenheit: 0x2109,
  28278. fathaarabic: 0x064E,
  28279. fathalowarabic: 0x064E,
  28280. fathatanarabic: 0x064B,
  28281. fbopomofo: 0x3108,
  28282. fcircle: 0x24D5,
  28283. fdotaccent: 0x1E1F,
  28284. feharabic: 0x0641,
  28285. feharmenian: 0x0586,
  28286. fehfinalarabic: 0xFED2,
  28287. fehinitialarabic: 0xFED3,
  28288. fehmedialarabic: 0xFED4,
  28289. feicoptic: 0x03E5,
  28290. female: 0x2640,
  28291. ff: 0xFB00,
  28292. ffi: 0xFB03,
  28293. ffl: 0xFB04,
  28294. fi: 0xFB01,
  28295. fifteencircle: 0x246E,
  28296. fifteenparen: 0x2482,
  28297. fifteenperiod: 0x2496,
  28298. figuredash: 0x2012,
  28299. filledbox: 0x25A0,
  28300. filledrect: 0x25AC,
  28301. finalkaf: 0x05DA,
  28302. finalkafdagesh: 0xFB3A,
  28303. finalkafdageshhebrew: 0xFB3A,
  28304. finalkafhebrew: 0x05DA,
  28305. finalmem: 0x05DD,
  28306. finalmemhebrew: 0x05DD,
  28307. finalnun: 0x05DF,
  28308. finalnunhebrew: 0x05DF,
  28309. finalpe: 0x05E3,
  28310. finalpehebrew: 0x05E3,
  28311. finaltsadi: 0x05E5,
  28312. finaltsadihebrew: 0x05E5,
  28313. firsttonechinese: 0x02C9,
  28314. fisheye: 0x25C9,
  28315. fitacyrillic: 0x0473,
  28316. five: 0x0035,
  28317. fivearabic: 0x0665,
  28318. fivebengali: 0x09EB,
  28319. fivecircle: 0x2464,
  28320. fivecircleinversesansserif: 0x278E,
  28321. fivedeva: 0x096B,
  28322. fiveeighths: 0x215D,
  28323. fivegujarati: 0x0AEB,
  28324. fivegurmukhi: 0x0A6B,
  28325. fivehackarabic: 0x0665,
  28326. fivehangzhou: 0x3025,
  28327. fiveideographicparen: 0x3224,
  28328. fiveinferior: 0x2085,
  28329. fivemonospace: 0xFF15,
  28330. fiveoldstyle: 0xF735,
  28331. fiveparen: 0x2478,
  28332. fiveperiod: 0x248C,
  28333. fivepersian: 0x06F5,
  28334. fiveroman: 0x2174,
  28335. fivesuperior: 0x2075,
  28336. fivethai: 0x0E55,
  28337. fl: 0xFB02,
  28338. florin: 0x0192,
  28339. fmonospace: 0xFF46,
  28340. fmsquare: 0x3399,
  28341. fofanthai: 0x0E1F,
  28342. fofathai: 0x0E1D,
  28343. fongmanthai: 0x0E4F,
  28344. forall: 0x2200,
  28345. four: 0x0034,
  28346. fourarabic: 0x0664,
  28347. fourbengali: 0x09EA,
  28348. fourcircle: 0x2463,
  28349. fourcircleinversesansserif: 0x278D,
  28350. fourdeva: 0x096A,
  28351. fourgujarati: 0x0AEA,
  28352. fourgurmukhi: 0x0A6A,
  28353. fourhackarabic: 0x0664,
  28354. fourhangzhou: 0x3024,
  28355. fourideographicparen: 0x3223,
  28356. fourinferior: 0x2084,
  28357. fourmonospace: 0xFF14,
  28358. fournumeratorbengali: 0x09F7,
  28359. fouroldstyle: 0xF734,
  28360. fourparen: 0x2477,
  28361. fourperiod: 0x248B,
  28362. fourpersian: 0x06F4,
  28363. fourroman: 0x2173,
  28364. foursuperior: 0x2074,
  28365. fourteencircle: 0x246D,
  28366. fourteenparen: 0x2481,
  28367. fourteenperiod: 0x2495,
  28368. fourthai: 0x0E54,
  28369. fourthtonechinese: 0x02CB,
  28370. fparen: 0x24A1,
  28371. fraction: 0x2044,
  28372. franc: 0x20A3,
  28373. g: 0x0067,
  28374. gabengali: 0x0997,
  28375. gacute: 0x01F5,
  28376. gadeva: 0x0917,
  28377. gafarabic: 0x06AF,
  28378. gaffinalarabic: 0xFB93,
  28379. gafinitialarabic: 0xFB94,
  28380. gafmedialarabic: 0xFB95,
  28381. gagujarati: 0x0A97,
  28382. gagurmukhi: 0x0A17,
  28383. gahiragana: 0x304C,
  28384. gakatakana: 0x30AC,
  28385. gamma: 0x03B3,
  28386. gammalatinsmall: 0x0263,
  28387. gammasuperior: 0x02E0,
  28388. gangiacoptic: 0x03EB,
  28389. gbopomofo: 0x310D,
  28390. gbreve: 0x011F,
  28391. gcaron: 0x01E7,
  28392. gcedilla: 0x0123,
  28393. gcircle: 0x24D6,
  28394. gcircumflex: 0x011D,
  28395. gcommaaccent: 0x0123,
  28396. gdot: 0x0121,
  28397. gdotaccent: 0x0121,
  28398. gecyrillic: 0x0433,
  28399. gehiragana: 0x3052,
  28400. gekatakana: 0x30B2,
  28401. geometricallyequal: 0x2251,
  28402. gereshaccenthebrew: 0x059C,
  28403. gereshhebrew: 0x05F3,
  28404. gereshmuqdamhebrew: 0x059D,
  28405. germandbls: 0x00DF,
  28406. gershayimaccenthebrew: 0x059E,
  28407. gershayimhebrew: 0x05F4,
  28408. getamark: 0x3013,
  28409. ghabengali: 0x0998,
  28410. ghadarmenian: 0x0572,
  28411. ghadeva: 0x0918,
  28412. ghagujarati: 0x0A98,
  28413. ghagurmukhi: 0x0A18,
  28414. ghainarabic: 0x063A,
  28415. ghainfinalarabic: 0xFECE,
  28416. ghaininitialarabic: 0xFECF,
  28417. ghainmedialarabic: 0xFED0,
  28418. ghemiddlehookcyrillic: 0x0495,
  28419. ghestrokecyrillic: 0x0493,
  28420. gheupturncyrillic: 0x0491,
  28421. ghhadeva: 0x095A,
  28422. ghhagurmukhi: 0x0A5A,
  28423. ghook: 0x0260,
  28424. ghzsquare: 0x3393,
  28425. gihiragana: 0x304E,
  28426. gikatakana: 0x30AE,
  28427. gimarmenian: 0x0563,
  28428. gimel: 0x05D2,
  28429. gimeldagesh: 0xFB32,
  28430. gimeldageshhebrew: 0xFB32,
  28431. gimelhebrew: 0x05D2,
  28432. gjecyrillic: 0x0453,
  28433. glottalinvertedstroke: 0x01BE,
  28434. glottalstop: 0x0294,
  28435. glottalstopinverted: 0x0296,
  28436. glottalstopmod: 0x02C0,
  28437. glottalstopreversed: 0x0295,
  28438. glottalstopreversedmod: 0x02C1,
  28439. glottalstopreversedsuperior: 0x02E4,
  28440. glottalstopstroke: 0x02A1,
  28441. glottalstopstrokereversed: 0x02A2,
  28442. gmacron: 0x1E21,
  28443. gmonospace: 0xFF47,
  28444. gohiragana: 0x3054,
  28445. gokatakana: 0x30B4,
  28446. gparen: 0x24A2,
  28447. gpasquare: 0x33AC,
  28448. gradient: 0x2207,
  28449. grave: 0x0060,
  28450. gravebelowcmb: 0x0316,
  28451. gravecmb: 0x0300,
  28452. gravecomb: 0x0300,
  28453. gravedeva: 0x0953,
  28454. gravelowmod: 0x02CE,
  28455. gravemonospace: 0xFF40,
  28456. gravetonecmb: 0x0340,
  28457. greater: 0x003E,
  28458. greaterequal: 0x2265,
  28459. greaterequalorless: 0x22DB,
  28460. greatermonospace: 0xFF1E,
  28461. greaterorequivalent: 0x2273,
  28462. greaterorless: 0x2277,
  28463. greateroverequal: 0x2267,
  28464. greatersmall: 0xFE65,
  28465. gscript: 0x0261,
  28466. gstroke: 0x01E5,
  28467. guhiragana: 0x3050,
  28468. guillemotleft: 0x00AB,
  28469. guillemotright: 0x00BB,
  28470. guilsinglleft: 0x2039,
  28471. guilsinglright: 0x203A,
  28472. gukatakana: 0x30B0,
  28473. guramusquare: 0x3318,
  28474. gysquare: 0x33C9,
  28475. h: 0x0068,
  28476. haabkhasiancyrillic: 0x04A9,
  28477. haaltonearabic: 0x06C1,
  28478. habengali: 0x09B9,
  28479. hadescendercyrillic: 0x04B3,
  28480. hadeva: 0x0939,
  28481. hagujarati: 0x0AB9,
  28482. hagurmukhi: 0x0A39,
  28483. haharabic: 0x062D,
  28484. hahfinalarabic: 0xFEA2,
  28485. hahinitialarabic: 0xFEA3,
  28486. hahiragana: 0x306F,
  28487. hahmedialarabic: 0xFEA4,
  28488. haitusquare: 0x332A,
  28489. hakatakana: 0x30CF,
  28490. hakatakanahalfwidth: 0xFF8A,
  28491. halantgurmukhi: 0x0A4D,
  28492. hamzaarabic: 0x0621,
  28493. hamzalowarabic: 0x0621,
  28494. hangulfiller: 0x3164,
  28495. hardsigncyrillic: 0x044A,
  28496. harpoonleftbarbup: 0x21BC,
  28497. harpoonrightbarbup: 0x21C0,
  28498. hasquare: 0x33CA,
  28499. hatafpatah: 0x05B2,
  28500. hatafpatah16: 0x05B2,
  28501. hatafpatah23: 0x05B2,
  28502. hatafpatah2f: 0x05B2,
  28503. hatafpatahhebrew: 0x05B2,
  28504. hatafpatahnarrowhebrew: 0x05B2,
  28505. hatafpatahquarterhebrew: 0x05B2,
  28506. hatafpatahwidehebrew: 0x05B2,
  28507. hatafqamats: 0x05B3,
  28508. hatafqamats1b: 0x05B3,
  28509. hatafqamats28: 0x05B3,
  28510. hatafqamats34: 0x05B3,
  28511. hatafqamatshebrew: 0x05B3,
  28512. hatafqamatsnarrowhebrew: 0x05B3,
  28513. hatafqamatsquarterhebrew: 0x05B3,
  28514. hatafqamatswidehebrew: 0x05B3,
  28515. hatafsegol: 0x05B1,
  28516. hatafsegol17: 0x05B1,
  28517. hatafsegol24: 0x05B1,
  28518. hatafsegol30: 0x05B1,
  28519. hatafsegolhebrew: 0x05B1,
  28520. hatafsegolnarrowhebrew: 0x05B1,
  28521. hatafsegolquarterhebrew: 0x05B1,
  28522. hatafsegolwidehebrew: 0x05B1,
  28523. hbar: 0x0127,
  28524. hbopomofo: 0x310F,
  28525. hbrevebelow: 0x1E2B,
  28526. hcedilla: 0x1E29,
  28527. hcircle: 0x24D7,
  28528. hcircumflex: 0x0125,
  28529. hdieresis: 0x1E27,
  28530. hdotaccent: 0x1E23,
  28531. hdotbelow: 0x1E25,
  28532. he: 0x05D4,
  28533. heart: 0x2665,
  28534. heartsuitblack: 0x2665,
  28535. heartsuitwhite: 0x2661,
  28536. hedagesh: 0xFB34,
  28537. hedageshhebrew: 0xFB34,
  28538. hehaltonearabic: 0x06C1,
  28539. heharabic: 0x0647,
  28540. hehebrew: 0x05D4,
  28541. hehfinalaltonearabic: 0xFBA7,
  28542. hehfinalalttwoarabic: 0xFEEA,
  28543. hehfinalarabic: 0xFEEA,
  28544. hehhamzaabovefinalarabic: 0xFBA5,
  28545. hehhamzaaboveisolatedarabic: 0xFBA4,
  28546. hehinitialaltonearabic: 0xFBA8,
  28547. hehinitialarabic: 0xFEEB,
  28548. hehiragana: 0x3078,
  28549. hehmedialaltonearabic: 0xFBA9,
  28550. hehmedialarabic: 0xFEEC,
  28551. heiseierasquare: 0x337B,
  28552. hekatakana: 0x30D8,
  28553. hekatakanahalfwidth: 0xFF8D,
  28554. hekutaarusquare: 0x3336,
  28555. henghook: 0x0267,
  28556. herutusquare: 0x3339,
  28557. het: 0x05D7,
  28558. hethebrew: 0x05D7,
  28559. hhook: 0x0266,
  28560. hhooksuperior: 0x02B1,
  28561. hieuhacirclekorean: 0x327B,
  28562. hieuhaparenkorean: 0x321B,
  28563. hieuhcirclekorean: 0x326D,
  28564. hieuhkorean: 0x314E,
  28565. hieuhparenkorean: 0x320D,
  28566. hihiragana: 0x3072,
  28567. hikatakana: 0x30D2,
  28568. hikatakanahalfwidth: 0xFF8B,
  28569. hiriq: 0x05B4,
  28570. hiriq14: 0x05B4,
  28571. hiriq21: 0x05B4,
  28572. hiriq2d: 0x05B4,
  28573. hiriqhebrew: 0x05B4,
  28574. hiriqnarrowhebrew: 0x05B4,
  28575. hiriqquarterhebrew: 0x05B4,
  28576. hiriqwidehebrew: 0x05B4,
  28577. hlinebelow: 0x1E96,
  28578. hmonospace: 0xFF48,
  28579. hoarmenian: 0x0570,
  28580. hohipthai: 0x0E2B,
  28581. hohiragana: 0x307B,
  28582. hokatakana: 0x30DB,
  28583. hokatakanahalfwidth: 0xFF8E,
  28584. holam: 0x05B9,
  28585. holam19: 0x05B9,
  28586. holam26: 0x05B9,
  28587. holam32: 0x05B9,
  28588. holamhebrew: 0x05B9,
  28589. holamnarrowhebrew: 0x05B9,
  28590. holamquarterhebrew: 0x05B9,
  28591. holamwidehebrew: 0x05B9,
  28592. honokhukthai: 0x0E2E,
  28593. hookabovecomb: 0x0309,
  28594. hookcmb: 0x0309,
  28595. hookpalatalizedbelowcmb: 0x0321,
  28596. hookretroflexbelowcmb: 0x0322,
  28597. hoonsquare: 0x3342,
  28598. horicoptic: 0x03E9,
  28599. horizontalbar: 0x2015,
  28600. horncmb: 0x031B,
  28601. hotsprings: 0x2668,
  28602. house: 0x2302,
  28603. hparen: 0x24A3,
  28604. hsuperior: 0x02B0,
  28605. hturned: 0x0265,
  28606. huhiragana: 0x3075,
  28607. huiitosquare: 0x3333,
  28608. hukatakana: 0x30D5,
  28609. hukatakanahalfwidth: 0xFF8C,
  28610. hungarumlaut: 0x02DD,
  28611. hungarumlautcmb: 0x030B,
  28612. hv: 0x0195,
  28613. hyphen: 0x002D,
  28614. hypheninferior: 0xF6E5,
  28615. hyphenmonospace: 0xFF0D,
  28616. hyphensmall: 0xFE63,
  28617. hyphensuperior: 0xF6E6,
  28618. hyphentwo: 0x2010,
  28619. i: 0x0069,
  28620. iacute: 0x00ED,
  28621. iacyrillic: 0x044F,
  28622. ibengali: 0x0987,
  28623. ibopomofo: 0x3127,
  28624. ibreve: 0x012D,
  28625. icaron: 0x01D0,
  28626. icircle: 0x24D8,
  28627. icircumflex: 0x00EE,
  28628. icyrillic: 0x0456,
  28629. idblgrave: 0x0209,
  28630. ideographearthcircle: 0x328F,
  28631. ideographfirecircle: 0x328B,
  28632. ideographicallianceparen: 0x323F,
  28633. ideographiccallparen: 0x323A,
  28634. ideographiccentrecircle: 0x32A5,
  28635. ideographicclose: 0x3006,
  28636. ideographiccomma: 0x3001,
  28637. ideographiccommaleft: 0xFF64,
  28638. ideographiccongratulationparen: 0x3237,
  28639. ideographiccorrectcircle: 0x32A3,
  28640. ideographicearthparen: 0x322F,
  28641. ideographicenterpriseparen: 0x323D,
  28642. ideographicexcellentcircle: 0x329D,
  28643. ideographicfestivalparen: 0x3240,
  28644. ideographicfinancialcircle: 0x3296,
  28645. ideographicfinancialparen: 0x3236,
  28646. ideographicfireparen: 0x322B,
  28647. ideographichaveparen: 0x3232,
  28648. ideographichighcircle: 0x32A4,
  28649. ideographiciterationmark: 0x3005,
  28650. ideographiclaborcircle: 0x3298,
  28651. ideographiclaborparen: 0x3238,
  28652. ideographicleftcircle: 0x32A7,
  28653. ideographiclowcircle: 0x32A6,
  28654. ideographicmedicinecircle: 0x32A9,
  28655. ideographicmetalparen: 0x322E,
  28656. ideographicmoonparen: 0x322A,
  28657. ideographicnameparen: 0x3234,
  28658. ideographicperiod: 0x3002,
  28659. ideographicprintcircle: 0x329E,
  28660. ideographicreachparen: 0x3243,
  28661. ideographicrepresentparen: 0x3239,
  28662. ideographicresourceparen: 0x323E,
  28663. ideographicrightcircle: 0x32A8,
  28664. ideographicsecretcircle: 0x3299,
  28665. ideographicselfparen: 0x3242,
  28666. ideographicsocietyparen: 0x3233,
  28667. ideographicspace: 0x3000,
  28668. ideographicspecialparen: 0x3235,
  28669. ideographicstockparen: 0x3231,
  28670. ideographicstudyparen: 0x323B,
  28671. ideographicsunparen: 0x3230,
  28672. ideographicsuperviseparen: 0x323C,
  28673. ideographicwaterparen: 0x322C,
  28674. ideographicwoodparen: 0x322D,
  28675. ideographiczero: 0x3007,
  28676. ideographmetalcircle: 0x328E,
  28677. ideographmooncircle: 0x328A,
  28678. ideographnamecircle: 0x3294,
  28679. ideographsuncircle: 0x3290,
  28680. ideographwatercircle: 0x328C,
  28681. ideographwoodcircle: 0x328D,
  28682. ideva: 0x0907,
  28683. idieresis: 0x00EF,
  28684. idieresisacute: 0x1E2F,
  28685. idieresiscyrillic: 0x04E5,
  28686. idotbelow: 0x1ECB,
  28687. iebrevecyrillic: 0x04D7,
  28688. iecyrillic: 0x0435,
  28689. ieungacirclekorean: 0x3275,
  28690. ieungaparenkorean: 0x3215,
  28691. ieungcirclekorean: 0x3267,
  28692. ieungkorean: 0x3147,
  28693. ieungparenkorean: 0x3207,
  28694. igrave: 0x00EC,
  28695. igujarati: 0x0A87,
  28696. igurmukhi: 0x0A07,
  28697. ihiragana: 0x3044,
  28698. ihookabove: 0x1EC9,
  28699. iibengali: 0x0988,
  28700. iicyrillic: 0x0438,
  28701. iideva: 0x0908,
  28702. iigujarati: 0x0A88,
  28703. iigurmukhi: 0x0A08,
  28704. iimatragurmukhi: 0x0A40,
  28705. iinvertedbreve: 0x020B,
  28706. iishortcyrillic: 0x0439,
  28707. iivowelsignbengali: 0x09C0,
  28708. iivowelsigndeva: 0x0940,
  28709. iivowelsigngujarati: 0x0AC0,
  28710. ij: 0x0133,
  28711. ikatakana: 0x30A4,
  28712. ikatakanahalfwidth: 0xFF72,
  28713. ikorean: 0x3163,
  28714. ilde: 0x02DC,
  28715. iluyhebrew: 0x05AC,
  28716. imacron: 0x012B,
  28717. imacroncyrillic: 0x04E3,
  28718. imageorapproximatelyequal: 0x2253,
  28719. imatragurmukhi: 0x0A3F,
  28720. imonospace: 0xFF49,
  28721. increment: 0x2206,
  28722. infinity: 0x221E,
  28723. iniarmenian: 0x056B,
  28724. integral: 0x222B,
  28725. integralbottom: 0x2321,
  28726. integralbt: 0x2321,
  28727. integralex: 0xF8F5,
  28728. integraltop: 0x2320,
  28729. integraltp: 0x2320,
  28730. intersection: 0x2229,
  28731. intisquare: 0x3305,
  28732. invbullet: 0x25D8,
  28733. invcircle: 0x25D9,
  28734. invsmileface: 0x263B,
  28735. iocyrillic: 0x0451,
  28736. iogonek: 0x012F,
  28737. iota: 0x03B9,
  28738. iotadieresis: 0x03CA,
  28739. iotadieresistonos: 0x0390,
  28740. iotalatin: 0x0269,
  28741. iotatonos: 0x03AF,
  28742. iparen: 0x24A4,
  28743. irigurmukhi: 0x0A72,
  28744. ismallhiragana: 0x3043,
  28745. ismallkatakana: 0x30A3,
  28746. ismallkatakanahalfwidth: 0xFF68,
  28747. issharbengali: 0x09FA,
  28748. istroke: 0x0268,
  28749. isuperior: 0xF6ED,
  28750. iterationhiragana: 0x309D,
  28751. iterationkatakana: 0x30FD,
  28752. itilde: 0x0129,
  28753. itildebelow: 0x1E2D,
  28754. iubopomofo: 0x3129,
  28755. iucyrillic: 0x044E,
  28756. ivowelsignbengali: 0x09BF,
  28757. ivowelsigndeva: 0x093F,
  28758. ivowelsigngujarati: 0x0ABF,
  28759. izhitsacyrillic: 0x0475,
  28760. izhitsadblgravecyrillic: 0x0477,
  28761. j: 0x006A,
  28762. jaarmenian: 0x0571,
  28763. jabengali: 0x099C,
  28764. jadeva: 0x091C,
  28765. jagujarati: 0x0A9C,
  28766. jagurmukhi: 0x0A1C,
  28767. jbopomofo: 0x3110,
  28768. jcaron: 0x01F0,
  28769. jcircle: 0x24D9,
  28770. jcircumflex: 0x0135,
  28771. jcrossedtail: 0x029D,
  28772. jdotlessstroke: 0x025F,
  28773. jecyrillic: 0x0458,
  28774. jeemarabic: 0x062C,
  28775. jeemfinalarabic: 0xFE9E,
  28776. jeeminitialarabic: 0xFE9F,
  28777. jeemmedialarabic: 0xFEA0,
  28778. jeharabic: 0x0698,
  28779. jehfinalarabic: 0xFB8B,
  28780. jhabengali: 0x099D,
  28781. jhadeva: 0x091D,
  28782. jhagujarati: 0x0A9D,
  28783. jhagurmukhi: 0x0A1D,
  28784. jheharmenian: 0x057B,
  28785. jis: 0x3004,
  28786. jmonospace: 0xFF4A,
  28787. jparen: 0x24A5,
  28788. jsuperior: 0x02B2,
  28789. k: 0x006B,
  28790. kabashkircyrillic: 0x04A1,
  28791. kabengali: 0x0995,
  28792. kacute: 0x1E31,
  28793. kacyrillic: 0x043A,
  28794. kadescendercyrillic: 0x049B,
  28795. kadeva: 0x0915,
  28796. kaf: 0x05DB,
  28797. kafarabic: 0x0643,
  28798. kafdagesh: 0xFB3B,
  28799. kafdageshhebrew: 0xFB3B,
  28800. kaffinalarabic: 0xFEDA,
  28801. kafhebrew: 0x05DB,
  28802. kafinitialarabic: 0xFEDB,
  28803. kafmedialarabic: 0xFEDC,
  28804. kafrafehebrew: 0xFB4D,
  28805. kagujarati: 0x0A95,
  28806. kagurmukhi: 0x0A15,
  28807. kahiragana: 0x304B,
  28808. kahookcyrillic: 0x04C4,
  28809. kakatakana: 0x30AB,
  28810. kakatakanahalfwidth: 0xFF76,
  28811. kappa: 0x03BA,
  28812. kappasymbolgreek: 0x03F0,
  28813. kapyeounmieumkorean: 0x3171,
  28814. kapyeounphieuphkorean: 0x3184,
  28815. kapyeounpieupkorean: 0x3178,
  28816. kapyeounssangpieupkorean: 0x3179,
  28817. karoriisquare: 0x330D,
  28818. kashidaautoarabic: 0x0640,
  28819. kashidaautonosidebearingarabic: 0x0640,
  28820. kasmallkatakana: 0x30F5,
  28821. kasquare: 0x3384,
  28822. kasraarabic: 0x0650,
  28823. kasratanarabic: 0x064D,
  28824. kastrokecyrillic: 0x049F,
  28825. katahiraprolongmarkhalfwidth: 0xFF70,
  28826. kaverticalstrokecyrillic: 0x049D,
  28827. kbopomofo: 0x310E,
  28828. kcalsquare: 0x3389,
  28829. kcaron: 0x01E9,
  28830. kcedilla: 0x0137,
  28831. kcircle: 0x24DA,
  28832. kcommaaccent: 0x0137,
  28833. kdotbelow: 0x1E33,
  28834. keharmenian: 0x0584,
  28835. kehiragana: 0x3051,
  28836. kekatakana: 0x30B1,
  28837. kekatakanahalfwidth: 0xFF79,
  28838. kenarmenian: 0x056F,
  28839. kesmallkatakana: 0x30F6,
  28840. kgreenlandic: 0x0138,
  28841. khabengali: 0x0996,
  28842. khacyrillic: 0x0445,
  28843. khadeva: 0x0916,
  28844. khagujarati: 0x0A96,
  28845. khagurmukhi: 0x0A16,
  28846. khaharabic: 0x062E,
  28847. khahfinalarabic: 0xFEA6,
  28848. khahinitialarabic: 0xFEA7,
  28849. khahmedialarabic: 0xFEA8,
  28850. kheicoptic: 0x03E7,
  28851. khhadeva: 0x0959,
  28852. khhagurmukhi: 0x0A59,
  28853. khieukhacirclekorean: 0x3278,
  28854. khieukhaparenkorean: 0x3218,
  28855. khieukhcirclekorean: 0x326A,
  28856. khieukhkorean: 0x314B,
  28857. khieukhparenkorean: 0x320A,
  28858. khokhaithai: 0x0E02,
  28859. khokhonthai: 0x0E05,
  28860. khokhuatthai: 0x0E03,
  28861. khokhwaithai: 0x0E04,
  28862. khomutthai: 0x0E5B,
  28863. khook: 0x0199,
  28864. khorakhangthai: 0x0E06,
  28865. khzsquare: 0x3391,
  28866. kihiragana: 0x304D,
  28867. kikatakana: 0x30AD,
  28868. kikatakanahalfwidth: 0xFF77,
  28869. kiroguramusquare: 0x3315,
  28870. kiromeetorusquare: 0x3316,
  28871. kirosquare: 0x3314,
  28872. kiyeokacirclekorean: 0x326E,
  28873. kiyeokaparenkorean: 0x320E,
  28874. kiyeokcirclekorean: 0x3260,
  28875. kiyeokkorean: 0x3131,
  28876. kiyeokparenkorean: 0x3200,
  28877. kiyeoksioskorean: 0x3133,
  28878. kjecyrillic: 0x045C,
  28879. klinebelow: 0x1E35,
  28880. klsquare: 0x3398,
  28881. kmcubedsquare: 0x33A6,
  28882. kmonospace: 0xFF4B,
  28883. kmsquaredsquare: 0x33A2,
  28884. kohiragana: 0x3053,
  28885. kohmsquare: 0x33C0,
  28886. kokaithai: 0x0E01,
  28887. kokatakana: 0x30B3,
  28888. kokatakanahalfwidth: 0xFF7A,
  28889. kooposquare: 0x331E,
  28890. koppacyrillic: 0x0481,
  28891. koreanstandardsymbol: 0x327F,
  28892. koroniscmb: 0x0343,
  28893. kparen: 0x24A6,
  28894. kpasquare: 0x33AA,
  28895. ksicyrillic: 0x046F,
  28896. ktsquare: 0x33CF,
  28897. kturned: 0x029E,
  28898. kuhiragana: 0x304F,
  28899. kukatakana: 0x30AF,
  28900. kukatakanahalfwidth: 0xFF78,
  28901. kvsquare: 0x33B8,
  28902. kwsquare: 0x33BE,
  28903. l: 0x006C,
  28904. labengali: 0x09B2,
  28905. lacute: 0x013A,
  28906. ladeva: 0x0932,
  28907. lagujarati: 0x0AB2,
  28908. lagurmukhi: 0x0A32,
  28909. lakkhangyaothai: 0x0E45,
  28910. lamaleffinalarabic: 0xFEFC,
  28911. lamalefhamzaabovefinalarabic: 0xFEF8,
  28912. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28913. lamalefhamzabelowfinalarabic: 0xFEFA,
  28914. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28915. lamalefisolatedarabic: 0xFEFB,
  28916. lamalefmaddaabovefinalarabic: 0xFEF6,
  28917. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28918. lamarabic: 0x0644,
  28919. lambda: 0x03BB,
  28920. lambdastroke: 0x019B,
  28921. lamed: 0x05DC,
  28922. lameddagesh: 0xFB3C,
  28923. lameddageshhebrew: 0xFB3C,
  28924. lamedhebrew: 0x05DC,
  28925. lamfinalarabic: 0xFEDE,
  28926. lamhahinitialarabic: 0xFCCA,
  28927. laminitialarabic: 0xFEDF,
  28928. lamjeeminitialarabic: 0xFCC9,
  28929. lamkhahinitialarabic: 0xFCCB,
  28930. lamlamhehisolatedarabic: 0xFDF2,
  28931. lammedialarabic: 0xFEE0,
  28932. lammeemhahinitialarabic: 0xFD88,
  28933. lammeeminitialarabic: 0xFCCC,
  28934. largecircle: 0x25EF,
  28935. lbar: 0x019A,
  28936. lbelt: 0x026C,
  28937. lbopomofo: 0x310C,
  28938. lcaron: 0x013E,
  28939. lcedilla: 0x013C,
  28940. lcircle: 0x24DB,
  28941. lcircumflexbelow: 0x1E3D,
  28942. lcommaaccent: 0x013C,
  28943. ldot: 0x0140,
  28944. ldotaccent: 0x0140,
  28945. ldotbelow: 0x1E37,
  28946. ldotbelowmacron: 0x1E39,
  28947. leftangleabovecmb: 0x031A,
  28948. lefttackbelowcmb: 0x0318,
  28949. less: 0x003C,
  28950. lessequal: 0x2264,
  28951. lessequalorgreater: 0x22DA,
  28952. lessmonospace: 0xFF1C,
  28953. lessorequivalent: 0x2272,
  28954. lessorgreater: 0x2276,
  28955. lessoverequal: 0x2266,
  28956. lesssmall: 0xFE64,
  28957. lezh: 0x026E,
  28958. lfblock: 0x258C,
  28959. lhookretroflex: 0x026D,
  28960. lira: 0x20A4,
  28961. liwnarmenian: 0x056C,
  28962. lj: 0x01C9,
  28963. ljecyrillic: 0x0459,
  28964. ll: 0xF6C0,
  28965. lladeva: 0x0933,
  28966. llagujarati: 0x0AB3,
  28967. llinebelow: 0x1E3B,
  28968. llladeva: 0x0934,
  28969. llvocalicbengali: 0x09E1,
  28970. llvocalicdeva: 0x0961,
  28971. llvocalicvowelsignbengali: 0x09E3,
  28972. llvocalicvowelsigndeva: 0x0963,
  28973. lmiddletilde: 0x026B,
  28974. lmonospace: 0xFF4C,
  28975. lmsquare: 0x33D0,
  28976. lochulathai: 0x0E2C,
  28977. logicaland: 0x2227,
  28978. logicalnot: 0x00AC,
  28979. logicalnotreversed: 0x2310,
  28980. logicalor: 0x2228,
  28981. lolingthai: 0x0E25,
  28982. longs: 0x017F,
  28983. lowlinecenterline: 0xFE4E,
  28984. lowlinecmb: 0x0332,
  28985. lowlinedashed: 0xFE4D,
  28986. lozenge: 0x25CA,
  28987. lparen: 0x24A7,
  28988. lslash: 0x0142,
  28989. lsquare: 0x2113,
  28990. lsuperior: 0xF6EE,
  28991. ltshade: 0x2591,
  28992. luthai: 0x0E26,
  28993. lvocalicbengali: 0x098C,
  28994. lvocalicdeva: 0x090C,
  28995. lvocalicvowelsignbengali: 0x09E2,
  28996. lvocalicvowelsigndeva: 0x0962,
  28997. lxsquare: 0x33D3,
  28998. m: 0x006D,
  28999. mabengali: 0x09AE,
  29000. macron: 0x00AF,
  29001. macronbelowcmb: 0x0331,
  29002. macroncmb: 0x0304,
  29003. macronlowmod: 0x02CD,
  29004. macronmonospace: 0xFFE3,
  29005. macute: 0x1E3F,
  29006. madeva: 0x092E,
  29007. magujarati: 0x0AAE,
  29008. magurmukhi: 0x0A2E,
  29009. mahapakhhebrew: 0x05A4,
  29010. mahapakhlefthebrew: 0x05A4,
  29011. mahiragana: 0x307E,
  29012. maichattawalowleftthai: 0xF895,
  29013. maichattawalowrightthai: 0xF894,
  29014. maichattawathai: 0x0E4B,
  29015. maichattawaupperleftthai: 0xF893,
  29016. maieklowleftthai: 0xF88C,
  29017. maieklowrightthai: 0xF88B,
  29018. maiekthai: 0x0E48,
  29019. maiekupperleftthai: 0xF88A,
  29020. maihanakatleftthai: 0xF884,
  29021. maihanakatthai: 0x0E31,
  29022. maitaikhuleftthai: 0xF889,
  29023. maitaikhuthai: 0x0E47,
  29024. maitholowleftthai: 0xF88F,
  29025. maitholowrightthai: 0xF88E,
  29026. maithothai: 0x0E49,
  29027. maithoupperleftthai: 0xF88D,
  29028. maitrilowleftthai: 0xF892,
  29029. maitrilowrightthai: 0xF891,
  29030. maitrithai: 0x0E4A,
  29031. maitriupperleftthai: 0xF890,
  29032. maiyamokthai: 0x0E46,
  29033. makatakana: 0x30DE,
  29034. makatakanahalfwidth: 0xFF8F,
  29035. male: 0x2642,
  29036. mansyonsquare: 0x3347,
  29037. maqafhebrew: 0x05BE,
  29038. mars: 0x2642,
  29039. masoracirclehebrew: 0x05AF,
  29040. masquare: 0x3383,
  29041. mbopomofo: 0x3107,
  29042. mbsquare: 0x33D4,
  29043. mcircle: 0x24DC,
  29044. mcubedsquare: 0x33A5,
  29045. mdotaccent: 0x1E41,
  29046. mdotbelow: 0x1E43,
  29047. meemarabic: 0x0645,
  29048. meemfinalarabic: 0xFEE2,
  29049. meeminitialarabic: 0xFEE3,
  29050. meemmedialarabic: 0xFEE4,
  29051. meemmeeminitialarabic: 0xFCD1,
  29052. meemmeemisolatedarabic: 0xFC48,
  29053. meetorusquare: 0x334D,
  29054. mehiragana: 0x3081,
  29055. meizierasquare: 0x337E,
  29056. mekatakana: 0x30E1,
  29057. mekatakanahalfwidth: 0xFF92,
  29058. mem: 0x05DE,
  29059. memdagesh: 0xFB3E,
  29060. memdageshhebrew: 0xFB3E,
  29061. memhebrew: 0x05DE,
  29062. menarmenian: 0x0574,
  29063. merkhahebrew: 0x05A5,
  29064. merkhakefulahebrew: 0x05A6,
  29065. merkhakefulalefthebrew: 0x05A6,
  29066. merkhalefthebrew: 0x05A5,
  29067. mhook: 0x0271,
  29068. mhzsquare: 0x3392,
  29069. middledotkatakanahalfwidth: 0xFF65,
  29070. middot: 0x00B7,
  29071. mieumacirclekorean: 0x3272,
  29072. mieumaparenkorean: 0x3212,
  29073. mieumcirclekorean: 0x3264,
  29074. mieumkorean: 0x3141,
  29075. mieumpansioskorean: 0x3170,
  29076. mieumparenkorean: 0x3204,
  29077. mieumpieupkorean: 0x316E,
  29078. mieumsioskorean: 0x316F,
  29079. mihiragana: 0x307F,
  29080. mikatakana: 0x30DF,
  29081. mikatakanahalfwidth: 0xFF90,
  29082. minus: 0x2212,
  29083. minusbelowcmb: 0x0320,
  29084. minuscircle: 0x2296,
  29085. minusmod: 0x02D7,
  29086. minusplus: 0x2213,
  29087. minute: 0x2032,
  29088. miribaarusquare: 0x334A,
  29089. mirisquare: 0x3349,
  29090. mlonglegturned: 0x0270,
  29091. mlsquare: 0x3396,
  29092. mmcubedsquare: 0x33A3,
  29093. mmonospace: 0xFF4D,
  29094. mmsquaredsquare: 0x339F,
  29095. mohiragana: 0x3082,
  29096. mohmsquare: 0x33C1,
  29097. mokatakana: 0x30E2,
  29098. mokatakanahalfwidth: 0xFF93,
  29099. molsquare: 0x33D6,
  29100. momathai: 0x0E21,
  29101. moverssquare: 0x33A7,
  29102. moverssquaredsquare: 0x33A8,
  29103. mparen: 0x24A8,
  29104. mpasquare: 0x33AB,
  29105. mssquare: 0x33B3,
  29106. msuperior: 0xF6EF,
  29107. mturned: 0x026F,
  29108. mu: 0x00B5,
  29109. mu1: 0x00B5,
  29110. muasquare: 0x3382,
  29111. muchgreater: 0x226B,
  29112. muchless: 0x226A,
  29113. mufsquare: 0x338C,
  29114. mugreek: 0x03BC,
  29115. mugsquare: 0x338D,
  29116. muhiragana: 0x3080,
  29117. mukatakana: 0x30E0,
  29118. mukatakanahalfwidth: 0xFF91,
  29119. mulsquare: 0x3395,
  29120. multiply: 0x00D7,
  29121. mumsquare: 0x339B,
  29122. munahhebrew: 0x05A3,
  29123. munahlefthebrew: 0x05A3,
  29124. musicalnote: 0x266A,
  29125. musicalnotedbl: 0x266B,
  29126. musicflatsign: 0x266D,
  29127. musicsharpsign: 0x266F,
  29128. mussquare: 0x33B2,
  29129. muvsquare: 0x33B6,
  29130. muwsquare: 0x33BC,
  29131. mvmegasquare: 0x33B9,
  29132. mvsquare: 0x33B7,
  29133. mwmegasquare: 0x33BF,
  29134. mwsquare: 0x33BD,
  29135. n: 0x006E,
  29136. nabengali: 0x09A8,
  29137. nabla: 0x2207,
  29138. nacute: 0x0144,
  29139. nadeva: 0x0928,
  29140. nagujarati: 0x0AA8,
  29141. nagurmukhi: 0x0A28,
  29142. nahiragana: 0x306A,
  29143. nakatakana: 0x30CA,
  29144. nakatakanahalfwidth: 0xFF85,
  29145. napostrophe: 0x0149,
  29146. nasquare: 0x3381,
  29147. nbopomofo: 0x310B,
  29148. nbspace: 0x00A0,
  29149. ncaron: 0x0148,
  29150. ncedilla: 0x0146,
  29151. ncircle: 0x24DD,
  29152. ncircumflexbelow: 0x1E4B,
  29153. ncommaaccent: 0x0146,
  29154. ndotaccent: 0x1E45,
  29155. ndotbelow: 0x1E47,
  29156. nehiragana: 0x306D,
  29157. nekatakana: 0x30CD,
  29158. nekatakanahalfwidth: 0xFF88,
  29159. newsheqelsign: 0x20AA,
  29160. nfsquare: 0x338B,
  29161. ngabengali: 0x0999,
  29162. ngadeva: 0x0919,
  29163. ngagujarati: 0x0A99,
  29164. ngagurmukhi: 0x0A19,
  29165. ngonguthai: 0x0E07,
  29166. nhiragana: 0x3093,
  29167. nhookleft: 0x0272,
  29168. nhookretroflex: 0x0273,
  29169. nieunacirclekorean: 0x326F,
  29170. nieunaparenkorean: 0x320F,
  29171. nieuncieuckorean: 0x3135,
  29172. nieuncirclekorean: 0x3261,
  29173. nieunhieuhkorean: 0x3136,
  29174. nieunkorean: 0x3134,
  29175. nieunpansioskorean: 0x3168,
  29176. nieunparenkorean: 0x3201,
  29177. nieunsioskorean: 0x3167,
  29178. nieuntikeutkorean: 0x3166,
  29179. nihiragana: 0x306B,
  29180. nikatakana: 0x30CB,
  29181. nikatakanahalfwidth: 0xFF86,
  29182. nikhahitleftthai: 0xF899,
  29183. nikhahitthai: 0x0E4D,
  29184. nine: 0x0039,
  29185. ninearabic: 0x0669,
  29186. ninebengali: 0x09EF,
  29187. ninecircle: 0x2468,
  29188. ninecircleinversesansserif: 0x2792,
  29189. ninedeva: 0x096F,
  29190. ninegujarati: 0x0AEF,
  29191. ninegurmukhi: 0x0A6F,
  29192. ninehackarabic: 0x0669,
  29193. ninehangzhou: 0x3029,
  29194. nineideographicparen: 0x3228,
  29195. nineinferior: 0x2089,
  29196. ninemonospace: 0xFF19,
  29197. nineoldstyle: 0xF739,
  29198. nineparen: 0x247C,
  29199. nineperiod: 0x2490,
  29200. ninepersian: 0x06F9,
  29201. nineroman: 0x2178,
  29202. ninesuperior: 0x2079,
  29203. nineteencircle: 0x2472,
  29204. nineteenparen: 0x2486,
  29205. nineteenperiod: 0x249A,
  29206. ninethai: 0x0E59,
  29207. nj: 0x01CC,
  29208. njecyrillic: 0x045A,
  29209. nkatakana: 0x30F3,
  29210. nkatakanahalfwidth: 0xFF9D,
  29211. nlegrightlong: 0x019E,
  29212. nlinebelow: 0x1E49,
  29213. nmonospace: 0xFF4E,
  29214. nmsquare: 0x339A,
  29215. nnabengali: 0x09A3,
  29216. nnadeva: 0x0923,
  29217. nnagujarati: 0x0AA3,
  29218. nnagurmukhi: 0x0A23,
  29219. nnnadeva: 0x0929,
  29220. nohiragana: 0x306E,
  29221. nokatakana: 0x30CE,
  29222. nokatakanahalfwidth: 0xFF89,
  29223. nonbreakingspace: 0x00A0,
  29224. nonenthai: 0x0E13,
  29225. nonuthai: 0x0E19,
  29226. noonarabic: 0x0646,
  29227. noonfinalarabic: 0xFEE6,
  29228. noonghunnaarabic: 0x06BA,
  29229. noonghunnafinalarabic: 0xFB9F,
  29230. nooninitialarabic: 0xFEE7,
  29231. noonjeeminitialarabic: 0xFCD2,
  29232. noonjeemisolatedarabic: 0xFC4B,
  29233. noonmedialarabic: 0xFEE8,
  29234. noonmeeminitialarabic: 0xFCD5,
  29235. noonmeemisolatedarabic: 0xFC4E,
  29236. noonnoonfinalarabic: 0xFC8D,
  29237. notcontains: 0x220C,
  29238. notelement: 0x2209,
  29239. notelementof: 0x2209,
  29240. notequal: 0x2260,
  29241. notgreater: 0x226F,
  29242. notgreaternorequal: 0x2271,
  29243. notgreaternorless: 0x2279,
  29244. notidentical: 0x2262,
  29245. notless: 0x226E,
  29246. notlessnorequal: 0x2270,
  29247. notparallel: 0x2226,
  29248. notprecedes: 0x2280,
  29249. notsubset: 0x2284,
  29250. notsucceeds: 0x2281,
  29251. notsuperset: 0x2285,
  29252. nowarmenian: 0x0576,
  29253. nparen: 0x24A9,
  29254. nssquare: 0x33B1,
  29255. nsuperior: 0x207F,
  29256. ntilde: 0x00F1,
  29257. nu: 0x03BD,
  29258. nuhiragana: 0x306C,
  29259. nukatakana: 0x30CC,
  29260. nukatakanahalfwidth: 0xFF87,
  29261. nuktabengali: 0x09BC,
  29262. nuktadeva: 0x093C,
  29263. nuktagujarati: 0x0ABC,
  29264. nuktagurmukhi: 0x0A3C,
  29265. numbersign: 0x0023,
  29266. numbersignmonospace: 0xFF03,
  29267. numbersignsmall: 0xFE5F,
  29268. numeralsigngreek: 0x0374,
  29269. numeralsignlowergreek: 0x0375,
  29270. numero: 0x2116,
  29271. nun: 0x05E0,
  29272. nundagesh: 0xFB40,
  29273. nundageshhebrew: 0xFB40,
  29274. nunhebrew: 0x05E0,
  29275. nvsquare: 0x33B5,
  29276. nwsquare: 0x33BB,
  29277. nyabengali: 0x099E,
  29278. nyadeva: 0x091E,
  29279. nyagujarati: 0x0A9E,
  29280. nyagurmukhi: 0x0A1E,
  29281. o: 0x006F,
  29282. oacute: 0x00F3,
  29283. oangthai: 0x0E2D,
  29284. obarred: 0x0275,
  29285. obarredcyrillic: 0x04E9,
  29286. obarreddieresiscyrillic: 0x04EB,
  29287. obengali: 0x0993,
  29288. obopomofo: 0x311B,
  29289. obreve: 0x014F,
  29290. ocandradeva: 0x0911,
  29291. ocandragujarati: 0x0A91,
  29292. ocandravowelsigndeva: 0x0949,
  29293. ocandravowelsigngujarati: 0x0AC9,
  29294. ocaron: 0x01D2,
  29295. ocircle: 0x24DE,
  29296. ocircumflex: 0x00F4,
  29297. ocircumflexacute: 0x1ED1,
  29298. ocircumflexdotbelow: 0x1ED9,
  29299. ocircumflexgrave: 0x1ED3,
  29300. ocircumflexhookabove: 0x1ED5,
  29301. ocircumflextilde: 0x1ED7,
  29302. ocyrillic: 0x043E,
  29303. odblacute: 0x0151,
  29304. odblgrave: 0x020D,
  29305. odeva: 0x0913,
  29306. odieresis: 0x00F6,
  29307. odieresiscyrillic: 0x04E7,
  29308. odotbelow: 0x1ECD,
  29309. oe: 0x0153,
  29310. oekorean: 0x315A,
  29311. ogonek: 0x02DB,
  29312. ogonekcmb: 0x0328,
  29313. ograve: 0x00F2,
  29314. ogujarati: 0x0A93,
  29315. oharmenian: 0x0585,
  29316. ohiragana: 0x304A,
  29317. ohookabove: 0x1ECF,
  29318. ohorn: 0x01A1,
  29319. ohornacute: 0x1EDB,
  29320. ohorndotbelow: 0x1EE3,
  29321. ohorngrave: 0x1EDD,
  29322. ohornhookabove: 0x1EDF,
  29323. ohorntilde: 0x1EE1,
  29324. ohungarumlaut: 0x0151,
  29325. oi: 0x01A3,
  29326. oinvertedbreve: 0x020F,
  29327. okatakana: 0x30AA,
  29328. okatakanahalfwidth: 0xFF75,
  29329. okorean: 0x3157,
  29330. olehebrew: 0x05AB,
  29331. omacron: 0x014D,
  29332. omacronacute: 0x1E53,
  29333. omacrongrave: 0x1E51,
  29334. omdeva: 0x0950,
  29335. omega: 0x03C9,
  29336. omega1: 0x03D6,
  29337. omegacyrillic: 0x0461,
  29338. omegalatinclosed: 0x0277,
  29339. omegaroundcyrillic: 0x047B,
  29340. omegatitlocyrillic: 0x047D,
  29341. omegatonos: 0x03CE,
  29342. omgujarati: 0x0AD0,
  29343. omicron: 0x03BF,
  29344. omicrontonos: 0x03CC,
  29345. omonospace: 0xFF4F,
  29346. one: 0x0031,
  29347. onearabic: 0x0661,
  29348. onebengali: 0x09E7,
  29349. onecircle: 0x2460,
  29350. onecircleinversesansserif: 0x278A,
  29351. onedeva: 0x0967,
  29352. onedotenleader: 0x2024,
  29353. oneeighth: 0x215B,
  29354. onefitted: 0xF6DC,
  29355. onegujarati: 0x0AE7,
  29356. onegurmukhi: 0x0A67,
  29357. onehackarabic: 0x0661,
  29358. onehalf: 0x00BD,
  29359. onehangzhou: 0x3021,
  29360. oneideographicparen: 0x3220,
  29361. oneinferior: 0x2081,
  29362. onemonospace: 0xFF11,
  29363. onenumeratorbengali: 0x09F4,
  29364. oneoldstyle: 0xF731,
  29365. oneparen: 0x2474,
  29366. oneperiod: 0x2488,
  29367. onepersian: 0x06F1,
  29368. onequarter: 0x00BC,
  29369. oneroman: 0x2170,
  29370. onesuperior: 0x00B9,
  29371. onethai: 0x0E51,
  29372. onethird: 0x2153,
  29373. oogonek: 0x01EB,
  29374. oogonekmacron: 0x01ED,
  29375. oogurmukhi: 0x0A13,
  29376. oomatragurmukhi: 0x0A4B,
  29377. oopen: 0x0254,
  29378. oparen: 0x24AA,
  29379. openbullet: 0x25E6,
  29380. option: 0x2325,
  29381. ordfeminine: 0x00AA,
  29382. ordmasculine: 0x00BA,
  29383. orthogonal: 0x221F,
  29384. oshortdeva: 0x0912,
  29385. oshortvowelsigndeva: 0x094A,
  29386. oslash: 0x00F8,
  29387. oslashacute: 0x01FF,
  29388. osmallhiragana: 0x3049,
  29389. osmallkatakana: 0x30A9,
  29390. osmallkatakanahalfwidth: 0xFF6B,
  29391. ostrokeacute: 0x01FF,
  29392. osuperior: 0xF6F0,
  29393. otcyrillic: 0x047F,
  29394. otilde: 0x00F5,
  29395. otildeacute: 0x1E4D,
  29396. otildedieresis: 0x1E4F,
  29397. oubopomofo: 0x3121,
  29398. overline: 0x203E,
  29399. overlinecenterline: 0xFE4A,
  29400. overlinecmb: 0x0305,
  29401. overlinedashed: 0xFE49,
  29402. overlinedblwavy: 0xFE4C,
  29403. overlinewavy: 0xFE4B,
  29404. overscore: 0x00AF,
  29405. ovowelsignbengali: 0x09CB,
  29406. ovowelsigndeva: 0x094B,
  29407. ovowelsigngujarati: 0x0ACB,
  29408. p: 0x0070,
  29409. paampssquare: 0x3380,
  29410. paasentosquare: 0x332B,
  29411. pabengali: 0x09AA,
  29412. pacute: 0x1E55,
  29413. padeva: 0x092A,
  29414. pagedown: 0x21DF,
  29415. pageup: 0x21DE,
  29416. pagujarati: 0x0AAA,
  29417. pagurmukhi: 0x0A2A,
  29418. pahiragana: 0x3071,
  29419. paiyannoithai: 0x0E2F,
  29420. pakatakana: 0x30D1,
  29421. palatalizationcyrilliccmb: 0x0484,
  29422. palochkacyrillic: 0x04C0,
  29423. pansioskorean: 0x317F,
  29424. paragraph: 0x00B6,
  29425. parallel: 0x2225,
  29426. parenleft: 0x0028,
  29427. parenleftaltonearabic: 0xFD3E,
  29428. parenleftbt: 0xF8ED,
  29429. parenleftex: 0xF8EC,
  29430. parenleftinferior: 0x208D,
  29431. parenleftmonospace: 0xFF08,
  29432. parenleftsmall: 0xFE59,
  29433. parenleftsuperior: 0x207D,
  29434. parenlefttp: 0xF8EB,
  29435. parenleftvertical: 0xFE35,
  29436. parenright: 0x0029,
  29437. parenrightaltonearabic: 0xFD3F,
  29438. parenrightbt: 0xF8F8,
  29439. parenrightex: 0xF8F7,
  29440. parenrightinferior: 0x208E,
  29441. parenrightmonospace: 0xFF09,
  29442. parenrightsmall: 0xFE5A,
  29443. parenrightsuperior: 0x207E,
  29444. parenrighttp: 0xF8F6,
  29445. parenrightvertical: 0xFE36,
  29446. partialdiff: 0x2202,
  29447. paseqhebrew: 0x05C0,
  29448. pashtahebrew: 0x0599,
  29449. pasquare: 0x33A9,
  29450. patah: 0x05B7,
  29451. patah11: 0x05B7,
  29452. patah1d: 0x05B7,
  29453. patah2a: 0x05B7,
  29454. patahhebrew: 0x05B7,
  29455. patahnarrowhebrew: 0x05B7,
  29456. patahquarterhebrew: 0x05B7,
  29457. patahwidehebrew: 0x05B7,
  29458. pazerhebrew: 0x05A1,
  29459. pbopomofo: 0x3106,
  29460. pcircle: 0x24DF,
  29461. pdotaccent: 0x1E57,
  29462. pe: 0x05E4,
  29463. pecyrillic: 0x043F,
  29464. pedagesh: 0xFB44,
  29465. pedageshhebrew: 0xFB44,
  29466. peezisquare: 0x333B,
  29467. pefinaldageshhebrew: 0xFB43,
  29468. peharabic: 0x067E,
  29469. peharmenian: 0x057A,
  29470. pehebrew: 0x05E4,
  29471. pehfinalarabic: 0xFB57,
  29472. pehinitialarabic: 0xFB58,
  29473. pehiragana: 0x307A,
  29474. pehmedialarabic: 0xFB59,
  29475. pekatakana: 0x30DA,
  29476. pemiddlehookcyrillic: 0x04A7,
  29477. perafehebrew: 0xFB4E,
  29478. percent: 0x0025,
  29479. percentarabic: 0x066A,
  29480. percentmonospace: 0xFF05,
  29481. percentsmall: 0xFE6A,
  29482. period: 0x002E,
  29483. periodarmenian: 0x0589,
  29484. periodcentered: 0x00B7,
  29485. periodhalfwidth: 0xFF61,
  29486. periodinferior: 0xF6E7,
  29487. periodmonospace: 0xFF0E,
  29488. periodsmall: 0xFE52,
  29489. periodsuperior: 0xF6E8,
  29490. perispomenigreekcmb: 0x0342,
  29491. perpendicular: 0x22A5,
  29492. perthousand: 0x2030,
  29493. peseta: 0x20A7,
  29494. pfsquare: 0x338A,
  29495. phabengali: 0x09AB,
  29496. phadeva: 0x092B,
  29497. phagujarati: 0x0AAB,
  29498. phagurmukhi: 0x0A2B,
  29499. phi: 0x03C6,
  29500. phi1: 0x03D5,
  29501. phieuphacirclekorean: 0x327A,
  29502. phieuphaparenkorean: 0x321A,
  29503. phieuphcirclekorean: 0x326C,
  29504. phieuphkorean: 0x314D,
  29505. phieuphparenkorean: 0x320C,
  29506. philatin: 0x0278,
  29507. phinthuthai: 0x0E3A,
  29508. phisymbolgreek: 0x03D5,
  29509. phook: 0x01A5,
  29510. phophanthai: 0x0E1E,
  29511. phophungthai: 0x0E1C,
  29512. phosamphaothai: 0x0E20,
  29513. pi: 0x03C0,
  29514. pieupacirclekorean: 0x3273,
  29515. pieupaparenkorean: 0x3213,
  29516. pieupcieuckorean: 0x3176,
  29517. pieupcirclekorean: 0x3265,
  29518. pieupkiyeokkorean: 0x3172,
  29519. pieupkorean: 0x3142,
  29520. pieupparenkorean: 0x3205,
  29521. pieupsioskiyeokkorean: 0x3174,
  29522. pieupsioskorean: 0x3144,
  29523. pieupsiostikeutkorean: 0x3175,
  29524. pieupthieuthkorean: 0x3177,
  29525. pieuptikeutkorean: 0x3173,
  29526. pihiragana: 0x3074,
  29527. pikatakana: 0x30D4,
  29528. pisymbolgreek: 0x03D6,
  29529. piwrarmenian: 0x0583,
  29530. plus: 0x002B,
  29531. plusbelowcmb: 0x031F,
  29532. pluscircle: 0x2295,
  29533. plusminus: 0x00B1,
  29534. plusmod: 0x02D6,
  29535. plusmonospace: 0xFF0B,
  29536. plussmall: 0xFE62,
  29537. plussuperior: 0x207A,
  29538. pmonospace: 0xFF50,
  29539. pmsquare: 0x33D8,
  29540. pohiragana: 0x307D,
  29541. pointingindexdownwhite: 0x261F,
  29542. pointingindexleftwhite: 0x261C,
  29543. pointingindexrightwhite: 0x261E,
  29544. pointingindexupwhite: 0x261D,
  29545. pokatakana: 0x30DD,
  29546. poplathai: 0x0E1B,
  29547. postalmark: 0x3012,
  29548. postalmarkface: 0x3020,
  29549. pparen: 0x24AB,
  29550. precedes: 0x227A,
  29551. prescription: 0x211E,
  29552. primemod: 0x02B9,
  29553. primereversed: 0x2035,
  29554. product: 0x220F,
  29555. projective: 0x2305,
  29556. prolongedkana: 0x30FC,
  29557. propellor: 0x2318,
  29558. propersubset: 0x2282,
  29559. propersuperset: 0x2283,
  29560. proportion: 0x2237,
  29561. proportional: 0x221D,
  29562. psi: 0x03C8,
  29563. psicyrillic: 0x0471,
  29564. psilipneumatacyrilliccmb: 0x0486,
  29565. pssquare: 0x33B0,
  29566. puhiragana: 0x3077,
  29567. pukatakana: 0x30D7,
  29568. pvsquare: 0x33B4,
  29569. pwsquare: 0x33BA,
  29570. q: 0x0071,
  29571. qadeva: 0x0958,
  29572. qadmahebrew: 0x05A8,
  29573. qafarabic: 0x0642,
  29574. qaffinalarabic: 0xFED6,
  29575. qafinitialarabic: 0xFED7,
  29576. qafmedialarabic: 0xFED8,
  29577. qamats: 0x05B8,
  29578. qamats10: 0x05B8,
  29579. qamats1a: 0x05B8,
  29580. qamats1c: 0x05B8,
  29581. qamats27: 0x05B8,
  29582. qamats29: 0x05B8,
  29583. qamats33: 0x05B8,
  29584. qamatsde: 0x05B8,
  29585. qamatshebrew: 0x05B8,
  29586. qamatsnarrowhebrew: 0x05B8,
  29587. qamatsqatanhebrew: 0x05B8,
  29588. qamatsqatannarrowhebrew: 0x05B8,
  29589. qamatsqatanquarterhebrew: 0x05B8,
  29590. qamatsqatanwidehebrew: 0x05B8,
  29591. qamatsquarterhebrew: 0x05B8,
  29592. qamatswidehebrew: 0x05B8,
  29593. qarneyparahebrew: 0x059F,
  29594. qbopomofo: 0x3111,
  29595. qcircle: 0x24E0,
  29596. qhook: 0x02A0,
  29597. qmonospace: 0xFF51,
  29598. qof: 0x05E7,
  29599. qofdagesh: 0xFB47,
  29600. qofdageshhebrew: 0xFB47,
  29601. qofhebrew: 0x05E7,
  29602. qparen: 0x24AC,
  29603. quarternote: 0x2669,
  29604. qubuts: 0x05BB,
  29605. qubuts18: 0x05BB,
  29606. qubuts25: 0x05BB,
  29607. qubuts31: 0x05BB,
  29608. qubutshebrew: 0x05BB,
  29609. qubutsnarrowhebrew: 0x05BB,
  29610. qubutsquarterhebrew: 0x05BB,
  29611. qubutswidehebrew: 0x05BB,
  29612. question: 0x003F,
  29613. questionarabic: 0x061F,
  29614. questionarmenian: 0x055E,
  29615. questiondown: 0x00BF,
  29616. questiondownsmall: 0xF7BF,
  29617. questiongreek: 0x037E,
  29618. questionmonospace: 0xFF1F,
  29619. questionsmall: 0xF73F,
  29620. quotedbl: 0x0022,
  29621. quotedblbase: 0x201E,
  29622. quotedblleft: 0x201C,
  29623. quotedblmonospace: 0xFF02,
  29624. quotedblprime: 0x301E,
  29625. quotedblprimereversed: 0x301D,
  29626. quotedblright: 0x201D,
  29627. quoteleft: 0x2018,
  29628. quoteleftreversed: 0x201B,
  29629. quotereversed: 0x201B,
  29630. quoteright: 0x2019,
  29631. quoterightn: 0x0149,
  29632. quotesinglbase: 0x201A,
  29633. quotesingle: 0x0027,
  29634. quotesinglemonospace: 0xFF07,
  29635. r: 0x0072,
  29636. raarmenian: 0x057C,
  29637. rabengali: 0x09B0,
  29638. racute: 0x0155,
  29639. radeva: 0x0930,
  29640. radical: 0x221A,
  29641. radicalex: 0xF8E5,
  29642. radoverssquare: 0x33AE,
  29643. radoverssquaredsquare: 0x33AF,
  29644. radsquare: 0x33AD,
  29645. rafe: 0x05BF,
  29646. rafehebrew: 0x05BF,
  29647. ragujarati: 0x0AB0,
  29648. ragurmukhi: 0x0A30,
  29649. rahiragana: 0x3089,
  29650. rakatakana: 0x30E9,
  29651. rakatakanahalfwidth: 0xFF97,
  29652. ralowerdiagonalbengali: 0x09F1,
  29653. ramiddlediagonalbengali: 0x09F0,
  29654. ramshorn: 0x0264,
  29655. ratio: 0x2236,
  29656. rbopomofo: 0x3116,
  29657. rcaron: 0x0159,
  29658. rcedilla: 0x0157,
  29659. rcircle: 0x24E1,
  29660. rcommaaccent: 0x0157,
  29661. rdblgrave: 0x0211,
  29662. rdotaccent: 0x1E59,
  29663. rdotbelow: 0x1E5B,
  29664. rdotbelowmacron: 0x1E5D,
  29665. referencemark: 0x203B,
  29666. reflexsubset: 0x2286,
  29667. reflexsuperset: 0x2287,
  29668. registered: 0x00AE,
  29669. registersans: 0xF8E8,
  29670. registerserif: 0xF6DA,
  29671. reharabic: 0x0631,
  29672. reharmenian: 0x0580,
  29673. rehfinalarabic: 0xFEAE,
  29674. rehiragana: 0x308C,
  29675. rekatakana: 0x30EC,
  29676. rekatakanahalfwidth: 0xFF9A,
  29677. resh: 0x05E8,
  29678. reshdageshhebrew: 0xFB48,
  29679. reshhebrew: 0x05E8,
  29680. reversedtilde: 0x223D,
  29681. reviahebrew: 0x0597,
  29682. reviamugrashhebrew: 0x0597,
  29683. revlogicalnot: 0x2310,
  29684. rfishhook: 0x027E,
  29685. rfishhookreversed: 0x027F,
  29686. rhabengali: 0x09DD,
  29687. rhadeva: 0x095D,
  29688. rho: 0x03C1,
  29689. rhook: 0x027D,
  29690. rhookturned: 0x027B,
  29691. rhookturnedsuperior: 0x02B5,
  29692. rhosymbolgreek: 0x03F1,
  29693. rhotichookmod: 0x02DE,
  29694. rieulacirclekorean: 0x3271,
  29695. rieulaparenkorean: 0x3211,
  29696. rieulcirclekorean: 0x3263,
  29697. rieulhieuhkorean: 0x3140,
  29698. rieulkiyeokkorean: 0x313A,
  29699. rieulkiyeoksioskorean: 0x3169,
  29700. rieulkorean: 0x3139,
  29701. rieulmieumkorean: 0x313B,
  29702. rieulpansioskorean: 0x316C,
  29703. rieulparenkorean: 0x3203,
  29704. rieulphieuphkorean: 0x313F,
  29705. rieulpieupkorean: 0x313C,
  29706. rieulpieupsioskorean: 0x316B,
  29707. rieulsioskorean: 0x313D,
  29708. rieulthieuthkorean: 0x313E,
  29709. rieultikeutkorean: 0x316A,
  29710. rieulyeorinhieuhkorean: 0x316D,
  29711. rightangle: 0x221F,
  29712. righttackbelowcmb: 0x0319,
  29713. righttriangle: 0x22BF,
  29714. rihiragana: 0x308A,
  29715. rikatakana: 0x30EA,
  29716. rikatakanahalfwidth: 0xFF98,
  29717. ring: 0x02DA,
  29718. ringbelowcmb: 0x0325,
  29719. ringcmb: 0x030A,
  29720. ringhalfleft: 0x02BF,
  29721. ringhalfleftarmenian: 0x0559,
  29722. ringhalfleftbelowcmb: 0x031C,
  29723. ringhalfleftcentered: 0x02D3,
  29724. ringhalfright: 0x02BE,
  29725. ringhalfrightbelowcmb: 0x0339,
  29726. ringhalfrightcentered: 0x02D2,
  29727. rinvertedbreve: 0x0213,
  29728. rittorusquare: 0x3351,
  29729. rlinebelow: 0x1E5F,
  29730. rlongleg: 0x027C,
  29731. rlonglegturned: 0x027A,
  29732. rmonospace: 0xFF52,
  29733. rohiragana: 0x308D,
  29734. rokatakana: 0x30ED,
  29735. rokatakanahalfwidth: 0xFF9B,
  29736. roruathai: 0x0E23,
  29737. rparen: 0x24AD,
  29738. rrabengali: 0x09DC,
  29739. rradeva: 0x0931,
  29740. rragurmukhi: 0x0A5C,
  29741. rreharabic: 0x0691,
  29742. rrehfinalarabic: 0xFB8D,
  29743. rrvocalicbengali: 0x09E0,
  29744. rrvocalicdeva: 0x0960,
  29745. rrvocalicgujarati: 0x0AE0,
  29746. rrvocalicvowelsignbengali: 0x09C4,
  29747. rrvocalicvowelsigndeva: 0x0944,
  29748. rrvocalicvowelsigngujarati: 0x0AC4,
  29749. rsuperior: 0xF6F1,
  29750. rtblock: 0x2590,
  29751. rturned: 0x0279,
  29752. rturnedsuperior: 0x02B4,
  29753. ruhiragana: 0x308B,
  29754. rukatakana: 0x30EB,
  29755. rukatakanahalfwidth: 0xFF99,
  29756. rupeemarkbengali: 0x09F2,
  29757. rupeesignbengali: 0x09F3,
  29758. rupiah: 0xF6DD,
  29759. ruthai: 0x0E24,
  29760. rvocalicbengali: 0x098B,
  29761. rvocalicdeva: 0x090B,
  29762. rvocalicgujarati: 0x0A8B,
  29763. rvocalicvowelsignbengali: 0x09C3,
  29764. rvocalicvowelsigndeva: 0x0943,
  29765. rvocalicvowelsigngujarati: 0x0AC3,
  29766. s: 0x0073,
  29767. sabengali: 0x09B8,
  29768. sacute: 0x015B,
  29769. sacutedotaccent: 0x1E65,
  29770. sadarabic: 0x0635,
  29771. sadeva: 0x0938,
  29772. sadfinalarabic: 0xFEBA,
  29773. sadinitialarabic: 0xFEBB,
  29774. sadmedialarabic: 0xFEBC,
  29775. sagujarati: 0x0AB8,
  29776. sagurmukhi: 0x0A38,
  29777. sahiragana: 0x3055,
  29778. sakatakana: 0x30B5,
  29779. sakatakanahalfwidth: 0xFF7B,
  29780. sallallahoualayhewasallamarabic: 0xFDFA,
  29781. samekh: 0x05E1,
  29782. samekhdagesh: 0xFB41,
  29783. samekhdageshhebrew: 0xFB41,
  29784. samekhhebrew: 0x05E1,
  29785. saraaathai: 0x0E32,
  29786. saraaethai: 0x0E41,
  29787. saraaimaimalaithai: 0x0E44,
  29788. saraaimaimuanthai: 0x0E43,
  29789. saraamthai: 0x0E33,
  29790. saraathai: 0x0E30,
  29791. saraethai: 0x0E40,
  29792. saraiileftthai: 0xF886,
  29793. saraiithai: 0x0E35,
  29794. saraileftthai: 0xF885,
  29795. saraithai: 0x0E34,
  29796. saraothai: 0x0E42,
  29797. saraueeleftthai: 0xF888,
  29798. saraueethai: 0x0E37,
  29799. saraueleftthai: 0xF887,
  29800. sarauethai: 0x0E36,
  29801. sarauthai: 0x0E38,
  29802. sarauuthai: 0x0E39,
  29803. sbopomofo: 0x3119,
  29804. scaron: 0x0161,
  29805. scarondotaccent: 0x1E67,
  29806. scedilla: 0x015F,
  29807. schwa: 0x0259,
  29808. schwacyrillic: 0x04D9,
  29809. schwadieresiscyrillic: 0x04DB,
  29810. schwahook: 0x025A,
  29811. scircle: 0x24E2,
  29812. scircumflex: 0x015D,
  29813. scommaaccent: 0x0219,
  29814. sdotaccent: 0x1E61,
  29815. sdotbelow: 0x1E63,
  29816. sdotbelowdotaccent: 0x1E69,
  29817. seagullbelowcmb: 0x033C,
  29818. second: 0x2033,
  29819. secondtonechinese: 0x02CA,
  29820. section: 0x00A7,
  29821. seenarabic: 0x0633,
  29822. seenfinalarabic: 0xFEB2,
  29823. seeninitialarabic: 0xFEB3,
  29824. seenmedialarabic: 0xFEB4,
  29825. segol: 0x05B6,
  29826. segol13: 0x05B6,
  29827. segol1f: 0x05B6,
  29828. segol2c: 0x05B6,
  29829. segolhebrew: 0x05B6,
  29830. segolnarrowhebrew: 0x05B6,
  29831. segolquarterhebrew: 0x05B6,
  29832. segoltahebrew: 0x0592,
  29833. segolwidehebrew: 0x05B6,
  29834. seharmenian: 0x057D,
  29835. sehiragana: 0x305B,
  29836. sekatakana: 0x30BB,
  29837. sekatakanahalfwidth: 0xFF7E,
  29838. semicolon: 0x003B,
  29839. semicolonarabic: 0x061B,
  29840. semicolonmonospace: 0xFF1B,
  29841. semicolonsmall: 0xFE54,
  29842. semivoicedmarkkana: 0x309C,
  29843. semivoicedmarkkanahalfwidth: 0xFF9F,
  29844. sentisquare: 0x3322,
  29845. sentosquare: 0x3323,
  29846. seven: 0x0037,
  29847. sevenarabic: 0x0667,
  29848. sevenbengali: 0x09ED,
  29849. sevencircle: 0x2466,
  29850. sevencircleinversesansserif: 0x2790,
  29851. sevendeva: 0x096D,
  29852. seveneighths: 0x215E,
  29853. sevengujarati: 0x0AED,
  29854. sevengurmukhi: 0x0A6D,
  29855. sevenhackarabic: 0x0667,
  29856. sevenhangzhou: 0x3027,
  29857. sevenideographicparen: 0x3226,
  29858. seveninferior: 0x2087,
  29859. sevenmonospace: 0xFF17,
  29860. sevenoldstyle: 0xF737,
  29861. sevenparen: 0x247A,
  29862. sevenperiod: 0x248E,
  29863. sevenpersian: 0x06F7,
  29864. sevenroman: 0x2176,
  29865. sevensuperior: 0x2077,
  29866. seventeencircle: 0x2470,
  29867. seventeenparen: 0x2484,
  29868. seventeenperiod: 0x2498,
  29869. seventhai: 0x0E57,
  29870. sfthyphen: 0x00AD,
  29871. shaarmenian: 0x0577,
  29872. shabengali: 0x09B6,
  29873. shacyrillic: 0x0448,
  29874. shaddaarabic: 0x0651,
  29875. shaddadammaarabic: 0xFC61,
  29876. shaddadammatanarabic: 0xFC5E,
  29877. shaddafathaarabic: 0xFC60,
  29878. shaddakasraarabic: 0xFC62,
  29879. shaddakasratanarabic: 0xFC5F,
  29880. shade: 0x2592,
  29881. shadedark: 0x2593,
  29882. shadelight: 0x2591,
  29883. shademedium: 0x2592,
  29884. shadeva: 0x0936,
  29885. shagujarati: 0x0AB6,
  29886. shagurmukhi: 0x0A36,
  29887. shalshelethebrew: 0x0593,
  29888. shbopomofo: 0x3115,
  29889. shchacyrillic: 0x0449,
  29890. sheenarabic: 0x0634,
  29891. sheenfinalarabic: 0xFEB6,
  29892. sheeninitialarabic: 0xFEB7,
  29893. sheenmedialarabic: 0xFEB8,
  29894. sheicoptic: 0x03E3,
  29895. sheqel: 0x20AA,
  29896. sheqelhebrew: 0x20AA,
  29897. sheva: 0x05B0,
  29898. sheva115: 0x05B0,
  29899. sheva15: 0x05B0,
  29900. sheva22: 0x05B0,
  29901. sheva2e: 0x05B0,
  29902. shevahebrew: 0x05B0,
  29903. shevanarrowhebrew: 0x05B0,
  29904. shevaquarterhebrew: 0x05B0,
  29905. shevawidehebrew: 0x05B0,
  29906. shhacyrillic: 0x04BB,
  29907. shimacoptic: 0x03ED,
  29908. shin: 0x05E9,
  29909. shindagesh: 0xFB49,
  29910. shindageshhebrew: 0xFB49,
  29911. shindageshshindot: 0xFB2C,
  29912. shindageshshindothebrew: 0xFB2C,
  29913. shindageshsindot: 0xFB2D,
  29914. shindageshsindothebrew: 0xFB2D,
  29915. shindothebrew: 0x05C1,
  29916. shinhebrew: 0x05E9,
  29917. shinshindot: 0xFB2A,
  29918. shinshindothebrew: 0xFB2A,
  29919. shinsindot: 0xFB2B,
  29920. shinsindothebrew: 0xFB2B,
  29921. shook: 0x0282,
  29922. sigma: 0x03C3,
  29923. sigma1: 0x03C2,
  29924. sigmafinal: 0x03C2,
  29925. sigmalunatesymbolgreek: 0x03F2,
  29926. sihiragana: 0x3057,
  29927. sikatakana: 0x30B7,
  29928. sikatakanahalfwidth: 0xFF7C,
  29929. siluqhebrew: 0x05BD,
  29930. siluqlefthebrew: 0x05BD,
  29931. similar: 0x223C,
  29932. sindothebrew: 0x05C2,
  29933. siosacirclekorean: 0x3274,
  29934. siosaparenkorean: 0x3214,
  29935. sioscieuckorean: 0x317E,
  29936. sioscirclekorean: 0x3266,
  29937. sioskiyeokkorean: 0x317A,
  29938. sioskorean: 0x3145,
  29939. siosnieunkorean: 0x317B,
  29940. siosparenkorean: 0x3206,
  29941. siospieupkorean: 0x317D,
  29942. siostikeutkorean: 0x317C,
  29943. six: 0x0036,
  29944. sixarabic: 0x0666,
  29945. sixbengali: 0x09EC,
  29946. sixcircle: 0x2465,
  29947. sixcircleinversesansserif: 0x278F,
  29948. sixdeva: 0x096C,
  29949. sixgujarati: 0x0AEC,
  29950. sixgurmukhi: 0x0A6C,
  29951. sixhackarabic: 0x0666,
  29952. sixhangzhou: 0x3026,
  29953. sixideographicparen: 0x3225,
  29954. sixinferior: 0x2086,
  29955. sixmonospace: 0xFF16,
  29956. sixoldstyle: 0xF736,
  29957. sixparen: 0x2479,
  29958. sixperiod: 0x248D,
  29959. sixpersian: 0x06F6,
  29960. sixroman: 0x2175,
  29961. sixsuperior: 0x2076,
  29962. sixteencircle: 0x246F,
  29963. sixteencurrencydenominatorbengali: 0x09F9,
  29964. sixteenparen: 0x2483,
  29965. sixteenperiod: 0x2497,
  29966. sixthai: 0x0E56,
  29967. slash: 0x002F,
  29968. slashmonospace: 0xFF0F,
  29969. slong: 0x017F,
  29970. slongdotaccent: 0x1E9B,
  29971. smileface: 0x263A,
  29972. smonospace: 0xFF53,
  29973. sofpasuqhebrew: 0x05C3,
  29974. softhyphen: 0x00AD,
  29975. softsigncyrillic: 0x044C,
  29976. sohiragana: 0x305D,
  29977. sokatakana: 0x30BD,
  29978. sokatakanahalfwidth: 0xFF7F,
  29979. soliduslongoverlaycmb: 0x0338,
  29980. solidusshortoverlaycmb: 0x0337,
  29981. sorusithai: 0x0E29,
  29982. sosalathai: 0x0E28,
  29983. sosothai: 0x0E0B,
  29984. sosuathai: 0x0E2A,
  29985. space: 0x0020,
  29986. spacehackarabic: 0x0020,
  29987. spade: 0x2660,
  29988. spadesuitblack: 0x2660,
  29989. spadesuitwhite: 0x2664,
  29990. sparen: 0x24AE,
  29991. squarebelowcmb: 0x033B,
  29992. squarecc: 0x33C4,
  29993. squarecm: 0x339D,
  29994. squarediagonalcrosshatchfill: 0x25A9,
  29995. squarehorizontalfill: 0x25A4,
  29996. squarekg: 0x338F,
  29997. squarekm: 0x339E,
  29998. squarekmcapital: 0x33CE,
  29999. squareln: 0x33D1,
  30000. squarelog: 0x33D2,
  30001. squaremg: 0x338E,
  30002. squaremil: 0x33D5,
  30003. squaremm: 0x339C,
  30004. squaremsquared: 0x33A1,
  30005. squareorthogonalcrosshatchfill: 0x25A6,
  30006. squareupperlefttolowerrightfill: 0x25A7,
  30007. squareupperrighttolowerleftfill: 0x25A8,
  30008. squareverticalfill: 0x25A5,
  30009. squarewhitewithsmallblack: 0x25A3,
  30010. srsquare: 0x33DB,
  30011. ssabengali: 0x09B7,
  30012. ssadeva: 0x0937,
  30013. ssagujarati: 0x0AB7,
  30014. ssangcieuckorean: 0x3149,
  30015. ssanghieuhkorean: 0x3185,
  30016. ssangieungkorean: 0x3180,
  30017. ssangkiyeokkorean: 0x3132,
  30018. ssangnieunkorean: 0x3165,
  30019. ssangpieupkorean: 0x3143,
  30020. ssangsioskorean: 0x3146,
  30021. ssangtikeutkorean: 0x3138,
  30022. ssuperior: 0xF6F2,
  30023. sterling: 0x00A3,
  30024. sterlingmonospace: 0xFFE1,
  30025. strokelongoverlaycmb: 0x0336,
  30026. strokeshortoverlaycmb: 0x0335,
  30027. subset: 0x2282,
  30028. subsetnotequal: 0x228A,
  30029. subsetorequal: 0x2286,
  30030. succeeds: 0x227B,
  30031. suchthat: 0x220B,
  30032. suhiragana: 0x3059,
  30033. sukatakana: 0x30B9,
  30034. sukatakanahalfwidth: 0xFF7D,
  30035. sukunarabic: 0x0652,
  30036. summation: 0x2211,
  30037. sun: 0x263C,
  30038. superset: 0x2283,
  30039. supersetnotequal: 0x228B,
  30040. supersetorequal: 0x2287,
  30041. svsquare: 0x33DC,
  30042. syouwaerasquare: 0x337C,
  30043. t: 0x0074,
  30044. tabengali: 0x09A4,
  30045. tackdown: 0x22A4,
  30046. tackleft: 0x22A3,
  30047. tadeva: 0x0924,
  30048. tagujarati: 0x0AA4,
  30049. tagurmukhi: 0x0A24,
  30050. taharabic: 0x0637,
  30051. tahfinalarabic: 0xFEC2,
  30052. tahinitialarabic: 0xFEC3,
  30053. tahiragana: 0x305F,
  30054. tahmedialarabic: 0xFEC4,
  30055. taisyouerasquare: 0x337D,
  30056. takatakana: 0x30BF,
  30057. takatakanahalfwidth: 0xFF80,
  30058. tatweelarabic: 0x0640,
  30059. tau: 0x03C4,
  30060. tav: 0x05EA,
  30061. tavdages: 0xFB4A,
  30062. tavdagesh: 0xFB4A,
  30063. tavdageshhebrew: 0xFB4A,
  30064. tavhebrew: 0x05EA,
  30065. tbar: 0x0167,
  30066. tbopomofo: 0x310A,
  30067. tcaron: 0x0165,
  30068. tccurl: 0x02A8,
  30069. tcedilla: 0x0163,
  30070. tcheharabic: 0x0686,
  30071. tchehfinalarabic: 0xFB7B,
  30072. tchehinitialarabic: 0xFB7C,
  30073. tchehmedialarabic: 0xFB7D,
  30074. tcircle: 0x24E3,
  30075. tcircumflexbelow: 0x1E71,
  30076. tcommaaccent: 0x0163,
  30077. tdieresis: 0x1E97,
  30078. tdotaccent: 0x1E6B,
  30079. tdotbelow: 0x1E6D,
  30080. tecyrillic: 0x0442,
  30081. tedescendercyrillic: 0x04AD,
  30082. teharabic: 0x062A,
  30083. tehfinalarabic: 0xFE96,
  30084. tehhahinitialarabic: 0xFCA2,
  30085. tehhahisolatedarabic: 0xFC0C,
  30086. tehinitialarabic: 0xFE97,
  30087. tehiragana: 0x3066,
  30088. tehjeeminitialarabic: 0xFCA1,
  30089. tehjeemisolatedarabic: 0xFC0B,
  30090. tehmarbutaarabic: 0x0629,
  30091. tehmarbutafinalarabic: 0xFE94,
  30092. tehmedialarabic: 0xFE98,
  30093. tehmeeminitialarabic: 0xFCA4,
  30094. tehmeemisolatedarabic: 0xFC0E,
  30095. tehnoonfinalarabic: 0xFC73,
  30096. tekatakana: 0x30C6,
  30097. tekatakanahalfwidth: 0xFF83,
  30098. telephone: 0x2121,
  30099. telephoneblack: 0x260E,
  30100. telishagedolahebrew: 0x05A0,
  30101. telishaqetanahebrew: 0x05A9,
  30102. tencircle: 0x2469,
  30103. tenideographicparen: 0x3229,
  30104. tenparen: 0x247D,
  30105. tenperiod: 0x2491,
  30106. tenroman: 0x2179,
  30107. tesh: 0x02A7,
  30108. tet: 0x05D8,
  30109. tetdagesh: 0xFB38,
  30110. tetdageshhebrew: 0xFB38,
  30111. tethebrew: 0x05D8,
  30112. tetsecyrillic: 0x04B5,
  30113. tevirhebrew: 0x059B,
  30114. tevirlefthebrew: 0x059B,
  30115. thabengali: 0x09A5,
  30116. thadeva: 0x0925,
  30117. thagujarati: 0x0AA5,
  30118. thagurmukhi: 0x0A25,
  30119. thalarabic: 0x0630,
  30120. thalfinalarabic: 0xFEAC,
  30121. thanthakhatlowleftthai: 0xF898,
  30122. thanthakhatlowrightthai: 0xF897,
  30123. thanthakhatthai: 0x0E4C,
  30124. thanthakhatupperleftthai: 0xF896,
  30125. theharabic: 0x062B,
  30126. thehfinalarabic: 0xFE9A,
  30127. thehinitialarabic: 0xFE9B,
  30128. thehmedialarabic: 0xFE9C,
  30129. thereexists: 0x2203,
  30130. therefore: 0x2234,
  30131. theta: 0x03B8,
  30132. theta1: 0x03D1,
  30133. thetasymbolgreek: 0x03D1,
  30134. thieuthacirclekorean: 0x3279,
  30135. thieuthaparenkorean: 0x3219,
  30136. thieuthcirclekorean: 0x326B,
  30137. thieuthkorean: 0x314C,
  30138. thieuthparenkorean: 0x320B,
  30139. thirteencircle: 0x246C,
  30140. thirteenparen: 0x2480,
  30141. thirteenperiod: 0x2494,
  30142. thonangmonthothai: 0x0E11,
  30143. thook: 0x01AD,
  30144. thophuthaothai: 0x0E12,
  30145. thorn: 0x00FE,
  30146. thothahanthai: 0x0E17,
  30147. thothanthai: 0x0E10,
  30148. thothongthai: 0x0E18,
  30149. thothungthai: 0x0E16,
  30150. thousandcyrillic: 0x0482,
  30151. thousandsseparatorarabic: 0x066C,
  30152. thousandsseparatorpersian: 0x066C,
  30153. three: 0x0033,
  30154. threearabic: 0x0663,
  30155. threebengali: 0x09E9,
  30156. threecircle: 0x2462,
  30157. threecircleinversesansserif: 0x278C,
  30158. threedeva: 0x0969,
  30159. threeeighths: 0x215C,
  30160. threegujarati: 0x0AE9,
  30161. threegurmukhi: 0x0A69,
  30162. threehackarabic: 0x0663,
  30163. threehangzhou: 0x3023,
  30164. threeideographicparen: 0x3222,
  30165. threeinferior: 0x2083,
  30166. threemonospace: 0xFF13,
  30167. threenumeratorbengali: 0x09F6,
  30168. threeoldstyle: 0xF733,
  30169. threeparen: 0x2476,
  30170. threeperiod: 0x248A,
  30171. threepersian: 0x06F3,
  30172. threequarters: 0x00BE,
  30173. threequartersemdash: 0xF6DE,
  30174. threeroman: 0x2172,
  30175. threesuperior: 0x00B3,
  30176. threethai: 0x0E53,
  30177. thzsquare: 0x3394,
  30178. tihiragana: 0x3061,
  30179. tikatakana: 0x30C1,
  30180. tikatakanahalfwidth: 0xFF81,
  30181. tikeutacirclekorean: 0x3270,
  30182. tikeutaparenkorean: 0x3210,
  30183. tikeutcirclekorean: 0x3262,
  30184. tikeutkorean: 0x3137,
  30185. tikeutparenkorean: 0x3202,
  30186. tilde: 0x02DC,
  30187. tildebelowcmb: 0x0330,
  30188. tildecmb: 0x0303,
  30189. tildecomb: 0x0303,
  30190. tildedoublecmb: 0x0360,
  30191. tildeoperator: 0x223C,
  30192. tildeoverlaycmb: 0x0334,
  30193. tildeverticalcmb: 0x033E,
  30194. timescircle: 0x2297,
  30195. tipehahebrew: 0x0596,
  30196. tipehalefthebrew: 0x0596,
  30197. tippigurmukhi: 0x0A70,
  30198. titlocyrilliccmb: 0x0483,
  30199. tiwnarmenian: 0x057F,
  30200. tlinebelow: 0x1E6F,
  30201. tmonospace: 0xFF54,
  30202. toarmenian: 0x0569,
  30203. tohiragana: 0x3068,
  30204. tokatakana: 0x30C8,
  30205. tokatakanahalfwidth: 0xFF84,
  30206. tonebarextrahighmod: 0x02E5,
  30207. tonebarextralowmod: 0x02E9,
  30208. tonebarhighmod: 0x02E6,
  30209. tonebarlowmod: 0x02E8,
  30210. tonebarmidmod: 0x02E7,
  30211. tonefive: 0x01BD,
  30212. tonesix: 0x0185,
  30213. tonetwo: 0x01A8,
  30214. tonos: 0x0384,
  30215. tonsquare: 0x3327,
  30216. topatakthai: 0x0E0F,
  30217. tortoiseshellbracketleft: 0x3014,
  30218. tortoiseshellbracketleftsmall: 0xFE5D,
  30219. tortoiseshellbracketleftvertical: 0xFE39,
  30220. tortoiseshellbracketright: 0x3015,
  30221. tortoiseshellbracketrightsmall: 0xFE5E,
  30222. tortoiseshellbracketrightvertical: 0xFE3A,
  30223. totaothai: 0x0E15,
  30224. tpalatalhook: 0x01AB,
  30225. tparen: 0x24AF,
  30226. trademark: 0x2122,
  30227. trademarksans: 0xF8EA,
  30228. trademarkserif: 0xF6DB,
  30229. tretroflexhook: 0x0288,
  30230. triagdn: 0x25BC,
  30231. triaglf: 0x25C4,
  30232. triagrt: 0x25BA,
  30233. triagup: 0x25B2,
  30234. ts: 0x02A6,
  30235. tsadi: 0x05E6,
  30236. tsadidagesh: 0xFB46,
  30237. tsadidageshhebrew: 0xFB46,
  30238. tsadihebrew: 0x05E6,
  30239. tsecyrillic: 0x0446,
  30240. tsere: 0x05B5,
  30241. tsere12: 0x05B5,
  30242. tsere1e: 0x05B5,
  30243. tsere2b: 0x05B5,
  30244. tserehebrew: 0x05B5,
  30245. tserenarrowhebrew: 0x05B5,
  30246. tserequarterhebrew: 0x05B5,
  30247. tserewidehebrew: 0x05B5,
  30248. tshecyrillic: 0x045B,
  30249. tsuperior: 0xF6F3,
  30250. ttabengali: 0x099F,
  30251. ttadeva: 0x091F,
  30252. ttagujarati: 0x0A9F,
  30253. ttagurmukhi: 0x0A1F,
  30254. tteharabic: 0x0679,
  30255. ttehfinalarabic: 0xFB67,
  30256. ttehinitialarabic: 0xFB68,
  30257. ttehmedialarabic: 0xFB69,
  30258. tthabengali: 0x09A0,
  30259. tthadeva: 0x0920,
  30260. tthagujarati: 0x0AA0,
  30261. tthagurmukhi: 0x0A20,
  30262. tturned: 0x0287,
  30263. tuhiragana: 0x3064,
  30264. tukatakana: 0x30C4,
  30265. tukatakanahalfwidth: 0xFF82,
  30266. tusmallhiragana: 0x3063,
  30267. tusmallkatakana: 0x30C3,
  30268. tusmallkatakanahalfwidth: 0xFF6F,
  30269. twelvecircle: 0x246B,
  30270. twelveparen: 0x247F,
  30271. twelveperiod: 0x2493,
  30272. twelveroman: 0x217B,
  30273. twentycircle: 0x2473,
  30274. twentyhangzhou: 0x5344,
  30275. twentyparen: 0x2487,
  30276. twentyperiod: 0x249B,
  30277. two: 0x0032,
  30278. twoarabic: 0x0662,
  30279. twobengali: 0x09E8,
  30280. twocircle: 0x2461,
  30281. twocircleinversesansserif: 0x278B,
  30282. twodeva: 0x0968,
  30283. twodotenleader: 0x2025,
  30284. twodotleader: 0x2025,
  30285. twodotleadervertical: 0xFE30,
  30286. twogujarati: 0x0AE8,
  30287. twogurmukhi: 0x0A68,
  30288. twohackarabic: 0x0662,
  30289. twohangzhou: 0x3022,
  30290. twoideographicparen: 0x3221,
  30291. twoinferior: 0x2082,
  30292. twomonospace: 0xFF12,
  30293. twonumeratorbengali: 0x09F5,
  30294. twooldstyle: 0xF732,
  30295. twoparen: 0x2475,
  30296. twoperiod: 0x2489,
  30297. twopersian: 0x06F2,
  30298. tworoman: 0x2171,
  30299. twostroke: 0x01BB,
  30300. twosuperior: 0x00B2,
  30301. twothai: 0x0E52,
  30302. twothirds: 0x2154,
  30303. u: 0x0075,
  30304. uacute: 0x00FA,
  30305. ubar: 0x0289,
  30306. ubengali: 0x0989,
  30307. ubopomofo: 0x3128,
  30308. ubreve: 0x016D,
  30309. ucaron: 0x01D4,
  30310. ucircle: 0x24E4,
  30311. ucircumflex: 0x00FB,
  30312. ucircumflexbelow: 0x1E77,
  30313. ucyrillic: 0x0443,
  30314. udattadeva: 0x0951,
  30315. udblacute: 0x0171,
  30316. udblgrave: 0x0215,
  30317. udeva: 0x0909,
  30318. udieresis: 0x00FC,
  30319. udieresisacute: 0x01D8,
  30320. udieresisbelow: 0x1E73,
  30321. udieresiscaron: 0x01DA,
  30322. udieresiscyrillic: 0x04F1,
  30323. udieresisgrave: 0x01DC,
  30324. udieresismacron: 0x01D6,
  30325. udotbelow: 0x1EE5,
  30326. ugrave: 0x00F9,
  30327. ugujarati: 0x0A89,
  30328. ugurmukhi: 0x0A09,
  30329. uhiragana: 0x3046,
  30330. uhookabove: 0x1EE7,
  30331. uhorn: 0x01B0,
  30332. uhornacute: 0x1EE9,
  30333. uhorndotbelow: 0x1EF1,
  30334. uhorngrave: 0x1EEB,
  30335. uhornhookabove: 0x1EED,
  30336. uhorntilde: 0x1EEF,
  30337. uhungarumlaut: 0x0171,
  30338. uhungarumlautcyrillic: 0x04F3,
  30339. uinvertedbreve: 0x0217,
  30340. ukatakana: 0x30A6,
  30341. ukatakanahalfwidth: 0xFF73,
  30342. ukcyrillic: 0x0479,
  30343. ukorean: 0x315C,
  30344. umacron: 0x016B,
  30345. umacroncyrillic: 0x04EF,
  30346. umacrondieresis: 0x1E7B,
  30347. umatragurmukhi: 0x0A41,
  30348. umonospace: 0xFF55,
  30349. underscore: 0x005F,
  30350. underscoredbl: 0x2017,
  30351. underscoremonospace: 0xFF3F,
  30352. underscorevertical: 0xFE33,
  30353. underscorewavy: 0xFE4F,
  30354. union: 0x222A,
  30355. universal: 0x2200,
  30356. uogonek: 0x0173,
  30357. uparen: 0x24B0,
  30358. upblock: 0x2580,
  30359. upperdothebrew: 0x05C4,
  30360. upsilon: 0x03C5,
  30361. upsilondieresis: 0x03CB,
  30362. upsilondieresistonos: 0x03B0,
  30363. upsilonlatin: 0x028A,
  30364. upsilontonos: 0x03CD,
  30365. uptackbelowcmb: 0x031D,
  30366. uptackmod: 0x02D4,
  30367. uragurmukhi: 0x0A73,
  30368. uring: 0x016F,
  30369. ushortcyrillic: 0x045E,
  30370. usmallhiragana: 0x3045,
  30371. usmallkatakana: 0x30A5,
  30372. usmallkatakanahalfwidth: 0xFF69,
  30373. ustraightcyrillic: 0x04AF,
  30374. ustraightstrokecyrillic: 0x04B1,
  30375. utilde: 0x0169,
  30376. utildeacute: 0x1E79,
  30377. utildebelow: 0x1E75,
  30378. uubengali: 0x098A,
  30379. uudeva: 0x090A,
  30380. uugujarati: 0x0A8A,
  30381. uugurmukhi: 0x0A0A,
  30382. uumatragurmukhi: 0x0A42,
  30383. uuvowelsignbengali: 0x09C2,
  30384. uuvowelsigndeva: 0x0942,
  30385. uuvowelsigngujarati: 0x0AC2,
  30386. uvowelsignbengali: 0x09C1,
  30387. uvowelsigndeva: 0x0941,
  30388. uvowelsigngujarati: 0x0AC1,
  30389. v: 0x0076,
  30390. vadeva: 0x0935,
  30391. vagujarati: 0x0AB5,
  30392. vagurmukhi: 0x0A35,
  30393. vakatakana: 0x30F7,
  30394. vav: 0x05D5,
  30395. vavdagesh: 0xFB35,
  30396. vavdagesh65: 0xFB35,
  30397. vavdageshhebrew: 0xFB35,
  30398. vavhebrew: 0x05D5,
  30399. vavholam: 0xFB4B,
  30400. vavholamhebrew: 0xFB4B,
  30401. vavvavhebrew: 0x05F0,
  30402. vavyodhebrew: 0x05F1,
  30403. vcircle: 0x24E5,
  30404. vdotbelow: 0x1E7F,
  30405. vecyrillic: 0x0432,
  30406. veharabic: 0x06A4,
  30407. vehfinalarabic: 0xFB6B,
  30408. vehinitialarabic: 0xFB6C,
  30409. vehmedialarabic: 0xFB6D,
  30410. vekatakana: 0x30F9,
  30411. venus: 0x2640,
  30412. verticalbar: 0x007C,
  30413. verticallineabovecmb: 0x030D,
  30414. verticallinebelowcmb: 0x0329,
  30415. verticallinelowmod: 0x02CC,
  30416. verticallinemod: 0x02C8,
  30417. vewarmenian: 0x057E,
  30418. vhook: 0x028B,
  30419. vikatakana: 0x30F8,
  30420. viramabengali: 0x09CD,
  30421. viramadeva: 0x094D,
  30422. viramagujarati: 0x0ACD,
  30423. visargabengali: 0x0983,
  30424. visargadeva: 0x0903,
  30425. visargagujarati: 0x0A83,
  30426. vmonospace: 0xFF56,
  30427. voarmenian: 0x0578,
  30428. voicediterationhiragana: 0x309E,
  30429. voicediterationkatakana: 0x30FE,
  30430. voicedmarkkana: 0x309B,
  30431. voicedmarkkanahalfwidth: 0xFF9E,
  30432. vokatakana: 0x30FA,
  30433. vparen: 0x24B1,
  30434. vtilde: 0x1E7D,
  30435. vturned: 0x028C,
  30436. vuhiragana: 0x3094,
  30437. vukatakana: 0x30F4,
  30438. w: 0x0077,
  30439. wacute: 0x1E83,
  30440. waekorean: 0x3159,
  30441. wahiragana: 0x308F,
  30442. wakatakana: 0x30EF,
  30443. wakatakanahalfwidth: 0xFF9C,
  30444. wakorean: 0x3158,
  30445. wasmallhiragana: 0x308E,
  30446. wasmallkatakana: 0x30EE,
  30447. wattosquare: 0x3357,
  30448. wavedash: 0x301C,
  30449. wavyunderscorevertical: 0xFE34,
  30450. wawarabic: 0x0648,
  30451. wawfinalarabic: 0xFEEE,
  30452. wawhamzaabovearabic: 0x0624,
  30453. wawhamzaabovefinalarabic: 0xFE86,
  30454. wbsquare: 0x33DD,
  30455. wcircle: 0x24E6,
  30456. wcircumflex: 0x0175,
  30457. wdieresis: 0x1E85,
  30458. wdotaccent: 0x1E87,
  30459. wdotbelow: 0x1E89,
  30460. wehiragana: 0x3091,
  30461. weierstrass: 0x2118,
  30462. wekatakana: 0x30F1,
  30463. wekorean: 0x315E,
  30464. weokorean: 0x315D,
  30465. wgrave: 0x1E81,
  30466. whitebullet: 0x25E6,
  30467. whitecircle: 0x25CB,
  30468. whitecircleinverse: 0x25D9,
  30469. whitecornerbracketleft: 0x300E,
  30470. whitecornerbracketleftvertical: 0xFE43,
  30471. whitecornerbracketright: 0x300F,
  30472. whitecornerbracketrightvertical: 0xFE44,
  30473. whitediamond: 0x25C7,
  30474. whitediamondcontainingblacksmalldiamond: 0x25C8,
  30475. whitedownpointingsmalltriangle: 0x25BF,
  30476. whitedownpointingtriangle: 0x25BD,
  30477. whiteleftpointingsmalltriangle: 0x25C3,
  30478. whiteleftpointingtriangle: 0x25C1,
  30479. whitelenticularbracketleft: 0x3016,
  30480. whitelenticularbracketright: 0x3017,
  30481. whiterightpointingsmalltriangle: 0x25B9,
  30482. whiterightpointingtriangle: 0x25B7,
  30483. whitesmallsquare: 0x25AB,
  30484. whitesmilingface: 0x263A,
  30485. whitesquare: 0x25A1,
  30486. whitestar: 0x2606,
  30487. whitetelephone: 0x260F,
  30488. whitetortoiseshellbracketleft: 0x3018,
  30489. whitetortoiseshellbracketright: 0x3019,
  30490. whiteuppointingsmalltriangle: 0x25B5,
  30491. whiteuppointingtriangle: 0x25B3,
  30492. wihiragana: 0x3090,
  30493. wikatakana: 0x30F0,
  30494. wikorean: 0x315F,
  30495. wmonospace: 0xFF57,
  30496. wohiragana: 0x3092,
  30497. wokatakana: 0x30F2,
  30498. wokatakanahalfwidth: 0xFF66,
  30499. won: 0x20A9,
  30500. wonmonospace: 0xFFE6,
  30501. wowaenthai: 0x0E27,
  30502. wparen: 0x24B2,
  30503. wring: 0x1E98,
  30504. wsuperior: 0x02B7,
  30505. wturned: 0x028D,
  30506. wynn: 0x01BF,
  30507. x: 0x0078,
  30508. xabovecmb: 0x033D,
  30509. xbopomofo: 0x3112,
  30510. xcircle: 0x24E7,
  30511. xdieresis: 0x1E8D,
  30512. xdotaccent: 0x1E8B,
  30513. xeharmenian: 0x056D,
  30514. xi: 0x03BE,
  30515. xmonospace: 0xFF58,
  30516. xparen: 0x24B3,
  30517. xsuperior: 0x02E3,
  30518. y: 0x0079,
  30519. yaadosquare: 0x334E,
  30520. yabengali: 0x09AF,
  30521. yacute: 0x00FD,
  30522. yadeva: 0x092F,
  30523. yaekorean: 0x3152,
  30524. yagujarati: 0x0AAF,
  30525. yagurmukhi: 0x0A2F,
  30526. yahiragana: 0x3084,
  30527. yakatakana: 0x30E4,
  30528. yakatakanahalfwidth: 0xFF94,
  30529. yakorean: 0x3151,
  30530. yamakkanthai: 0x0E4E,
  30531. yasmallhiragana: 0x3083,
  30532. yasmallkatakana: 0x30E3,
  30533. yasmallkatakanahalfwidth: 0xFF6C,
  30534. yatcyrillic: 0x0463,
  30535. ycircle: 0x24E8,
  30536. ycircumflex: 0x0177,
  30537. ydieresis: 0x00FF,
  30538. ydotaccent: 0x1E8F,
  30539. ydotbelow: 0x1EF5,
  30540. yeharabic: 0x064A,
  30541. yehbarreearabic: 0x06D2,
  30542. yehbarreefinalarabic: 0xFBAF,
  30543. yehfinalarabic: 0xFEF2,
  30544. yehhamzaabovearabic: 0x0626,
  30545. yehhamzaabovefinalarabic: 0xFE8A,
  30546. yehhamzaaboveinitialarabic: 0xFE8B,
  30547. yehhamzaabovemedialarabic: 0xFE8C,
  30548. yehinitialarabic: 0xFEF3,
  30549. yehmedialarabic: 0xFEF4,
  30550. yehmeeminitialarabic: 0xFCDD,
  30551. yehmeemisolatedarabic: 0xFC58,
  30552. yehnoonfinalarabic: 0xFC94,
  30553. yehthreedotsbelowarabic: 0x06D1,
  30554. yekorean: 0x3156,
  30555. yen: 0x00A5,
  30556. yenmonospace: 0xFFE5,
  30557. yeokorean: 0x3155,
  30558. yeorinhieuhkorean: 0x3186,
  30559. yerahbenyomohebrew: 0x05AA,
  30560. yerahbenyomolefthebrew: 0x05AA,
  30561. yericyrillic: 0x044B,
  30562. yerudieresiscyrillic: 0x04F9,
  30563. yesieungkorean: 0x3181,
  30564. yesieungpansioskorean: 0x3183,
  30565. yesieungsioskorean: 0x3182,
  30566. yetivhebrew: 0x059A,
  30567. ygrave: 0x1EF3,
  30568. yhook: 0x01B4,
  30569. yhookabove: 0x1EF7,
  30570. yiarmenian: 0x0575,
  30571. yicyrillic: 0x0457,
  30572. yikorean: 0x3162,
  30573. yinyang: 0x262F,
  30574. yiwnarmenian: 0x0582,
  30575. ymonospace: 0xFF59,
  30576. yod: 0x05D9,
  30577. yoddagesh: 0xFB39,
  30578. yoddageshhebrew: 0xFB39,
  30579. yodhebrew: 0x05D9,
  30580. yodyodhebrew: 0x05F2,
  30581. yodyodpatahhebrew: 0xFB1F,
  30582. yohiragana: 0x3088,
  30583. yoikorean: 0x3189,
  30584. yokatakana: 0x30E8,
  30585. yokatakanahalfwidth: 0xFF96,
  30586. yokorean: 0x315B,
  30587. yosmallhiragana: 0x3087,
  30588. yosmallkatakana: 0x30E7,
  30589. yosmallkatakanahalfwidth: 0xFF6E,
  30590. yotgreek: 0x03F3,
  30591. yoyaekorean: 0x3188,
  30592. yoyakorean: 0x3187,
  30593. yoyakthai: 0x0E22,
  30594. yoyingthai: 0x0E0D,
  30595. yparen: 0x24B4,
  30596. ypogegrammeni: 0x037A,
  30597. ypogegrammenigreekcmb: 0x0345,
  30598. yr: 0x01A6,
  30599. yring: 0x1E99,
  30600. ysuperior: 0x02B8,
  30601. ytilde: 0x1EF9,
  30602. yturned: 0x028E,
  30603. yuhiragana: 0x3086,
  30604. yuikorean: 0x318C,
  30605. yukatakana: 0x30E6,
  30606. yukatakanahalfwidth: 0xFF95,
  30607. yukorean: 0x3160,
  30608. yusbigcyrillic: 0x046B,
  30609. yusbigiotifiedcyrillic: 0x046D,
  30610. yuslittlecyrillic: 0x0467,
  30611. yuslittleiotifiedcyrillic: 0x0469,
  30612. yusmallhiragana: 0x3085,
  30613. yusmallkatakana: 0x30E5,
  30614. yusmallkatakanahalfwidth: 0xFF6D,
  30615. yuyekorean: 0x318B,
  30616. yuyeokorean: 0x318A,
  30617. yyabengali: 0x09DF,
  30618. yyadeva: 0x095F,
  30619. z: 0x007A,
  30620. zaarmenian: 0x0566,
  30621. zacute: 0x017A,
  30622. zadeva: 0x095B,
  30623. zagurmukhi: 0x0A5B,
  30624. zaharabic: 0x0638,
  30625. zahfinalarabic: 0xFEC6,
  30626. zahinitialarabic: 0xFEC7,
  30627. zahiragana: 0x3056,
  30628. zahmedialarabic: 0xFEC8,
  30629. zainarabic: 0x0632,
  30630. zainfinalarabic: 0xFEB0,
  30631. zakatakana: 0x30B6,
  30632. zaqefgadolhebrew: 0x0595,
  30633. zaqefqatanhebrew: 0x0594,
  30634. zarqahebrew: 0x0598,
  30635. zayin: 0x05D6,
  30636. zayindagesh: 0xFB36,
  30637. zayindageshhebrew: 0xFB36,
  30638. zayinhebrew: 0x05D6,
  30639. zbopomofo: 0x3117,
  30640. zcaron: 0x017E,
  30641. zcircle: 0x24E9,
  30642. zcircumflex: 0x1E91,
  30643. zcurl: 0x0291,
  30644. zdot: 0x017C,
  30645. zdotaccent: 0x017C,
  30646. zdotbelow: 0x1E93,
  30647. zecyrillic: 0x0437,
  30648. zedescendercyrillic: 0x0499,
  30649. zedieresiscyrillic: 0x04DF,
  30650. zehiragana: 0x305C,
  30651. zekatakana: 0x30BC,
  30652. zero: 0x0030,
  30653. zeroarabic: 0x0660,
  30654. zerobengali: 0x09E6,
  30655. zerodeva: 0x0966,
  30656. zerogujarati: 0x0AE6,
  30657. zerogurmukhi: 0x0A66,
  30658. zerohackarabic: 0x0660,
  30659. zeroinferior: 0x2080,
  30660. zeromonospace: 0xFF10,
  30661. zerooldstyle: 0xF730,
  30662. zeropersian: 0x06F0,
  30663. zerosuperior: 0x2070,
  30664. zerothai: 0x0E50,
  30665. zerowidthjoiner: 0xFEFF,
  30666. zerowidthnonjoiner: 0x200C,
  30667. zerowidthspace: 0x200B,
  30668. zeta: 0x03B6,
  30669. zhbopomofo: 0x3113,
  30670. zhearmenian: 0x056A,
  30671. zhebrevecyrillic: 0x04C2,
  30672. zhecyrillic: 0x0436,
  30673. zhedescendercyrillic: 0x0497,
  30674. zhedieresiscyrillic: 0x04DD,
  30675. zihiragana: 0x3058,
  30676. zikatakana: 0x30B8,
  30677. zinorhebrew: 0x05AE,
  30678. zlinebelow: 0x1E95,
  30679. zmonospace: 0xFF5A,
  30680. zohiragana: 0x305E,
  30681. zokatakana: 0x30BE,
  30682. zparen: 0x24B5,
  30683. zretroflexhook: 0x0290,
  30684. zstroke: 0x01B6,
  30685. zuhiragana: 0x305A,
  30686. zukatakana: 0x30BA,
  30687. '.notdef': 0x0000
  30688. };
  30689. var DingbatsGlyphsUnicode = {
  30690. space: 0x0020,
  30691. a1: 0x2701,
  30692. a2: 0x2702,
  30693. a202: 0x2703,
  30694. a3: 0x2704,
  30695. a4: 0x260E,
  30696. a5: 0x2706,
  30697. a119: 0x2707,
  30698. a118: 0x2708,
  30699. a117: 0x2709,
  30700. a11: 0x261B,
  30701. a12: 0x261E,
  30702. a13: 0x270C,
  30703. a14: 0x270D,
  30704. a15: 0x270E,
  30705. a16: 0x270F,
  30706. a105: 0x2710,
  30707. a17: 0x2711,
  30708. a18: 0x2712,
  30709. a19: 0x2713,
  30710. a20: 0x2714,
  30711. a21: 0x2715,
  30712. a22: 0x2716,
  30713. a23: 0x2717,
  30714. a24: 0x2718,
  30715. a25: 0x2719,
  30716. a26: 0x271A,
  30717. a27: 0x271B,
  30718. a28: 0x271C,
  30719. a6: 0x271D,
  30720. a7: 0x271E,
  30721. a8: 0x271F,
  30722. a9: 0x2720,
  30723. a10: 0x2721,
  30724. a29: 0x2722,
  30725. a30: 0x2723,
  30726. a31: 0x2724,
  30727. a32: 0x2725,
  30728. a33: 0x2726,
  30729. a34: 0x2727,
  30730. a35: 0x2605,
  30731. a36: 0x2729,
  30732. a37: 0x272A,
  30733. a38: 0x272B,
  30734. a39: 0x272C,
  30735. a40: 0x272D,
  30736. a41: 0x272E,
  30737. a42: 0x272F,
  30738. a43: 0x2730,
  30739. a44: 0x2731,
  30740. a45: 0x2732,
  30741. a46: 0x2733,
  30742. a47: 0x2734,
  30743. a48: 0x2735,
  30744. a49: 0x2736,
  30745. a50: 0x2737,
  30746. a51: 0x2738,
  30747. a52: 0x2739,
  30748. a53: 0x273A,
  30749. a54: 0x273B,
  30750. a55: 0x273C,
  30751. a56: 0x273D,
  30752. a57: 0x273E,
  30753. a58: 0x273F,
  30754. a59: 0x2740,
  30755. a60: 0x2741,
  30756. a61: 0x2742,
  30757. a62: 0x2743,
  30758. a63: 0x2744,
  30759. a64: 0x2745,
  30760. a65: 0x2746,
  30761. a66: 0x2747,
  30762. a67: 0x2748,
  30763. a68: 0x2749,
  30764. a69: 0x274A,
  30765. a70: 0x274B,
  30766. a71: 0x25CF,
  30767. a72: 0x274D,
  30768. a73: 0x25A0,
  30769. a74: 0x274F,
  30770. a203: 0x2750,
  30771. a75: 0x2751,
  30772. a204: 0x2752,
  30773. a76: 0x25B2,
  30774. a77: 0x25BC,
  30775. a78: 0x25C6,
  30776. a79: 0x2756,
  30777. a81: 0x25D7,
  30778. a82: 0x2758,
  30779. a83: 0x2759,
  30780. a84: 0x275A,
  30781. a97: 0x275B,
  30782. a98: 0x275C,
  30783. a99: 0x275D,
  30784. a100: 0x275E,
  30785. a101: 0x2761,
  30786. a102: 0x2762,
  30787. a103: 0x2763,
  30788. a104: 0x2764,
  30789. a106: 0x2765,
  30790. a107: 0x2766,
  30791. a108: 0x2767,
  30792. a112: 0x2663,
  30793. a111: 0x2666,
  30794. a110: 0x2665,
  30795. a109: 0x2660,
  30796. a120: 0x2460,
  30797. a121: 0x2461,
  30798. a122: 0x2462,
  30799. a123: 0x2463,
  30800. a124: 0x2464,
  30801. a125: 0x2465,
  30802. a126: 0x2466,
  30803. a127: 0x2467,
  30804. a128: 0x2468,
  30805. a129: 0x2469,
  30806. a130: 0x2776,
  30807. a131: 0x2777,
  30808. a132: 0x2778,
  30809. a133: 0x2779,
  30810. a134: 0x277A,
  30811. a135: 0x277B,
  30812. a136: 0x277C,
  30813. a137: 0x277D,
  30814. a138: 0x277E,
  30815. a139: 0x277F,
  30816. a140: 0x2780,
  30817. a141: 0x2781,
  30818. a142: 0x2782,
  30819. a143: 0x2783,
  30820. a144: 0x2784,
  30821. a145: 0x2785,
  30822. a146: 0x2786,
  30823. a147: 0x2787,
  30824. a148: 0x2788,
  30825. a149: 0x2789,
  30826. a150: 0x278A,
  30827. a151: 0x278B,
  30828. a152: 0x278C,
  30829. a153: 0x278D,
  30830. a154: 0x278E,
  30831. a155: 0x278F,
  30832. a156: 0x2790,
  30833. a157: 0x2791,
  30834. a158: 0x2792,
  30835. a159: 0x2793,
  30836. a160: 0x2794,
  30837. a161: 0x2192,
  30838. a163: 0x2194,
  30839. a164: 0x2195,
  30840. a196: 0x2798,
  30841. a165: 0x2799,
  30842. a192: 0x279A,
  30843. a166: 0x279B,
  30844. a167: 0x279C,
  30845. a168: 0x279D,
  30846. a169: 0x279E,
  30847. a170: 0x279F,
  30848. a171: 0x27A0,
  30849. a172: 0x27A1,
  30850. a173: 0x27A2,
  30851. a162: 0x27A3,
  30852. a174: 0x27A4,
  30853. a175: 0x27A5,
  30854. a176: 0x27A6,
  30855. a177: 0x27A7,
  30856. a178: 0x27A8,
  30857. a179: 0x27A9,
  30858. a193: 0x27AA,
  30859. a180: 0x27AB,
  30860. a199: 0x27AC,
  30861. a181: 0x27AD,
  30862. a200: 0x27AE,
  30863. a182: 0x27AF,
  30864. a201: 0x27B1,
  30865. a183: 0x27B2,
  30866. a184: 0x27B3,
  30867. a197: 0x27B4,
  30868. a185: 0x27B5,
  30869. a194: 0x27B6,
  30870. a198: 0x27B7,
  30871. a186: 0x27B8,
  30872. a195: 0x27B9,
  30873. a187: 0x27BA,
  30874. a188: 0x27BB,
  30875. a189: 0x27BC,
  30876. a190: 0x27BD,
  30877. a191: 0x27BE,
  30878. a89: 0x2768, // 0xF8D7
  30879. a90: 0x2769, // 0xF8D8
  30880. a93: 0x276A, // 0xF8D9
  30881. a94: 0x276B, // 0xF8DA
  30882. a91: 0x276C, // 0xF8DB
  30883. a92: 0x276D, // 0xF8DC
  30884. a205: 0x276E, // 0xF8DD
  30885. a85: 0x276F, // 0xF8DE
  30886. a206: 0x2770, // 0xF8DF
  30887. a86: 0x2771, // 0xF8E0
  30888. a87: 0x2772, // 0xF8E1
  30889. a88: 0x2773, // 0xF8E2
  30890. a95: 0x2774, // 0xF8E3
  30891. a96: 0x2775, // 0xF8E4
  30892. '.notdef': 0x0000
  30893. };
  30894. var PDFImage = (function PDFImageClosure() {
  30895. /**
  30896. * Decode the image in the main thread if it supported. Resovles the promise
  30897. * when the image data is ready.
  30898. */
  30899. function handleImageData(handler, xref, res, image) {
  30900. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30901. // For natively supported jpegs send them to the main thread for decoding.
  30902. var dict = image.dict;
  30903. var colorSpace = dict.get('ColorSpace', 'CS');
  30904. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30905. var numComps = colorSpace.numComps;
  30906. var decodePromise = handler.sendWithPromise('JpegDecode',
  30907. [image.getIR(), numComps]);
  30908. return decodePromise.then(function (message) {
  30909. var data = message.data;
  30910. return new Stream(data, 0, data.length, image.dict);
  30911. });
  30912. } else {
  30913. return Promise.resolve(image);
  30914. }
  30915. }
  30916. /**
  30917. * Decode and clamp a value. The formula is different from the spec because we
  30918. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30919. */
  30920. function decodeAndClamp(value, addend, coefficient, max) {
  30921. value = addend + value * coefficient;
  30922. // Clamp the value to the range
  30923. return (value < 0 ? 0 : (value > max ? max : value));
  30924. }
  30925. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30926. this.image = image;
  30927. var dict = image.dict;
  30928. if (dict.has('Filter')) {
  30929. var filter = dict.get('Filter').name;
  30930. if (filter === 'JPXDecode') {
  30931. var jpxImage = new JpxImage();
  30932. jpxImage.parseImageProperties(image.stream);
  30933. image.stream.reset();
  30934. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30935. image.numComps = jpxImage.componentsCount;
  30936. } else if (filter === 'JBIG2Decode') {
  30937. image.bitsPerComponent = 1;
  30938. image.numComps = 1;
  30939. }
  30940. }
  30941. // TODO cache rendered images?
  30942. this.width = dict.get('Width', 'W');
  30943. this.height = dict.get('Height', 'H');
  30944. if (this.width < 1 || this.height < 1) {
  30945. error('Invalid image width: ' + this.width + ' or height: ' +
  30946. this.height);
  30947. }
  30948. this.interpolate = dict.get('Interpolate', 'I') || false;
  30949. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30950. this.matte = dict.get('Matte') || false;
  30951. var bitsPerComponent = image.bitsPerComponent;
  30952. if (!bitsPerComponent) {
  30953. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30954. if (!bitsPerComponent) {
  30955. if (this.imageMask) {
  30956. bitsPerComponent = 1;
  30957. } else {
  30958. error('Bits per component missing in image: ' + this.imageMask);
  30959. }
  30960. }
  30961. }
  30962. this.bpc = bitsPerComponent;
  30963. if (!this.imageMask) {
  30964. var colorSpace = dict.get('ColorSpace', 'CS');
  30965. if (!colorSpace) {
  30966. info('JPX images (which do not require color spaces)');
  30967. switch (image.numComps) {
  30968. case 1:
  30969. colorSpace = Name.get('DeviceGray');
  30970. break;
  30971. case 3:
  30972. colorSpace = Name.get('DeviceRGB');
  30973. break;
  30974. case 4:
  30975. colorSpace = Name.get('DeviceCMYK');
  30976. break;
  30977. default:
  30978. error('JPX images with ' + this.numComps +
  30979. ' color components not supported.');
  30980. }
  30981. }
  30982. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30983. this.numComps = this.colorSpace.numComps;
  30984. }
  30985. this.decode = dict.get('Decode', 'D');
  30986. this.needsDecode = false;
  30987. if (this.decode &&
  30988. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30989. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30990. this.needsDecode = true;
  30991. // Do some preprocessing to avoid more math.
  30992. var max = (1 << bitsPerComponent) - 1;
  30993. this.decodeCoefficients = [];
  30994. this.decodeAddends = [];
  30995. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30996. var dmin = this.decode[i];
  30997. var dmax = this.decode[i + 1];
  30998. this.decodeCoefficients[j] = dmax - dmin;
  30999. this.decodeAddends[j] = max * dmin;
  31000. }
  31001. }
  31002. if (smask) {
  31003. this.smask = new PDFImage(xref, res, smask, false);
  31004. } else if (mask) {
  31005. if (isStream(mask)) {
  31006. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  31007. } else {
  31008. // Color key mask (just an array).
  31009. this.mask = mask;
  31010. }
  31011. }
  31012. }
  31013. /**
  31014. * Handles processing of image data and returns the Promise that is resolved
  31015. * with a PDFImage when the image is ready to be used.
  31016. */
  31017. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  31018. res, image, inline) {
  31019. var imagePromise = handleImageData(handler, xref, res, image);
  31020. var smaskPromise;
  31021. var maskPromise;
  31022. var smask = image.dict.get('SMask');
  31023. var mask = image.dict.get('Mask');
  31024. if (smask) {
  31025. smaskPromise = handleImageData(handler, xref, res, smask);
  31026. maskPromise = Promise.resolve(null);
  31027. } else {
  31028. smaskPromise = Promise.resolve(null);
  31029. if (mask) {
  31030. if (isStream(mask)) {
  31031. maskPromise = handleImageData(handler, xref, res, mask);
  31032. } else if (isArray(mask)) {
  31033. maskPromise = Promise.resolve(mask);
  31034. } else {
  31035. warn('Unsupported mask format.');
  31036. maskPromise = Promise.resolve(null);
  31037. }
  31038. } else {
  31039. maskPromise = Promise.resolve(null);
  31040. }
  31041. }
  31042. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  31043. function(results) {
  31044. var imageData = results[0];
  31045. var smaskData = results[1];
  31046. var maskData = results[2];
  31047. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  31048. });
  31049. };
  31050. /**
  31051. * Resize an image using the nearest neighbor algorithm. Currently only
  31052. * supports one and three component images.
  31053. * @param {TypedArray} pixels The original image with one component.
  31054. * @param {Number} bpc Number of bits per component.
  31055. * @param {Number} components Number of color components, 1 or 3 is supported.
  31056. * @param {Number} w1 Original width.
  31057. * @param {Number} h1 Original height.
  31058. * @param {Number} w2 New width.
  31059. * @param {Number} h2 New height.
  31060. * @param {TypedArray} dest (Optional) The destination buffer.
  31061. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  31062. * @return {TypedArray} Resized image data.
  31063. */
  31064. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  31065. w1, h1, w2, h2, dest, alpha01) {
  31066. if (components !== 1 && components !== 3) {
  31067. error('Unsupported component count for resizing.');
  31068. }
  31069. var length = w2 * h2 * components;
  31070. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  31071. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  31072. var xRatio = w1 / w2;
  31073. var yRatio = h1 / h2;
  31074. var i, j, py, newIndex = 0, oldIndex;
  31075. var xScaled = new Uint16Array(w2);
  31076. var w1Scanline = w1 * components;
  31077. if (alpha01 !== 1) {
  31078. alpha01 = 0;
  31079. }
  31080. for (j = 0; j < w2; j++) {
  31081. xScaled[j] = Math.floor(j * xRatio) * components;
  31082. }
  31083. if (components === 1) {
  31084. for (i = 0; i < h2; i++) {
  31085. py = Math.floor(i * yRatio) * w1Scanline;
  31086. for (j = 0; j < w2; j++) {
  31087. oldIndex = py + xScaled[j];
  31088. temp[newIndex++] = pixels[oldIndex];
  31089. }
  31090. }
  31091. } else if (components === 3) {
  31092. for (i = 0; i < h2; i++) {
  31093. py = Math.floor(i * yRatio) * w1Scanline;
  31094. for (j = 0; j < w2; j++) {
  31095. oldIndex = py + xScaled[j];
  31096. temp[newIndex++] = pixels[oldIndex++];
  31097. temp[newIndex++] = pixels[oldIndex++];
  31098. temp[newIndex++] = pixels[oldIndex++];
  31099. newIndex += alpha01;
  31100. }
  31101. }
  31102. }
  31103. return temp;
  31104. };
  31105. PDFImage.createMask =
  31106. function PDFImage_createMask(imgArray, width, height,
  31107. imageIsFromDecodeStream, inverseDecode) {
  31108. // |imgArray| might not contain full data for every pixel of the mask, so
  31109. // we need to distinguish between |computedLength| and |actualLength|.
  31110. // In particular, if inverseDecode is true, then the array we return must
  31111. // have a length of |computedLength|.
  31112. var computedLength = ((width + 7) >> 3) * height;
  31113. var actualLength = imgArray.byteLength;
  31114. var haveFullData = computedLength === actualLength;
  31115. var data, i;
  31116. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  31117. // imgArray came from a DecodeStream and its data is in an appropriate
  31118. // form, so we can just transfer it.
  31119. data = imgArray;
  31120. } else if (!inverseDecode) {
  31121. data = new Uint8Array(actualLength);
  31122. data.set(imgArray);
  31123. } else {
  31124. data = new Uint8Array(computedLength);
  31125. data.set(imgArray);
  31126. for (i = actualLength; i < computedLength; i++) {
  31127. data[i] = 0xff;
  31128. }
  31129. }
  31130. // If necessary, invert the original mask data (but not any extra we might
  31131. // have added above). It's safe to modify the array -- whether it's the
  31132. // original or a copy, we're about to transfer it anyway, so nothing else
  31133. // in this thread can be relying on its contents.
  31134. if (inverseDecode) {
  31135. for (i = 0; i < actualLength; i++) {
  31136. data[i] = ~data[i];
  31137. }
  31138. }
  31139. return {data: data, width: width, height: height};
  31140. };
  31141. PDFImage.prototype = {
  31142. get drawWidth() {
  31143. return Math.max(this.width,
  31144. this.smask && this.smask.width || 0,
  31145. this.mask && this.mask.width || 0);
  31146. },
  31147. get drawHeight() {
  31148. return Math.max(this.height,
  31149. this.smask && this.smask.height || 0,
  31150. this.mask && this.mask.height || 0);
  31151. },
  31152. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  31153. var bpc = this.bpc;
  31154. var numComps = this.numComps;
  31155. var decodeAddends = this.decodeAddends;
  31156. var decodeCoefficients = this.decodeCoefficients;
  31157. var max = (1 << bpc) - 1;
  31158. var i, ii;
  31159. if (bpc === 1) {
  31160. // If the buffer needed decode that means it just needs to be inverted.
  31161. for (i = 0, ii = buffer.length; i < ii; i++) {
  31162. buffer[i] = +!(buffer[i]);
  31163. }
  31164. return;
  31165. }
  31166. var index = 0;
  31167. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  31168. for (var j = 0; j < numComps; j++) {
  31169. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  31170. decodeCoefficients[j], max);
  31171. index++;
  31172. }
  31173. }
  31174. },
  31175. getComponents: function PDFImage_getComponents(buffer) {
  31176. var bpc = this.bpc;
  31177. // This image doesn't require any extra work.
  31178. if (bpc === 8) {
  31179. return buffer;
  31180. }
  31181. var width = this.width;
  31182. var height = this.height;
  31183. var numComps = this.numComps;
  31184. var length = width * height * numComps;
  31185. var bufferPos = 0;
  31186. var output = (bpc <= 8 ? new Uint8Array(length) :
  31187. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  31188. var rowComps = width * numComps;
  31189. var max = (1 << bpc) - 1;
  31190. var i = 0, ii, buf;
  31191. if (bpc === 1) {
  31192. // Optimization for reading 1 bpc images.
  31193. var mask, loop1End, loop2End;
  31194. for (var j = 0; j < height; j++) {
  31195. loop1End = i + (rowComps & ~7);
  31196. loop2End = i + rowComps;
  31197. // unroll loop for all full bytes
  31198. while (i < loop1End) {
  31199. buf = buffer[bufferPos++];
  31200. output[i] = (buf >> 7) & 1;
  31201. output[i + 1] = (buf >> 6) & 1;
  31202. output[i + 2] = (buf >> 5) & 1;
  31203. output[i + 3] = (buf >> 4) & 1;
  31204. output[i + 4] = (buf >> 3) & 1;
  31205. output[i + 5] = (buf >> 2) & 1;
  31206. output[i + 6] = (buf >> 1) & 1;
  31207. output[i + 7] = buf & 1;
  31208. i += 8;
  31209. }
  31210. // handle remaing bits
  31211. if (i < loop2End) {
  31212. buf = buffer[bufferPos++];
  31213. mask = 128;
  31214. while (i < loop2End) {
  31215. output[i++] = +!!(buf & mask);
  31216. mask >>= 1;
  31217. }
  31218. }
  31219. }
  31220. } else {
  31221. // The general case that handles all other bpc values.
  31222. var bits = 0;
  31223. buf = 0;
  31224. for (i = 0, ii = length; i < ii; ++i) {
  31225. if (i % rowComps === 0) {
  31226. buf = 0;
  31227. bits = 0;
  31228. }
  31229. while (bits < bpc) {
  31230. buf = (buf << 8) | buffer[bufferPos++];
  31231. bits += 8;
  31232. }
  31233. var remainingBits = bits - bpc;
  31234. var value = buf >> remainingBits;
  31235. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  31236. buf = buf & ((1 << remainingBits) - 1);
  31237. bits = remainingBits;
  31238. }
  31239. }
  31240. return output;
  31241. },
  31242. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  31243. actualHeight, image) {
  31244. var smask = this.smask;
  31245. var mask = this.mask;
  31246. var alphaBuf, sw, sh, i, ii, j;
  31247. if (smask) {
  31248. sw = smask.width;
  31249. sh = smask.height;
  31250. alphaBuf = new Uint8Array(sw * sh);
  31251. smask.fillGrayBuffer(alphaBuf);
  31252. if (sw !== width || sh !== height) {
  31253. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  31254. height);
  31255. }
  31256. } else if (mask) {
  31257. if (mask instanceof PDFImage) {
  31258. sw = mask.width;
  31259. sh = mask.height;
  31260. alphaBuf = new Uint8Array(sw * sh);
  31261. mask.numComps = 1;
  31262. mask.fillGrayBuffer(alphaBuf);
  31263. // Need to invert values in rgbaBuf
  31264. for (i = 0, ii = sw * sh; i < ii; ++i) {
  31265. alphaBuf[i] = 255 - alphaBuf[i];
  31266. }
  31267. if (sw !== width || sh !== height) {
  31268. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  31269. height);
  31270. }
  31271. } else if (isArray(mask)) {
  31272. // Color key mask: if any of the compontents are outside the range
  31273. // then they should be painted.
  31274. alphaBuf = new Uint8Array(width * height);
  31275. var numComps = this.numComps;
  31276. for (i = 0, ii = width * height; i < ii; ++i) {
  31277. var opacity = 0;
  31278. var imageOffset = i * numComps;
  31279. for (j = 0; j < numComps; ++j) {
  31280. var color = image[imageOffset + j];
  31281. var maskOffset = j * 2;
  31282. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  31283. opacity = 255;
  31284. break;
  31285. }
  31286. }
  31287. alphaBuf[i] = opacity;
  31288. }
  31289. } else {
  31290. error('Unknown mask format.');
  31291. }
  31292. }
  31293. if (alphaBuf) {
  31294. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  31295. rgbaBuf[j] = alphaBuf[i];
  31296. }
  31297. } else {
  31298. // No mask.
  31299. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  31300. rgbaBuf[j] = 255;
  31301. }
  31302. }
  31303. },
  31304. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  31305. var matte = this.smask && this.smask.matte;
  31306. if (!matte) {
  31307. return;
  31308. }
  31309. var matteRgb = this.colorSpace.getRgb(matte, 0);
  31310. var matteR = matteRgb[0];
  31311. var matteG = matteRgb[1];
  31312. var matteB = matteRgb[2];
  31313. var length = width * height * 4;
  31314. var r, g, b;
  31315. for (var i = 0; i < length; i += 4) {
  31316. var alpha = buffer[i + 3];
  31317. if (alpha === 0) {
  31318. // according formula we have to get Infinity in all components
  31319. // making it white (typical paper color) should be okay
  31320. buffer[i] = 255;
  31321. buffer[i + 1] = 255;
  31322. buffer[i + 2] = 255;
  31323. continue;
  31324. }
  31325. var k = 255 / alpha;
  31326. r = (buffer[i] - matteR) * k + matteR;
  31327. g = (buffer[i + 1] - matteG) * k + matteG;
  31328. b = (buffer[i + 2] - matteB) * k + matteB;
  31329. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  31330. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  31331. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  31332. }
  31333. },
  31334. createImageData: function PDFImage_createImageData(forceRGBA) {
  31335. var drawWidth = this.drawWidth;
  31336. var drawHeight = this.drawHeight;
  31337. var imgData = { // other fields are filled in below
  31338. width: drawWidth,
  31339. height: drawHeight
  31340. };
  31341. var numComps = this.numComps;
  31342. var originalWidth = this.width;
  31343. var originalHeight = this.height;
  31344. var bpc = this.bpc;
  31345. // Rows start at byte boundary.
  31346. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  31347. var imgArray;
  31348. if (!forceRGBA) {
  31349. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  31350. // without any complications, we pass a same-sized copy to the main
  31351. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  31352. // of memory for many scanned documents. It's also much faster.
  31353. //
  31354. // Similarly, if it is a 24-bit-per pixel RGB image without any
  31355. // complications, we avoid expanding by 1.333x to RGBA form.
  31356. var kind;
  31357. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  31358. kind = ImageKind.GRAYSCALE_1BPP;
  31359. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  31360. !this.needsDecode) {
  31361. kind = ImageKind.RGB_24BPP;
  31362. }
  31363. if (kind && !this.smask && !this.mask &&
  31364. drawWidth === originalWidth && drawHeight === originalHeight) {
  31365. imgData.kind = kind;
  31366. imgArray = this.getImageBytes(originalHeight * rowBytes);
  31367. // If imgArray came from a DecodeStream, we're safe to transfer it
  31368. // (and thus neuter it) because it will constitute the entire
  31369. // DecodeStream's data. But if it came from a Stream, we need to
  31370. // copy it because it'll only be a portion of the Stream's data, and
  31371. // the rest will be read later on.
  31372. if (this.image instanceof DecodeStream) {
  31373. imgData.data = imgArray;
  31374. } else {
  31375. var newArray = new Uint8Array(imgArray.length);
  31376. newArray.set(imgArray);
  31377. imgData.data = newArray;
  31378. }
  31379. if (this.needsDecode) {
  31380. // Invert the buffer (which must be grayscale if we reached here).
  31381. assert(kind === ImageKind.GRAYSCALE_1BPP);
  31382. var buffer = imgData.data;
  31383. for (var i = 0, ii = buffer.length; i < ii; i++) {
  31384. buffer[i] ^= 0xff;
  31385. }
  31386. }
  31387. return imgData;
  31388. }
  31389. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  31390. (this.colorSpace.name === 'DeviceGray' ||
  31391. this.colorSpace.name === 'DeviceRGB' ||
  31392. this.colorSpace.name === 'DeviceCMYK')) {
  31393. imgData.kind = ImageKind.RGB_24BPP;
  31394. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  31395. drawWidth, drawHeight, true);
  31396. return imgData;
  31397. }
  31398. }
  31399. imgArray = this.getImageBytes(originalHeight * rowBytes);
  31400. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  31401. var actualHeight = 0 | (imgArray.length / rowBytes *
  31402. drawHeight / originalHeight);
  31403. var comps = this.getComponents(imgArray);
  31404. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  31405. // more compact RGB_24BPP form if allowable.
  31406. var alpha01, maybeUndoPreblend;
  31407. if (!forceRGBA && !this.smask && !this.mask) {
  31408. imgData.kind = ImageKind.RGB_24BPP;
  31409. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  31410. alpha01 = 0;
  31411. maybeUndoPreblend = false;
  31412. } else {
  31413. imgData.kind = ImageKind.RGBA_32BPP;
  31414. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  31415. alpha01 = 1;
  31416. maybeUndoPreblend = true;
  31417. // Color key masking (opacity) must be performed before decoding.
  31418. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  31419. comps);
  31420. }
  31421. if (this.needsDecode) {
  31422. this.decodeBuffer(comps);
  31423. }
  31424. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  31425. drawWidth, drawHeight, actualHeight, bpc, comps,
  31426. alpha01);
  31427. if (maybeUndoPreblend) {
  31428. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  31429. }
  31430. return imgData;
  31431. },
  31432. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  31433. var numComps = this.numComps;
  31434. if (numComps !== 1) {
  31435. error('Reading gray scale from a color image: ' + numComps);
  31436. }
  31437. var width = this.width;
  31438. var height = this.height;
  31439. var bpc = this.bpc;
  31440. // rows start at byte boundary
  31441. var rowBytes = (width * numComps * bpc + 7) >> 3;
  31442. var imgArray = this.getImageBytes(height * rowBytes);
  31443. var comps = this.getComponents(imgArray);
  31444. var i, length;
  31445. if (bpc === 1) {
  31446. // inline decoding (= inversion) for 1 bpc images
  31447. length = width * height;
  31448. if (this.needsDecode) {
  31449. // invert and scale to {0, 255}
  31450. for (i = 0; i < length; ++i) {
  31451. buffer[i] = (comps[i] - 1) & 255;
  31452. }
  31453. } else {
  31454. // scale to {0, 255}
  31455. for (i = 0; i < length; ++i) {
  31456. buffer[i] = (-comps[i]) & 255;
  31457. }
  31458. }
  31459. return;
  31460. }
  31461. if (this.needsDecode) {
  31462. this.decodeBuffer(comps);
  31463. }
  31464. length = width * height;
  31465. // we aren't using a colorspace so we need to scale the value
  31466. var scale = 255 / ((1 << bpc) - 1);
  31467. for (i = 0; i < length; ++i) {
  31468. buffer[i] = (scale * comps[i]) | 0;
  31469. }
  31470. },
  31471. getImageBytes: function PDFImage_getImageBytes(length,
  31472. drawWidth, drawHeight,
  31473. forceRGB) {
  31474. this.image.reset();
  31475. this.image.drawWidth = drawWidth || this.width;
  31476. this.image.drawHeight = drawHeight || this.height;
  31477. this.image.forceRGB = !!forceRGB;
  31478. return this.image.getBytes(length);
  31479. }
  31480. };
  31481. return PDFImage;
  31482. })();
  31483. // The Metrics object contains glyph widths (in glyph space units).
  31484. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  31485. // space unit corresponds to 1/1000th of text space unit.
  31486. var Metrics = {
  31487. 'Courier': 600,
  31488. 'Courier-Bold': 600,
  31489. 'Courier-BoldOblique': 600,
  31490. 'Courier-Oblique': 600,
  31491. 'Helvetica' : {
  31492. 'space': 278,
  31493. 'exclam': 278,
  31494. 'quotedbl': 355,
  31495. 'numbersign': 556,
  31496. 'dollar': 556,
  31497. 'percent': 889,
  31498. 'ampersand': 667,
  31499. 'quoteright': 222,
  31500. 'parenleft': 333,
  31501. 'parenright': 333,
  31502. 'asterisk': 389,
  31503. 'plus': 584,
  31504. 'comma': 278,
  31505. 'hyphen': 333,
  31506. 'period': 278,
  31507. 'slash': 278,
  31508. 'zero': 556,
  31509. 'one': 556,
  31510. 'two': 556,
  31511. 'three': 556,
  31512. 'four': 556,
  31513. 'five': 556,
  31514. 'six': 556,
  31515. 'seven': 556,
  31516. 'eight': 556,
  31517. 'nine': 556,
  31518. 'colon': 278,
  31519. 'semicolon': 278,
  31520. 'less': 584,
  31521. 'equal': 584,
  31522. 'greater': 584,
  31523. 'question': 556,
  31524. 'at': 1015,
  31525. 'A': 667,
  31526. 'B': 667,
  31527. 'C': 722,
  31528. 'D': 722,
  31529. 'E': 667,
  31530. 'F': 611,
  31531. 'G': 778,
  31532. 'H': 722,
  31533. 'I': 278,
  31534. 'J': 500,
  31535. 'K': 667,
  31536. 'L': 556,
  31537. 'M': 833,
  31538. 'N': 722,
  31539. 'O': 778,
  31540. 'P': 667,
  31541. 'Q': 778,
  31542. 'R': 722,
  31543. 'S': 667,
  31544. 'T': 611,
  31545. 'U': 722,
  31546. 'V': 667,
  31547. 'W': 944,
  31548. 'X': 667,
  31549. 'Y': 667,
  31550. 'Z': 611,
  31551. 'bracketleft': 278,
  31552. 'backslash': 278,
  31553. 'bracketright': 278,
  31554. 'asciicircum': 469,
  31555. 'underscore': 556,
  31556. 'quoteleft': 222,
  31557. 'a': 556,
  31558. 'b': 556,
  31559. 'c': 500,
  31560. 'd': 556,
  31561. 'e': 556,
  31562. 'f': 278,
  31563. 'g': 556,
  31564. 'h': 556,
  31565. 'i': 222,
  31566. 'j': 222,
  31567. 'k': 500,
  31568. 'l': 222,
  31569. 'm': 833,
  31570. 'n': 556,
  31571. 'o': 556,
  31572. 'p': 556,
  31573. 'q': 556,
  31574. 'r': 333,
  31575. 's': 500,
  31576. 't': 278,
  31577. 'u': 556,
  31578. 'v': 500,
  31579. 'w': 722,
  31580. 'x': 500,
  31581. 'y': 500,
  31582. 'z': 500,
  31583. 'braceleft': 334,
  31584. 'bar': 260,
  31585. 'braceright': 334,
  31586. 'asciitilde': 584,
  31587. 'exclamdown': 333,
  31588. 'cent': 556,
  31589. 'sterling': 556,
  31590. 'fraction': 167,
  31591. 'yen': 556,
  31592. 'florin': 556,
  31593. 'section': 556,
  31594. 'currency': 556,
  31595. 'quotesingle': 191,
  31596. 'quotedblleft': 333,
  31597. 'guillemotleft': 556,
  31598. 'guilsinglleft': 333,
  31599. 'guilsinglright': 333,
  31600. 'fi': 500,
  31601. 'fl': 500,
  31602. 'endash': 556,
  31603. 'dagger': 556,
  31604. 'daggerdbl': 556,
  31605. 'periodcentered': 278,
  31606. 'paragraph': 537,
  31607. 'bullet': 350,
  31608. 'quotesinglbase': 222,
  31609. 'quotedblbase': 333,
  31610. 'quotedblright': 333,
  31611. 'guillemotright': 556,
  31612. 'ellipsis': 1000,
  31613. 'perthousand': 1000,
  31614. 'questiondown': 611,
  31615. 'grave': 333,
  31616. 'acute': 333,
  31617. 'circumflex': 333,
  31618. 'tilde': 333,
  31619. 'macron': 333,
  31620. 'breve': 333,
  31621. 'dotaccent': 333,
  31622. 'dieresis': 333,
  31623. 'ring': 333,
  31624. 'cedilla': 333,
  31625. 'hungarumlaut': 333,
  31626. 'ogonek': 333,
  31627. 'caron': 333,
  31628. 'emdash': 1000,
  31629. 'AE': 1000,
  31630. 'ordfeminine': 370,
  31631. 'Lslash': 556,
  31632. 'Oslash': 778,
  31633. 'OE': 1000,
  31634. 'ordmasculine': 365,
  31635. 'ae': 889,
  31636. 'dotlessi': 278,
  31637. 'lslash': 222,
  31638. 'oslash': 611,
  31639. 'oe': 944,
  31640. 'germandbls': 611,
  31641. 'Idieresis': 278,
  31642. 'eacute': 556,
  31643. 'abreve': 556,
  31644. 'uhungarumlaut': 556,
  31645. 'ecaron': 556,
  31646. 'Ydieresis': 667,
  31647. 'divide': 584,
  31648. 'Yacute': 667,
  31649. 'Acircumflex': 667,
  31650. 'aacute': 556,
  31651. 'Ucircumflex': 722,
  31652. 'yacute': 500,
  31653. 'scommaaccent': 500,
  31654. 'ecircumflex': 556,
  31655. 'Uring': 722,
  31656. 'Udieresis': 722,
  31657. 'aogonek': 556,
  31658. 'Uacute': 722,
  31659. 'uogonek': 556,
  31660. 'Edieresis': 667,
  31661. 'Dcroat': 722,
  31662. 'commaaccent': 250,
  31663. 'copyright': 737,
  31664. 'Emacron': 667,
  31665. 'ccaron': 500,
  31666. 'aring': 556,
  31667. 'Ncommaaccent': 722,
  31668. 'lacute': 222,
  31669. 'agrave': 556,
  31670. 'Tcommaaccent': 611,
  31671. 'Cacute': 722,
  31672. 'atilde': 556,
  31673. 'Edotaccent': 667,
  31674. 'scaron': 500,
  31675. 'scedilla': 500,
  31676. 'iacute': 278,
  31677. 'lozenge': 471,
  31678. 'Rcaron': 722,
  31679. 'Gcommaaccent': 778,
  31680. 'ucircumflex': 556,
  31681. 'acircumflex': 556,
  31682. 'Amacron': 667,
  31683. 'rcaron': 333,
  31684. 'ccedilla': 500,
  31685. 'Zdotaccent': 611,
  31686. 'Thorn': 667,
  31687. 'Omacron': 778,
  31688. 'Racute': 722,
  31689. 'Sacute': 667,
  31690. 'dcaron': 643,
  31691. 'Umacron': 722,
  31692. 'uring': 556,
  31693. 'threesuperior': 333,
  31694. 'Ograve': 778,
  31695. 'Agrave': 667,
  31696. 'Abreve': 667,
  31697. 'multiply': 584,
  31698. 'uacute': 556,
  31699. 'Tcaron': 611,
  31700. 'partialdiff': 476,
  31701. 'ydieresis': 500,
  31702. 'Nacute': 722,
  31703. 'icircumflex': 278,
  31704. 'Ecircumflex': 667,
  31705. 'adieresis': 556,
  31706. 'edieresis': 556,
  31707. 'cacute': 500,
  31708. 'nacute': 556,
  31709. 'umacron': 556,
  31710. 'Ncaron': 722,
  31711. 'Iacute': 278,
  31712. 'plusminus': 584,
  31713. 'brokenbar': 260,
  31714. 'registered': 737,
  31715. 'Gbreve': 778,
  31716. 'Idotaccent': 278,
  31717. 'summation': 600,
  31718. 'Egrave': 667,
  31719. 'racute': 333,
  31720. 'omacron': 556,
  31721. 'Zacute': 611,
  31722. 'Zcaron': 611,
  31723. 'greaterequal': 549,
  31724. 'Eth': 722,
  31725. 'Ccedilla': 722,
  31726. 'lcommaaccent': 222,
  31727. 'tcaron': 317,
  31728. 'eogonek': 556,
  31729. 'Uogonek': 722,
  31730. 'Aacute': 667,
  31731. 'Adieresis': 667,
  31732. 'egrave': 556,
  31733. 'zacute': 500,
  31734. 'iogonek': 222,
  31735. 'Oacute': 778,
  31736. 'oacute': 556,
  31737. 'amacron': 556,
  31738. 'sacute': 500,
  31739. 'idieresis': 278,
  31740. 'Ocircumflex': 778,
  31741. 'Ugrave': 722,
  31742. 'Delta': 612,
  31743. 'thorn': 556,
  31744. 'twosuperior': 333,
  31745. 'Odieresis': 778,
  31746. 'mu': 556,
  31747. 'igrave': 278,
  31748. 'ohungarumlaut': 556,
  31749. 'Eogonek': 667,
  31750. 'dcroat': 556,
  31751. 'threequarters': 834,
  31752. 'Scedilla': 667,
  31753. 'lcaron': 299,
  31754. 'Kcommaaccent': 667,
  31755. 'Lacute': 556,
  31756. 'trademark': 1000,
  31757. 'edotaccent': 556,
  31758. 'Igrave': 278,
  31759. 'Imacron': 278,
  31760. 'Lcaron': 556,
  31761. 'onehalf': 834,
  31762. 'lessequal': 549,
  31763. 'ocircumflex': 556,
  31764. 'ntilde': 556,
  31765. 'Uhungarumlaut': 722,
  31766. 'Eacute': 667,
  31767. 'emacron': 556,
  31768. 'gbreve': 556,
  31769. 'onequarter': 834,
  31770. 'Scaron': 667,
  31771. 'Scommaaccent': 667,
  31772. 'Ohungarumlaut': 778,
  31773. 'degree': 400,
  31774. 'ograve': 556,
  31775. 'Ccaron': 722,
  31776. 'ugrave': 556,
  31777. 'radical': 453,
  31778. 'Dcaron': 722,
  31779. 'rcommaaccent': 333,
  31780. 'Ntilde': 722,
  31781. 'otilde': 556,
  31782. 'Rcommaaccent': 722,
  31783. 'Lcommaaccent': 556,
  31784. 'Atilde': 667,
  31785. 'Aogonek': 667,
  31786. 'Aring': 667,
  31787. 'Otilde': 778,
  31788. 'zdotaccent': 500,
  31789. 'Ecaron': 667,
  31790. 'Iogonek': 278,
  31791. 'kcommaaccent': 500,
  31792. 'minus': 584,
  31793. 'Icircumflex': 278,
  31794. 'ncaron': 556,
  31795. 'tcommaaccent': 278,
  31796. 'logicalnot': 584,
  31797. 'odieresis': 556,
  31798. 'udieresis': 556,
  31799. 'notequal': 549,
  31800. 'gcommaaccent': 556,
  31801. 'eth': 556,
  31802. 'zcaron': 500,
  31803. 'ncommaaccent': 556,
  31804. 'onesuperior': 333,
  31805. 'imacron': 278,
  31806. 'Euro': 556
  31807. },
  31808. 'Helvetica-Bold': {
  31809. 'space': 278,
  31810. 'exclam': 333,
  31811. 'quotedbl': 474,
  31812. 'numbersign': 556,
  31813. 'dollar': 556,
  31814. 'percent': 889,
  31815. 'ampersand': 722,
  31816. 'quoteright': 278,
  31817. 'parenleft': 333,
  31818. 'parenright': 333,
  31819. 'asterisk': 389,
  31820. 'plus': 584,
  31821. 'comma': 278,
  31822. 'hyphen': 333,
  31823. 'period': 278,
  31824. 'slash': 278,
  31825. 'zero': 556,
  31826. 'one': 556,
  31827. 'two': 556,
  31828. 'three': 556,
  31829. 'four': 556,
  31830. 'five': 556,
  31831. 'six': 556,
  31832. 'seven': 556,
  31833. 'eight': 556,
  31834. 'nine': 556,
  31835. 'colon': 333,
  31836. 'semicolon': 333,
  31837. 'less': 584,
  31838. 'equal': 584,
  31839. 'greater': 584,
  31840. 'question': 611,
  31841. 'at': 975,
  31842. 'A': 722,
  31843. 'B': 722,
  31844. 'C': 722,
  31845. 'D': 722,
  31846. 'E': 667,
  31847. 'F': 611,
  31848. 'G': 778,
  31849. 'H': 722,
  31850. 'I': 278,
  31851. 'J': 556,
  31852. 'K': 722,
  31853. 'L': 611,
  31854. 'M': 833,
  31855. 'N': 722,
  31856. 'O': 778,
  31857. 'P': 667,
  31858. 'Q': 778,
  31859. 'R': 722,
  31860. 'S': 667,
  31861. 'T': 611,
  31862. 'U': 722,
  31863. 'V': 667,
  31864. 'W': 944,
  31865. 'X': 667,
  31866. 'Y': 667,
  31867. 'Z': 611,
  31868. 'bracketleft': 333,
  31869. 'backslash': 278,
  31870. 'bracketright': 333,
  31871. 'asciicircum': 584,
  31872. 'underscore': 556,
  31873. 'quoteleft': 278,
  31874. 'a': 556,
  31875. 'b': 611,
  31876. 'c': 556,
  31877. 'd': 611,
  31878. 'e': 556,
  31879. 'f': 333,
  31880. 'g': 611,
  31881. 'h': 611,
  31882. 'i': 278,
  31883. 'j': 278,
  31884. 'k': 556,
  31885. 'l': 278,
  31886. 'm': 889,
  31887. 'n': 611,
  31888. 'o': 611,
  31889. 'p': 611,
  31890. 'q': 611,
  31891. 'r': 389,
  31892. 's': 556,
  31893. 't': 333,
  31894. 'u': 611,
  31895. 'v': 556,
  31896. 'w': 778,
  31897. 'x': 556,
  31898. 'y': 556,
  31899. 'z': 500,
  31900. 'braceleft': 389,
  31901. 'bar': 280,
  31902. 'braceright': 389,
  31903. 'asciitilde': 584,
  31904. 'exclamdown': 333,
  31905. 'cent': 556,
  31906. 'sterling': 556,
  31907. 'fraction': 167,
  31908. 'yen': 556,
  31909. 'florin': 556,
  31910. 'section': 556,
  31911. 'currency': 556,
  31912. 'quotesingle': 238,
  31913. 'quotedblleft': 500,
  31914. 'guillemotleft': 556,
  31915. 'guilsinglleft': 333,
  31916. 'guilsinglright': 333,
  31917. 'fi': 611,
  31918. 'fl': 611,
  31919. 'endash': 556,
  31920. 'dagger': 556,
  31921. 'daggerdbl': 556,
  31922. 'periodcentered': 278,
  31923. 'paragraph': 556,
  31924. 'bullet': 350,
  31925. 'quotesinglbase': 278,
  31926. 'quotedblbase': 500,
  31927. 'quotedblright': 500,
  31928. 'guillemotright': 556,
  31929. 'ellipsis': 1000,
  31930. 'perthousand': 1000,
  31931. 'questiondown': 611,
  31932. 'grave': 333,
  31933. 'acute': 333,
  31934. 'circumflex': 333,
  31935. 'tilde': 333,
  31936. 'macron': 333,
  31937. 'breve': 333,
  31938. 'dotaccent': 333,
  31939. 'dieresis': 333,
  31940. 'ring': 333,
  31941. 'cedilla': 333,
  31942. 'hungarumlaut': 333,
  31943. 'ogonek': 333,
  31944. 'caron': 333,
  31945. 'emdash': 1000,
  31946. 'AE': 1000,
  31947. 'ordfeminine': 370,
  31948. 'Lslash': 611,
  31949. 'Oslash': 778,
  31950. 'OE': 1000,
  31951. 'ordmasculine': 365,
  31952. 'ae': 889,
  31953. 'dotlessi': 278,
  31954. 'lslash': 278,
  31955. 'oslash': 611,
  31956. 'oe': 944,
  31957. 'germandbls': 611,
  31958. 'Idieresis': 278,
  31959. 'eacute': 556,
  31960. 'abreve': 556,
  31961. 'uhungarumlaut': 611,
  31962. 'ecaron': 556,
  31963. 'Ydieresis': 667,
  31964. 'divide': 584,
  31965. 'Yacute': 667,
  31966. 'Acircumflex': 722,
  31967. 'aacute': 556,
  31968. 'Ucircumflex': 722,
  31969. 'yacute': 556,
  31970. 'scommaaccent': 556,
  31971. 'ecircumflex': 556,
  31972. 'Uring': 722,
  31973. 'Udieresis': 722,
  31974. 'aogonek': 556,
  31975. 'Uacute': 722,
  31976. 'uogonek': 611,
  31977. 'Edieresis': 667,
  31978. 'Dcroat': 722,
  31979. 'commaaccent': 250,
  31980. 'copyright': 737,
  31981. 'Emacron': 667,
  31982. 'ccaron': 556,
  31983. 'aring': 556,
  31984. 'Ncommaaccent': 722,
  31985. 'lacute': 278,
  31986. 'agrave': 556,
  31987. 'Tcommaaccent': 611,
  31988. 'Cacute': 722,
  31989. 'atilde': 556,
  31990. 'Edotaccent': 667,
  31991. 'scaron': 556,
  31992. 'scedilla': 556,
  31993. 'iacute': 278,
  31994. 'lozenge': 494,
  31995. 'Rcaron': 722,
  31996. 'Gcommaaccent': 778,
  31997. 'ucircumflex': 611,
  31998. 'acircumflex': 556,
  31999. 'Amacron': 722,
  32000. 'rcaron': 389,
  32001. 'ccedilla': 556,
  32002. 'Zdotaccent': 611,
  32003. 'Thorn': 667,
  32004. 'Omacron': 778,
  32005. 'Racute': 722,
  32006. 'Sacute': 667,
  32007. 'dcaron': 743,
  32008. 'Umacron': 722,
  32009. 'uring': 611,
  32010. 'threesuperior': 333,
  32011. 'Ograve': 778,
  32012. 'Agrave': 722,
  32013. 'Abreve': 722,
  32014. 'multiply': 584,
  32015. 'uacute': 611,
  32016. 'Tcaron': 611,
  32017. 'partialdiff': 494,
  32018. 'ydieresis': 556,
  32019. 'Nacute': 722,
  32020. 'icircumflex': 278,
  32021. 'Ecircumflex': 667,
  32022. 'adieresis': 556,
  32023. 'edieresis': 556,
  32024. 'cacute': 556,
  32025. 'nacute': 611,
  32026. 'umacron': 611,
  32027. 'Ncaron': 722,
  32028. 'Iacute': 278,
  32029. 'plusminus': 584,
  32030. 'brokenbar': 280,
  32031. 'registered': 737,
  32032. 'Gbreve': 778,
  32033. 'Idotaccent': 278,
  32034. 'summation': 600,
  32035. 'Egrave': 667,
  32036. 'racute': 389,
  32037. 'omacron': 611,
  32038. 'Zacute': 611,
  32039. 'Zcaron': 611,
  32040. 'greaterequal': 549,
  32041. 'Eth': 722,
  32042. 'Ccedilla': 722,
  32043. 'lcommaaccent': 278,
  32044. 'tcaron': 389,
  32045. 'eogonek': 556,
  32046. 'Uogonek': 722,
  32047. 'Aacute': 722,
  32048. 'Adieresis': 722,
  32049. 'egrave': 556,
  32050. 'zacute': 500,
  32051. 'iogonek': 278,
  32052. 'Oacute': 778,
  32053. 'oacute': 611,
  32054. 'amacron': 556,
  32055. 'sacute': 556,
  32056. 'idieresis': 278,
  32057. 'Ocircumflex': 778,
  32058. 'Ugrave': 722,
  32059. 'Delta': 612,
  32060. 'thorn': 611,
  32061. 'twosuperior': 333,
  32062. 'Odieresis': 778,
  32063. 'mu': 611,
  32064. 'igrave': 278,
  32065. 'ohungarumlaut': 611,
  32066. 'Eogonek': 667,
  32067. 'dcroat': 611,
  32068. 'threequarters': 834,
  32069. 'Scedilla': 667,
  32070. 'lcaron': 400,
  32071. 'Kcommaaccent': 722,
  32072. 'Lacute': 611,
  32073. 'trademark': 1000,
  32074. 'edotaccent': 556,
  32075. 'Igrave': 278,
  32076. 'Imacron': 278,
  32077. 'Lcaron': 611,
  32078. 'onehalf': 834,
  32079. 'lessequal': 549,
  32080. 'ocircumflex': 611,
  32081. 'ntilde': 611,
  32082. 'Uhungarumlaut': 722,
  32083. 'Eacute': 667,
  32084. 'emacron': 556,
  32085. 'gbreve': 611,
  32086. 'onequarter': 834,
  32087. 'Scaron': 667,
  32088. 'Scommaaccent': 667,
  32089. 'Ohungarumlaut': 778,
  32090. 'degree': 400,
  32091. 'ograve': 611,
  32092. 'Ccaron': 722,
  32093. 'ugrave': 611,
  32094. 'radical': 549,
  32095. 'Dcaron': 722,
  32096. 'rcommaaccent': 389,
  32097. 'Ntilde': 722,
  32098. 'otilde': 611,
  32099. 'Rcommaaccent': 722,
  32100. 'Lcommaaccent': 611,
  32101. 'Atilde': 722,
  32102. 'Aogonek': 722,
  32103. 'Aring': 722,
  32104. 'Otilde': 778,
  32105. 'zdotaccent': 500,
  32106. 'Ecaron': 667,
  32107. 'Iogonek': 278,
  32108. 'kcommaaccent': 556,
  32109. 'minus': 584,
  32110. 'Icircumflex': 278,
  32111. 'ncaron': 611,
  32112. 'tcommaaccent': 333,
  32113. 'logicalnot': 584,
  32114. 'odieresis': 611,
  32115. 'udieresis': 611,
  32116. 'notequal': 549,
  32117. 'gcommaaccent': 611,
  32118. 'eth': 611,
  32119. 'zcaron': 500,
  32120. 'ncommaaccent': 611,
  32121. 'onesuperior': 333,
  32122. 'imacron': 278,
  32123. 'Euro': 556
  32124. },
  32125. 'Helvetica-BoldOblique': {
  32126. 'space': 278,
  32127. 'exclam': 333,
  32128. 'quotedbl': 474,
  32129. 'numbersign': 556,
  32130. 'dollar': 556,
  32131. 'percent': 889,
  32132. 'ampersand': 722,
  32133. 'quoteright': 278,
  32134. 'parenleft': 333,
  32135. 'parenright': 333,
  32136. 'asterisk': 389,
  32137. 'plus': 584,
  32138. 'comma': 278,
  32139. 'hyphen': 333,
  32140. 'period': 278,
  32141. 'slash': 278,
  32142. 'zero': 556,
  32143. 'one': 556,
  32144. 'two': 556,
  32145. 'three': 556,
  32146. 'four': 556,
  32147. 'five': 556,
  32148. 'six': 556,
  32149. 'seven': 556,
  32150. 'eight': 556,
  32151. 'nine': 556,
  32152. 'colon': 333,
  32153. 'semicolon': 333,
  32154. 'less': 584,
  32155. 'equal': 584,
  32156. 'greater': 584,
  32157. 'question': 611,
  32158. 'at': 975,
  32159. 'A': 722,
  32160. 'B': 722,
  32161. 'C': 722,
  32162. 'D': 722,
  32163. 'E': 667,
  32164. 'F': 611,
  32165. 'G': 778,
  32166. 'H': 722,
  32167. 'I': 278,
  32168. 'J': 556,
  32169. 'K': 722,
  32170. 'L': 611,
  32171. 'M': 833,
  32172. 'N': 722,
  32173. 'O': 778,
  32174. 'P': 667,
  32175. 'Q': 778,
  32176. 'R': 722,
  32177. 'S': 667,
  32178. 'T': 611,
  32179. 'U': 722,
  32180. 'V': 667,
  32181. 'W': 944,
  32182. 'X': 667,
  32183. 'Y': 667,
  32184. 'Z': 611,
  32185. 'bracketleft': 333,
  32186. 'backslash': 278,
  32187. 'bracketright': 333,
  32188. 'asciicircum': 584,
  32189. 'underscore': 556,
  32190. 'quoteleft': 278,
  32191. 'a': 556,
  32192. 'b': 611,
  32193. 'c': 556,
  32194. 'd': 611,
  32195. 'e': 556,
  32196. 'f': 333,
  32197. 'g': 611,
  32198. 'h': 611,
  32199. 'i': 278,
  32200. 'j': 278,
  32201. 'k': 556,
  32202. 'l': 278,
  32203. 'm': 889,
  32204. 'n': 611,
  32205. 'o': 611,
  32206. 'p': 611,
  32207. 'q': 611,
  32208. 'r': 389,
  32209. 's': 556,
  32210. 't': 333,
  32211. 'u': 611,
  32212. 'v': 556,
  32213. 'w': 778,
  32214. 'x': 556,
  32215. 'y': 556,
  32216. 'z': 500,
  32217. 'braceleft': 389,
  32218. 'bar': 280,
  32219. 'braceright': 389,
  32220. 'asciitilde': 584,
  32221. 'exclamdown': 333,
  32222. 'cent': 556,
  32223. 'sterling': 556,
  32224. 'fraction': 167,
  32225. 'yen': 556,
  32226. 'florin': 556,
  32227. 'section': 556,
  32228. 'currency': 556,
  32229. 'quotesingle': 238,
  32230. 'quotedblleft': 500,
  32231. 'guillemotleft': 556,
  32232. 'guilsinglleft': 333,
  32233. 'guilsinglright': 333,
  32234. 'fi': 611,
  32235. 'fl': 611,
  32236. 'endash': 556,
  32237. 'dagger': 556,
  32238. 'daggerdbl': 556,
  32239. 'periodcentered': 278,
  32240. 'paragraph': 556,
  32241. 'bullet': 350,
  32242. 'quotesinglbase': 278,
  32243. 'quotedblbase': 500,
  32244. 'quotedblright': 500,
  32245. 'guillemotright': 556,
  32246. 'ellipsis': 1000,
  32247. 'perthousand': 1000,
  32248. 'questiondown': 611,
  32249. 'grave': 333,
  32250. 'acute': 333,
  32251. 'circumflex': 333,
  32252. 'tilde': 333,
  32253. 'macron': 333,
  32254. 'breve': 333,
  32255. 'dotaccent': 333,
  32256. 'dieresis': 333,
  32257. 'ring': 333,
  32258. 'cedilla': 333,
  32259. 'hungarumlaut': 333,
  32260. 'ogonek': 333,
  32261. 'caron': 333,
  32262. 'emdash': 1000,
  32263. 'AE': 1000,
  32264. 'ordfeminine': 370,
  32265. 'Lslash': 611,
  32266. 'Oslash': 778,
  32267. 'OE': 1000,
  32268. 'ordmasculine': 365,
  32269. 'ae': 889,
  32270. 'dotlessi': 278,
  32271. 'lslash': 278,
  32272. 'oslash': 611,
  32273. 'oe': 944,
  32274. 'germandbls': 611,
  32275. 'Idieresis': 278,
  32276. 'eacute': 556,
  32277. 'abreve': 556,
  32278. 'uhungarumlaut': 611,
  32279. 'ecaron': 556,
  32280. 'Ydieresis': 667,
  32281. 'divide': 584,
  32282. 'Yacute': 667,
  32283. 'Acircumflex': 722,
  32284. 'aacute': 556,
  32285. 'Ucircumflex': 722,
  32286. 'yacute': 556,
  32287. 'scommaaccent': 556,
  32288. 'ecircumflex': 556,
  32289. 'Uring': 722,
  32290. 'Udieresis': 722,
  32291. 'aogonek': 556,
  32292. 'Uacute': 722,
  32293. 'uogonek': 611,
  32294. 'Edieresis': 667,
  32295. 'Dcroat': 722,
  32296. 'commaaccent': 250,
  32297. 'copyright': 737,
  32298. 'Emacron': 667,
  32299. 'ccaron': 556,
  32300. 'aring': 556,
  32301. 'Ncommaaccent': 722,
  32302. 'lacute': 278,
  32303. 'agrave': 556,
  32304. 'Tcommaaccent': 611,
  32305. 'Cacute': 722,
  32306. 'atilde': 556,
  32307. 'Edotaccent': 667,
  32308. 'scaron': 556,
  32309. 'scedilla': 556,
  32310. 'iacute': 278,
  32311. 'lozenge': 494,
  32312. 'Rcaron': 722,
  32313. 'Gcommaaccent': 778,
  32314. 'ucircumflex': 611,
  32315. 'acircumflex': 556,
  32316. 'Amacron': 722,
  32317. 'rcaron': 389,
  32318. 'ccedilla': 556,
  32319. 'Zdotaccent': 611,
  32320. 'Thorn': 667,
  32321. 'Omacron': 778,
  32322. 'Racute': 722,
  32323. 'Sacute': 667,
  32324. 'dcaron': 743,
  32325. 'Umacron': 722,
  32326. 'uring': 611,
  32327. 'threesuperior': 333,
  32328. 'Ograve': 778,
  32329. 'Agrave': 722,
  32330. 'Abreve': 722,
  32331. 'multiply': 584,
  32332. 'uacute': 611,
  32333. 'Tcaron': 611,
  32334. 'partialdiff': 494,
  32335. 'ydieresis': 556,
  32336. 'Nacute': 722,
  32337. 'icircumflex': 278,
  32338. 'Ecircumflex': 667,
  32339. 'adieresis': 556,
  32340. 'edieresis': 556,
  32341. 'cacute': 556,
  32342. 'nacute': 611,
  32343. 'umacron': 611,
  32344. 'Ncaron': 722,
  32345. 'Iacute': 278,
  32346. 'plusminus': 584,
  32347. 'brokenbar': 280,
  32348. 'registered': 737,
  32349. 'Gbreve': 778,
  32350. 'Idotaccent': 278,
  32351. 'summation': 600,
  32352. 'Egrave': 667,
  32353. 'racute': 389,
  32354. 'omacron': 611,
  32355. 'Zacute': 611,
  32356. 'Zcaron': 611,
  32357. 'greaterequal': 549,
  32358. 'Eth': 722,
  32359. 'Ccedilla': 722,
  32360. 'lcommaaccent': 278,
  32361. 'tcaron': 389,
  32362. 'eogonek': 556,
  32363. 'Uogonek': 722,
  32364. 'Aacute': 722,
  32365. 'Adieresis': 722,
  32366. 'egrave': 556,
  32367. 'zacute': 500,
  32368. 'iogonek': 278,
  32369. 'Oacute': 778,
  32370. 'oacute': 611,
  32371. 'amacron': 556,
  32372. 'sacute': 556,
  32373. 'idieresis': 278,
  32374. 'Ocircumflex': 778,
  32375. 'Ugrave': 722,
  32376. 'Delta': 612,
  32377. 'thorn': 611,
  32378. 'twosuperior': 333,
  32379. 'Odieresis': 778,
  32380. 'mu': 611,
  32381. 'igrave': 278,
  32382. 'ohungarumlaut': 611,
  32383. 'Eogonek': 667,
  32384. 'dcroat': 611,
  32385. 'threequarters': 834,
  32386. 'Scedilla': 667,
  32387. 'lcaron': 400,
  32388. 'Kcommaaccent': 722,
  32389. 'Lacute': 611,
  32390. 'trademark': 1000,
  32391. 'edotaccent': 556,
  32392. 'Igrave': 278,
  32393. 'Imacron': 278,
  32394. 'Lcaron': 611,
  32395. 'onehalf': 834,
  32396. 'lessequal': 549,
  32397. 'ocircumflex': 611,
  32398. 'ntilde': 611,
  32399. 'Uhungarumlaut': 722,
  32400. 'Eacute': 667,
  32401. 'emacron': 556,
  32402. 'gbreve': 611,
  32403. 'onequarter': 834,
  32404. 'Scaron': 667,
  32405. 'Scommaaccent': 667,
  32406. 'Ohungarumlaut': 778,
  32407. 'degree': 400,
  32408. 'ograve': 611,
  32409. 'Ccaron': 722,
  32410. 'ugrave': 611,
  32411. 'radical': 549,
  32412. 'Dcaron': 722,
  32413. 'rcommaaccent': 389,
  32414. 'Ntilde': 722,
  32415. 'otilde': 611,
  32416. 'Rcommaaccent': 722,
  32417. 'Lcommaaccent': 611,
  32418. 'Atilde': 722,
  32419. 'Aogonek': 722,
  32420. 'Aring': 722,
  32421. 'Otilde': 778,
  32422. 'zdotaccent': 500,
  32423. 'Ecaron': 667,
  32424. 'Iogonek': 278,
  32425. 'kcommaaccent': 556,
  32426. 'minus': 584,
  32427. 'Icircumflex': 278,
  32428. 'ncaron': 611,
  32429. 'tcommaaccent': 333,
  32430. 'logicalnot': 584,
  32431. 'odieresis': 611,
  32432. 'udieresis': 611,
  32433. 'notequal': 549,
  32434. 'gcommaaccent': 611,
  32435. 'eth': 611,
  32436. 'zcaron': 500,
  32437. 'ncommaaccent': 611,
  32438. 'onesuperior': 333,
  32439. 'imacron': 278,
  32440. 'Euro': 556
  32441. },
  32442. 'Helvetica-Oblique' : {
  32443. 'space': 278,
  32444. 'exclam': 278,
  32445. 'quotedbl': 355,
  32446. 'numbersign': 556,
  32447. 'dollar': 556,
  32448. 'percent': 889,
  32449. 'ampersand': 667,
  32450. 'quoteright': 222,
  32451. 'parenleft': 333,
  32452. 'parenright': 333,
  32453. 'asterisk': 389,
  32454. 'plus': 584,
  32455. 'comma': 278,
  32456. 'hyphen': 333,
  32457. 'period': 278,
  32458. 'slash': 278,
  32459. 'zero': 556,
  32460. 'one': 556,
  32461. 'two': 556,
  32462. 'three': 556,
  32463. 'four': 556,
  32464. 'five': 556,
  32465. 'six': 556,
  32466. 'seven': 556,
  32467. 'eight': 556,
  32468. 'nine': 556,
  32469. 'colon': 278,
  32470. 'semicolon': 278,
  32471. 'less': 584,
  32472. 'equal': 584,
  32473. 'greater': 584,
  32474. 'question': 556,
  32475. 'at': 1015,
  32476. 'A': 667,
  32477. 'B': 667,
  32478. 'C': 722,
  32479. 'D': 722,
  32480. 'E': 667,
  32481. 'F': 611,
  32482. 'G': 778,
  32483. 'H': 722,
  32484. 'I': 278,
  32485. 'J': 500,
  32486. 'K': 667,
  32487. 'L': 556,
  32488. 'M': 833,
  32489. 'N': 722,
  32490. 'O': 778,
  32491. 'P': 667,
  32492. 'Q': 778,
  32493. 'R': 722,
  32494. 'S': 667,
  32495. 'T': 611,
  32496. 'U': 722,
  32497. 'V': 667,
  32498. 'W': 944,
  32499. 'X': 667,
  32500. 'Y': 667,
  32501. 'Z': 611,
  32502. 'bracketleft': 278,
  32503. 'backslash': 278,
  32504. 'bracketright': 278,
  32505. 'asciicircum': 469,
  32506. 'underscore': 556,
  32507. 'quoteleft': 222,
  32508. 'a': 556,
  32509. 'b': 556,
  32510. 'c': 500,
  32511. 'd': 556,
  32512. 'e': 556,
  32513. 'f': 278,
  32514. 'g': 556,
  32515. 'h': 556,
  32516. 'i': 222,
  32517. 'j': 222,
  32518. 'k': 500,
  32519. 'l': 222,
  32520. 'm': 833,
  32521. 'n': 556,
  32522. 'o': 556,
  32523. 'p': 556,
  32524. 'q': 556,
  32525. 'r': 333,
  32526. 's': 500,
  32527. 't': 278,
  32528. 'u': 556,
  32529. 'v': 500,
  32530. 'w': 722,
  32531. 'x': 500,
  32532. 'y': 500,
  32533. 'z': 500,
  32534. 'braceleft': 334,
  32535. 'bar': 260,
  32536. 'braceright': 334,
  32537. 'asciitilde': 584,
  32538. 'exclamdown': 333,
  32539. 'cent': 556,
  32540. 'sterling': 556,
  32541. 'fraction': 167,
  32542. 'yen': 556,
  32543. 'florin': 556,
  32544. 'section': 556,
  32545. 'currency': 556,
  32546. 'quotesingle': 191,
  32547. 'quotedblleft': 333,
  32548. 'guillemotleft': 556,
  32549. 'guilsinglleft': 333,
  32550. 'guilsinglright': 333,
  32551. 'fi': 500,
  32552. 'fl': 500,
  32553. 'endash': 556,
  32554. 'dagger': 556,
  32555. 'daggerdbl': 556,
  32556. 'periodcentered': 278,
  32557. 'paragraph': 537,
  32558. 'bullet': 350,
  32559. 'quotesinglbase': 222,
  32560. 'quotedblbase': 333,
  32561. 'quotedblright': 333,
  32562. 'guillemotright': 556,
  32563. 'ellipsis': 1000,
  32564. 'perthousand': 1000,
  32565. 'questiondown': 611,
  32566. 'grave': 333,
  32567. 'acute': 333,
  32568. 'circumflex': 333,
  32569. 'tilde': 333,
  32570. 'macron': 333,
  32571. 'breve': 333,
  32572. 'dotaccent': 333,
  32573. 'dieresis': 333,
  32574. 'ring': 333,
  32575. 'cedilla': 333,
  32576. 'hungarumlaut': 333,
  32577. 'ogonek': 333,
  32578. 'caron': 333,
  32579. 'emdash': 1000,
  32580. 'AE': 1000,
  32581. 'ordfeminine': 370,
  32582. 'Lslash': 556,
  32583. 'Oslash': 778,
  32584. 'OE': 1000,
  32585. 'ordmasculine': 365,
  32586. 'ae': 889,
  32587. 'dotlessi': 278,
  32588. 'lslash': 222,
  32589. 'oslash': 611,
  32590. 'oe': 944,
  32591. 'germandbls': 611,
  32592. 'Idieresis': 278,
  32593. 'eacute': 556,
  32594. 'abreve': 556,
  32595. 'uhungarumlaut': 556,
  32596. 'ecaron': 556,
  32597. 'Ydieresis': 667,
  32598. 'divide': 584,
  32599. 'Yacute': 667,
  32600. 'Acircumflex': 667,
  32601. 'aacute': 556,
  32602. 'Ucircumflex': 722,
  32603. 'yacute': 500,
  32604. 'scommaaccent': 500,
  32605. 'ecircumflex': 556,
  32606. 'Uring': 722,
  32607. 'Udieresis': 722,
  32608. 'aogonek': 556,
  32609. 'Uacute': 722,
  32610. 'uogonek': 556,
  32611. 'Edieresis': 667,
  32612. 'Dcroat': 722,
  32613. 'commaaccent': 250,
  32614. 'copyright': 737,
  32615. 'Emacron': 667,
  32616. 'ccaron': 500,
  32617. 'aring': 556,
  32618. 'Ncommaaccent': 722,
  32619. 'lacute': 222,
  32620. 'agrave': 556,
  32621. 'Tcommaaccent': 611,
  32622. 'Cacute': 722,
  32623. 'atilde': 556,
  32624. 'Edotaccent': 667,
  32625. 'scaron': 500,
  32626. 'scedilla': 500,
  32627. 'iacute': 278,
  32628. 'lozenge': 471,
  32629. 'Rcaron': 722,
  32630. 'Gcommaaccent': 778,
  32631. 'ucircumflex': 556,
  32632. 'acircumflex': 556,
  32633. 'Amacron': 667,
  32634. 'rcaron': 333,
  32635. 'ccedilla': 500,
  32636. 'Zdotaccent': 611,
  32637. 'Thorn': 667,
  32638. 'Omacron': 778,
  32639. 'Racute': 722,
  32640. 'Sacute': 667,
  32641. 'dcaron': 643,
  32642. 'Umacron': 722,
  32643. 'uring': 556,
  32644. 'threesuperior': 333,
  32645. 'Ograve': 778,
  32646. 'Agrave': 667,
  32647. 'Abreve': 667,
  32648. 'multiply': 584,
  32649. 'uacute': 556,
  32650. 'Tcaron': 611,
  32651. 'partialdiff': 476,
  32652. 'ydieresis': 500,
  32653. 'Nacute': 722,
  32654. 'icircumflex': 278,
  32655. 'Ecircumflex': 667,
  32656. 'adieresis': 556,
  32657. 'edieresis': 556,
  32658. 'cacute': 500,
  32659. 'nacute': 556,
  32660. 'umacron': 556,
  32661. 'Ncaron': 722,
  32662. 'Iacute': 278,
  32663. 'plusminus': 584,
  32664. 'brokenbar': 260,
  32665. 'registered': 737,
  32666. 'Gbreve': 778,
  32667. 'Idotaccent': 278,
  32668. 'summation': 600,
  32669. 'Egrave': 667,
  32670. 'racute': 333,
  32671. 'omacron': 556,
  32672. 'Zacute': 611,
  32673. 'Zcaron': 611,
  32674. 'greaterequal': 549,
  32675. 'Eth': 722,
  32676. 'Ccedilla': 722,
  32677. 'lcommaaccent': 222,
  32678. 'tcaron': 317,
  32679. 'eogonek': 556,
  32680. 'Uogonek': 722,
  32681. 'Aacute': 667,
  32682. 'Adieresis': 667,
  32683. 'egrave': 556,
  32684. 'zacute': 500,
  32685. 'iogonek': 222,
  32686. 'Oacute': 778,
  32687. 'oacute': 556,
  32688. 'amacron': 556,
  32689. 'sacute': 500,
  32690. 'idieresis': 278,
  32691. 'Ocircumflex': 778,
  32692. 'Ugrave': 722,
  32693. 'Delta': 612,
  32694. 'thorn': 556,
  32695. 'twosuperior': 333,
  32696. 'Odieresis': 778,
  32697. 'mu': 556,
  32698. 'igrave': 278,
  32699. 'ohungarumlaut': 556,
  32700. 'Eogonek': 667,
  32701. 'dcroat': 556,
  32702. 'threequarters': 834,
  32703. 'Scedilla': 667,
  32704. 'lcaron': 299,
  32705. 'Kcommaaccent': 667,
  32706. 'Lacute': 556,
  32707. 'trademark': 1000,
  32708. 'edotaccent': 556,
  32709. 'Igrave': 278,
  32710. 'Imacron': 278,
  32711. 'Lcaron': 556,
  32712. 'onehalf': 834,
  32713. 'lessequal': 549,
  32714. 'ocircumflex': 556,
  32715. 'ntilde': 556,
  32716. 'Uhungarumlaut': 722,
  32717. 'Eacute': 667,
  32718. 'emacron': 556,
  32719. 'gbreve': 556,
  32720. 'onequarter': 834,
  32721. 'Scaron': 667,
  32722. 'Scommaaccent': 667,
  32723. 'Ohungarumlaut': 778,
  32724. 'degree': 400,
  32725. 'ograve': 556,
  32726. 'Ccaron': 722,
  32727. 'ugrave': 556,
  32728. 'radical': 453,
  32729. 'Dcaron': 722,
  32730. 'rcommaaccent': 333,
  32731. 'Ntilde': 722,
  32732. 'otilde': 556,
  32733. 'Rcommaaccent': 722,
  32734. 'Lcommaaccent': 556,
  32735. 'Atilde': 667,
  32736. 'Aogonek': 667,
  32737. 'Aring': 667,
  32738. 'Otilde': 778,
  32739. 'zdotaccent': 500,
  32740. 'Ecaron': 667,
  32741. 'Iogonek': 278,
  32742. 'kcommaaccent': 500,
  32743. 'minus': 584,
  32744. 'Icircumflex': 278,
  32745. 'ncaron': 556,
  32746. 'tcommaaccent': 278,
  32747. 'logicalnot': 584,
  32748. 'odieresis': 556,
  32749. 'udieresis': 556,
  32750. 'notequal': 549,
  32751. 'gcommaaccent': 556,
  32752. 'eth': 556,
  32753. 'zcaron': 500,
  32754. 'ncommaaccent': 556,
  32755. 'onesuperior': 333,
  32756. 'imacron': 278,
  32757. 'Euro': 556
  32758. },
  32759. 'Symbol': {
  32760. 'space': 250,
  32761. 'exclam': 333,
  32762. 'universal': 713,
  32763. 'numbersign': 500,
  32764. 'existential': 549,
  32765. 'percent': 833,
  32766. 'ampersand': 778,
  32767. 'suchthat': 439,
  32768. 'parenleft': 333,
  32769. 'parenright': 333,
  32770. 'asteriskmath': 500,
  32771. 'plus': 549,
  32772. 'comma': 250,
  32773. 'minus': 549,
  32774. 'period': 250,
  32775. 'slash': 278,
  32776. 'zero': 500,
  32777. 'one': 500,
  32778. 'two': 500,
  32779. 'three': 500,
  32780. 'four': 500,
  32781. 'five': 500,
  32782. 'six': 500,
  32783. 'seven': 500,
  32784. 'eight': 500,
  32785. 'nine': 500,
  32786. 'colon': 278,
  32787. 'semicolon': 278,
  32788. 'less': 549,
  32789. 'equal': 549,
  32790. 'greater': 549,
  32791. 'question': 444,
  32792. 'congruent': 549,
  32793. 'Alpha': 722,
  32794. 'Beta': 667,
  32795. 'Chi': 722,
  32796. 'Delta': 612,
  32797. 'Epsilon': 611,
  32798. 'Phi': 763,
  32799. 'Gamma': 603,
  32800. 'Eta': 722,
  32801. 'Iota': 333,
  32802. 'theta1': 631,
  32803. 'Kappa': 722,
  32804. 'Lambda': 686,
  32805. 'Mu': 889,
  32806. 'Nu': 722,
  32807. 'Omicron': 722,
  32808. 'Pi': 768,
  32809. 'Theta': 741,
  32810. 'Rho': 556,
  32811. 'Sigma': 592,
  32812. 'Tau': 611,
  32813. 'Upsilon': 690,
  32814. 'sigma1': 439,
  32815. 'Omega': 768,
  32816. 'Xi': 645,
  32817. 'Psi': 795,
  32818. 'Zeta': 611,
  32819. 'bracketleft': 333,
  32820. 'therefore': 863,
  32821. 'bracketright': 333,
  32822. 'perpendicular': 658,
  32823. 'underscore': 500,
  32824. 'radicalex': 500,
  32825. 'alpha': 631,
  32826. 'beta': 549,
  32827. 'chi': 549,
  32828. 'delta': 494,
  32829. 'epsilon': 439,
  32830. 'phi': 521,
  32831. 'gamma': 411,
  32832. 'eta': 603,
  32833. 'iota': 329,
  32834. 'phi1': 603,
  32835. 'kappa': 549,
  32836. 'lambda': 549,
  32837. 'mu': 576,
  32838. 'nu': 521,
  32839. 'omicron': 549,
  32840. 'pi': 549,
  32841. 'theta': 521,
  32842. 'rho': 549,
  32843. 'sigma': 603,
  32844. 'tau': 439,
  32845. 'upsilon': 576,
  32846. 'omega1': 713,
  32847. 'omega': 686,
  32848. 'xi': 493,
  32849. 'psi': 686,
  32850. 'zeta': 494,
  32851. 'braceleft': 480,
  32852. 'bar': 200,
  32853. 'braceright': 480,
  32854. 'similar': 549,
  32855. 'Euro': 750,
  32856. 'Upsilon1': 620,
  32857. 'minute': 247,
  32858. 'lessequal': 549,
  32859. 'fraction': 167,
  32860. 'infinity': 713,
  32861. 'florin': 500,
  32862. 'club': 753,
  32863. 'diamond': 753,
  32864. 'heart': 753,
  32865. 'spade': 753,
  32866. 'arrowboth': 1042,
  32867. 'arrowleft': 987,
  32868. 'arrowup': 603,
  32869. 'arrowright': 987,
  32870. 'arrowdown': 603,
  32871. 'degree': 400,
  32872. 'plusminus': 549,
  32873. 'second': 411,
  32874. 'greaterequal': 549,
  32875. 'multiply': 549,
  32876. 'proportional': 713,
  32877. 'partialdiff': 494,
  32878. 'bullet': 460,
  32879. 'divide': 549,
  32880. 'notequal': 549,
  32881. 'equivalence': 549,
  32882. 'approxequal': 549,
  32883. 'ellipsis': 1000,
  32884. 'arrowvertex': 603,
  32885. 'arrowhorizex': 1000,
  32886. 'carriagereturn': 658,
  32887. 'aleph': 823,
  32888. 'Ifraktur': 686,
  32889. 'Rfraktur': 795,
  32890. 'weierstrass': 987,
  32891. 'circlemultiply': 768,
  32892. 'circleplus': 768,
  32893. 'emptyset': 823,
  32894. 'intersection': 768,
  32895. 'union': 768,
  32896. 'propersuperset': 713,
  32897. 'reflexsuperset': 713,
  32898. 'notsubset': 713,
  32899. 'propersubset': 713,
  32900. 'reflexsubset': 713,
  32901. 'element': 713,
  32902. 'notelement': 713,
  32903. 'angle': 768,
  32904. 'gradient': 713,
  32905. 'registerserif': 790,
  32906. 'copyrightserif': 790,
  32907. 'trademarkserif': 890,
  32908. 'product': 823,
  32909. 'radical': 549,
  32910. 'dotmath': 250,
  32911. 'logicalnot': 713,
  32912. 'logicaland': 603,
  32913. 'logicalor': 603,
  32914. 'arrowdblboth': 1042,
  32915. 'arrowdblleft': 987,
  32916. 'arrowdblup': 603,
  32917. 'arrowdblright': 987,
  32918. 'arrowdbldown': 603,
  32919. 'lozenge': 494,
  32920. 'angleleft': 329,
  32921. 'registersans': 790,
  32922. 'copyrightsans': 790,
  32923. 'trademarksans': 786,
  32924. 'summation': 713,
  32925. 'parenlefttp': 384,
  32926. 'parenleftex': 384,
  32927. 'parenleftbt': 384,
  32928. 'bracketlefttp': 384,
  32929. 'bracketleftex': 384,
  32930. 'bracketleftbt': 384,
  32931. 'bracelefttp': 494,
  32932. 'braceleftmid': 494,
  32933. 'braceleftbt': 494,
  32934. 'braceex': 494,
  32935. 'angleright': 329,
  32936. 'integral': 274,
  32937. 'integraltp': 686,
  32938. 'integralex': 686,
  32939. 'integralbt': 686,
  32940. 'parenrighttp': 384,
  32941. 'parenrightex': 384,
  32942. 'parenrightbt': 384,
  32943. 'bracketrighttp': 384,
  32944. 'bracketrightex': 384,
  32945. 'bracketrightbt': 384,
  32946. 'bracerighttp': 494,
  32947. 'bracerightmid': 494,
  32948. 'bracerightbt': 494,
  32949. 'apple': 790
  32950. },
  32951. 'Times-Roman': {
  32952. 'space': 250,
  32953. 'exclam': 333,
  32954. 'quotedbl': 408,
  32955. 'numbersign': 500,
  32956. 'dollar': 500,
  32957. 'percent': 833,
  32958. 'ampersand': 778,
  32959. 'quoteright': 333,
  32960. 'parenleft': 333,
  32961. 'parenright': 333,
  32962. 'asterisk': 500,
  32963. 'plus': 564,
  32964. 'comma': 250,
  32965. 'hyphen': 333,
  32966. 'period': 250,
  32967. 'slash': 278,
  32968. 'zero': 500,
  32969. 'one': 500,
  32970. 'two': 500,
  32971. 'three': 500,
  32972. 'four': 500,
  32973. 'five': 500,
  32974. 'six': 500,
  32975. 'seven': 500,
  32976. 'eight': 500,
  32977. 'nine': 500,
  32978. 'colon': 278,
  32979. 'semicolon': 278,
  32980. 'less': 564,
  32981. 'equal': 564,
  32982. 'greater': 564,
  32983. 'question': 444,
  32984. 'at': 921,
  32985. 'A': 722,
  32986. 'B': 667,
  32987. 'C': 667,
  32988. 'D': 722,
  32989. 'E': 611,
  32990. 'F': 556,
  32991. 'G': 722,
  32992. 'H': 722,
  32993. 'I': 333,
  32994. 'J': 389,
  32995. 'K': 722,
  32996. 'L': 611,
  32997. 'M': 889,
  32998. 'N': 722,
  32999. 'O': 722,
  33000. 'P': 556,
  33001. 'Q': 722,
  33002. 'R': 667,
  33003. 'S': 556,
  33004. 'T': 611,
  33005. 'U': 722,
  33006. 'V': 722,
  33007. 'W': 944,
  33008. 'X': 722,
  33009. 'Y': 722,
  33010. 'Z': 611,
  33011. 'bracketleft': 333,
  33012. 'backslash': 278,
  33013. 'bracketright': 333,
  33014. 'asciicircum': 469,
  33015. 'underscore': 500,
  33016. 'quoteleft': 333,
  33017. 'a': 444,
  33018. 'b': 500,
  33019. 'c': 444,
  33020. 'd': 500,
  33021. 'e': 444,
  33022. 'f': 333,
  33023. 'g': 500,
  33024. 'h': 500,
  33025. 'i': 278,
  33026. 'j': 278,
  33027. 'k': 500,
  33028. 'l': 278,
  33029. 'm': 778,
  33030. 'n': 500,
  33031. 'o': 500,
  33032. 'p': 500,
  33033. 'q': 500,
  33034. 'r': 333,
  33035. 's': 389,
  33036. 't': 278,
  33037. 'u': 500,
  33038. 'v': 500,
  33039. 'w': 722,
  33040. 'x': 500,
  33041. 'y': 500,
  33042. 'z': 444,
  33043. 'braceleft': 480,
  33044. 'bar': 200,
  33045. 'braceright': 480,
  33046. 'asciitilde': 541,
  33047. 'exclamdown': 333,
  33048. 'cent': 500,
  33049. 'sterling': 500,
  33050. 'fraction': 167,
  33051. 'yen': 500,
  33052. 'florin': 500,
  33053. 'section': 500,
  33054. 'currency': 500,
  33055. 'quotesingle': 180,
  33056. 'quotedblleft': 444,
  33057. 'guillemotleft': 500,
  33058. 'guilsinglleft': 333,
  33059. 'guilsinglright': 333,
  33060. 'fi': 556,
  33061. 'fl': 556,
  33062. 'endash': 500,
  33063. 'dagger': 500,
  33064. 'daggerdbl': 500,
  33065. 'periodcentered': 250,
  33066. 'paragraph': 453,
  33067. 'bullet': 350,
  33068. 'quotesinglbase': 333,
  33069. 'quotedblbase': 444,
  33070. 'quotedblright': 444,
  33071. 'guillemotright': 500,
  33072. 'ellipsis': 1000,
  33073. 'perthousand': 1000,
  33074. 'questiondown': 444,
  33075. 'grave': 333,
  33076. 'acute': 333,
  33077. 'circumflex': 333,
  33078. 'tilde': 333,
  33079. 'macron': 333,
  33080. 'breve': 333,
  33081. 'dotaccent': 333,
  33082. 'dieresis': 333,
  33083. 'ring': 333,
  33084. 'cedilla': 333,
  33085. 'hungarumlaut': 333,
  33086. 'ogonek': 333,
  33087. 'caron': 333,
  33088. 'emdash': 1000,
  33089. 'AE': 889,
  33090. 'ordfeminine': 276,
  33091. 'Lslash': 611,
  33092. 'Oslash': 722,
  33093. 'OE': 889,
  33094. 'ordmasculine': 310,
  33095. 'ae': 667,
  33096. 'dotlessi': 278,
  33097. 'lslash': 278,
  33098. 'oslash': 500,
  33099. 'oe': 722,
  33100. 'germandbls': 500,
  33101. 'Idieresis': 333,
  33102. 'eacute': 444,
  33103. 'abreve': 444,
  33104. 'uhungarumlaut': 500,
  33105. 'ecaron': 444,
  33106. 'Ydieresis': 722,
  33107. 'divide': 564,
  33108. 'Yacute': 722,
  33109. 'Acircumflex': 722,
  33110. 'aacute': 444,
  33111. 'Ucircumflex': 722,
  33112. 'yacute': 500,
  33113. 'scommaaccent': 389,
  33114. 'ecircumflex': 444,
  33115. 'Uring': 722,
  33116. 'Udieresis': 722,
  33117. 'aogonek': 444,
  33118. 'Uacute': 722,
  33119. 'uogonek': 500,
  33120. 'Edieresis': 611,
  33121. 'Dcroat': 722,
  33122. 'commaaccent': 250,
  33123. 'copyright': 760,
  33124. 'Emacron': 611,
  33125. 'ccaron': 444,
  33126. 'aring': 444,
  33127. 'Ncommaaccent': 722,
  33128. 'lacute': 278,
  33129. 'agrave': 444,
  33130. 'Tcommaaccent': 611,
  33131. 'Cacute': 667,
  33132. 'atilde': 444,
  33133. 'Edotaccent': 611,
  33134. 'scaron': 389,
  33135. 'scedilla': 389,
  33136. 'iacute': 278,
  33137. 'lozenge': 471,
  33138. 'Rcaron': 667,
  33139. 'Gcommaaccent': 722,
  33140. 'ucircumflex': 500,
  33141. 'acircumflex': 444,
  33142. 'Amacron': 722,
  33143. 'rcaron': 333,
  33144. 'ccedilla': 444,
  33145. 'Zdotaccent': 611,
  33146. 'Thorn': 556,
  33147. 'Omacron': 722,
  33148. 'Racute': 667,
  33149. 'Sacute': 556,
  33150. 'dcaron': 588,
  33151. 'Umacron': 722,
  33152. 'uring': 500,
  33153. 'threesuperior': 300,
  33154. 'Ograve': 722,
  33155. 'Agrave': 722,
  33156. 'Abreve': 722,
  33157. 'multiply': 564,
  33158. 'uacute': 500,
  33159. 'Tcaron': 611,
  33160. 'partialdiff': 476,
  33161. 'ydieresis': 500,
  33162. 'Nacute': 722,
  33163. 'icircumflex': 278,
  33164. 'Ecircumflex': 611,
  33165. 'adieresis': 444,
  33166. 'edieresis': 444,
  33167. 'cacute': 444,
  33168. 'nacute': 500,
  33169. 'umacron': 500,
  33170. 'Ncaron': 722,
  33171. 'Iacute': 333,
  33172. 'plusminus': 564,
  33173. 'brokenbar': 200,
  33174. 'registered': 760,
  33175. 'Gbreve': 722,
  33176. 'Idotaccent': 333,
  33177. 'summation': 600,
  33178. 'Egrave': 611,
  33179. 'racute': 333,
  33180. 'omacron': 500,
  33181. 'Zacute': 611,
  33182. 'Zcaron': 611,
  33183. 'greaterequal': 549,
  33184. 'Eth': 722,
  33185. 'Ccedilla': 667,
  33186. 'lcommaaccent': 278,
  33187. 'tcaron': 326,
  33188. 'eogonek': 444,
  33189. 'Uogonek': 722,
  33190. 'Aacute': 722,
  33191. 'Adieresis': 722,
  33192. 'egrave': 444,
  33193. 'zacute': 444,
  33194. 'iogonek': 278,
  33195. 'Oacute': 722,
  33196. 'oacute': 500,
  33197. 'amacron': 444,
  33198. 'sacute': 389,
  33199. 'idieresis': 278,
  33200. 'Ocircumflex': 722,
  33201. 'Ugrave': 722,
  33202. 'Delta': 612,
  33203. 'thorn': 500,
  33204. 'twosuperior': 300,
  33205. 'Odieresis': 722,
  33206. 'mu': 500,
  33207. 'igrave': 278,
  33208. 'ohungarumlaut': 500,
  33209. 'Eogonek': 611,
  33210. 'dcroat': 500,
  33211. 'threequarters': 750,
  33212. 'Scedilla': 556,
  33213. 'lcaron': 344,
  33214. 'Kcommaaccent': 722,
  33215. 'Lacute': 611,
  33216. 'trademark': 980,
  33217. 'edotaccent': 444,
  33218. 'Igrave': 333,
  33219. 'Imacron': 333,
  33220. 'Lcaron': 611,
  33221. 'onehalf': 750,
  33222. 'lessequal': 549,
  33223. 'ocircumflex': 500,
  33224. 'ntilde': 500,
  33225. 'Uhungarumlaut': 722,
  33226. 'Eacute': 611,
  33227. 'emacron': 444,
  33228. 'gbreve': 500,
  33229. 'onequarter': 750,
  33230. 'Scaron': 556,
  33231. 'Scommaaccent': 556,
  33232. 'Ohungarumlaut': 722,
  33233. 'degree': 400,
  33234. 'ograve': 500,
  33235. 'Ccaron': 667,
  33236. 'ugrave': 500,
  33237. 'radical': 453,
  33238. 'Dcaron': 722,
  33239. 'rcommaaccent': 333,
  33240. 'Ntilde': 722,
  33241. 'otilde': 500,
  33242. 'Rcommaaccent': 667,
  33243. 'Lcommaaccent': 611,
  33244. 'Atilde': 722,
  33245. 'Aogonek': 722,
  33246. 'Aring': 722,
  33247. 'Otilde': 722,
  33248. 'zdotaccent': 444,
  33249. 'Ecaron': 611,
  33250. 'Iogonek': 333,
  33251. 'kcommaaccent': 500,
  33252. 'minus': 564,
  33253. 'Icircumflex': 333,
  33254. 'ncaron': 500,
  33255. 'tcommaaccent': 278,
  33256. 'logicalnot': 564,
  33257. 'odieresis': 500,
  33258. 'udieresis': 500,
  33259. 'notequal': 549,
  33260. 'gcommaaccent': 500,
  33261. 'eth': 500,
  33262. 'zcaron': 444,
  33263. 'ncommaaccent': 500,
  33264. 'onesuperior': 300,
  33265. 'imacron': 278,
  33266. 'Euro': 500
  33267. },
  33268. 'Times-Bold': {
  33269. 'space': 250,
  33270. 'exclam': 333,
  33271. 'quotedbl': 555,
  33272. 'numbersign': 500,
  33273. 'dollar': 500,
  33274. 'percent': 1000,
  33275. 'ampersand': 833,
  33276. 'quoteright': 333,
  33277. 'parenleft': 333,
  33278. 'parenright': 333,
  33279. 'asterisk': 500,
  33280. 'plus': 570,
  33281. 'comma': 250,
  33282. 'hyphen': 333,
  33283. 'period': 250,
  33284. 'slash': 278,
  33285. 'zero': 500,
  33286. 'one': 500,
  33287. 'two': 500,
  33288. 'three': 500,
  33289. 'four': 500,
  33290. 'five': 500,
  33291. 'six': 500,
  33292. 'seven': 500,
  33293. 'eight': 500,
  33294. 'nine': 500,
  33295. 'colon': 333,
  33296. 'semicolon': 333,
  33297. 'less': 570,
  33298. 'equal': 570,
  33299. 'greater': 570,
  33300. 'question': 500,
  33301. 'at': 930,
  33302. 'A': 722,
  33303. 'B': 667,
  33304. 'C': 722,
  33305. 'D': 722,
  33306. 'E': 667,
  33307. 'F': 611,
  33308. 'G': 778,
  33309. 'H': 778,
  33310. 'I': 389,
  33311. 'J': 500,
  33312. 'K': 778,
  33313. 'L': 667,
  33314. 'M': 944,
  33315. 'N': 722,
  33316. 'O': 778,
  33317. 'P': 611,
  33318. 'Q': 778,
  33319. 'R': 722,
  33320. 'S': 556,
  33321. 'T': 667,
  33322. 'U': 722,
  33323. 'V': 722,
  33324. 'W': 1000,
  33325. 'X': 722,
  33326. 'Y': 722,
  33327. 'Z': 667,
  33328. 'bracketleft': 333,
  33329. 'backslash': 278,
  33330. 'bracketright': 333,
  33331. 'asciicircum': 581,
  33332. 'underscore': 500,
  33333. 'quoteleft': 333,
  33334. 'a': 500,
  33335. 'b': 556,
  33336. 'c': 444,
  33337. 'd': 556,
  33338. 'e': 444,
  33339. 'f': 333,
  33340. 'g': 500,
  33341. 'h': 556,
  33342. 'i': 278,
  33343. 'j': 333,
  33344. 'k': 556,
  33345. 'l': 278,
  33346. 'm': 833,
  33347. 'n': 556,
  33348. 'o': 500,
  33349. 'p': 556,
  33350. 'q': 556,
  33351. 'r': 444,
  33352. 's': 389,
  33353. 't': 333,
  33354. 'u': 556,
  33355. 'v': 500,
  33356. 'w': 722,
  33357. 'x': 500,
  33358. 'y': 500,
  33359. 'z': 444,
  33360. 'braceleft': 394,
  33361. 'bar': 220,
  33362. 'braceright': 394,
  33363. 'asciitilde': 520,
  33364. 'exclamdown': 333,
  33365. 'cent': 500,
  33366. 'sterling': 500,
  33367. 'fraction': 167,
  33368. 'yen': 500,
  33369. 'florin': 500,
  33370. 'section': 500,
  33371. 'currency': 500,
  33372. 'quotesingle': 278,
  33373. 'quotedblleft': 500,
  33374. 'guillemotleft': 500,
  33375. 'guilsinglleft': 333,
  33376. 'guilsinglright': 333,
  33377. 'fi': 556,
  33378. 'fl': 556,
  33379. 'endash': 500,
  33380. 'dagger': 500,
  33381. 'daggerdbl': 500,
  33382. 'periodcentered': 250,
  33383. 'paragraph': 540,
  33384. 'bullet': 350,
  33385. 'quotesinglbase': 333,
  33386. 'quotedblbase': 500,
  33387. 'quotedblright': 500,
  33388. 'guillemotright': 500,
  33389. 'ellipsis': 1000,
  33390. 'perthousand': 1000,
  33391. 'questiondown': 500,
  33392. 'grave': 333,
  33393. 'acute': 333,
  33394. 'circumflex': 333,
  33395. 'tilde': 333,
  33396. 'macron': 333,
  33397. 'breve': 333,
  33398. 'dotaccent': 333,
  33399. 'dieresis': 333,
  33400. 'ring': 333,
  33401. 'cedilla': 333,
  33402. 'hungarumlaut': 333,
  33403. 'ogonek': 333,
  33404. 'caron': 333,
  33405. 'emdash': 1000,
  33406. 'AE': 1000,
  33407. 'ordfeminine': 300,
  33408. 'Lslash': 667,
  33409. 'Oslash': 778,
  33410. 'OE': 1000,
  33411. 'ordmasculine': 330,
  33412. 'ae': 722,
  33413. 'dotlessi': 278,
  33414. 'lslash': 278,
  33415. 'oslash': 500,
  33416. 'oe': 722,
  33417. 'germandbls': 556,
  33418. 'Idieresis': 389,
  33419. 'eacute': 444,
  33420. 'abreve': 500,
  33421. 'uhungarumlaut': 556,
  33422. 'ecaron': 444,
  33423. 'Ydieresis': 722,
  33424. 'divide': 570,
  33425. 'Yacute': 722,
  33426. 'Acircumflex': 722,
  33427. 'aacute': 500,
  33428. 'Ucircumflex': 722,
  33429. 'yacute': 500,
  33430. 'scommaaccent': 389,
  33431. 'ecircumflex': 444,
  33432. 'Uring': 722,
  33433. 'Udieresis': 722,
  33434. 'aogonek': 500,
  33435. 'Uacute': 722,
  33436. 'uogonek': 556,
  33437. 'Edieresis': 667,
  33438. 'Dcroat': 722,
  33439. 'commaaccent': 250,
  33440. 'copyright': 747,
  33441. 'Emacron': 667,
  33442. 'ccaron': 444,
  33443. 'aring': 500,
  33444. 'Ncommaaccent': 722,
  33445. 'lacute': 278,
  33446. 'agrave': 500,
  33447. 'Tcommaaccent': 667,
  33448. 'Cacute': 722,
  33449. 'atilde': 500,
  33450. 'Edotaccent': 667,
  33451. 'scaron': 389,
  33452. 'scedilla': 389,
  33453. 'iacute': 278,
  33454. 'lozenge': 494,
  33455. 'Rcaron': 722,
  33456. 'Gcommaaccent': 778,
  33457. 'ucircumflex': 556,
  33458. 'acircumflex': 500,
  33459. 'Amacron': 722,
  33460. 'rcaron': 444,
  33461. 'ccedilla': 444,
  33462. 'Zdotaccent': 667,
  33463. 'Thorn': 611,
  33464. 'Omacron': 778,
  33465. 'Racute': 722,
  33466. 'Sacute': 556,
  33467. 'dcaron': 672,
  33468. 'Umacron': 722,
  33469. 'uring': 556,
  33470. 'threesuperior': 300,
  33471. 'Ograve': 778,
  33472. 'Agrave': 722,
  33473. 'Abreve': 722,
  33474. 'multiply': 570,
  33475. 'uacute': 556,
  33476. 'Tcaron': 667,
  33477. 'partialdiff': 494,
  33478. 'ydieresis': 500,
  33479. 'Nacute': 722,
  33480. 'icircumflex': 278,
  33481. 'Ecircumflex': 667,
  33482. 'adieresis': 500,
  33483. 'edieresis': 444,
  33484. 'cacute': 444,
  33485. 'nacute': 556,
  33486. 'umacron': 556,
  33487. 'Ncaron': 722,
  33488. 'Iacute': 389,
  33489. 'plusminus': 570,
  33490. 'brokenbar': 220,
  33491. 'registered': 747,
  33492. 'Gbreve': 778,
  33493. 'Idotaccent': 389,
  33494. 'summation': 600,
  33495. 'Egrave': 667,
  33496. 'racute': 444,
  33497. 'omacron': 500,
  33498. 'Zacute': 667,
  33499. 'Zcaron': 667,
  33500. 'greaterequal': 549,
  33501. 'Eth': 722,
  33502. 'Ccedilla': 722,
  33503. 'lcommaaccent': 278,
  33504. 'tcaron': 416,
  33505. 'eogonek': 444,
  33506. 'Uogonek': 722,
  33507. 'Aacute': 722,
  33508. 'Adieresis': 722,
  33509. 'egrave': 444,
  33510. 'zacute': 444,
  33511. 'iogonek': 278,
  33512. 'Oacute': 778,
  33513. 'oacute': 500,
  33514. 'amacron': 500,
  33515. 'sacute': 389,
  33516. 'idieresis': 278,
  33517. 'Ocircumflex': 778,
  33518. 'Ugrave': 722,
  33519. 'Delta': 612,
  33520. 'thorn': 556,
  33521. 'twosuperior': 300,
  33522. 'Odieresis': 778,
  33523. 'mu': 556,
  33524. 'igrave': 278,
  33525. 'ohungarumlaut': 500,
  33526. 'Eogonek': 667,
  33527. 'dcroat': 556,
  33528. 'threequarters': 750,
  33529. 'Scedilla': 556,
  33530. 'lcaron': 394,
  33531. 'Kcommaaccent': 778,
  33532. 'Lacute': 667,
  33533. 'trademark': 1000,
  33534. 'edotaccent': 444,
  33535. 'Igrave': 389,
  33536. 'Imacron': 389,
  33537. 'Lcaron': 667,
  33538. 'onehalf': 750,
  33539. 'lessequal': 549,
  33540. 'ocircumflex': 500,
  33541. 'ntilde': 556,
  33542. 'Uhungarumlaut': 722,
  33543. 'Eacute': 667,
  33544. 'emacron': 444,
  33545. 'gbreve': 500,
  33546. 'onequarter': 750,
  33547. 'Scaron': 556,
  33548. 'Scommaaccent': 556,
  33549. 'Ohungarumlaut': 778,
  33550. 'degree': 400,
  33551. 'ograve': 500,
  33552. 'Ccaron': 722,
  33553. 'ugrave': 556,
  33554. 'radical': 549,
  33555. 'Dcaron': 722,
  33556. 'rcommaaccent': 444,
  33557. 'Ntilde': 722,
  33558. 'otilde': 500,
  33559. 'Rcommaaccent': 722,
  33560. 'Lcommaaccent': 667,
  33561. 'Atilde': 722,
  33562. 'Aogonek': 722,
  33563. 'Aring': 722,
  33564. 'Otilde': 778,
  33565. 'zdotaccent': 444,
  33566. 'Ecaron': 667,
  33567. 'Iogonek': 389,
  33568. 'kcommaaccent': 556,
  33569. 'minus': 570,
  33570. 'Icircumflex': 389,
  33571. 'ncaron': 556,
  33572. 'tcommaaccent': 333,
  33573. 'logicalnot': 570,
  33574. 'odieresis': 500,
  33575. 'udieresis': 556,
  33576. 'notequal': 549,
  33577. 'gcommaaccent': 500,
  33578. 'eth': 500,
  33579. 'zcaron': 444,
  33580. 'ncommaaccent': 556,
  33581. 'onesuperior': 300,
  33582. 'imacron': 278,
  33583. 'Euro': 500
  33584. },
  33585. 'Times-BoldItalic': {
  33586. 'space': 250,
  33587. 'exclam': 389,
  33588. 'quotedbl': 555,
  33589. 'numbersign': 500,
  33590. 'dollar': 500,
  33591. 'percent': 833,
  33592. 'ampersand': 778,
  33593. 'quoteright': 333,
  33594. 'parenleft': 333,
  33595. 'parenright': 333,
  33596. 'asterisk': 500,
  33597. 'plus': 570,
  33598. 'comma': 250,
  33599. 'hyphen': 333,
  33600. 'period': 250,
  33601. 'slash': 278,
  33602. 'zero': 500,
  33603. 'one': 500,
  33604. 'two': 500,
  33605. 'three': 500,
  33606. 'four': 500,
  33607. 'five': 500,
  33608. 'six': 500,
  33609. 'seven': 500,
  33610. 'eight': 500,
  33611. 'nine': 500,
  33612. 'colon': 333,
  33613. 'semicolon': 333,
  33614. 'less': 570,
  33615. 'equal': 570,
  33616. 'greater': 570,
  33617. 'question': 500,
  33618. 'at': 832,
  33619. 'A': 667,
  33620. 'B': 667,
  33621. 'C': 667,
  33622. 'D': 722,
  33623. 'E': 667,
  33624. 'F': 667,
  33625. 'G': 722,
  33626. 'H': 778,
  33627. 'I': 389,
  33628. 'J': 500,
  33629. 'K': 667,
  33630. 'L': 611,
  33631. 'M': 889,
  33632. 'N': 722,
  33633. 'O': 722,
  33634. 'P': 611,
  33635. 'Q': 722,
  33636. 'R': 667,
  33637. 'S': 556,
  33638. 'T': 611,
  33639. 'U': 722,
  33640. 'V': 667,
  33641. 'W': 889,
  33642. 'X': 667,
  33643. 'Y': 611,
  33644. 'Z': 611,
  33645. 'bracketleft': 333,
  33646. 'backslash': 278,
  33647. 'bracketright': 333,
  33648. 'asciicircum': 570,
  33649. 'underscore': 500,
  33650. 'quoteleft': 333,
  33651. 'a': 500,
  33652. 'b': 500,
  33653. 'c': 444,
  33654. 'd': 500,
  33655. 'e': 444,
  33656. 'f': 333,
  33657. 'g': 500,
  33658. 'h': 556,
  33659. 'i': 278,
  33660. 'j': 278,
  33661. 'k': 500,
  33662. 'l': 278,
  33663. 'm': 778,
  33664. 'n': 556,
  33665. 'o': 500,
  33666. 'p': 500,
  33667. 'q': 500,
  33668. 'r': 389,
  33669. 's': 389,
  33670. 't': 278,
  33671. 'u': 556,
  33672. 'v': 444,
  33673. 'w': 667,
  33674. 'x': 500,
  33675. 'y': 444,
  33676. 'z': 389,
  33677. 'braceleft': 348,
  33678. 'bar': 220,
  33679. 'braceright': 348,
  33680. 'asciitilde': 570,
  33681. 'exclamdown': 389,
  33682. 'cent': 500,
  33683. 'sterling': 500,
  33684. 'fraction': 167,
  33685. 'yen': 500,
  33686. 'florin': 500,
  33687. 'section': 500,
  33688. 'currency': 500,
  33689. 'quotesingle': 278,
  33690. 'quotedblleft': 500,
  33691. 'guillemotleft': 500,
  33692. 'guilsinglleft': 333,
  33693. 'guilsinglright': 333,
  33694. 'fi': 556,
  33695. 'fl': 556,
  33696. 'endash': 500,
  33697. 'dagger': 500,
  33698. 'daggerdbl': 500,
  33699. 'periodcentered': 250,
  33700. 'paragraph': 500,
  33701. 'bullet': 350,
  33702. 'quotesinglbase': 333,
  33703. 'quotedblbase': 500,
  33704. 'quotedblright': 500,
  33705. 'guillemotright': 500,
  33706. 'ellipsis': 1000,
  33707. 'perthousand': 1000,
  33708. 'questiondown': 500,
  33709. 'grave': 333,
  33710. 'acute': 333,
  33711. 'circumflex': 333,
  33712. 'tilde': 333,
  33713. 'macron': 333,
  33714. 'breve': 333,
  33715. 'dotaccent': 333,
  33716. 'dieresis': 333,
  33717. 'ring': 333,
  33718. 'cedilla': 333,
  33719. 'hungarumlaut': 333,
  33720. 'ogonek': 333,
  33721. 'caron': 333,
  33722. 'emdash': 1000,
  33723. 'AE': 944,
  33724. 'ordfeminine': 266,
  33725. 'Lslash': 611,
  33726. 'Oslash': 722,
  33727. 'OE': 944,
  33728. 'ordmasculine': 300,
  33729. 'ae': 722,
  33730. 'dotlessi': 278,
  33731. 'lslash': 278,
  33732. 'oslash': 500,
  33733. 'oe': 722,
  33734. 'germandbls': 500,
  33735. 'Idieresis': 389,
  33736. 'eacute': 444,
  33737. 'abreve': 500,
  33738. 'uhungarumlaut': 556,
  33739. 'ecaron': 444,
  33740. 'Ydieresis': 611,
  33741. 'divide': 570,
  33742. 'Yacute': 611,
  33743. 'Acircumflex': 667,
  33744. 'aacute': 500,
  33745. 'Ucircumflex': 722,
  33746. 'yacute': 444,
  33747. 'scommaaccent': 389,
  33748. 'ecircumflex': 444,
  33749. 'Uring': 722,
  33750. 'Udieresis': 722,
  33751. 'aogonek': 500,
  33752. 'Uacute': 722,
  33753. 'uogonek': 556,
  33754. 'Edieresis': 667,
  33755. 'Dcroat': 722,
  33756. 'commaaccent': 250,
  33757. 'copyright': 747,
  33758. 'Emacron': 667,
  33759. 'ccaron': 444,
  33760. 'aring': 500,
  33761. 'Ncommaaccent': 722,
  33762. 'lacute': 278,
  33763. 'agrave': 500,
  33764. 'Tcommaaccent': 611,
  33765. 'Cacute': 667,
  33766. 'atilde': 500,
  33767. 'Edotaccent': 667,
  33768. 'scaron': 389,
  33769. 'scedilla': 389,
  33770. 'iacute': 278,
  33771. 'lozenge': 494,
  33772. 'Rcaron': 667,
  33773. 'Gcommaaccent': 722,
  33774. 'ucircumflex': 556,
  33775. 'acircumflex': 500,
  33776. 'Amacron': 667,
  33777. 'rcaron': 389,
  33778. 'ccedilla': 444,
  33779. 'Zdotaccent': 611,
  33780. 'Thorn': 611,
  33781. 'Omacron': 722,
  33782. 'Racute': 667,
  33783. 'Sacute': 556,
  33784. 'dcaron': 608,
  33785. 'Umacron': 722,
  33786. 'uring': 556,
  33787. 'threesuperior': 300,
  33788. 'Ograve': 722,
  33789. 'Agrave': 667,
  33790. 'Abreve': 667,
  33791. 'multiply': 570,
  33792. 'uacute': 556,
  33793. 'Tcaron': 611,
  33794. 'partialdiff': 494,
  33795. 'ydieresis': 444,
  33796. 'Nacute': 722,
  33797. 'icircumflex': 278,
  33798. 'Ecircumflex': 667,
  33799. 'adieresis': 500,
  33800. 'edieresis': 444,
  33801. 'cacute': 444,
  33802. 'nacute': 556,
  33803. 'umacron': 556,
  33804. 'Ncaron': 722,
  33805. 'Iacute': 389,
  33806. 'plusminus': 570,
  33807. 'brokenbar': 220,
  33808. 'registered': 747,
  33809. 'Gbreve': 722,
  33810. 'Idotaccent': 389,
  33811. 'summation': 600,
  33812. 'Egrave': 667,
  33813. 'racute': 389,
  33814. 'omacron': 500,
  33815. 'Zacute': 611,
  33816. 'Zcaron': 611,
  33817. 'greaterequal': 549,
  33818. 'Eth': 722,
  33819. 'Ccedilla': 667,
  33820. 'lcommaaccent': 278,
  33821. 'tcaron': 366,
  33822. 'eogonek': 444,
  33823. 'Uogonek': 722,
  33824. 'Aacute': 667,
  33825. 'Adieresis': 667,
  33826. 'egrave': 444,
  33827. 'zacute': 389,
  33828. 'iogonek': 278,
  33829. 'Oacute': 722,
  33830. 'oacute': 500,
  33831. 'amacron': 500,
  33832. 'sacute': 389,
  33833. 'idieresis': 278,
  33834. 'Ocircumflex': 722,
  33835. 'Ugrave': 722,
  33836. 'Delta': 612,
  33837. 'thorn': 500,
  33838. 'twosuperior': 300,
  33839. 'Odieresis': 722,
  33840. 'mu': 576,
  33841. 'igrave': 278,
  33842. 'ohungarumlaut': 500,
  33843. 'Eogonek': 667,
  33844. 'dcroat': 500,
  33845. 'threequarters': 750,
  33846. 'Scedilla': 556,
  33847. 'lcaron': 382,
  33848. 'Kcommaaccent': 667,
  33849. 'Lacute': 611,
  33850. 'trademark': 1000,
  33851. 'edotaccent': 444,
  33852. 'Igrave': 389,
  33853. 'Imacron': 389,
  33854. 'Lcaron': 611,
  33855. 'onehalf': 750,
  33856. 'lessequal': 549,
  33857. 'ocircumflex': 500,
  33858. 'ntilde': 556,
  33859. 'Uhungarumlaut': 722,
  33860. 'Eacute': 667,
  33861. 'emacron': 444,
  33862. 'gbreve': 500,
  33863. 'onequarter': 750,
  33864. 'Scaron': 556,
  33865. 'Scommaaccent': 556,
  33866. 'Ohungarumlaut': 722,
  33867. 'degree': 400,
  33868. 'ograve': 500,
  33869. 'Ccaron': 667,
  33870. 'ugrave': 556,
  33871. 'radical': 549,
  33872. 'Dcaron': 722,
  33873. 'rcommaaccent': 389,
  33874. 'Ntilde': 722,
  33875. 'otilde': 500,
  33876. 'Rcommaaccent': 667,
  33877. 'Lcommaaccent': 611,
  33878. 'Atilde': 667,
  33879. 'Aogonek': 667,
  33880. 'Aring': 667,
  33881. 'Otilde': 722,
  33882. 'zdotaccent': 389,
  33883. 'Ecaron': 667,
  33884. 'Iogonek': 389,
  33885. 'kcommaaccent': 500,
  33886. 'minus': 606,
  33887. 'Icircumflex': 389,
  33888. 'ncaron': 556,
  33889. 'tcommaaccent': 278,
  33890. 'logicalnot': 606,
  33891. 'odieresis': 500,
  33892. 'udieresis': 556,
  33893. 'notequal': 549,
  33894. 'gcommaaccent': 500,
  33895. 'eth': 500,
  33896. 'zcaron': 389,
  33897. 'ncommaaccent': 556,
  33898. 'onesuperior': 300,
  33899. 'imacron': 278,
  33900. 'Euro': 500
  33901. },
  33902. 'Times-Italic': {
  33903. 'space': 250,
  33904. 'exclam': 333,
  33905. 'quotedbl': 420,
  33906. 'numbersign': 500,
  33907. 'dollar': 500,
  33908. 'percent': 833,
  33909. 'ampersand': 778,
  33910. 'quoteright': 333,
  33911. 'parenleft': 333,
  33912. 'parenright': 333,
  33913. 'asterisk': 500,
  33914. 'plus': 675,
  33915. 'comma': 250,
  33916. 'hyphen': 333,
  33917. 'period': 250,
  33918. 'slash': 278,
  33919. 'zero': 500,
  33920. 'one': 500,
  33921. 'two': 500,
  33922. 'three': 500,
  33923. 'four': 500,
  33924. 'five': 500,
  33925. 'six': 500,
  33926. 'seven': 500,
  33927. 'eight': 500,
  33928. 'nine': 500,
  33929. 'colon': 333,
  33930. 'semicolon': 333,
  33931. 'less': 675,
  33932. 'equal': 675,
  33933. 'greater': 675,
  33934. 'question': 500,
  33935. 'at': 920,
  33936. 'A': 611,
  33937. 'B': 611,
  33938. 'C': 667,
  33939. 'D': 722,
  33940. 'E': 611,
  33941. 'F': 611,
  33942. 'G': 722,
  33943. 'H': 722,
  33944. 'I': 333,
  33945. 'J': 444,
  33946. 'K': 667,
  33947. 'L': 556,
  33948. 'M': 833,
  33949. 'N': 667,
  33950. 'O': 722,
  33951. 'P': 611,
  33952. 'Q': 722,
  33953. 'R': 611,
  33954. 'S': 500,
  33955. 'T': 556,
  33956. 'U': 722,
  33957. 'V': 611,
  33958. 'W': 833,
  33959. 'X': 611,
  33960. 'Y': 556,
  33961. 'Z': 556,
  33962. 'bracketleft': 389,
  33963. 'backslash': 278,
  33964. 'bracketright': 389,
  33965. 'asciicircum': 422,
  33966. 'underscore': 500,
  33967. 'quoteleft': 333,
  33968. 'a': 500,
  33969. 'b': 500,
  33970. 'c': 444,
  33971. 'd': 500,
  33972. 'e': 444,
  33973. 'f': 278,
  33974. 'g': 500,
  33975. 'h': 500,
  33976. 'i': 278,
  33977. 'j': 278,
  33978. 'k': 444,
  33979. 'l': 278,
  33980. 'm': 722,
  33981. 'n': 500,
  33982. 'o': 500,
  33983. 'p': 500,
  33984. 'q': 500,
  33985. 'r': 389,
  33986. 's': 389,
  33987. 't': 278,
  33988. 'u': 500,
  33989. 'v': 444,
  33990. 'w': 667,
  33991. 'x': 444,
  33992. 'y': 444,
  33993. 'z': 389,
  33994. 'braceleft': 400,
  33995. 'bar': 275,
  33996. 'braceright': 400,
  33997. 'asciitilde': 541,
  33998. 'exclamdown': 389,
  33999. 'cent': 500,
  34000. 'sterling': 500,
  34001. 'fraction': 167,
  34002. 'yen': 500,
  34003. 'florin': 500,
  34004. 'section': 500,
  34005. 'currency': 500,
  34006. 'quotesingle': 214,
  34007. 'quotedblleft': 556,
  34008. 'guillemotleft': 500,
  34009. 'guilsinglleft': 333,
  34010. 'guilsinglright': 333,
  34011. 'fi': 500,
  34012. 'fl': 500,
  34013. 'endash': 500,
  34014. 'dagger': 500,
  34015. 'daggerdbl': 500,
  34016. 'periodcentered': 250,
  34017. 'paragraph': 523,
  34018. 'bullet': 350,
  34019. 'quotesinglbase': 333,
  34020. 'quotedblbase': 556,
  34021. 'quotedblright': 556,
  34022. 'guillemotright': 500,
  34023. 'ellipsis': 889,
  34024. 'perthousand': 1000,
  34025. 'questiondown': 500,
  34026. 'grave': 333,
  34027. 'acute': 333,
  34028. 'circumflex': 333,
  34029. 'tilde': 333,
  34030. 'macron': 333,
  34031. 'breve': 333,
  34032. 'dotaccent': 333,
  34033. 'dieresis': 333,
  34034. 'ring': 333,
  34035. 'cedilla': 333,
  34036. 'hungarumlaut': 333,
  34037. 'ogonek': 333,
  34038. 'caron': 333,
  34039. 'emdash': 889,
  34040. 'AE': 889,
  34041. 'ordfeminine': 276,
  34042. 'Lslash': 556,
  34043. 'Oslash': 722,
  34044. 'OE': 944,
  34045. 'ordmasculine': 310,
  34046. 'ae': 667,
  34047. 'dotlessi': 278,
  34048. 'lslash': 278,
  34049. 'oslash': 500,
  34050. 'oe': 667,
  34051. 'germandbls': 500,
  34052. 'Idieresis': 333,
  34053. 'eacute': 444,
  34054. 'abreve': 500,
  34055. 'uhungarumlaut': 500,
  34056. 'ecaron': 444,
  34057. 'Ydieresis': 556,
  34058. 'divide': 675,
  34059. 'Yacute': 556,
  34060. 'Acircumflex': 611,
  34061. 'aacute': 500,
  34062. 'Ucircumflex': 722,
  34063. 'yacute': 444,
  34064. 'scommaaccent': 389,
  34065. 'ecircumflex': 444,
  34066. 'Uring': 722,
  34067. 'Udieresis': 722,
  34068. 'aogonek': 500,
  34069. 'Uacute': 722,
  34070. 'uogonek': 500,
  34071. 'Edieresis': 611,
  34072. 'Dcroat': 722,
  34073. 'commaaccent': 250,
  34074. 'copyright': 760,
  34075. 'Emacron': 611,
  34076. 'ccaron': 444,
  34077. 'aring': 500,
  34078. 'Ncommaaccent': 667,
  34079. 'lacute': 278,
  34080. 'agrave': 500,
  34081. 'Tcommaaccent': 556,
  34082. 'Cacute': 667,
  34083. 'atilde': 500,
  34084. 'Edotaccent': 611,
  34085. 'scaron': 389,
  34086. 'scedilla': 389,
  34087. 'iacute': 278,
  34088. 'lozenge': 471,
  34089. 'Rcaron': 611,
  34090. 'Gcommaaccent': 722,
  34091. 'ucircumflex': 500,
  34092. 'acircumflex': 500,
  34093. 'Amacron': 611,
  34094. 'rcaron': 389,
  34095. 'ccedilla': 444,
  34096. 'Zdotaccent': 556,
  34097. 'Thorn': 611,
  34098. 'Omacron': 722,
  34099. 'Racute': 611,
  34100. 'Sacute': 500,
  34101. 'dcaron': 544,
  34102. 'Umacron': 722,
  34103. 'uring': 500,
  34104. 'threesuperior': 300,
  34105. 'Ograve': 722,
  34106. 'Agrave': 611,
  34107. 'Abreve': 611,
  34108. 'multiply': 675,
  34109. 'uacute': 500,
  34110. 'Tcaron': 556,
  34111. 'partialdiff': 476,
  34112. 'ydieresis': 444,
  34113. 'Nacute': 667,
  34114. 'icircumflex': 278,
  34115. 'Ecircumflex': 611,
  34116. 'adieresis': 500,
  34117. 'edieresis': 444,
  34118. 'cacute': 444,
  34119. 'nacute': 500,
  34120. 'umacron': 500,
  34121. 'Ncaron': 667,
  34122. 'Iacute': 333,
  34123. 'plusminus': 675,
  34124. 'brokenbar': 275,
  34125. 'registered': 760,
  34126. 'Gbreve': 722,
  34127. 'Idotaccent': 333,
  34128. 'summation': 600,
  34129. 'Egrave': 611,
  34130. 'racute': 389,
  34131. 'omacron': 500,
  34132. 'Zacute': 556,
  34133. 'Zcaron': 556,
  34134. 'greaterequal': 549,
  34135. 'Eth': 722,
  34136. 'Ccedilla': 667,
  34137. 'lcommaaccent': 278,
  34138. 'tcaron': 300,
  34139. 'eogonek': 444,
  34140. 'Uogonek': 722,
  34141. 'Aacute': 611,
  34142. 'Adieresis': 611,
  34143. 'egrave': 444,
  34144. 'zacute': 389,
  34145. 'iogonek': 278,
  34146. 'Oacute': 722,
  34147. 'oacute': 500,
  34148. 'amacron': 500,
  34149. 'sacute': 389,
  34150. 'idieresis': 278,
  34151. 'Ocircumflex': 722,
  34152. 'Ugrave': 722,
  34153. 'Delta': 612,
  34154. 'thorn': 500,
  34155. 'twosuperior': 300,
  34156. 'Odieresis': 722,
  34157. 'mu': 500,
  34158. 'igrave': 278,
  34159. 'ohungarumlaut': 500,
  34160. 'Eogonek': 611,
  34161. 'dcroat': 500,
  34162. 'threequarters': 750,
  34163. 'Scedilla': 500,
  34164. 'lcaron': 300,
  34165. 'Kcommaaccent': 667,
  34166. 'Lacute': 556,
  34167. 'trademark': 980,
  34168. 'edotaccent': 444,
  34169. 'Igrave': 333,
  34170. 'Imacron': 333,
  34171. 'Lcaron': 611,
  34172. 'onehalf': 750,
  34173. 'lessequal': 549,
  34174. 'ocircumflex': 500,
  34175. 'ntilde': 500,
  34176. 'Uhungarumlaut': 722,
  34177. 'Eacute': 611,
  34178. 'emacron': 444,
  34179. 'gbreve': 500,
  34180. 'onequarter': 750,
  34181. 'Scaron': 500,
  34182. 'Scommaaccent': 500,
  34183. 'Ohungarumlaut': 722,
  34184. 'degree': 400,
  34185. 'ograve': 500,
  34186. 'Ccaron': 667,
  34187. 'ugrave': 500,
  34188. 'radical': 453,
  34189. 'Dcaron': 722,
  34190. 'rcommaaccent': 389,
  34191. 'Ntilde': 667,
  34192. 'otilde': 500,
  34193. 'Rcommaaccent': 611,
  34194. 'Lcommaaccent': 556,
  34195. 'Atilde': 611,
  34196. 'Aogonek': 611,
  34197. 'Aring': 611,
  34198. 'Otilde': 722,
  34199. 'zdotaccent': 389,
  34200. 'Ecaron': 611,
  34201. 'Iogonek': 333,
  34202. 'kcommaaccent': 444,
  34203. 'minus': 675,
  34204. 'Icircumflex': 333,
  34205. 'ncaron': 500,
  34206. 'tcommaaccent': 278,
  34207. 'logicalnot': 675,
  34208. 'odieresis': 500,
  34209. 'udieresis': 500,
  34210. 'notequal': 549,
  34211. 'gcommaaccent': 500,
  34212. 'eth': 500,
  34213. 'zcaron': 389,
  34214. 'ncommaaccent': 500,
  34215. 'onesuperior': 300,
  34216. 'imacron': 278,
  34217. 'Euro': 500
  34218. },
  34219. 'ZapfDingbats': {
  34220. 'space': 278,
  34221. 'a1': 974,
  34222. 'a2': 961,
  34223. 'a202': 974,
  34224. 'a3': 980,
  34225. 'a4': 719,
  34226. 'a5': 789,
  34227. 'a119': 790,
  34228. 'a118': 791,
  34229. 'a117': 690,
  34230. 'a11': 960,
  34231. 'a12': 939,
  34232. 'a13': 549,
  34233. 'a14': 855,
  34234. 'a15': 911,
  34235. 'a16': 933,
  34236. 'a105': 911,
  34237. 'a17': 945,
  34238. 'a18': 974,
  34239. 'a19': 755,
  34240. 'a20': 846,
  34241. 'a21': 762,
  34242. 'a22': 761,
  34243. 'a23': 571,
  34244. 'a24': 677,
  34245. 'a25': 763,
  34246. 'a26': 760,
  34247. 'a27': 759,
  34248. 'a28': 754,
  34249. 'a6': 494,
  34250. 'a7': 552,
  34251. 'a8': 537,
  34252. 'a9': 577,
  34253. 'a10': 692,
  34254. 'a29': 786,
  34255. 'a30': 788,
  34256. 'a31': 788,
  34257. 'a32': 790,
  34258. 'a33': 793,
  34259. 'a34': 794,
  34260. 'a35': 816,
  34261. 'a36': 823,
  34262. 'a37': 789,
  34263. 'a38': 841,
  34264. 'a39': 823,
  34265. 'a40': 833,
  34266. 'a41': 816,
  34267. 'a42': 831,
  34268. 'a43': 923,
  34269. 'a44': 744,
  34270. 'a45': 723,
  34271. 'a46': 749,
  34272. 'a47': 790,
  34273. 'a48': 792,
  34274. 'a49': 695,
  34275. 'a50': 776,
  34276. 'a51': 768,
  34277. 'a52': 792,
  34278. 'a53': 759,
  34279. 'a54': 707,
  34280. 'a55': 708,
  34281. 'a56': 682,
  34282. 'a57': 701,
  34283. 'a58': 826,
  34284. 'a59': 815,
  34285. 'a60': 789,
  34286. 'a61': 789,
  34287. 'a62': 707,
  34288. 'a63': 687,
  34289. 'a64': 696,
  34290. 'a65': 689,
  34291. 'a66': 786,
  34292. 'a67': 787,
  34293. 'a68': 713,
  34294. 'a69': 791,
  34295. 'a70': 785,
  34296. 'a71': 791,
  34297. 'a72': 873,
  34298. 'a73': 761,
  34299. 'a74': 762,
  34300. 'a203': 762,
  34301. 'a75': 759,
  34302. 'a204': 759,
  34303. 'a76': 892,
  34304. 'a77': 892,
  34305. 'a78': 788,
  34306. 'a79': 784,
  34307. 'a81': 438,
  34308. 'a82': 138,
  34309. 'a83': 277,
  34310. 'a84': 415,
  34311. 'a97': 392,
  34312. 'a98': 392,
  34313. 'a99': 668,
  34314. 'a100': 668,
  34315. 'a89': 390,
  34316. 'a90': 390,
  34317. 'a93': 317,
  34318. 'a94': 317,
  34319. 'a91': 276,
  34320. 'a92': 276,
  34321. 'a205': 509,
  34322. 'a85': 509,
  34323. 'a206': 410,
  34324. 'a86': 410,
  34325. 'a87': 234,
  34326. 'a88': 234,
  34327. 'a95': 334,
  34328. 'a96': 334,
  34329. 'a101': 732,
  34330. 'a102': 544,
  34331. 'a103': 544,
  34332. 'a104': 910,
  34333. 'a106': 667,
  34334. 'a107': 760,
  34335. 'a108': 760,
  34336. 'a112': 776,
  34337. 'a111': 595,
  34338. 'a110': 694,
  34339. 'a109': 626,
  34340. 'a120': 788,
  34341. 'a121': 788,
  34342. 'a122': 788,
  34343. 'a123': 788,
  34344. 'a124': 788,
  34345. 'a125': 788,
  34346. 'a126': 788,
  34347. 'a127': 788,
  34348. 'a128': 788,
  34349. 'a129': 788,
  34350. 'a130': 788,
  34351. 'a131': 788,
  34352. 'a132': 788,
  34353. 'a133': 788,
  34354. 'a134': 788,
  34355. 'a135': 788,
  34356. 'a136': 788,
  34357. 'a137': 788,
  34358. 'a138': 788,
  34359. 'a139': 788,
  34360. 'a140': 788,
  34361. 'a141': 788,
  34362. 'a142': 788,
  34363. 'a143': 788,
  34364. 'a144': 788,
  34365. 'a145': 788,
  34366. 'a146': 788,
  34367. 'a147': 788,
  34368. 'a148': 788,
  34369. 'a149': 788,
  34370. 'a150': 788,
  34371. 'a151': 788,
  34372. 'a152': 788,
  34373. 'a153': 788,
  34374. 'a154': 788,
  34375. 'a155': 788,
  34376. 'a156': 788,
  34377. 'a157': 788,
  34378. 'a158': 788,
  34379. 'a159': 788,
  34380. 'a160': 894,
  34381. 'a161': 838,
  34382. 'a163': 1016,
  34383. 'a164': 458,
  34384. 'a196': 748,
  34385. 'a165': 924,
  34386. 'a192': 748,
  34387. 'a166': 918,
  34388. 'a167': 927,
  34389. 'a168': 928,
  34390. 'a169': 928,
  34391. 'a170': 834,
  34392. 'a171': 873,
  34393. 'a172': 828,
  34394. 'a173': 924,
  34395. 'a162': 924,
  34396. 'a174': 917,
  34397. 'a175': 930,
  34398. 'a176': 931,
  34399. 'a177': 463,
  34400. 'a178': 883,
  34401. 'a179': 836,
  34402. 'a193': 836,
  34403. 'a180': 867,
  34404. 'a199': 867,
  34405. 'a181': 696,
  34406. 'a200': 696,
  34407. 'a182': 874,
  34408. 'a201': 874,
  34409. 'a183': 760,
  34410. 'a184': 946,
  34411. 'a197': 771,
  34412. 'a185': 865,
  34413. 'a194': 771,
  34414. 'a198': 888,
  34415. 'a186': 967,
  34416. 'a195': 888,
  34417. 'a187': 831,
  34418. 'a188': 873,
  34419. 'a189': 927,
  34420. 'a190': 970,
  34421. 'a191': 918
  34422. }
  34423. };
  34424. var EOF = {};
  34425. function isEOF(v) {
  34426. return (v === EOF);
  34427. }
  34428. var MAX_LENGTH_TO_CACHE = 1000;
  34429. var Parser = (function ParserClosure() {
  34430. function Parser(lexer, allowStreams, xref) {
  34431. this.lexer = lexer;
  34432. this.allowStreams = allowStreams;
  34433. this.xref = xref;
  34434. this.imageCache = {};
  34435. this.refill();
  34436. }
  34437. Parser.prototype = {
  34438. refill: function Parser_refill() {
  34439. this.buf1 = this.lexer.getObj();
  34440. this.buf2 = this.lexer.getObj();
  34441. },
  34442. shift: function Parser_shift() {
  34443. if (isCmd(this.buf2, 'ID')) {
  34444. this.buf1 = this.buf2;
  34445. this.buf2 = null;
  34446. } else {
  34447. this.buf1 = this.buf2;
  34448. this.buf2 = this.lexer.getObj();
  34449. }
  34450. },
  34451. tryShift: function Parser_tryShift() {
  34452. try {
  34453. this.shift();
  34454. return true;
  34455. } catch (e) {
  34456. if (e instanceof MissingDataException) {
  34457. throw e;
  34458. }
  34459. // Upon failure, the caller should reset this.lexer.pos to a known good
  34460. // state and call this.shift() twice to reset the buffers.
  34461. return false;
  34462. }
  34463. },
  34464. getObj: function Parser_getObj(cipherTransform) {
  34465. var buf1 = this.buf1;
  34466. this.shift();
  34467. if (buf1 instanceof Cmd) {
  34468. switch (buf1.cmd) {
  34469. case 'BI': // inline image
  34470. return this.makeInlineImage(cipherTransform);
  34471. case '[': // array
  34472. var array = [];
  34473. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  34474. array.push(this.getObj(cipherTransform));
  34475. }
  34476. if (isEOF(this.buf1)) {
  34477. error('End of file inside array');
  34478. }
  34479. this.shift();
  34480. return array;
  34481. case '<<': // dictionary or stream
  34482. var dict = new Dict(this.xref);
  34483. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  34484. if (!isName(this.buf1)) {
  34485. info('Malformed dictionary: key must be a name object');
  34486. this.shift();
  34487. continue;
  34488. }
  34489. var key = this.buf1.name;
  34490. this.shift();
  34491. if (isEOF(this.buf1)) {
  34492. break;
  34493. }
  34494. dict.set(key, this.getObj(cipherTransform));
  34495. }
  34496. if (isEOF(this.buf1)) {
  34497. error('End of file inside dictionary');
  34498. }
  34499. // Stream objects are not allowed inside content streams or
  34500. // object streams.
  34501. if (isCmd(this.buf2, 'stream')) {
  34502. return (this.allowStreams ?
  34503. this.makeStream(dict, cipherTransform) : dict);
  34504. }
  34505. this.shift();
  34506. return dict;
  34507. default: // simple object
  34508. return buf1;
  34509. }
  34510. }
  34511. if (isInt(buf1)) { // indirect reference or integer
  34512. var num = buf1;
  34513. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  34514. var ref = new Ref(num, this.buf1);
  34515. this.shift();
  34516. this.shift();
  34517. return ref;
  34518. }
  34519. return num;
  34520. }
  34521. if (isString(buf1)) { // string
  34522. var str = buf1;
  34523. if (cipherTransform) {
  34524. str = cipherTransform.decryptString(str);
  34525. }
  34526. return str;
  34527. }
  34528. // simple object
  34529. return buf1;
  34530. },
  34531. /**
  34532. * Find the end of the stream by searching for the /EI\s/.
  34533. * @returns {number} The inline stream length.
  34534. */
  34535. findDefaultInlineStreamEnd:
  34536. function Parser_findDefaultInlineStreamEnd(stream) {
  34537. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  34538. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  34539. while ((ch = stream.getByte()) !== -1) {
  34540. if (state === 0) {
  34541. state = (ch === E) ? 1 : 0;
  34542. } else if (state === 1) {
  34543. state = (ch === I) ? 2 : 0;
  34544. } else {
  34545. assert(state === 2);
  34546. if (ch === SPACE || ch === LF || ch === CR) {
  34547. // Let's check the next five bytes are ASCII... just be sure.
  34548. n = 5;
  34549. followingBytes = stream.peekBytes(n);
  34550. for (i = 0; i < n; i++) {
  34551. ch = followingBytes[i];
  34552. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  34553. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  34554. // it's binary stuff. Resetting the state.
  34555. state = 0;
  34556. break;
  34557. }
  34558. }
  34559. if (state === 2) {
  34560. break; // Finished!
  34561. }
  34562. } else {
  34563. state = 0;
  34564. }
  34565. }
  34566. }
  34567. return ((stream.pos - 4) - startPos);
  34568. },
  34569. /**
  34570. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34571. * @returns {number} The inline stream length.
  34572. */
  34573. findDCTDecodeInlineStreamEnd:
  34574. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34575. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34576. while ((b = stream.getByte()) !== -1) {
  34577. if (b !== 0xFF) { // Not a valid marker.
  34578. continue;
  34579. }
  34580. switch (stream.getByte()) {
  34581. case 0x00: // Byte stuffing.
  34582. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34583. break;
  34584. case 0xFF: // Fill byte.
  34585. // Avoid skipping a valid marker, resetting the stream position.
  34586. stream.skip(-1);
  34587. break;
  34588. case 0xD9: // EOI
  34589. foundEOI = true;
  34590. break;
  34591. case 0xC0: // SOF0
  34592. case 0xC1: // SOF1
  34593. case 0xC2: // SOF2
  34594. case 0xC3: // SOF3
  34595. case 0xC5: // SOF5
  34596. case 0xC6: // SOF6
  34597. case 0xC7: // SOF7
  34598. case 0xC9: // SOF9
  34599. case 0xCA: // SOF10
  34600. case 0xCB: // SOF11
  34601. case 0xCD: // SOF13
  34602. case 0xCE: // SOF14
  34603. case 0xCF: // SOF15
  34604. case 0xC4: // DHT
  34605. case 0xCC: // DAC
  34606. case 0xDA: // SOS
  34607. case 0xDB: // DQT
  34608. case 0xDC: // DNL
  34609. case 0xDD: // DRI
  34610. case 0xDE: // DHP
  34611. case 0xDF: // EXP
  34612. case 0xE0: // APP0
  34613. case 0xE1: // APP1
  34614. case 0xE2: // APP2
  34615. case 0xE3: // APP3
  34616. case 0xE4: // APP4
  34617. case 0xE5: // APP5
  34618. case 0xE6: // APP6
  34619. case 0xE7: // APP7
  34620. case 0xE8: // APP8
  34621. case 0xE9: // APP9
  34622. case 0xEA: // APP10
  34623. case 0xEB: // APP11
  34624. case 0xEC: // APP12
  34625. case 0xED: // APP13
  34626. case 0xEE: // APP14
  34627. case 0xEF: // APP15
  34628. case 0xFE: // COM
  34629. // The marker should be followed by the length of the segment.
  34630. markerLength = stream.getUint16();
  34631. if (markerLength > 2) {
  34632. // |markerLength| contains the byte length of the marker segment,
  34633. // including its own length (2 bytes) and excluding the marker.
  34634. stream.skip(markerLength - 2); // Jump to the next marker.
  34635. } else {
  34636. // The marker length is invalid, resetting the stream position.
  34637. stream.skip(-2);
  34638. }
  34639. break;
  34640. }
  34641. if (foundEOI) {
  34642. break;
  34643. }
  34644. }
  34645. length = stream.pos - startPos;
  34646. if (b === -1) {
  34647. warn('Inline DCTDecode image stream: ' +
  34648. 'EOI marker not found, searching for /EI/ instead.');
  34649. stream.skip(-length); // Reset the stream position.
  34650. return this.findDefaultInlineStreamEnd(stream);
  34651. }
  34652. this.inlineStreamSkipEI(stream);
  34653. return length;
  34654. },
  34655. /**
  34656. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34657. * @returns {number} The inline stream length.
  34658. */
  34659. findASCII85DecodeInlineStreamEnd:
  34660. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34661. var TILDE = 0x7E, GT = 0x3E;
  34662. var startPos = stream.pos, ch, length;
  34663. while ((ch = stream.getByte()) !== -1) {
  34664. if (ch === TILDE && stream.peekByte() === GT) {
  34665. stream.skip();
  34666. break;
  34667. }
  34668. }
  34669. length = stream.pos - startPos;
  34670. if (ch === -1) {
  34671. warn('Inline ASCII85Decode image stream: ' +
  34672. 'EOD marker not found, searching for /EI/ instead.');
  34673. stream.skip(-length); // Reset the stream position.
  34674. return this.findDefaultInlineStreamEnd(stream);
  34675. }
  34676. this.inlineStreamSkipEI(stream);
  34677. return length;
  34678. },
  34679. /**
  34680. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34681. * @returns {number} The inline stream length.
  34682. */
  34683. findASCIIHexDecodeInlineStreamEnd:
  34684. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34685. var GT = 0x3E;
  34686. var startPos = stream.pos, ch, length;
  34687. while ((ch = stream.getByte()) !== -1) {
  34688. if (ch === GT) {
  34689. break;
  34690. }
  34691. }
  34692. length = stream.pos - startPos;
  34693. if (ch === -1) {
  34694. warn('Inline ASCIIHexDecode image stream: ' +
  34695. 'EOD marker not found, searching for /EI/ instead.');
  34696. stream.skip(-length); // Reset the stream position.
  34697. return this.findDefaultInlineStreamEnd(stream);
  34698. }
  34699. this.inlineStreamSkipEI(stream);
  34700. return length;
  34701. },
  34702. /**
  34703. * Skip over the /EI/ for streams where we search for an EOD marker.
  34704. */
  34705. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34706. var E = 0x45, I = 0x49;
  34707. var state = 0, ch;
  34708. while ((ch = stream.getByte()) !== -1) {
  34709. if (state === 0) {
  34710. state = (ch === E) ? 1 : 0;
  34711. } else if (state === 1) {
  34712. state = (ch === I) ? 2 : 0;
  34713. } else if (state === 2) {
  34714. break;
  34715. }
  34716. }
  34717. },
  34718. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34719. var lexer = this.lexer;
  34720. var stream = lexer.stream;
  34721. // Parse dictionary.
  34722. var dict = new Dict(this.xref);
  34723. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34724. if (!isName(this.buf1)) {
  34725. error('Dictionary key must be a name object');
  34726. }
  34727. var key = this.buf1.name;
  34728. this.shift();
  34729. if (isEOF(this.buf1)) {
  34730. break;
  34731. }
  34732. dict.set(key, this.getObj(cipherTransform));
  34733. }
  34734. // Extract the name of the first (i.e. the current) image filter.
  34735. var filter = dict.get('Filter', 'F'), filterName;
  34736. if (isName(filter)) {
  34737. filterName = filter.name;
  34738. } else if (isArray(filter) && isName(filter[0])) {
  34739. filterName = filter[0].name;
  34740. }
  34741. // Parse image stream.
  34742. var startPos = stream.pos, length, i, ii;
  34743. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34744. length = this.findDCTDecodeInlineStreamEnd(stream);
  34745. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34746. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34747. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34748. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34749. } else {
  34750. length = this.findDefaultInlineStreamEnd(stream);
  34751. }
  34752. var imageStream = stream.makeSubStream(startPos, length, dict);
  34753. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34754. // adler32 checksum.
  34755. var adler32;
  34756. if (length < MAX_LENGTH_TO_CACHE) {
  34757. var imageBytes = imageStream.getBytes();
  34758. imageStream.reset();
  34759. var a = 1;
  34760. var b = 0;
  34761. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34762. // No modulo required in the loop if imageBytes.length < 5552.
  34763. a += imageBytes[i] & 0xff;
  34764. b += a;
  34765. }
  34766. adler32 = ((b % 65521) << 16) | (a % 65521);
  34767. if (this.imageCache.adler32 === adler32) {
  34768. this.buf2 = Cmd.get('EI');
  34769. this.shift();
  34770. this.imageCache[adler32].reset();
  34771. return this.imageCache[adler32];
  34772. }
  34773. }
  34774. if (cipherTransform) {
  34775. imageStream = cipherTransform.createStream(imageStream, length);
  34776. }
  34777. imageStream = this.filter(imageStream, dict, length);
  34778. imageStream.dict = dict;
  34779. if (adler32 !== undefined) {
  34780. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34781. this.imageCache[adler32] = imageStream;
  34782. }
  34783. this.buf2 = Cmd.get('EI');
  34784. this.shift();
  34785. return imageStream;
  34786. },
  34787. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34788. var lexer = this.lexer;
  34789. var stream = lexer.stream;
  34790. // get stream start position
  34791. lexer.skipToNextLine();
  34792. var pos = stream.pos - 1;
  34793. // get length
  34794. var length = dict.get('Length');
  34795. if (!isInt(length)) {
  34796. info('Bad ' + length + ' attribute in stream');
  34797. length = 0;
  34798. }
  34799. // skip over the stream data
  34800. stream.pos = pos + length;
  34801. lexer.nextChar();
  34802. // Shift '>>' and check whether the new object marks the end of the stream
  34803. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  34804. this.shift(); // 'stream'
  34805. } else {
  34806. // bad stream length, scanning for endstream
  34807. stream.pos = pos;
  34808. var SCAN_BLOCK_SIZE = 2048;
  34809. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34810. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34811. 0x61, 0x6D];
  34812. var skipped = 0, found = false, i, j;
  34813. while (stream.pos < stream.end) {
  34814. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34815. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34816. if (scanLength <= 0) {
  34817. break;
  34818. }
  34819. found = false;
  34820. for (i = 0, j = 0; i < scanLength; i++) {
  34821. var b = scanBytes[i];
  34822. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34823. i -= j;
  34824. j = 0;
  34825. } else {
  34826. j++;
  34827. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34828. i++;
  34829. found = true;
  34830. break;
  34831. }
  34832. }
  34833. }
  34834. if (found) {
  34835. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34836. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34837. break;
  34838. }
  34839. skipped += scanLength;
  34840. stream.pos += scanLength;
  34841. }
  34842. if (!found) {
  34843. error('Missing endstream');
  34844. }
  34845. length = skipped;
  34846. lexer.nextChar();
  34847. this.shift();
  34848. this.shift();
  34849. }
  34850. this.shift(); // 'endstream'
  34851. stream = stream.makeSubStream(pos, length, dict);
  34852. if (cipherTransform) {
  34853. stream = cipherTransform.createStream(stream, length);
  34854. }
  34855. stream = this.filter(stream, dict, length);
  34856. stream.dict = dict;
  34857. return stream;
  34858. },
  34859. filter: function Parser_filter(stream, dict, length) {
  34860. var filter = dict.get('Filter', 'F');
  34861. var params = dict.get('DecodeParms', 'DP');
  34862. if (isName(filter)) {
  34863. return this.makeFilter(stream, filter.name, length, params);
  34864. }
  34865. var maybeLength = length;
  34866. if (isArray(filter)) {
  34867. var filterArray = filter;
  34868. var paramsArray = params;
  34869. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34870. filter = filterArray[i];
  34871. if (!isName(filter)) {
  34872. error('Bad filter name: ' + filter);
  34873. }
  34874. params = null;
  34875. if (isArray(paramsArray) && (i in paramsArray)) {
  34876. params = paramsArray[i];
  34877. }
  34878. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34879. // after the first stream the length variable is invalid
  34880. maybeLength = null;
  34881. }
  34882. }
  34883. return stream;
  34884. },
  34885. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34886. if (stream.dict.get('Length') === 0 && !maybeLength) {
  34887. warn('Empty "' + name + '" stream.');
  34888. return new NullStream(stream);
  34889. }
  34890. try {
  34891. if (params && this.xref) {
  34892. params = this.xref.fetchIfRef(params);
  34893. }
  34894. var xrefStreamStats = this.xref.stats.streamTypes;
  34895. if (name === 'FlateDecode' || name === 'Fl') {
  34896. xrefStreamStats[StreamType.FLATE] = true;
  34897. if (params) {
  34898. return new PredictorStream(new FlateStream(stream, maybeLength),
  34899. maybeLength, params);
  34900. }
  34901. return new FlateStream(stream, maybeLength);
  34902. }
  34903. if (name === 'LZWDecode' || name === 'LZW') {
  34904. xrefStreamStats[StreamType.LZW] = true;
  34905. var earlyChange = 1;
  34906. if (params) {
  34907. if (params.has('EarlyChange')) {
  34908. earlyChange = params.get('EarlyChange');
  34909. }
  34910. return new PredictorStream(
  34911. new LZWStream(stream, maybeLength, earlyChange),
  34912. maybeLength, params);
  34913. }
  34914. return new LZWStream(stream, maybeLength, earlyChange);
  34915. }
  34916. if (name === 'DCTDecode' || name === 'DCT') {
  34917. xrefStreamStats[StreamType.DCT] = true;
  34918. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34919. }
  34920. if (name === 'JPXDecode' || name === 'JPX') {
  34921. xrefStreamStats[StreamType.JPX] = true;
  34922. return new JpxStream(stream, maybeLength, stream.dict);
  34923. }
  34924. if (name === 'ASCII85Decode' || name === 'A85') {
  34925. xrefStreamStats[StreamType.A85] = true;
  34926. return new Ascii85Stream(stream, maybeLength);
  34927. }
  34928. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34929. xrefStreamStats[StreamType.AHX] = true;
  34930. return new AsciiHexStream(stream, maybeLength);
  34931. }
  34932. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34933. xrefStreamStats[StreamType.CCF] = true;
  34934. return new CCITTFaxStream(stream, maybeLength, params);
  34935. }
  34936. if (name === 'RunLengthDecode' || name === 'RL') {
  34937. xrefStreamStats[StreamType.RL] = true;
  34938. return new RunLengthStream(stream, maybeLength);
  34939. }
  34940. if (name === 'JBIG2Decode') {
  34941. xrefStreamStats[StreamType.JBIG] = true;
  34942. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34943. }
  34944. warn('filter "' + name + '" not supported yet');
  34945. return stream;
  34946. } catch (ex) {
  34947. if (ex instanceof MissingDataException) {
  34948. throw ex;
  34949. }
  34950. warn('Invalid stream: \"' + ex + '\"');
  34951. return new NullStream(stream);
  34952. }
  34953. }
  34954. };
  34955. return Parser;
  34956. })();
  34957. var Lexer = (function LexerClosure() {
  34958. function Lexer(stream, knownCommands) {
  34959. this.stream = stream;
  34960. this.nextChar();
  34961. // While lexing, we build up many strings one char at a time. Using += for
  34962. // this can result in lots of garbage strings. It's better to build an
  34963. // array of single-char strings and then join() them together at the end.
  34964. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34965. // purpose uses less memory than using a new array for each string.
  34966. this.strBuf = [];
  34967. // The PDFs might have "glued" commands with other commands, operands or
  34968. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34969. // commands and their prefixes. The prefixes are built the following way:
  34970. // if there a command that is a prefix of the other valid command or
  34971. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34972. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34973. // other commands or literals as a prefix. The knowCommands is optional.
  34974. this.knownCommands = knownCommands;
  34975. }
  34976. Lexer.isSpace = function Lexer_isSpace(ch) {
  34977. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34978. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34979. };
  34980. // A '1' in this array means the character is white space. A '1' or
  34981. // '2' means the character ends a name or command.
  34982. var specialChars = [
  34983. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34985. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34999. ];
  35000. function toHexDigit(ch) {
  35001. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  35002. return ch & 0x0F;
  35003. }
  35004. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  35005. // 'A'-'F', 'a'-'f'
  35006. return (ch & 0x0F) + 9;
  35007. }
  35008. return -1;
  35009. }
  35010. Lexer.prototype = {
  35011. nextChar: function Lexer_nextChar() {
  35012. return (this.currentChar = this.stream.getByte());
  35013. },
  35014. peekChar: function Lexer_peekChar() {
  35015. return this.stream.peekByte();
  35016. },
  35017. getNumber: function Lexer_getNumber() {
  35018. var ch = this.currentChar;
  35019. var eNotation = false;
  35020. var divideBy = 0; // different from 0 if it's a floating point value
  35021. var sign = 1;
  35022. if (ch === 0x2D) { // '-'
  35023. sign = -1;
  35024. ch = this.nextChar();
  35025. if (ch === 0x2D) { // '-'
  35026. // Ignore double negative (this is consistent with Adobe Reader).
  35027. ch = this.nextChar();
  35028. }
  35029. } else if (ch === 0x2B) { // '+'
  35030. ch = this.nextChar();
  35031. }
  35032. if (ch === 0x2E) { // '.'
  35033. divideBy = 10;
  35034. ch = this.nextChar();
  35035. }
  35036. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  35037. error('Invalid number: ' + String.fromCharCode(ch));
  35038. return 0;
  35039. }
  35040. var baseValue = ch - 0x30; // '0'
  35041. var powerValue = 0;
  35042. var powerValueSign = 1;
  35043. while ((ch = this.nextChar()) >= 0) {
  35044. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  35045. var currentDigit = ch - 0x30; // '0'
  35046. if (eNotation) { // We are after an 'e' or 'E'
  35047. powerValue = powerValue * 10 + currentDigit;
  35048. } else {
  35049. if (divideBy !== 0) { // We are after a point
  35050. divideBy *= 10;
  35051. }
  35052. baseValue = baseValue * 10 + currentDigit;
  35053. }
  35054. } else if (ch === 0x2E) { // '.'
  35055. if (divideBy === 0) {
  35056. divideBy = 1;
  35057. } else {
  35058. // A number can have only one '.'
  35059. break;
  35060. }
  35061. } else if (ch === 0x2D) { // '-'
  35062. // ignore minus signs in the middle of numbers to match
  35063. // Adobe's behavior
  35064. warn('Badly formated number');
  35065. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  35066. // 'E' can be either a scientific notation or the beginning of a new
  35067. // operator
  35068. ch = this.peekChar();
  35069. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  35070. powerValueSign = (ch === 0x2D) ? -1 : 1;
  35071. this.nextChar(); // Consume the sign character
  35072. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  35073. // The 'E' must be the beginning of a new operator
  35074. break;
  35075. }
  35076. eNotation = true;
  35077. } else {
  35078. // the last character doesn't belong to us
  35079. break;
  35080. }
  35081. }
  35082. if (divideBy !== 0) {
  35083. baseValue /= divideBy;
  35084. }
  35085. if (eNotation) {
  35086. baseValue *= Math.pow(10, powerValueSign * powerValue);
  35087. }
  35088. return sign * baseValue;
  35089. },
  35090. getString: function Lexer_getString() {
  35091. var numParen = 1;
  35092. var done = false;
  35093. var strBuf = this.strBuf;
  35094. strBuf.length = 0;
  35095. var ch = this.nextChar();
  35096. while (true) {
  35097. var charBuffered = false;
  35098. switch (ch | 0) {
  35099. case -1:
  35100. warn('Unterminated string');
  35101. done = true;
  35102. break;
  35103. case 0x28: // '('
  35104. ++numParen;
  35105. strBuf.push('(');
  35106. break;
  35107. case 0x29: // ')'
  35108. if (--numParen === 0) {
  35109. this.nextChar(); // consume strings ')'
  35110. done = true;
  35111. } else {
  35112. strBuf.push(')');
  35113. }
  35114. break;
  35115. case 0x5C: // '\\'
  35116. ch = this.nextChar();
  35117. switch (ch) {
  35118. case -1:
  35119. warn('Unterminated string');
  35120. done = true;
  35121. break;
  35122. case 0x6E: // 'n'
  35123. strBuf.push('\n');
  35124. break;
  35125. case 0x72: // 'r'
  35126. strBuf.push('\r');
  35127. break;
  35128. case 0x74: // 't'
  35129. strBuf.push('\t');
  35130. break;
  35131. case 0x62: // 'b'
  35132. strBuf.push('\b');
  35133. break;
  35134. case 0x66: // 'f'
  35135. strBuf.push('\f');
  35136. break;
  35137. case 0x5C: // '\'
  35138. case 0x28: // '('
  35139. case 0x29: // ')'
  35140. strBuf.push(String.fromCharCode(ch));
  35141. break;
  35142. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  35143. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  35144. var x = ch & 0x0F;
  35145. ch = this.nextChar();
  35146. charBuffered = true;
  35147. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  35148. x = (x << 3) + (ch & 0x0F);
  35149. ch = this.nextChar();
  35150. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  35151. charBuffered = false;
  35152. x = (x << 3) + (ch & 0x0F);
  35153. }
  35154. }
  35155. strBuf.push(String.fromCharCode(x));
  35156. break;
  35157. case 0x0D: // CR
  35158. if (this.peekChar() === 0x0A) { // LF
  35159. this.nextChar();
  35160. }
  35161. break;
  35162. case 0x0A: // LF
  35163. break;
  35164. default:
  35165. strBuf.push(String.fromCharCode(ch));
  35166. break;
  35167. }
  35168. break;
  35169. default:
  35170. strBuf.push(String.fromCharCode(ch));
  35171. break;
  35172. }
  35173. if (done) {
  35174. break;
  35175. }
  35176. if (!charBuffered) {
  35177. ch = this.nextChar();
  35178. }
  35179. }
  35180. return strBuf.join('');
  35181. },
  35182. getName: function Lexer_getName() {
  35183. var ch;
  35184. var strBuf = this.strBuf;
  35185. strBuf.length = 0;
  35186. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  35187. if (ch === 0x23) { // '#'
  35188. ch = this.nextChar();
  35189. var x = toHexDigit(ch);
  35190. if (x !== -1) {
  35191. var x2 = toHexDigit(this.nextChar());
  35192. if (x2 === -1) {
  35193. error('Illegal digit in hex char in name: ' + x2);
  35194. }
  35195. strBuf.push(String.fromCharCode((x << 4) | x2));
  35196. } else {
  35197. strBuf.push('#', String.fromCharCode(ch));
  35198. }
  35199. } else {
  35200. strBuf.push(String.fromCharCode(ch));
  35201. }
  35202. }
  35203. if (strBuf.length > 127) {
  35204. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  35205. }
  35206. return Name.get(strBuf.join(''));
  35207. },
  35208. getHexString: function Lexer_getHexString() {
  35209. var strBuf = this.strBuf;
  35210. strBuf.length = 0;
  35211. var ch = this.currentChar;
  35212. var isFirstHex = true;
  35213. var firstDigit;
  35214. var secondDigit;
  35215. while (true) {
  35216. if (ch < 0) {
  35217. warn('Unterminated hex string');
  35218. break;
  35219. } else if (ch === 0x3E) { // '>'
  35220. this.nextChar();
  35221. break;
  35222. } else if (specialChars[ch] === 1) {
  35223. ch = this.nextChar();
  35224. continue;
  35225. } else {
  35226. if (isFirstHex) {
  35227. firstDigit = toHexDigit(ch);
  35228. if (firstDigit === -1) {
  35229. warn('Ignoring invalid character "' + ch + '" in hex string');
  35230. ch = this.nextChar();
  35231. continue;
  35232. }
  35233. } else {
  35234. secondDigit = toHexDigit(ch);
  35235. if (secondDigit === -1) {
  35236. warn('Ignoring invalid character "' + ch + '" in hex string');
  35237. ch = this.nextChar();
  35238. continue;
  35239. }
  35240. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  35241. }
  35242. isFirstHex = !isFirstHex;
  35243. ch = this.nextChar();
  35244. }
  35245. }
  35246. return strBuf.join('');
  35247. },
  35248. getObj: function Lexer_getObj() {
  35249. // skip whitespace and comments
  35250. var comment = false;
  35251. var ch = this.currentChar;
  35252. while (true) {
  35253. if (ch < 0) {
  35254. return EOF;
  35255. }
  35256. if (comment) {
  35257. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  35258. comment = false;
  35259. }
  35260. } else if (ch === 0x25) { // '%'
  35261. comment = true;
  35262. } else if (specialChars[ch] !== 1) {
  35263. break;
  35264. }
  35265. ch = this.nextChar();
  35266. }
  35267. // start reading token
  35268. switch (ch | 0) {
  35269. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35270. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35271. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35272. return this.getNumber();
  35273. case 0x28: // '('
  35274. return this.getString();
  35275. case 0x2F: // '/'
  35276. return this.getName();
  35277. // array punctuation
  35278. case 0x5B: // '['
  35279. this.nextChar();
  35280. return Cmd.get('[');
  35281. case 0x5D: // ']'
  35282. this.nextChar();
  35283. return Cmd.get(']');
  35284. // hex string or dict punctuation
  35285. case 0x3C: // '<'
  35286. ch = this.nextChar();
  35287. if (ch === 0x3C) {
  35288. // dict punctuation
  35289. this.nextChar();
  35290. return Cmd.get('<<');
  35291. }
  35292. return this.getHexString();
  35293. // dict punctuation
  35294. case 0x3E: // '>'
  35295. ch = this.nextChar();
  35296. if (ch === 0x3E) {
  35297. this.nextChar();
  35298. return Cmd.get('>>');
  35299. }
  35300. return Cmd.get('>');
  35301. case 0x7B: // '{'
  35302. this.nextChar();
  35303. return Cmd.get('{');
  35304. case 0x7D: // '}'
  35305. this.nextChar();
  35306. return Cmd.get('}');
  35307. case 0x29: // ')'
  35308. error('Illegal character: ' + ch);
  35309. break;
  35310. }
  35311. // command
  35312. var str = String.fromCharCode(ch);
  35313. var knownCommands = this.knownCommands;
  35314. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  35315. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  35316. // stop if known command is found and next character does not make
  35317. // the str a command
  35318. var possibleCommand = str + String.fromCharCode(ch);
  35319. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  35320. break;
  35321. }
  35322. if (str.length === 128) {
  35323. error('Command token too long: ' + str.length);
  35324. }
  35325. str = possibleCommand;
  35326. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  35327. }
  35328. if (str === 'true') {
  35329. return true;
  35330. }
  35331. if (str === 'false') {
  35332. return false;
  35333. }
  35334. if (str === 'null') {
  35335. return null;
  35336. }
  35337. return Cmd.get(str);
  35338. },
  35339. skipToNextLine: function Lexer_skipToNextLine() {
  35340. var ch = this.currentChar;
  35341. while (ch >= 0) {
  35342. if (ch === 0x0D) { // CR
  35343. ch = this.nextChar();
  35344. if (ch === 0x0A) { // LF
  35345. this.nextChar();
  35346. }
  35347. break;
  35348. } else if (ch === 0x0A) { // LF
  35349. this.nextChar();
  35350. break;
  35351. }
  35352. ch = this.nextChar();
  35353. }
  35354. }
  35355. };
  35356. return Lexer;
  35357. })();
  35358. var Linearization = {
  35359. create: function LinearizationCreate(stream) {
  35360. function getInt(name, allowZeroValue) {
  35361. var obj = linDict.get(name);
  35362. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  35363. return obj;
  35364. }
  35365. throw new Error('The "' + name + '" parameter in the linearization ' +
  35366. 'dictionary is invalid.');
  35367. }
  35368. function getHints() {
  35369. var hints = linDict.get('H'), hintsLength, item;
  35370. if (isArray(hints) &&
  35371. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  35372. for (var index = 0; index < hintsLength; index++) {
  35373. if (!(isInt(item = hints[index]) && item > 0)) {
  35374. throw new Error('Hint (' + index +
  35375. ') in the linearization dictionary is invalid.');
  35376. }
  35377. }
  35378. return hints;
  35379. }
  35380. throw new Error('Hint array in the linearization dictionary is invalid.');
  35381. }
  35382. var parser = new Parser(new Lexer(stream), false, null);
  35383. var obj1 = parser.getObj();
  35384. var obj2 = parser.getObj();
  35385. var obj3 = parser.getObj();
  35386. var linDict = parser.getObj();
  35387. var obj, length;
  35388. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  35389. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  35390. return null; // No valid linearization dictionary found.
  35391. } else if ((length = getInt('L')) !== stream.length) {
  35392. throw new Error('The "L" parameter in the linearization dictionary ' +
  35393. 'does not equal the stream length.');
  35394. }
  35395. return {
  35396. length: length,
  35397. hints: getHints(),
  35398. objectNumberFirst: getInt('O'),
  35399. endFirst: getInt('E'),
  35400. numPages: getInt('N'),
  35401. mainXRefEntriesOffset: getInt('T'),
  35402. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  35403. };
  35404. }
  35405. };
  35406. var PostScriptParser = (function PostScriptParserClosure() {
  35407. function PostScriptParser(lexer) {
  35408. this.lexer = lexer;
  35409. this.operators = [];
  35410. this.token = null;
  35411. this.prev = null;
  35412. }
  35413. PostScriptParser.prototype = {
  35414. nextToken: function PostScriptParser_nextToken() {
  35415. this.prev = this.token;
  35416. this.token = this.lexer.getToken();
  35417. },
  35418. accept: function PostScriptParser_accept(type) {
  35419. if (this.token.type === type) {
  35420. this.nextToken();
  35421. return true;
  35422. }
  35423. return false;
  35424. },
  35425. expect: function PostScriptParser_expect(type) {
  35426. if (this.accept(type)) {
  35427. return true;
  35428. }
  35429. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  35430. type + '.');
  35431. },
  35432. parse: function PostScriptParser_parse() {
  35433. this.nextToken();
  35434. this.expect(PostScriptTokenTypes.LBRACE);
  35435. this.parseBlock();
  35436. this.expect(PostScriptTokenTypes.RBRACE);
  35437. return this.operators;
  35438. },
  35439. parseBlock: function PostScriptParser_parseBlock() {
  35440. while (true) {
  35441. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  35442. this.operators.push(this.prev.value);
  35443. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  35444. this.operators.push(this.prev.value);
  35445. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  35446. this.parseCondition();
  35447. } else {
  35448. return;
  35449. }
  35450. }
  35451. },
  35452. parseCondition: function PostScriptParser_parseCondition() {
  35453. // Add two place holders that will be updated later
  35454. var conditionLocation = this.operators.length;
  35455. this.operators.push(null, null);
  35456. this.parseBlock();
  35457. this.expect(PostScriptTokenTypes.RBRACE);
  35458. if (this.accept(PostScriptTokenTypes.IF)) {
  35459. // The true block is right after the 'if' so it just falls through on
  35460. // true else it jumps and skips the true block.
  35461. this.operators[conditionLocation] = this.operators.length;
  35462. this.operators[conditionLocation + 1] = 'jz';
  35463. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  35464. var jumpLocation = this.operators.length;
  35465. this.operators.push(null, null);
  35466. var endOfTrue = this.operators.length;
  35467. this.parseBlock();
  35468. this.expect(PostScriptTokenTypes.RBRACE);
  35469. this.expect(PostScriptTokenTypes.IFELSE);
  35470. // The jump is added at the end of the true block to skip the false
  35471. // block.
  35472. this.operators[jumpLocation] = this.operators.length;
  35473. this.operators[jumpLocation + 1] = 'j';
  35474. this.operators[conditionLocation] = endOfTrue;
  35475. this.operators[conditionLocation + 1] = 'jz';
  35476. } else {
  35477. error('PS Function: error parsing conditional.');
  35478. }
  35479. }
  35480. };
  35481. return PostScriptParser;
  35482. })();
  35483. var PostScriptTokenTypes = {
  35484. LBRACE: 0,
  35485. RBRACE: 1,
  35486. NUMBER: 2,
  35487. OPERATOR: 3,
  35488. IF: 4,
  35489. IFELSE: 5
  35490. };
  35491. var PostScriptToken = (function PostScriptTokenClosure() {
  35492. function PostScriptToken(type, value) {
  35493. this.type = type;
  35494. this.value = value;
  35495. }
  35496. var opCache = {};
  35497. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  35498. var opValue = opCache[op];
  35499. if (opValue) {
  35500. return opValue;
  35501. }
  35502. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  35503. };
  35504. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  35505. '{');
  35506. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  35507. '}');
  35508. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  35509. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  35510. 'IFELSE');
  35511. return PostScriptToken;
  35512. })();
  35513. var PostScriptLexer = (function PostScriptLexerClosure() {
  35514. function PostScriptLexer(stream) {
  35515. this.stream = stream;
  35516. this.nextChar();
  35517. this.strBuf = [];
  35518. }
  35519. PostScriptLexer.prototype = {
  35520. nextChar: function PostScriptLexer_nextChar() {
  35521. return (this.currentChar = this.stream.getByte());
  35522. },
  35523. getToken: function PostScriptLexer_getToken() {
  35524. var comment = false;
  35525. var ch = this.currentChar;
  35526. // skip comments
  35527. while (true) {
  35528. if (ch < 0) {
  35529. return EOF;
  35530. }
  35531. if (comment) {
  35532. if (ch === 0x0A || ch === 0x0D) {
  35533. comment = false;
  35534. }
  35535. } else if (ch === 0x25) { // '%'
  35536. comment = true;
  35537. } else if (!Lexer.isSpace(ch)) {
  35538. break;
  35539. }
  35540. ch = this.nextChar();
  35541. }
  35542. switch (ch | 0) {
  35543. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35544. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35545. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35546. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  35547. this.getNumber());
  35548. case 0x7B: // '{'
  35549. this.nextChar();
  35550. return PostScriptToken.LBRACE;
  35551. case 0x7D: // '}'
  35552. this.nextChar();
  35553. return PostScriptToken.RBRACE;
  35554. }
  35555. // operator
  35556. var strBuf = this.strBuf;
  35557. strBuf.length = 0;
  35558. strBuf[0] = String.fromCharCode(ch);
  35559. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  35560. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  35561. strBuf.push(String.fromCharCode(ch));
  35562. }
  35563. var str = strBuf.join('');
  35564. switch (str.toLowerCase()) {
  35565. case 'if':
  35566. return PostScriptToken.IF;
  35567. case 'ifelse':
  35568. return PostScriptToken.IFELSE;
  35569. default:
  35570. return PostScriptToken.getOperator(str);
  35571. }
  35572. },
  35573. getNumber: function PostScriptLexer_getNumber() {
  35574. var ch = this.currentChar;
  35575. var strBuf = this.strBuf;
  35576. strBuf.length = 0;
  35577. strBuf[0] = String.fromCharCode(ch);
  35578. while ((ch = this.nextChar()) >= 0) {
  35579. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35580. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35581. strBuf.push(String.fromCharCode(ch));
  35582. } else {
  35583. break;
  35584. }
  35585. }
  35586. var value = parseFloat(strBuf.join(''));
  35587. if (isNaN(value)) {
  35588. error('Invalid floating point number: ' + value);
  35589. }
  35590. return value;
  35591. }
  35592. };
  35593. return PostScriptLexer;
  35594. })();
  35595. var Stream = (function StreamClosure() {
  35596. function Stream(arrayBuffer, start, length, dict) {
  35597. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35598. arrayBuffer : new Uint8Array(arrayBuffer));
  35599. this.start = start || 0;
  35600. this.pos = this.start;
  35601. this.end = (start + length) || this.bytes.length;
  35602. this.dict = dict;
  35603. }
  35604. // required methods for a stream. if a particular stream does not
  35605. // implement these, an error should be thrown
  35606. Stream.prototype = {
  35607. get length() {
  35608. return this.end - this.start;
  35609. },
  35610. get isEmpty() {
  35611. return this.length === 0;
  35612. },
  35613. getByte: function Stream_getByte() {
  35614. if (this.pos >= this.end) {
  35615. return -1;
  35616. }
  35617. return this.bytes[this.pos++];
  35618. },
  35619. getUint16: function Stream_getUint16() {
  35620. var b0 = this.getByte();
  35621. var b1 = this.getByte();
  35622. if (b0 === -1 || b1 === -1) {
  35623. return -1;
  35624. }
  35625. return (b0 << 8) + b1;
  35626. },
  35627. getInt32: function Stream_getInt32() {
  35628. var b0 = this.getByte();
  35629. var b1 = this.getByte();
  35630. var b2 = this.getByte();
  35631. var b3 = this.getByte();
  35632. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35633. },
  35634. // returns subarray of original buffer
  35635. // should only be read
  35636. getBytes: function Stream_getBytes(length) {
  35637. var bytes = this.bytes;
  35638. var pos = this.pos;
  35639. var strEnd = this.end;
  35640. if (!length) {
  35641. return bytes.subarray(pos, strEnd);
  35642. }
  35643. var end = pos + length;
  35644. if (end > strEnd) {
  35645. end = strEnd;
  35646. }
  35647. this.pos = end;
  35648. return bytes.subarray(pos, end);
  35649. },
  35650. peekByte: function Stream_peekByte() {
  35651. var peekedByte = this.getByte();
  35652. this.pos--;
  35653. return peekedByte;
  35654. },
  35655. peekBytes: function Stream_peekBytes(length) {
  35656. var bytes = this.getBytes(length);
  35657. this.pos -= bytes.length;
  35658. return bytes;
  35659. },
  35660. skip: function Stream_skip(n) {
  35661. if (!n) {
  35662. n = 1;
  35663. }
  35664. this.pos += n;
  35665. },
  35666. reset: function Stream_reset() {
  35667. this.pos = this.start;
  35668. },
  35669. moveStart: function Stream_moveStart() {
  35670. this.start = this.pos;
  35671. },
  35672. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35673. return new Stream(this.bytes.buffer, start, length, dict);
  35674. },
  35675. isStream: true
  35676. };
  35677. return Stream;
  35678. })();
  35679. var StringStream = (function StringStreamClosure() {
  35680. function StringStream(str) {
  35681. var length = str.length;
  35682. var bytes = new Uint8Array(length);
  35683. for (var n = 0; n < length; ++n) {
  35684. bytes[n] = str.charCodeAt(n);
  35685. }
  35686. Stream.call(this, bytes);
  35687. }
  35688. StringStream.prototype = Stream.prototype;
  35689. return StringStream;
  35690. })();
  35691. // super class for the decoding streams
  35692. var DecodeStream = (function DecodeStreamClosure() {
  35693. // Lots of DecodeStreams are created whose buffers are never used. For these
  35694. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35695. // having special cases that would be required if we used |null| for an empty
  35696. // buffer.
  35697. var emptyBuffer = new Uint8Array(0);
  35698. function DecodeStream(maybeMinBufferLength) {
  35699. this.pos = 0;
  35700. this.bufferLength = 0;
  35701. this.eof = false;
  35702. this.buffer = emptyBuffer;
  35703. this.minBufferLength = 512;
  35704. if (maybeMinBufferLength) {
  35705. // Compute the first power of two that is as big as maybeMinBufferLength.
  35706. while (this.minBufferLength < maybeMinBufferLength) {
  35707. this.minBufferLength *= 2;
  35708. }
  35709. }
  35710. }
  35711. DecodeStream.prototype = {
  35712. get isEmpty() {
  35713. while (!this.eof && this.bufferLength === 0) {
  35714. this.readBlock();
  35715. }
  35716. return this.bufferLength === 0;
  35717. },
  35718. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35719. var buffer = this.buffer;
  35720. if (requested <= buffer.byteLength) {
  35721. return buffer;
  35722. }
  35723. var size = this.minBufferLength;
  35724. while (size < requested) {
  35725. size *= 2;
  35726. }
  35727. var buffer2 = new Uint8Array(size);
  35728. buffer2.set(buffer);
  35729. return (this.buffer = buffer2);
  35730. },
  35731. getByte: function DecodeStream_getByte() {
  35732. var pos = this.pos;
  35733. while (this.bufferLength <= pos) {
  35734. if (this.eof) {
  35735. return -1;
  35736. }
  35737. this.readBlock();
  35738. }
  35739. return this.buffer[this.pos++];
  35740. },
  35741. getUint16: function DecodeStream_getUint16() {
  35742. var b0 = this.getByte();
  35743. var b1 = this.getByte();
  35744. if (b0 === -1 || b1 === -1) {
  35745. return -1;
  35746. }
  35747. return (b0 << 8) + b1;
  35748. },
  35749. getInt32: function DecodeStream_getInt32() {
  35750. var b0 = this.getByte();
  35751. var b1 = this.getByte();
  35752. var b2 = this.getByte();
  35753. var b3 = this.getByte();
  35754. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35755. },
  35756. getBytes: function DecodeStream_getBytes(length) {
  35757. var end, pos = this.pos;
  35758. if (length) {
  35759. this.ensureBuffer(pos + length);
  35760. end = pos + length;
  35761. while (!this.eof && this.bufferLength < end) {
  35762. this.readBlock();
  35763. }
  35764. var bufEnd = this.bufferLength;
  35765. if (end > bufEnd) {
  35766. end = bufEnd;
  35767. }
  35768. } else {
  35769. while (!this.eof) {
  35770. this.readBlock();
  35771. }
  35772. end = this.bufferLength;
  35773. }
  35774. this.pos = end;
  35775. return this.buffer.subarray(pos, end);
  35776. },
  35777. peekByte: function DecodeStream_peekByte() {
  35778. var peekedByte = this.getByte();
  35779. this.pos--;
  35780. return peekedByte;
  35781. },
  35782. peekBytes: function DecodeStream_peekBytes(length) {
  35783. var bytes = this.getBytes(length);
  35784. this.pos -= bytes.length;
  35785. return bytes;
  35786. },
  35787. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35788. var end = start + length;
  35789. while (this.bufferLength <= end && !this.eof) {
  35790. this.readBlock();
  35791. }
  35792. return new Stream(this.buffer, start, length, dict);
  35793. },
  35794. skip: function DecodeStream_skip(n) {
  35795. if (!n) {
  35796. n = 1;
  35797. }
  35798. this.pos += n;
  35799. },
  35800. reset: function DecodeStream_reset() {
  35801. this.pos = 0;
  35802. },
  35803. getBaseStreams: function DecodeStream_getBaseStreams() {
  35804. if (this.str && this.str.getBaseStreams) {
  35805. return this.str.getBaseStreams();
  35806. }
  35807. return [];
  35808. }
  35809. };
  35810. return DecodeStream;
  35811. })();
  35812. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35813. function StreamsSequenceStream(streams) {
  35814. this.streams = streams;
  35815. DecodeStream.call(this, /* maybeLength = */ null);
  35816. }
  35817. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35818. StreamsSequenceStream.prototype.readBlock =
  35819. function streamSequenceStreamReadBlock() {
  35820. var streams = this.streams;
  35821. if (streams.length === 0) {
  35822. this.eof = true;
  35823. return;
  35824. }
  35825. var stream = streams.shift();
  35826. var chunk = stream.getBytes();
  35827. var bufferLength = this.bufferLength;
  35828. var newLength = bufferLength + chunk.length;
  35829. var buffer = this.ensureBuffer(newLength);
  35830. buffer.set(chunk, bufferLength);
  35831. this.bufferLength = newLength;
  35832. };
  35833. StreamsSequenceStream.prototype.getBaseStreams =
  35834. function StreamsSequenceStream_getBaseStreams() {
  35835. var baseStreams = [];
  35836. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35837. var stream = this.streams[i];
  35838. if (stream.getBaseStreams) {
  35839. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35840. }
  35841. }
  35842. return baseStreams;
  35843. };
  35844. return StreamsSequenceStream;
  35845. })();
  35846. var FlateStream = (function FlateStreamClosure() {
  35847. var codeLenCodeMap = new Int32Array([
  35848. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35849. ]);
  35850. var lengthDecode = new Int32Array([
  35851. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35852. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35853. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35854. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35855. ]);
  35856. var distDecode = new Int32Array([
  35857. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35858. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35859. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35860. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35861. ]);
  35862. var fixedLitCodeTab = [new Int32Array([
  35863. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35864. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35865. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35866. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35867. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35868. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35869. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35870. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35871. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35872. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35873. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35874. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35875. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35876. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35877. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35878. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35879. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35880. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35881. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35882. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35883. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35884. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35885. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35886. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35887. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35888. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35889. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35890. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35891. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35892. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35893. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35894. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35895. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35896. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35897. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35898. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35899. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35900. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35901. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35902. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35903. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35904. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35905. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35906. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35907. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35908. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35909. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35910. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35911. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35912. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35913. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35914. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35915. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35916. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35917. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35918. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35919. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35920. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35921. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35922. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35923. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35924. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35925. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35926. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35927. ]), 9];
  35928. var fixedDistCodeTab = [new Int32Array([
  35929. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35930. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35931. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35932. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35933. ]), 5];
  35934. function FlateStream(str, maybeLength) {
  35935. this.str = str;
  35936. this.dict = str.dict;
  35937. var cmf = str.getByte();
  35938. var flg = str.getByte();
  35939. if (cmf === -1 || flg === -1) {
  35940. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35941. }
  35942. if ((cmf & 0x0f) !== 0x08) {
  35943. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35944. }
  35945. if ((((cmf << 8) + flg) % 31) !== 0) {
  35946. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35947. }
  35948. if (flg & 0x20) {
  35949. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35950. }
  35951. this.codeSize = 0;
  35952. this.codeBuf = 0;
  35953. DecodeStream.call(this, maybeLength);
  35954. }
  35955. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35956. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35957. var str = this.str;
  35958. var codeSize = this.codeSize;
  35959. var codeBuf = this.codeBuf;
  35960. var b;
  35961. while (codeSize < bits) {
  35962. if ((b = str.getByte()) === -1) {
  35963. error('Bad encoding in flate stream');
  35964. }
  35965. codeBuf |= b << codeSize;
  35966. codeSize += 8;
  35967. }
  35968. b = codeBuf & ((1 << bits) - 1);
  35969. this.codeBuf = codeBuf >> bits;
  35970. this.codeSize = codeSize -= bits;
  35971. return b;
  35972. };
  35973. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35974. var str = this.str;
  35975. var codes = table[0];
  35976. var maxLen = table[1];
  35977. var codeSize = this.codeSize;
  35978. var codeBuf = this.codeBuf;
  35979. var b;
  35980. while (codeSize < maxLen) {
  35981. if ((b = str.getByte()) === -1) {
  35982. // premature end of stream. code might however still be valid.
  35983. // codeSize < codeLen check below guards against incomplete codeVal.
  35984. break;
  35985. }
  35986. codeBuf |= (b << codeSize);
  35987. codeSize += 8;
  35988. }
  35989. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35990. var codeLen = code >> 16;
  35991. var codeVal = code & 0xffff;
  35992. if (codeLen < 1 || codeSize < codeLen) {
  35993. error('Bad encoding in flate stream');
  35994. }
  35995. this.codeBuf = (codeBuf >> codeLen);
  35996. this.codeSize = (codeSize - codeLen);
  35997. return codeVal;
  35998. };
  35999. FlateStream.prototype.generateHuffmanTable =
  36000. function flateStreamGenerateHuffmanTable(lengths) {
  36001. var n = lengths.length;
  36002. // find max code length
  36003. var maxLen = 0;
  36004. var i;
  36005. for (i = 0; i < n; ++i) {
  36006. if (lengths[i] > maxLen) {
  36007. maxLen = lengths[i];
  36008. }
  36009. }
  36010. // build the table
  36011. var size = 1 << maxLen;
  36012. var codes = new Int32Array(size);
  36013. for (var len = 1, code = 0, skip = 2;
  36014. len <= maxLen;
  36015. ++len, code <<= 1, skip <<= 1) {
  36016. for (var val = 0; val < n; ++val) {
  36017. if (lengths[val] === len) {
  36018. // bit-reverse the code
  36019. var code2 = 0;
  36020. var t = code;
  36021. for (i = 0; i < len; ++i) {
  36022. code2 = (code2 << 1) | (t & 1);
  36023. t >>= 1;
  36024. }
  36025. // fill the table entries
  36026. for (i = code2; i < size; i += skip) {
  36027. codes[i] = (len << 16) | val;
  36028. }
  36029. ++code;
  36030. }
  36031. }
  36032. }
  36033. return [codes, maxLen];
  36034. };
  36035. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  36036. var buffer, len;
  36037. var str = this.str;
  36038. // read block header
  36039. var hdr = this.getBits(3);
  36040. if (hdr & 1) {
  36041. this.eof = true;
  36042. }
  36043. hdr >>= 1;
  36044. if (hdr === 0) { // uncompressed block
  36045. var b;
  36046. if ((b = str.getByte()) === -1) {
  36047. error('Bad block header in flate stream');
  36048. }
  36049. var blockLen = b;
  36050. if ((b = str.getByte()) === -1) {
  36051. error('Bad block header in flate stream');
  36052. }
  36053. blockLen |= (b << 8);
  36054. if ((b = str.getByte()) === -1) {
  36055. error('Bad block header in flate stream');
  36056. }
  36057. var check = b;
  36058. if ((b = str.getByte()) === -1) {
  36059. error('Bad block header in flate stream');
  36060. }
  36061. check |= (b << 8);
  36062. if (check !== (~blockLen & 0xffff) &&
  36063. (blockLen !== 0 || check !== 0)) {
  36064. // Ignoring error for bad "empty" block (see issue 1277)
  36065. error('Bad uncompressed block length in flate stream');
  36066. }
  36067. this.codeBuf = 0;
  36068. this.codeSize = 0;
  36069. var bufferLength = this.bufferLength;
  36070. buffer = this.ensureBuffer(bufferLength + blockLen);
  36071. var end = bufferLength + blockLen;
  36072. this.bufferLength = end;
  36073. if (blockLen === 0) {
  36074. if (str.peekByte() === -1) {
  36075. this.eof = true;
  36076. }
  36077. } else {
  36078. for (var n = bufferLength; n < end; ++n) {
  36079. if ((b = str.getByte()) === -1) {
  36080. this.eof = true;
  36081. break;
  36082. }
  36083. buffer[n] = b;
  36084. }
  36085. }
  36086. return;
  36087. }
  36088. var litCodeTable;
  36089. var distCodeTable;
  36090. if (hdr === 1) { // compressed block, fixed codes
  36091. litCodeTable = fixedLitCodeTab;
  36092. distCodeTable = fixedDistCodeTab;
  36093. } else if (hdr === 2) { // compressed block, dynamic codes
  36094. var numLitCodes = this.getBits(5) + 257;
  36095. var numDistCodes = this.getBits(5) + 1;
  36096. var numCodeLenCodes = this.getBits(4) + 4;
  36097. // build the code lengths code table
  36098. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  36099. var i;
  36100. for (i = 0; i < numCodeLenCodes; ++i) {
  36101. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  36102. }
  36103. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  36104. // build the literal and distance code tables
  36105. len = 0;
  36106. i = 0;
  36107. var codes = numLitCodes + numDistCodes;
  36108. var codeLengths = new Uint8Array(codes);
  36109. var bitsLength, bitsOffset, what;
  36110. while (i < codes) {
  36111. var code = this.getCode(codeLenCodeTab);
  36112. if (code === 16) {
  36113. bitsLength = 2; bitsOffset = 3; what = len;
  36114. } else if (code === 17) {
  36115. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  36116. } else if (code === 18) {
  36117. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  36118. } else {
  36119. codeLengths[i++] = len = code;
  36120. continue;
  36121. }
  36122. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  36123. while (repeatLength-- > 0) {
  36124. codeLengths[i++] = what;
  36125. }
  36126. }
  36127. litCodeTable =
  36128. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  36129. distCodeTable =
  36130. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  36131. } else {
  36132. error('Unknown block type in flate stream');
  36133. }
  36134. buffer = this.buffer;
  36135. var limit = buffer ? buffer.length : 0;
  36136. var pos = this.bufferLength;
  36137. while (true) {
  36138. var code1 = this.getCode(litCodeTable);
  36139. if (code1 < 256) {
  36140. if (pos + 1 >= limit) {
  36141. buffer = this.ensureBuffer(pos + 1);
  36142. limit = buffer.length;
  36143. }
  36144. buffer[pos++] = code1;
  36145. continue;
  36146. }
  36147. if (code1 === 256) {
  36148. this.bufferLength = pos;
  36149. return;
  36150. }
  36151. code1 -= 257;
  36152. code1 = lengthDecode[code1];
  36153. var code2 = code1 >> 16;
  36154. if (code2 > 0) {
  36155. code2 = this.getBits(code2);
  36156. }
  36157. len = (code1 & 0xffff) + code2;
  36158. code1 = this.getCode(distCodeTable);
  36159. code1 = distDecode[code1];
  36160. code2 = code1 >> 16;
  36161. if (code2 > 0) {
  36162. code2 = this.getBits(code2);
  36163. }
  36164. var dist = (code1 & 0xffff) + code2;
  36165. if (pos + len >= limit) {
  36166. buffer = this.ensureBuffer(pos + len);
  36167. limit = buffer.length;
  36168. }
  36169. for (var k = 0; k < len; ++k, ++pos) {
  36170. buffer[pos] = buffer[pos - dist];
  36171. }
  36172. }
  36173. };
  36174. return FlateStream;
  36175. })();
  36176. var PredictorStream = (function PredictorStreamClosure() {
  36177. function PredictorStream(str, maybeLength, params) {
  36178. var predictor = this.predictor = params.get('Predictor') || 1;
  36179. if (predictor <= 1) {
  36180. return str; // no prediction
  36181. }
  36182. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  36183. error('Unsupported predictor: ' + predictor);
  36184. }
  36185. if (predictor === 2) {
  36186. this.readBlock = this.readBlockTiff;
  36187. } else {
  36188. this.readBlock = this.readBlockPng;
  36189. }
  36190. this.str = str;
  36191. this.dict = str.dict;
  36192. var colors = this.colors = params.get('Colors') || 1;
  36193. var bits = this.bits = params.get('BitsPerComponent') || 8;
  36194. var columns = this.columns = params.get('Columns') || 1;
  36195. this.pixBytes = (colors * bits + 7) >> 3;
  36196. this.rowBytes = (columns * colors * bits + 7) >> 3;
  36197. DecodeStream.call(this, maybeLength);
  36198. return this;
  36199. }
  36200. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  36201. PredictorStream.prototype.readBlockTiff =
  36202. function predictorStreamReadBlockTiff() {
  36203. var rowBytes = this.rowBytes;
  36204. var bufferLength = this.bufferLength;
  36205. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  36206. var bits = this.bits;
  36207. var colors = this.colors;
  36208. var rawBytes = this.str.getBytes(rowBytes);
  36209. this.eof = !rawBytes.length;
  36210. if (this.eof) {
  36211. return;
  36212. }
  36213. var inbuf = 0, outbuf = 0;
  36214. var inbits = 0, outbits = 0;
  36215. var pos = bufferLength;
  36216. var i;
  36217. if (bits === 1) {
  36218. for (i = 0; i < rowBytes; ++i) {
  36219. var c = rawBytes[i];
  36220. inbuf = (inbuf << 8) | c;
  36221. // bitwise addition is exclusive or
  36222. // first shift inbuf and then add
  36223. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  36224. // truncate inbuf (assumes colors < 16)
  36225. inbuf &= 0xFFFF;
  36226. }
  36227. } else if (bits === 8) {
  36228. for (i = 0; i < colors; ++i) {
  36229. buffer[pos++] = rawBytes[i];
  36230. }
  36231. for (; i < rowBytes; ++i) {
  36232. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  36233. pos++;
  36234. }
  36235. } else {
  36236. var compArray = new Uint8Array(colors + 1);
  36237. var bitMask = (1 << bits) - 1;
  36238. var j = 0, k = bufferLength;
  36239. var columns = this.columns;
  36240. for (i = 0; i < columns; ++i) {
  36241. for (var kk = 0; kk < colors; ++kk) {
  36242. if (inbits < bits) {
  36243. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  36244. inbits += 8;
  36245. }
  36246. compArray[kk] = (compArray[kk] +
  36247. (inbuf >> (inbits - bits))) & bitMask;
  36248. inbits -= bits;
  36249. outbuf = (outbuf << bits) | compArray[kk];
  36250. outbits += bits;
  36251. if (outbits >= 8) {
  36252. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  36253. outbits -= 8;
  36254. }
  36255. }
  36256. }
  36257. if (outbits > 0) {
  36258. buffer[k++] = (outbuf << (8 - outbits)) +
  36259. (inbuf & ((1 << (8 - outbits)) - 1));
  36260. }
  36261. }
  36262. this.bufferLength += rowBytes;
  36263. };
  36264. PredictorStream.prototype.readBlockPng =
  36265. function predictorStreamReadBlockPng() {
  36266. var rowBytes = this.rowBytes;
  36267. var pixBytes = this.pixBytes;
  36268. var predictor = this.str.getByte();
  36269. var rawBytes = this.str.getBytes(rowBytes);
  36270. this.eof = !rawBytes.length;
  36271. if (this.eof) {
  36272. return;
  36273. }
  36274. var bufferLength = this.bufferLength;
  36275. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  36276. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  36277. if (prevRow.length === 0) {
  36278. prevRow = new Uint8Array(rowBytes);
  36279. }
  36280. var i, j = bufferLength, up, c;
  36281. switch (predictor) {
  36282. case 0:
  36283. for (i = 0; i < rowBytes; ++i) {
  36284. buffer[j++] = rawBytes[i];
  36285. }
  36286. break;
  36287. case 1:
  36288. for (i = 0; i < pixBytes; ++i) {
  36289. buffer[j++] = rawBytes[i];
  36290. }
  36291. for (; i < rowBytes; ++i) {
  36292. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  36293. j++;
  36294. }
  36295. break;
  36296. case 2:
  36297. for (i = 0; i < rowBytes; ++i) {
  36298. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  36299. }
  36300. break;
  36301. case 3:
  36302. for (i = 0; i < pixBytes; ++i) {
  36303. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  36304. }
  36305. for (; i < rowBytes; ++i) {
  36306. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  36307. rawBytes[i]) & 0xFF;
  36308. j++;
  36309. }
  36310. break;
  36311. case 4:
  36312. // we need to save the up left pixels values. the simplest way
  36313. // is to create a new buffer
  36314. for (i = 0; i < pixBytes; ++i) {
  36315. up = prevRow[i];
  36316. c = rawBytes[i];
  36317. buffer[j++] = up + c;
  36318. }
  36319. for (; i < rowBytes; ++i) {
  36320. up = prevRow[i];
  36321. var upLeft = prevRow[i - pixBytes];
  36322. var left = buffer[j - pixBytes];
  36323. var p = left + up - upLeft;
  36324. var pa = p - left;
  36325. if (pa < 0) {
  36326. pa = -pa;
  36327. }
  36328. var pb = p - up;
  36329. if (pb < 0) {
  36330. pb = -pb;
  36331. }
  36332. var pc = p - upLeft;
  36333. if (pc < 0) {
  36334. pc = -pc;
  36335. }
  36336. c = rawBytes[i];
  36337. if (pa <= pb && pa <= pc) {
  36338. buffer[j++] = left + c;
  36339. } else if (pb <= pc) {
  36340. buffer[j++] = up + c;
  36341. } else {
  36342. buffer[j++] = upLeft + c;
  36343. }
  36344. }
  36345. break;
  36346. default:
  36347. error('Unsupported predictor: ' + predictor);
  36348. }
  36349. this.bufferLength += rowBytes;
  36350. };
  36351. return PredictorStream;
  36352. })();
  36353. /**
  36354. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  36355. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  36356. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  36357. * a library to decode these images and the stream behaves like all the other
  36358. * DecodeStreams.
  36359. */
  36360. var JpegStream = (function JpegStreamClosure() {
  36361. function JpegStream(stream, maybeLength, dict, xref) {
  36362. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  36363. // Note: this seems to mainly affect inline images.
  36364. var ch;
  36365. while ((ch = stream.getByte()) !== -1) {
  36366. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  36367. stream.skip(-1); // Reset the stream position to the SOI.
  36368. break;
  36369. }
  36370. }
  36371. this.stream = stream;
  36372. this.maybeLength = maybeLength;
  36373. this.dict = dict;
  36374. DecodeStream.call(this, maybeLength);
  36375. }
  36376. JpegStream.prototype = Object.create(DecodeStream.prototype);
  36377. Object.defineProperty(JpegStream.prototype, 'bytes', {
  36378. get: function JpegStream_bytes() {
  36379. // If this.maybeLength is null, we'll get the entire stream.
  36380. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36381. },
  36382. configurable: true
  36383. });
  36384. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  36385. if (this.bufferLength) {
  36386. return;
  36387. }
  36388. try {
  36389. var jpegImage = new JpegImage();
  36390. // checking if values needs to be transformed before conversion
  36391. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  36392. var decodeArr = this.dict.get('Decode');
  36393. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  36394. var decodeArrLength = decodeArr.length;
  36395. var transform = new Int32Array(decodeArrLength);
  36396. var transformNeeded = false;
  36397. var maxValue = (1 << bitsPerComponent) - 1;
  36398. for (var i = 0; i < decodeArrLength; i += 2) {
  36399. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  36400. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  36401. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  36402. transformNeeded = true;
  36403. }
  36404. }
  36405. if (transformNeeded) {
  36406. jpegImage.decodeTransform = transform;
  36407. }
  36408. }
  36409. jpegImage.parse(this.bytes);
  36410. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  36411. this.forceRGB);
  36412. this.buffer = data;
  36413. this.bufferLength = data.length;
  36414. this.eof = true;
  36415. } catch (e) {
  36416. error('JPEG error: ' + e);
  36417. }
  36418. };
  36419. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  36420. this.ensureBuffer();
  36421. return this.buffer;
  36422. };
  36423. JpegStream.prototype.getIR = function JpegStream_getIR() {
  36424. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  36425. };
  36426. /**
  36427. * Checks if the image can be decoded and displayed by the browser without any
  36428. * further processing such as color space conversions.
  36429. */
  36430. JpegStream.prototype.isNativelySupported =
  36431. function JpegStream_isNativelySupported(xref, res) {
  36432. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36433. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  36434. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  36435. };
  36436. /**
  36437. * Checks if the image can be decoded by the browser.
  36438. */
  36439. JpegStream.prototype.isNativelyDecodable =
  36440. function JpegStream_isNativelyDecodable(xref, res) {
  36441. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36442. return (cs.numComps === 1 || cs.numComps === 3) &&
  36443. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  36444. };
  36445. return JpegStream;
  36446. })();
  36447. /**
  36448. * For JPEG 2000's we use a library to decode these images and
  36449. * the stream behaves like all the other DecodeStreams.
  36450. */
  36451. var JpxStream = (function JpxStreamClosure() {
  36452. function JpxStream(stream, maybeLength, dict) {
  36453. this.stream = stream;
  36454. this.maybeLength = maybeLength;
  36455. this.dict = dict;
  36456. DecodeStream.call(this, maybeLength);
  36457. }
  36458. JpxStream.prototype = Object.create(DecodeStream.prototype);
  36459. Object.defineProperty(JpxStream.prototype, 'bytes', {
  36460. get: function JpxStream_bytes() {
  36461. // If this.maybeLength is null, we'll get the entire stream.
  36462. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36463. },
  36464. configurable: true
  36465. });
  36466. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  36467. if (this.bufferLength) {
  36468. return;
  36469. }
  36470. var jpxImage = new JpxImage();
  36471. jpxImage.parse(this.bytes);
  36472. var width = jpxImage.width;
  36473. var height = jpxImage.height;
  36474. var componentsCount = jpxImage.componentsCount;
  36475. var tileCount = jpxImage.tiles.length;
  36476. if (tileCount === 1) {
  36477. this.buffer = jpxImage.tiles[0].items;
  36478. } else {
  36479. var data = new Uint8Array(width * height * componentsCount);
  36480. for (var k = 0; k < tileCount; k++) {
  36481. var tileComponents = jpxImage.tiles[k];
  36482. var tileWidth = tileComponents.width;
  36483. var tileHeight = tileComponents.height;
  36484. var tileLeft = tileComponents.left;
  36485. var tileTop = tileComponents.top;
  36486. var src = tileComponents.items;
  36487. var srcPosition = 0;
  36488. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  36489. var imgRowSize = width * componentsCount;
  36490. var tileRowSize = tileWidth * componentsCount;
  36491. for (var j = 0; j < tileHeight; j++) {
  36492. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  36493. data.set(rowBytes, dataPosition);
  36494. srcPosition += tileRowSize;
  36495. dataPosition += imgRowSize;
  36496. }
  36497. }
  36498. this.buffer = data;
  36499. }
  36500. this.bufferLength = this.buffer.length;
  36501. this.eof = true;
  36502. };
  36503. return JpxStream;
  36504. })();
  36505. /**
  36506. * For JBIG2's we use a library to decode these images and
  36507. * the stream behaves like all the other DecodeStreams.
  36508. */
  36509. var Jbig2Stream = (function Jbig2StreamClosure() {
  36510. function Jbig2Stream(stream, maybeLength, dict) {
  36511. this.stream = stream;
  36512. this.maybeLength = maybeLength;
  36513. this.dict = dict;
  36514. DecodeStream.call(this, maybeLength);
  36515. }
  36516. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  36517. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  36518. get: function Jbig2Stream_bytes() {
  36519. // If this.maybeLength is null, we'll get the entire stream.
  36520. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36521. },
  36522. configurable: true
  36523. });
  36524. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  36525. if (this.bufferLength) {
  36526. return;
  36527. }
  36528. var jbig2Image = new Jbig2Image();
  36529. var chunks = [], xref = this.dict.xref;
  36530. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  36531. // According to the PDF specification, DecodeParms can be either
  36532. // a dictionary, or an array whose elements are dictionaries.
  36533. if (isArray(decodeParams)) {
  36534. if (decodeParams.length > 1) {
  36535. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  36536. 'not supported.');
  36537. }
  36538. decodeParams = xref.fetchIfRef(decodeParams[0]);
  36539. }
  36540. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  36541. var globalsStream = decodeParams.get('JBIG2Globals');
  36542. var globals = globalsStream.getBytes();
  36543. chunks.push({data: globals, start: 0, end: globals.length});
  36544. }
  36545. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  36546. var data = jbig2Image.parseChunks(chunks);
  36547. var dataLength = data.length;
  36548. // JBIG2 had black as 1 and white as 0, inverting the colors
  36549. for (var i = 0; i < dataLength; i++) {
  36550. data[i] ^= 0xFF;
  36551. }
  36552. this.buffer = data;
  36553. this.bufferLength = dataLength;
  36554. this.eof = true;
  36555. };
  36556. return Jbig2Stream;
  36557. })();
  36558. var DecryptStream = (function DecryptStreamClosure() {
  36559. function DecryptStream(str, maybeLength, decrypt) {
  36560. this.str = str;
  36561. this.dict = str.dict;
  36562. this.decrypt = decrypt;
  36563. this.nextChunk = null;
  36564. this.initialized = false;
  36565. DecodeStream.call(this, maybeLength);
  36566. }
  36567. var chunkSize = 512;
  36568. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36569. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36570. var chunk;
  36571. if (this.initialized) {
  36572. chunk = this.nextChunk;
  36573. } else {
  36574. chunk = this.str.getBytes(chunkSize);
  36575. this.initialized = true;
  36576. }
  36577. if (!chunk || chunk.length === 0) {
  36578. this.eof = true;
  36579. return;
  36580. }
  36581. this.nextChunk = this.str.getBytes(chunkSize);
  36582. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36583. var decrypt = this.decrypt;
  36584. chunk = decrypt(chunk, !hasMoreData);
  36585. var bufferLength = this.bufferLength;
  36586. var i, n = chunk.length;
  36587. var buffer = this.ensureBuffer(bufferLength + n);
  36588. for (i = 0; i < n; i++) {
  36589. buffer[bufferLength++] = chunk[i];
  36590. }
  36591. this.bufferLength = bufferLength;
  36592. };
  36593. return DecryptStream;
  36594. })();
  36595. var Ascii85Stream = (function Ascii85StreamClosure() {
  36596. function Ascii85Stream(str, maybeLength) {
  36597. this.str = str;
  36598. this.dict = str.dict;
  36599. this.input = new Uint8Array(5);
  36600. // Most streams increase in size when decoded, but Ascii85 streams
  36601. // typically shrink by ~20%.
  36602. if (maybeLength) {
  36603. maybeLength = 0.8 * maybeLength;
  36604. }
  36605. DecodeStream.call(this, maybeLength);
  36606. }
  36607. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36608. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36609. var TILDA_CHAR = 0x7E; // '~'
  36610. var Z_LOWER_CHAR = 0x7A; // 'z'
  36611. var EOF = -1;
  36612. var str = this.str;
  36613. var c = str.getByte();
  36614. while (Lexer.isSpace(c)) {
  36615. c = str.getByte();
  36616. }
  36617. if (c === EOF || c === TILDA_CHAR) {
  36618. this.eof = true;
  36619. return;
  36620. }
  36621. var bufferLength = this.bufferLength, buffer;
  36622. var i;
  36623. // special code for z
  36624. if (c === Z_LOWER_CHAR) {
  36625. buffer = this.ensureBuffer(bufferLength + 4);
  36626. for (i = 0; i < 4; ++i) {
  36627. buffer[bufferLength + i] = 0;
  36628. }
  36629. this.bufferLength += 4;
  36630. } else {
  36631. var input = this.input;
  36632. input[0] = c;
  36633. for (i = 1; i < 5; ++i) {
  36634. c = str.getByte();
  36635. while (Lexer.isSpace(c)) {
  36636. c = str.getByte();
  36637. }
  36638. input[i] = c;
  36639. if (c === EOF || c === TILDA_CHAR) {
  36640. break;
  36641. }
  36642. }
  36643. buffer = this.ensureBuffer(bufferLength + i - 1);
  36644. this.bufferLength += i - 1;
  36645. // partial ending;
  36646. if (i < 5) {
  36647. for (; i < 5; ++i) {
  36648. input[i] = 0x21 + 84;
  36649. }
  36650. this.eof = true;
  36651. }
  36652. var t = 0;
  36653. for (i = 0; i < 5; ++i) {
  36654. t = t * 85 + (input[i] - 0x21);
  36655. }
  36656. for (i = 3; i >= 0; --i) {
  36657. buffer[bufferLength + i] = t & 0xFF;
  36658. t >>= 8;
  36659. }
  36660. }
  36661. };
  36662. return Ascii85Stream;
  36663. })();
  36664. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36665. function AsciiHexStream(str, maybeLength) {
  36666. this.str = str;
  36667. this.dict = str.dict;
  36668. this.firstDigit = -1;
  36669. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36670. // by 50%.
  36671. if (maybeLength) {
  36672. maybeLength = 0.5 * maybeLength;
  36673. }
  36674. DecodeStream.call(this, maybeLength);
  36675. }
  36676. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36677. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36678. var UPSTREAM_BLOCK_SIZE = 8000;
  36679. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36680. if (!bytes.length) {
  36681. this.eof = true;
  36682. return;
  36683. }
  36684. var maxDecodeLength = (bytes.length + 1) >> 1;
  36685. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36686. var bufferLength = this.bufferLength;
  36687. var firstDigit = this.firstDigit;
  36688. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36689. var ch = bytes[i], digit;
  36690. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36691. digit = ch & 0x0F;
  36692. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36693. // 'A'-'Z', 'a'-'z'
  36694. digit = (ch & 0x0F) + 9;
  36695. } else if (ch === 0x3E) { // '>'
  36696. this.eof = true;
  36697. break;
  36698. } else { // probably whitespace
  36699. continue; // ignoring
  36700. }
  36701. if (firstDigit < 0) {
  36702. firstDigit = digit;
  36703. } else {
  36704. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36705. firstDigit = -1;
  36706. }
  36707. }
  36708. if (firstDigit >= 0 && this.eof) {
  36709. // incomplete byte
  36710. buffer[bufferLength++] = (firstDigit << 4);
  36711. firstDigit = -1;
  36712. }
  36713. this.firstDigit = firstDigit;
  36714. this.bufferLength = bufferLength;
  36715. };
  36716. return AsciiHexStream;
  36717. })();
  36718. var RunLengthStream = (function RunLengthStreamClosure() {
  36719. function RunLengthStream(str, maybeLength) {
  36720. this.str = str;
  36721. this.dict = str.dict;
  36722. DecodeStream.call(this, maybeLength);
  36723. }
  36724. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36725. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36726. // The repeatHeader has following format. The first byte defines type of run
  36727. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36728. // (in addition to the second byte from the header), n = 129 through 255 -
  36729. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36730. var repeatHeader = this.str.getBytes(2);
  36731. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36732. this.eof = true;
  36733. return;
  36734. }
  36735. var buffer;
  36736. var bufferLength = this.bufferLength;
  36737. var n = repeatHeader[0];
  36738. if (n < 128) {
  36739. // copy n bytes
  36740. buffer = this.ensureBuffer(bufferLength + n + 1);
  36741. buffer[bufferLength++] = repeatHeader[1];
  36742. if (n > 0) {
  36743. var source = this.str.getBytes(n);
  36744. buffer.set(source, bufferLength);
  36745. bufferLength += n;
  36746. }
  36747. } else {
  36748. n = 257 - n;
  36749. var b = repeatHeader[1];
  36750. buffer = this.ensureBuffer(bufferLength + n + 1);
  36751. for (var i = 0; i < n; i++) {
  36752. buffer[bufferLength++] = b;
  36753. }
  36754. }
  36755. this.bufferLength = bufferLength;
  36756. };
  36757. return RunLengthStream;
  36758. })();
  36759. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36760. var ccittEOL = -2;
  36761. var twoDimPass = 0;
  36762. var twoDimHoriz = 1;
  36763. var twoDimVert0 = 2;
  36764. var twoDimVertR1 = 3;
  36765. var twoDimVertL1 = 4;
  36766. var twoDimVertR2 = 5;
  36767. var twoDimVertL2 = 6;
  36768. var twoDimVertR3 = 7;
  36769. var twoDimVertL3 = 8;
  36770. var twoDimTable = [
  36771. [-1, -1], [-1, -1], // 000000x
  36772. [7, twoDimVertL3], // 0000010
  36773. [7, twoDimVertR3], // 0000011
  36774. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36775. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36776. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36777. [4, twoDimPass], [4, twoDimPass],
  36778. [4, twoDimPass], [4, twoDimPass],
  36779. [4, twoDimPass], [4, twoDimPass],
  36780. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36781. [3, twoDimHoriz], [3, twoDimHoriz],
  36782. [3, twoDimHoriz], [3, twoDimHoriz],
  36783. [3, twoDimHoriz], [3, twoDimHoriz],
  36784. [3, twoDimHoriz], [3, twoDimHoriz],
  36785. [3, twoDimHoriz], [3, twoDimHoriz],
  36786. [3, twoDimHoriz], [3, twoDimHoriz],
  36787. [3, twoDimHoriz], [3, twoDimHoriz],
  36788. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36789. [3, twoDimVertL1], [3, twoDimVertL1],
  36790. [3, twoDimVertL1], [3, twoDimVertL1],
  36791. [3, twoDimVertL1], [3, twoDimVertL1],
  36792. [3, twoDimVertL1], [3, twoDimVertL1],
  36793. [3, twoDimVertL1], [3, twoDimVertL1],
  36794. [3, twoDimVertL1], [3, twoDimVertL1],
  36795. [3, twoDimVertL1], [3, twoDimVertL1],
  36796. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36797. [3, twoDimVertR1], [3, twoDimVertR1],
  36798. [3, twoDimVertR1], [3, twoDimVertR1],
  36799. [3, twoDimVertR1], [3, twoDimVertR1],
  36800. [3, twoDimVertR1], [3, twoDimVertR1],
  36801. [3, twoDimVertR1], [3, twoDimVertR1],
  36802. [3, twoDimVertR1], [3, twoDimVertR1],
  36803. [3, twoDimVertR1], [3, twoDimVertR1],
  36804. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36805. [1, twoDimVert0], [1, twoDimVert0],
  36806. [1, twoDimVert0], [1, twoDimVert0],
  36807. [1, twoDimVert0], [1, twoDimVert0],
  36808. [1, twoDimVert0], [1, twoDimVert0],
  36809. [1, twoDimVert0], [1, twoDimVert0],
  36810. [1, twoDimVert0], [1, twoDimVert0],
  36811. [1, twoDimVert0], [1, twoDimVert0],
  36812. [1, twoDimVert0], [1, twoDimVert0],
  36813. [1, twoDimVert0], [1, twoDimVert0],
  36814. [1, twoDimVert0], [1, twoDimVert0],
  36815. [1, twoDimVert0], [1, twoDimVert0],
  36816. [1, twoDimVert0], [1, twoDimVert0],
  36817. [1, twoDimVert0], [1, twoDimVert0],
  36818. [1, twoDimVert0], [1, twoDimVert0],
  36819. [1, twoDimVert0], [1, twoDimVert0],
  36820. [1, twoDimVert0], [1, twoDimVert0],
  36821. [1, twoDimVert0], [1, twoDimVert0],
  36822. [1, twoDimVert0], [1, twoDimVert0],
  36823. [1, twoDimVert0], [1, twoDimVert0],
  36824. [1, twoDimVert0], [1, twoDimVert0],
  36825. [1, twoDimVert0], [1, twoDimVert0],
  36826. [1, twoDimVert0], [1, twoDimVert0],
  36827. [1, twoDimVert0], [1, twoDimVert0],
  36828. [1, twoDimVert0], [1, twoDimVert0],
  36829. [1, twoDimVert0], [1, twoDimVert0],
  36830. [1, twoDimVert0], [1, twoDimVert0],
  36831. [1, twoDimVert0], [1, twoDimVert0],
  36832. [1, twoDimVert0], [1, twoDimVert0],
  36833. [1, twoDimVert0], [1, twoDimVert0],
  36834. [1, twoDimVert0], [1, twoDimVert0],
  36835. [1, twoDimVert0], [1, twoDimVert0]
  36836. ];
  36837. var whiteTable1 = [
  36838. [-1, -1], // 00000
  36839. [12, ccittEOL], // 00001
  36840. [-1, -1], [-1, -1], // 0001x
  36841. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36842. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36843. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36844. [11, 1792], [11, 1792], // 1000x
  36845. [12, 1984], // 10010
  36846. [12, 2048], // 10011
  36847. [12, 2112], // 10100
  36848. [12, 2176], // 10101
  36849. [12, 2240], // 10110
  36850. [12, 2304], // 10111
  36851. [11, 1856], [11, 1856], // 1100x
  36852. [11, 1920], [11, 1920], // 1101x
  36853. [12, 2368], // 11100
  36854. [12, 2432], // 11101
  36855. [12, 2496], // 11110
  36856. [12, 2560] // 11111
  36857. ];
  36858. var whiteTable2 = [
  36859. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36860. [8, 29], [8, 29], // 00000010x
  36861. [8, 30], [8, 30], // 00000011x
  36862. [8, 45], [8, 45], // 00000100x
  36863. [8, 46], [8, 46], // 00000101x
  36864. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36865. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36866. [8, 47], [8, 47], // 00001010x
  36867. [8, 48], [8, 48], // 00001011x
  36868. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36869. [6, 13], [6, 13], [6, 13], [6, 13],
  36870. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36871. [8, 33], [8, 33], // 00010010x
  36872. [8, 34], [8, 34], // 00010011x
  36873. [8, 35], [8, 35], // 00010100x
  36874. [8, 36], [8, 36], // 00010101x
  36875. [8, 37], [8, 37], // 00010110x
  36876. [8, 38], [8, 38], // 00010111x
  36877. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36878. [8, 31], [8, 31], // 00011010x
  36879. [8, 32], [8, 32], // 00011011x
  36880. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36881. [6, 1], [6, 1], [6, 1], [6, 1],
  36882. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36883. [6, 12], [6, 12], [6, 12], [6, 12],
  36884. [8, 53], [8, 53], // 00100100x
  36885. [8, 54], [8, 54], // 00100101x
  36886. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36887. [8, 39], [8, 39], // 00101000x
  36888. [8, 40], [8, 40], // 00101001x
  36889. [8, 41], [8, 41], // 00101010x
  36890. [8, 42], [8, 42], // 00101011x
  36891. [8, 43], [8, 43], // 00101100x
  36892. [8, 44], [8, 44], // 00101101x
  36893. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36894. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36895. [8, 61], [8, 61], // 00110010x
  36896. [8, 62], [8, 62], // 00110011x
  36897. [8, 63], [8, 63], // 00110100x
  36898. [8, 0], [8, 0], // 00110101x
  36899. [8, 320], [8, 320], // 00110110x
  36900. [8, 384], [8, 384], // 00110111x
  36901. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36902. [5, 10], [5, 10], [5, 10], [5, 10],
  36903. [5, 10], [5, 10], [5, 10], [5, 10],
  36904. [5, 10], [5, 10], [5, 10], [5, 10],
  36905. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36906. [5, 11], [5, 11], [5, 11], [5, 11],
  36907. [5, 11], [5, 11], [5, 11], [5, 11],
  36908. [5, 11], [5, 11], [5, 11], [5, 11],
  36909. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36910. [8, 59], [8, 59], // 01001010x
  36911. [8, 60], [8, 60], // 01001011x
  36912. [9, 1472], // 010011000
  36913. [9, 1536], // 010011001
  36914. [9, 1600], // 010011010
  36915. [9, 1728], // 010011011
  36916. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36917. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36918. [8, 49], [8, 49], // 01010010x
  36919. [8, 50], [8, 50], // 01010011x
  36920. [8, 51], [8, 51], // 01010100x
  36921. [8, 52], [8, 52], // 01010101x
  36922. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36923. [8, 55], [8, 55], // 01011000x
  36924. [8, 56], [8, 56], // 01011001x
  36925. [8, 57], [8, 57], // 01011010x
  36926. [8, 58], [8, 58], // 01011011x
  36927. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36928. [6, 192], [6, 192], [6, 192], [6, 192],
  36929. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36930. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36931. [8, 448], [8, 448], // 01100100x
  36932. [8, 512], [8, 512], // 01100101x
  36933. [9, 704], // 011001100
  36934. [9, 768], // 011001101
  36935. [8, 640], [8, 640], // 01100111x
  36936. [8, 576], [8, 576], // 01101000x
  36937. [9, 832], // 011010010
  36938. [9, 896], // 011010011
  36939. [9, 960], // 011010100
  36940. [9, 1024], // 011010101
  36941. [9, 1088], // 011010110
  36942. [9, 1152], // 011010111
  36943. [9, 1216], // 011011000
  36944. [9, 1280], // 011011001
  36945. [9, 1344], // 011011010
  36946. [9, 1408], // 011011011
  36947. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36948. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36949. [4, 2], [4, 2], [4, 2], [4, 2],
  36950. [4, 2], [4, 2], [4, 2], [4, 2],
  36951. [4, 2], [4, 2], [4, 2], [4, 2],
  36952. [4, 2], [4, 2], [4, 2], [4, 2],
  36953. [4, 2], [4, 2], [4, 2], [4, 2],
  36954. [4, 2], [4, 2], [4, 2], [4, 2],
  36955. [4, 2], [4, 2], [4, 2], [4, 2],
  36956. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36957. [4, 3], [4, 3], [4, 3], [4, 3],
  36958. [4, 3], [4, 3], [4, 3], [4, 3],
  36959. [4, 3], [4, 3], [4, 3], [4, 3],
  36960. [4, 3], [4, 3], [4, 3], [4, 3],
  36961. [4, 3], [4, 3], [4, 3], [4, 3],
  36962. [4, 3], [4, 3], [4, 3], [4, 3],
  36963. [4, 3], [4, 3], [4, 3], [4, 3],
  36964. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36965. [5, 128], [5, 128], [5, 128], [5, 128],
  36966. [5, 128], [5, 128], [5, 128], [5, 128],
  36967. [5, 128], [5, 128], [5, 128], [5, 128],
  36968. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36969. [5, 8], [5, 8], [5, 8], [5, 8],
  36970. [5, 8], [5, 8], [5, 8], [5, 8],
  36971. [5, 8], [5, 8], [5, 8], [5, 8],
  36972. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36973. [5, 9], [5, 9], [5, 9], [5, 9],
  36974. [5, 9], [5, 9], [5, 9], [5, 9],
  36975. [5, 9], [5, 9], [5, 9], [5, 9],
  36976. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36977. [6, 16], [6, 16], [6, 16], [6, 16],
  36978. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36979. [6, 17], [6, 17], [6, 17], [6, 17],
  36980. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36981. [4, 4], [4, 4], [4, 4], [4, 4],
  36982. [4, 4], [4, 4], [4, 4], [4, 4],
  36983. [4, 4], [4, 4], [4, 4], [4, 4],
  36984. [4, 4], [4, 4], [4, 4], [4, 4],
  36985. [4, 4], [4, 4], [4, 4], [4, 4],
  36986. [4, 4], [4, 4], [4, 4], [4, 4],
  36987. [4, 4], [4, 4], [4, 4], [4, 4],
  36988. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36989. [4, 5], [4, 5], [4, 5], [4, 5],
  36990. [4, 5], [4, 5], [4, 5], [4, 5],
  36991. [4, 5], [4, 5], [4, 5], [4, 5],
  36992. [4, 5], [4, 5], [4, 5], [4, 5],
  36993. [4, 5], [4, 5], [4, 5], [4, 5],
  36994. [4, 5], [4, 5], [4, 5], [4, 5],
  36995. [4, 5], [4, 5], [4, 5], [4, 5],
  36996. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36997. [6, 14], [6, 14], [6, 14], [6, 14],
  36998. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36999. [6, 15], [6, 15], [6, 15], [6, 15],
  37000. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  37001. [5, 64], [5, 64], [5, 64], [5, 64],
  37002. [5, 64], [5, 64], [5, 64], [5, 64],
  37003. [5, 64], [5, 64], [5, 64], [5, 64],
  37004. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  37005. [4, 6], [4, 6], [4, 6], [4, 6],
  37006. [4, 6], [4, 6], [4, 6], [4, 6],
  37007. [4, 6], [4, 6], [4, 6], [4, 6],
  37008. [4, 6], [4, 6], [4, 6], [4, 6],
  37009. [4, 6], [4, 6], [4, 6], [4, 6],
  37010. [4, 6], [4, 6], [4, 6], [4, 6],
  37011. [4, 6], [4, 6], [4, 6], [4, 6],
  37012. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  37013. [4, 7], [4, 7], [4, 7], [4, 7],
  37014. [4, 7], [4, 7], [4, 7], [4, 7],
  37015. [4, 7], [4, 7], [4, 7], [4, 7],
  37016. [4, 7], [4, 7], [4, 7], [4, 7],
  37017. [4, 7], [4, 7], [4, 7], [4, 7],
  37018. [4, 7], [4, 7], [4, 7], [4, 7],
  37019. [4, 7], [4, 7], [4, 7], [4, 7]
  37020. ];
  37021. var blackTable1 = [
  37022. [-1, -1], [-1, -1], // 000000000000x
  37023. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  37024. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  37025. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  37026. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  37027. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  37028. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  37029. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  37030. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  37031. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  37032. [12, 1984], [12, 1984], // 000000010010x
  37033. [12, 2048], [12, 2048], // 000000010011x
  37034. [12, 2112], [12, 2112], // 000000010100x
  37035. [12, 2176], [12, 2176], // 000000010101x
  37036. [12, 2240], [12, 2240], // 000000010110x
  37037. [12, 2304], [12, 2304], // 000000010111x
  37038. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  37039. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  37040. [12, 2368], [12, 2368], // 000000011100x
  37041. [12, 2432], [12, 2432], // 000000011101x
  37042. [12, 2496], [12, 2496], // 000000011110x
  37043. [12, 2560], [12, 2560], // 000000011111x
  37044. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  37045. [10, 18], [10, 18], [10, 18], [10, 18],
  37046. [12, 52], [12, 52], // 000000100100x
  37047. [13, 640], // 0000001001010
  37048. [13, 704], // 0000001001011
  37049. [13, 768], // 0000001001100
  37050. [13, 832], // 0000001001101
  37051. [12, 55], [12, 55], // 000000100111x
  37052. [12, 56], [12, 56], // 000000101000x
  37053. [13, 1280], // 0000001010010
  37054. [13, 1344], // 0000001010011
  37055. [13, 1408], // 0000001010100
  37056. [13, 1472], // 0000001010101
  37057. [12, 59], [12, 59], // 000000101011x
  37058. [12, 60], [12, 60], // 000000101100x
  37059. [13, 1536], // 0000001011010
  37060. [13, 1600], // 0000001011011
  37061. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  37062. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  37063. [13, 1664], // 0000001100100
  37064. [13, 1728], // 0000001100101
  37065. [12, 320], [12, 320], // 000000110011x
  37066. [12, 384], [12, 384], // 000000110100x
  37067. [12, 448], [12, 448], // 000000110101x
  37068. [13, 512], // 0000001101100
  37069. [13, 576], // 0000001101101
  37070. [12, 53], [12, 53], // 000000110111x
  37071. [12, 54], [12, 54], // 000000111000x
  37072. [13, 896], // 0000001110010
  37073. [13, 960], // 0000001110011
  37074. [13, 1024], // 0000001110100
  37075. [13, 1088], // 0000001110101
  37076. [13, 1152], // 0000001110110
  37077. [13, 1216], // 0000001110111
  37078. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  37079. [10, 64], [10, 64], [10, 64], [10, 64]
  37080. ];
  37081. var blackTable2 = [
  37082. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  37083. [8, 13], [8, 13], [8, 13], [8, 13],
  37084. [8, 13], [8, 13], [8, 13], [8, 13],
  37085. [8, 13], [8, 13], [8, 13], [8, 13],
  37086. [11, 23], [11, 23], // 00000101000x
  37087. [12, 50], // 000001010010
  37088. [12, 51], // 000001010011
  37089. [12, 44], // 000001010100
  37090. [12, 45], // 000001010101
  37091. [12, 46], // 000001010110
  37092. [12, 47], // 000001010111
  37093. [12, 57], // 000001011000
  37094. [12, 58], // 000001011001
  37095. [12, 61], // 000001011010
  37096. [12, 256], // 000001011011
  37097. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  37098. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  37099. [12, 48], // 000001100100
  37100. [12, 49], // 000001100101
  37101. [12, 62], // 000001100110
  37102. [12, 63], // 000001100111
  37103. [12, 30], // 000001101000
  37104. [12, 31], // 000001101001
  37105. [12, 32], // 000001101010
  37106. [12, 33], // 000001101011
  37107. [12, 40], // 000001101100
  37108. [12, 41], // 000001101101
  37109. [11, 22], [11, 22], // 00000110111x
  37110. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  37111. [8, 14], [8, 14], [8, 14], [8, 14],
  37112. [8, 14], [8, 14], [8, 14], [8, 14],
  37113. [8, 14], [8, 14], [8, 14], [8, 14],
  37114. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  37115. [7, 10], [7, 10], [7, 10], [7, 10],
  37116. [7, 10], [7, 10], [7, 10], [7, 10],
  37117. [7, 10], [7, 10], [7, 10], [7, 10],
  37118. [7, 10], [7, 10], [7, 10], [7, 10],
  37119. [7, 10], [7, 10], [7, 10], [7, 10],
  37120. [7, 10], [7, 10], [7, 10], [7, 10],
  37121. [7, 10], [7, 10], [7, 10], [7, 10],
  37122. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  37123. [7, 11], [7, 11], [7, 11], [7, 11],
  37124. [7, 11], [7, 11], [7, 11], [7, 11],
  37125. [7, 11], [7, 11], [7, 11], [7, 11],
  37126. [7, 11], [7, 11], [7, 11], [7, 11],
  37127. [7, 11], [7, 11], [7, 11], [7, 11],
  37128. [7, 11], [7, 11], [7, 11], [7, 11],
  37129. [7, 11], [7, 11], [7, 11], [7, 11],
  37130. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  37131. [9, 15], [9, 15], [9, 15], [9, 15],
  37132. [12, 128], // 000011001000
  37133. [12, 192], // 000011001001
  37134. [12, 26], // 000011001010
  37135. [12, 27], // 000011001011
  37136. [12, 28], // 000011001100
  37137. [12, 29], // 000011001101
  37138. [11, 19], [11, 19], // 00001100111x
  37139. [11, 20], [11, 20], // 00001101000x
  37140. [12, 34], // 000011010010
  37141. [12, 35], // 000011010011
  37142. [12, 36], // 000011010100
  37143. [12, 37], // 000011010101
  37144. [12, 38], // 000011010110
  37145. [12, 39], // 000011010111
  37146. [11, 21], [11, 21], // 00001101100x
  37147. [12, 42], // 000011011010
  37148. [12, 43], // 000011011011
  37149. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  37150. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  37151. [7, 12], [7, 12], [7, 12], [7, 12],
  37152. [7, 12], [7, 12], [7, 12], [7, 12],
  37153. [7, 12], [7, 12], [7, 12], [7, 12],
  37154. [7, 12], [7, 12], [7, 12], [7, 12],
  37155. [7, 12], [7, 12], [7, 12], [7, 12],
  37156. [7, 12], [7, 12], [7, 12], [7, 12],
  37157. [7, 12], [7, 12], [7, 12], [7, 12]
  37158. ];
  37159. var blackTable3 = [
  37160. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  37161. [6, 9], // 000100
  37162. [6, 8], // 000101
  37163. [5, 7], [5, 7], // 00011x
  37164. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  37165. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  37166. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  37167. [3, 1], [3, 1], [3, 1], [3, 1],
  37168. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  37169. [3, 4], [3, 4], [3, 4], [3, 4],
  37170. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  37171. [2, 3], [2, 3], [2, 3], [2, 3],
  37172. [2, 3], [2, 3], [2, 3], [2, 3],
  37173. [2, 3], [2, 3], [2, 3], [2, 3],
  37174. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  37175. [2, 2], [2, 2], [2, 2], [2, 2],
  37176. [2, 2], [2, 2], [2, 2], [2, 2],
  37177. [2, 2], [2, 2], [2, 2], [2, 2]
  37178. ];
  37179. function CCITTFaxStream(str, maybeLength, params) {
  37180. this.str = str;
  37181. this.dict = str.dict;
  37182. params = params || Dict.empty;
  37183. this.encoding = params.get('K') || 0;
  37184. this.eoline = params.get('EndOfLine') || false;
  37185. this.byteAlign = params.get('EncodedByteAlign') || false;
  37186. this.columns = params.get('Columns') || 1728;
  37187. this.rows = params.get('Rows') || 0;
  37188. var eoblock = params.get('EndOfBlock');
  37189. if (eoblock === null || eoblock === undefined) {
  37190. eoblock = true;
  37191. }
  37192. this.eoblock = eoblock;
  37193. this.black = params.get('BlackIs1') || false;
  37194. this.codingLine = new Uint32Array(this.columns + 1);
  37195. this.refLine = new Uint32Array(this.columns + 2);
  37196. this.codingLine[0] = this.columns;
  37197. this.codingPos = 0;
  37198. this.row = 0;
  37199. this.nextLine2D = this.encoding < 0;
  37200. this.inputBits = 0;
  37201. this.inputBuf = 0;
  37202. this.outputBits = 0;
  37203. var code1;
  37204. while ((code1 = this.lookBits(12)) === 0) {
  37205. this.eatBits(1);
  37206. }
  37207. if (code1 === 1) {
  37208. this.eatBits(12);
  37209. }
  37210. if (this.encoding > 0) {
  37211. this.nextLine2D = !this.lookBits(1);
  37212. this.eatBits(1);
  37213. }
  37214. DecodeStream.call(this, maybeLength);
  37215. }
  37216. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  37217. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  37218. while (!this.eof) {
  37219. var c = this.lookChar();
  37220. this.ensureBuffer(this.bufferLength + 1);
  37221. this.buffer[this.bufferLength++] = c;
  37222. }
  37223. };
  37224. CCITTFaxStream.prototype.addPixels =
  37225. function ccittFaxStreamAddPixels(a1, blackPixels) {
  37226. var codingLine = this.codingLine;
  37227. var codingPos = this.codingPos;
  37228. if (a1 > codingLine[codingPos]) {
  37229. if (a1 > this.columns) {
  37230. info('row is wrong length');
  37231. this.err = true;
  37232. a1 = this.columns;
  37233. }
  37234. if ((codingPos & 1) ^ blackPixels) {
  37235. ++codingPos;
  37236. }
  37237. codingLine[codingPos] = a1;
  37238. }
  37239. this.codingPos = codingPos;
  37240. };
  37241. CCITTFaxStream.prototype.addPixelsNeg =
  37242. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  37243. var codingLine = this.codingLine;
  37244. var codingPos = this.codingPos;
  37245. if (a1 > codingLine[codingPos]) {
  37246. if (a1 > this.columns) {
  37247. info('row is wrong length');
  37248. this.err = true;
  37249. a1 = this.columns;
  37250. }
  37251. if ((codingPos & 1) ^ blackPixels) {
  37252. ++codingPos;
  37253. }
  37254. codingLine[codingPos] = a1;
  37255. } else if (a1 < codingLine[codingPos]) {
  37256. if (a1 < 0) {
  37257. info('invalid code');
  37258. this.err = true;
  37259. a1 = 0;
  37260. }
  37261. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  37262. --codingPos;
  37263. }
  37264. codingLine[codingPos] = a1;
  37265. }
  37266. this.codingPos = codingPos;
  37267. };
  37268. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  37269. var refLine = this.refLine;
  37270. var codingLine = this.codingLine;
  37271. var columns = this.columns;
  37272. var refPos, blackPixels, bits, i;
  37273. if (this.outputBits === 0) {
  37274. if (this.eof) {
  37275. return null;
  37276. }
  37277. this.err = false;
  37278. var code1, code2, code3;
  37279. if (this.nextLine2D) {
  37280. for (i = 0; codingLine[i] < columns; ++i) {
  37281. refLine[i] = codingLine[i];
  37282. }
  37283. refLine[i++] = columns;
  37284. refLine[i] = columns;
  37285. codingLine[0] = 0;
  37286. this.codingPos = 0;
  37287. refPos = 0;
  37288. blackPixels = 0;
  37289. while (codingLine[this.codingPos] < columns) {
  37290. code1 = this.getTwoDimCode();
  37291. switch (code1) {
  37292. case twoDimPass:
  37293. this.addPixels(refLine[refPos + 1], blackPixels);
  37294. if (refLine[refPos + 1] < columns) {
  37295. refPos += 2;
  37296. }
  37297. break;
  37298. case twoDimHoriz:
  37299. code1 = code2 = 0;
  37300. if (blackPixels) {
  37301. do {
  37302. code1 += (code3 = this.getBlackCode());
  37303. } while (code3 >= 64);
  37304. do {
  37305. code2 += (code3 = this.getWhiteCode());
  37306. } while (code3 >= 64);
  37307. } else {
  37308. do {
  37309. code1 += (code3 = this.getWhiteCode());
  37310. } while (code3 >= 64);
  37311. do {
  37312. code2 += (code3 = this.getBlackCode());
  37313. } while (code3 >= 64);
  37314. }
  37315. this.addPixels(codingLine[this.codingPos] +
  37316. code1, blackPixels);
  37317. if (codingLine[this.codingPos] < columns) {
  37318. this.addPixels(codingLine[this.codingPos] + code2,
  37319. blackPixels ^ 1);
  37320. }
  37321. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37322. refLine[refPos] < columns) {
  37323. refPos += 2;
  37324. }
  37325. break;
  37326. case twoDimVertR3:
  37327. this.addPixels(refLine[refPos] + 3, blackPixels);
  37328. blackPixels ^= 1;
  37329. if (codingLine[this.codingPos] < columns) {
  37330. ++refPos;
  37331. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37332. refLine[refPos] < columns) {
  37333. refPos += 2;
  37334. }
  37335. }
  37336. break;
  37337. case twoDimVertR2:
  37338. this.addPixels(refLine[refPos] + 2, blackPixels);
  37339. blackPixels ^= 1;
  37340. if (codingLine[this.codingPos] < columns) {
  37341. ++refPos;
  37342. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37343. refLine[refPos] < columns) {
  37344. refPos += 2;
  37345. }
  37346. }
  37347. break;
  37348. case twoDimVertR1:
  37349. this.addPixels(refLine[refPos] + 1, blackPixels);
  37350. blackPixels ^= 1;
  37351. if (codingLine[this.codingPos] < columns) {
  37352. ++refPos;
  37353. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37354. refLine[refPos] < columns) {
  37355. refPos += 2;
  37356. }
  37357. }
  37358. break;
  37359. case twoDimVert0:
  37360. this.addPixels(refLine[refPos], blackPixels);
  37361. blackPixels ^= 1;
  37362. if (codingLine[this.codingPos] < columns) {
  37363. ++refPos;
  37364. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37365. refLine[refPos] < columns) {
  37366. refPos += 2;
  37367. }
  37368. }
  37369. break;
  37370. case twoDimVertL3:
  37371. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  37372. blackPixels ^= 1;
  37373. if (codingLine[this.codingPos] < columns) {
  37374. if (refPos > 0) {
  37375. --refPos;
  37376. } else {
  37377. ++refPos;
  37378. }
  37379. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37380. refLine[refPos] < columns) {
  37381. refPos += 2;
  37382. }
  37383. }
  37384. break;
  37385. case twoDimVertL2:
  37386. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  37387. blackPixels ^= 1;
  37388. if (codingLine[this.codingPos] < columns) {
  37389. if (refPos > 0) {
  37390. --refPos;
  37391. } else {
  37392. ++refPos;
  37393. }
  37394. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37395. refLine[refPos] < columns) {
  37396. refPos += 2;
  37397. }
  37398. }
  37399. break;
  37400. case twoDimVertL1:
  37401. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  37402. blackPixels ^= 1;
  37403. if (codingLine[this.codingPos] < columns) {
  37404. if (refPos > 0) {
  37405. --refPos;
  37406. } else {
  37407. ++refPos;
  37408. }
  37409. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37410. refLine[refPos] < columns) {
  37411. refPos += 2;
  37412. }
  37413. }
  37414. break;
  37415. case EOF:
  37416. this.addPixels(columns, 0);
  37417. this.eof = true;
  37418. break;
  37419. default:
  37420. info('bad 2d code');
  37421. this.addPixels(columns, 0);
  37422. this.err = true;
  37423. }
  37424. }
  37425. } else {
  37426. codingLine[0] = 0;
  37427. this.codingPos = 0;
  37428. blackPixels = 0;
  37429. while (codingLine[this.codingPos] < columns) {
  37430. code1 = 0;
  37431. if (blackPixels) {
  37432. do {
  37433. code1 += (code3 = this.getBlackCode());
  37434. } while (code3 >= 64);
  37435. } else {
  37436. do {
  37437. code1 += (code3 = this.getWhiteCode());
  37438. } while (code3 >= 64);
  37439. }
  37440. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  37441. blackPixels ^= 1;
  37442. }
  37443. }
  37444. var gotEOL = false;
  37445. if (this.byteAlign) {
  37446. this.inputBits &= ~7;
  37447. }
  37448. if (!this.eoblock && this.row === this.rows - 1) {
  37449. this.eof = true;
  37450. } else {
  37451. code1 = this.lookBits(12);
  37452. if (this.eoline) {
  37453. while (code1 !== EOF && code1 !== 1) {
  37454. this.eatBits(1);
  37455. code1 = this.lookBits(12);
  37456. }
  37457. } else {
  37458. while (code1 === 0) {
  37459. this.eatBits(1);
  37460. code1 = this.lookBits(12);
  37461. }
  37462. }
  37463. if (code1 === 1) {
  37464. this.eatBits(12);
  37465. gotEOL = true;
  37466. } else if (code1 === EOF) {
  37467. this.eof = true;
  37468. }
  37469. }
  37470. if (!this.eof && this.encoding > 0) {
  37471. this.nextLine2D = !this.lookBits(1);
  37472. this.eatBits(1);
  37473. }
  37474. if (this.eoblock && gotEOL && this.byteAlign) {
  37475. code1 = this.lookBits(12);
  37476. if (code1 === 1) {
  37477. this.eatBits(12);
  37478. if (this.encoding > 0) {
  37479. this.lookBits(1);
  37480. this.eatBits(1);
  37481. }
  37482. if (this.encoding >= 0) {
  37483. for (i = 0; i < 4; ++i) {
  37484. code1 = this.lookBits(12);
  37485. if (code1 !== 1) {
  37486. info('bad rtc code: ' + code1);
  37487. }
  37488. this.eatBits(12);
  37489. if (this.encoding > 0) {
  37490. this.lookBits(1);
  37491. this.eatBits(1);
  37492. }
  37493. }
  37494. }
  37495. this.eof = true;
  37496. }
  37497. } else if (this.err && this.eoline) {
  37498. while (true) {
  37499. code1 = this.lookBits(13);
  37500. if (code1 === EOF) {
  37501. this.eof = true;
  37502. return null;
  37503. }
  37504. if ((code1 >> 1) === 1) {
  37505. break;
  37506. }
  37507. this.eatBits(1);
  37508. }
  37509. this.eatBits(12);
  37510. if (this.encoding > 0) {
  37511. this.eatBits(1);
  37512. this.nextLine2D = !(code1 & 1);
  37513. }
  37514. }
  37515. if (codingLine[0] > 0) {
  37516. this.outputBits = codingLine[this.codingPos = 0];
  37517. } else {
  37518. this.outputBits = codingLine[this.codingPos = 1];
  37519. }
  37520. this.row++;
  37521. }
  37522. var c;
  37523. if (this.outputBits >= 8) {
  37524. c = (this.codingPos & 1) ? 0 : 0xFF;
  37525. this.outputBits -= 8;
  37526. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  37527. this.codingPos++;
  37528. this.outputBits = (codingLine[this.codingPos] -
  37529. codingLine[this.codingPos - 1]);
  37530. }
  37531. } else {
  37532. bits = 8;
  37533. c = 0;
  37534. do {
  37535. if (this.outputBits > bits) {
  37536. c <<= bits;
  37537. if (!(this.codingPos & 1)) {
  37538. c |= 0xFF >> (8 - bits);
  37539. }
  37540. this.outputBits -= bits;
  37541. bits = 0;
  37542. } else {
  37543. c <<= this.outputBits;
  37544. if (!(this.codingPos & 1)) {
  37545. c |= 0xFF >> (8 - this.outputBits);
  37546. }
  37547. bits -= this.outputBits;
  37548. this.outputBits = 0;
  37549. if (codingLine[this.codingPos] < columns) {
  37550. this.codingPos++;
  37551. this.outputBits = (codingLine[this.codingPos] -
  37552. codingLine[this.codingPos - 1]);
  37553. } else if (bits > 0) {
  37554. c <<= bits;
  37555. bits = 0;
  37556. }
  37557. }
  37558. } while (bits);
  37559. }
  37560. if (this.black) {
  37561. c ^= 0xFF;
  37562. }
  37563. return c;
  37564. };
  37565. // This functions returns the code found from the table.
  37566. // The start and end parameters set the boundaries for searching the table.
  37567. // The limit parameter is optional. Function returns an array with three
  37568. // values. The first array element indicates whether a valid code is being
  37569. // returned. The second array element is the actual code. The third array
  37570. // element indicates whether EOF was reached.
  37571. CCITTFaxStream.prototype.findTableCode =
  37572. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37573. var limitValue = limit || 0;
  37574. for (var i = start; i <= end; ++i) {
  37575. var code = this.lookBits(i);
  37576. if (code === EOF) {
  37577. return [true, 1, false];
  37578. }
  37579. if (i < end) {
  37580. code <<= end - i;
  37581. }
  37582. if (!limitValue || code >= limitValue) {
  37583. var p = table[code - limitValue];
  37584. if (p[0] === i) {
  37585. this.eatBits(i);
  37586. return [true, p[1], true];
  37587. }
  37588. }
  37589. }
  37590. return [false, 0, false];
  37591. };
  37592. CCITTFaxStream.prototype.getTwoDimCode =
  37593. function ccittFaxStreamGetTwoDimCode() {
  37594. var code = 0;
  37595. var p;
  37596. if (this.eoblock) {
  37597. code = this.lookBits(7);
  37598. p = twoDimTable[code];
  37599. if (p && p[0] > 0) {
  37600. this.eatBits(p[0]);
  37601. return p[1];
  37602. }
  37603. } else {
  37604. var result = this.findTableCode(1, 7, twoDimTable);
  37605. if (result[0] && result[2]) {
  37606. return result[1];
  37607. }
  37608. }
  37609. info('Bad two dim code');
  37610. return EOF;
  37611. };
  37612. CCITTFaxStream.prototype.getWhiteCode =
  37613. function ccittFaxStreamGetWhiteCode() {
  37614. var code = 0;
  37615. var p;
  37616. if (this.eoblock) {
  37617. code = this.lookBits(12);
  37618. if (code === EOF) {
  37619. return 1;
  37620. }
  37621. if ((code >> 5) === 0) {
  37622. p = whiteTable1[code];
  37623. } else {
  37624. p = whiteTable2[code >> 3];
  37625. }
  37626. if (p[0] > 0) {
  37627. this.eatBits(p[0]);
  37628. return p[1];
  37629. }
  37630. } else {
  37631. var result = this.findTableCode(1, 9, whiteTable2);
  37632. if (result[0]) {
  37633. return result[1];
  37634. }
  37635. result = this.findTableCode(11, 12, whiteTable1);
  37636. if (result[0]) {
  37637. return result[1];
  37638. }
  37639. }
  37640. info('bad white code');
  37641. this.eatBits(1);
  37642. return 1;
  37643. };
  37644. CCITTFaxStream.prototype.getBlackCode =
  37645. function ccittFaxStreamGetBlackCode() {
  37646. var code, p;
  37647. if (this.eoblock) {
  37648. code = this.lookBits(13);
  37649. if (code === EOF) {
  37650. return 1;
  37651. }
  37652. if ((code >> 7) === 0) {
  37653. p = blackTable1[code];
  37654. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37655. p = blackTable2[(code >> 1) - 64];
  37656. } else {
  37657. p = blackTable3[code >> 7];
  37658. }
  37659. if (p[0] > 0) {
  37660. this.eatBits(p[0]);
  37661. return p[1];
  37662. }
  37663. } else {
  37664. var result = this.findTableCode(2, 6, blackTable3);
  37665. if (result[0]) {
  37666. return result[1];
  37667. }
  37668. result = this.findTableCode(7, 12, blackTable2, 64);
  37669. if (result[0]) {
  37670. return result[1];
  37671. }
  37672. result = this.findTableCode(10, 13, blackTable1);
  37673. if (result[0]) {
  37674. return result[1];
  37675. }
  37676. }
  37677. info('bad black code');
  37678. this.eatBits(1);
  37679. return 1;
  37680. };
  37681. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37682. var c;
  37683. while (this.inputBits < n) {
  37684. if ((c = this.str.getByte()) === -1) {
  37685. if (this.inputBits === 0) {
  37686. return EOF;
  37687. }
  37688. return ((this.inputBuf << (n - this.inputBits)) &
  37689. (0xFFFF >> (16 - n)));
  37690. }
  37691. this.inputBuf = (this.inputBuf << 8) + c;
  37692. this.inputBits += 8;
  37693. }
  37694. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37695. };
  37696. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37697. if ((this.inputBits -= n) < 0) {
  37698. this.inputBits = 0;
  37699. }
  37700. };
  37701. return CCITTFaxStream;
  37702. })();
  37703. var LZWStream = (function LZWStreamClosure() {
  37704. function LZWStream(str, maybeLength, earlyChange) {
  37705. this.str = str;
  37706. this.dict = str.dict;
  37707. this.cachedData = 0;
  37708. this.bitsCached = 0;
  37709. var maxLzwDictionarySize = 4096;
  37710. var lzwState = {
  37711. earlyChange: earlyChange,
  37712. codeLength: 9,
  37713. nextCode: 258,
  37714. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37715. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37716. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37717. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37718. currentSequenceLength: 0
  37719. };
  37720. for (var i = 0; i < 256; ++i) {
  37721. lzwState.dictionaryValues[i] = i;
  37722. lzwState.dictionaryLengths[i] = 1;
  37723. }
  37724. this.lzwState = lzwState;
  37725. DecodeStream.call(this, maybeLength);
  37726. }
  37727. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37728. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37729. var bitsCached = this.bitsCached;
  37730. var cachedData = this.cachedData;
  37731. while (bitsCached < n) {
  37732. var c = this.str.getByte();
  37733. if (c === -1) {
  37734. this.eof = true;
  37735. return null;
  37736. }
  37737. cachedData = (cachedData << 8) | c;
  37738. bitsCached += 8;
  37739. }
  37740. this.bitsCached = (bitsCached -= n);
  37741. this.cachedData = cachedData;
  37742. this.lastCode = null;
  37743. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37744. };
  37745. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37746. var blockSize = 512;
  37747. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37748. var i, j, q;
  37749. var lzwState = this.lzwState;
  37750. if (!lzwState) {
  37751. return; // eof was found
  37752. }
  37753. var earlyChange = lzwState.earlyChange;
  37754. var nextCode = lzwState.nextCode;
  37755. var dictionaryValues = lzwState.dictionaryValues;
  37756. var dictionaryLengths = lzwState.dictionaryLengths;
  37757. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37758. var codeLength = lzwState.codeLength;
  37759. var prevCode = lzwState.prevCode;
  37760. var currentSequence = lzwState.currentSequence;
  37761. var currentSequenceLength = lzwState.currentSequenceLength;
  37762. var decodedLength = 0;
  37763. var currentBufferLength = this.bufferLength;
  37764. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37765. for (i = 0; i < blockSize; i++) {
  37766. var code = this.readBits(codeLength);
  37767. var hasPrev = currentSequenceLength > 0;
  37768. if (code < 256) {
  37769. currentSequence[0] = code;
  37770. currentSequenceLength = 1;
  37771. } else if (code >= 258) {
  37772. if (code < nextCode) {
  37773. currentSequenceLength = dictionaryLengths[code];
  37774. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37775. currentSequence[j] = dictionaryValues[q];
  37776. q = dictionaryPrevCodes[q];
  37777. }
  37778. } else {
  37779. currentSequence[currentSequenceLength++] = currentSequence[0];
  37780. }
  37781. } else if (code === 256) {
  37782. codeLength = 9;
  37783. nextCode = 258;
  37784. currentSequenceLength = 0;
  37785. continue;
  37786. } else {
  37787. this.eof = true;
  37788. delete this.lzwState;
  37789. break;
  37790. }
  37791. if (hasPrev) {
  37792. dictionaryPrevCodes[nextCode] = prevCode;
  37793. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37794. dictionaryValues[nextCode] = currentSequence[0];
  37795. nextCode++;
  37796. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37797. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37798. 0.6931471805599453 + 1, 12) | 0;
  37799. }
  37800. prevCode = code;
  37801. decodedLength += currentSequenceLength;
  37802. if (estimatedDecodedSize < decodedLength) {
  37803. do {
  37804. estimatedDecodedSize += decodedSizeDelta;
  37805. } while (estimatedDecodedSize < decodedLength);
  37806. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37807. }
  37808. for (j = 0; j < currentSequenceLength; j++) {
  37809. buffer[currentBufferLength++] = currentSequence[j];
  37810. }
  37811. }
  37812. lzwState.nextCode = nextCode;
  37813. lzwState.codeLength = codeLength;
  37814. lzwState.prevCode = prevCode;
  37815. lzwState.currentSequenceLength = currentSequenceLength;
  37816. this.bufferLength = currentBufferLength;
  37817. };
  37818. return LZWStream;
  37819. })();
  37820. var NullStream = (function NullStreamClosure() {
  37821. function NullStream() {
  37822. Stream.call(this, new Uint8Array(0));
  37823. }
  37824. NullStream.prototype = Stream.prototype;
  37825. return NullStream;
  37826. })();
  37827. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37828. setup: function wphSetup(handler) {
  37829. var pdfManager;
  37830. function loadDocument(recoveryMode) {
  37831. var loadDocumentCapability = createPromiseCapability();
  37832. var parseSuccess = function parseSuccess() {
  37833. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37834. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37835. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37836. Promise.all([numPagesPromise, fingerprintPromise,
  37837. encryptedPromise]).then(function onDocReady(results) {
  37838. var doc = {
  37839. numPages: results[0],
  37840. fingerprint: results[1],
  37841. encrypted: !!results[2],
  37842. };
  37843. loadDocumentCapability.resolve(doc);
  37844. },
  37845. parseFailure);
  37846. };
  37847. var parseFailure = function parseFailure(e) {
  37848. loadDocumentCapability.reject(e);
  37849. };
  37850. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37851. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37852. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37853. parseSuccess, parseFailure);
  37854. }, parseFailure);
  37855. }, parseFailure);
  37856. return loadDocumentCapability.promise;
  37857. }
  37858. function getPdfManager(data) {
  37859. var pdfManagerCapability = createPromiseCapability();
  37860. var source = data.source;
  37861. var disableRange = data.disableRange;
  37862. if (source.data) {
  37863. try {
  37864. pdfManager = new LocalPdfManager(source.data, source.password);
  37865. pdfManagerCapability.resolve();
  37866. } catch (ex) {
  37867. pdfManagerCapability.reject(ex);
  37868. }
  37869. return pdfManagerCapability.promise;
  37870. } else if (source.chunkedViewerLoading) {
  37871. try {
  37872. pdfManager = new NetworkPdfManager(source, handler);
  37873. pdfManagerCapability.resolve();
  37874. } catch (ex) {
  37875. pdfManagerCapability.reject(ex);
  37876. }
  37877. return pdfManagerCapability.promise;
  37878. }
  37879. var networkManager = new NetworkManager(source.url, {
  37880. httpHeaders: source.httpHeaders,
  37881. withCredentials: source.withCredentials
  37882. });
  37883. var cachedChunks = [];
  37884. var fullRequestXhrId = networkManager.requestFull({
  37885. onHeadersReceived: function onHeadersReceived() {
  37886. if (disableRange) {
  37887. return;
  37888. }
  37889. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37890. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37891. return;
  37892. }
  37893. var contentEncoding =
  37894. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37895. if (contentEncoding !== 'identity') {
  37896. return;
  37897. }
  37898. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37899. length = parseInt(length, 10);
  37900. if (!isInt(length)) {
  37901. return;
  37902. }
  37903. source.length = length;
  37904. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37905. // The file size is smaller than the size of two chunks, so it does
  37906. // not make any sense to abort the request and retry with a range
  37907. // request.
  37908. return;
  37909. }
  37910. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37911. // We can continue fetching when progressive loading is enabled,
  37912. // and we don't need the autoFetch feature.
  37913. source.disableAutoFetch = true;
  37914. } else {
  37915. // NOTE: by cancelling the full request, and then issuing range
  37916. // requests, there will be an issue for sites where you can only
  37917. // request the pdf once. However, if this is the case, then the
  37918. // server should not be returning that it can support range
  37919. // requests.
  37920. networkManager.abortRequest(fullRequestXhrId);
  37921. }
  37922. try {
  37923. pdfManager = new NetworkPdfManager(source, handler);
  37924. pdfManagerCapability.resolve(pdfManager);
  37925. } catch (ex) {
  37926. pdfManagerCapability.reject(ex);
  37927. }
  37928. },
  37929. onProgressiveData: source.disableStream ? null :
  37930. function onProgressiveData(chunk) {
  37931. if (!pdfManager) {
  37932. cachedChunks.push(chunk);
  37933. return;
  37934. }
  37935. pdfManager.sendProgressiveData(chunk);
  37936. },
  37937. onDone: function onDone(args) {
  37938. if (pdfManager) {
  37939. return; // already processed
  37940. }
  37941. var pdfFile;
  37942. if (args === null) {
  37943. // TODO add some streaming manager, e.g. for unknown length files.
  37944. // The data was returned in the onProgressiveData, combining...
  37945. var pdfFileLength = 0, pos = 0;
  37946. cachedChunks.forEach(function (chunk) {
  37947. pdfFileLength += chunk.byteLength;
  37948. });
  37949. if (source.length && pdfFileLength !== source.length) {
  37950. warn('reported HTTP length is different from actual');
  37951. }
  37952. var pdfFileArray = new Uint8Array(pdfFileLength);
  37953. cachedChunks.forEach(function (chunk) {
  37954. pdfFileArray.set(new Uint8Array(chunk), pos);
  37955. pos += chunk.byteLength;
  37956. });
  37957. pdfFile = pdfFileArray.buffer;
  37958. } else {
  37959. pdfFile = args.chunk;
  37960. }
  37961. // the data is array, instantiating directly from it
  37962. try {
  37963. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37964. pdfManagerCapability.resolve();
  37965. } catch (ex) {
  37966. pdfManagerCapability.reject(ex);
  37967. }
  37968. },
  37969. onError: function onError(status) {
  37970. var exception;
  37971. if (status === 404) {
  37972. exception = new MissingPDFException('Missing PDF "' +
  37973. source.url + '".');
  37974. handler.send('MissingPDF', exception);
  37975. } else {
  37976. exception = new UnexpectedResponseException(
  37977. 'Unexpected server response (' + status +
  37978. ') while retrieving PDF "' + source.url + '".', status);
  37979. handler.send('UnexpectedResponse', exception);
  37980. }
  37981. },
  37982. onProgress: function onProgress(evt) {
  37983. handler.send('DocProgress', {
  37984. loaded: evt.loaded,
  37985. total: evt.lengthComputable ? evt.total : source.length
  37986. });
  37987. }
  37988. });
  37989. return pdfManagerCapability.promise;
  37990. }
  37991. handler.on('test', function wphSetupTest(data) {
  37992. // check if Uint8Array can be sent to worker
  37993. if (!(data instanceof Uint8Array)) {
  37994. handler.send('test', false);
  37995. return;
  37996. }
  37997. // making sure postMessage transfers are working
  37998. var supportTransfers = data[0] === 255;
  37999. handler.postMessageTransfers = supportTransfers;
  38000. // check if the response property is supported by xhr
  38001. var xhr = new XMLHttpRequest();
  38002. var responseExists = 'response' in xhr;
  38003. // check if the property is actually implemented
  38004. try {
  38005. var dummy = xhr.responseType;
  38006. } catch (e) {
  38007. responseExists = false;
  38008. }
  38009. if (!responseExists) {
  38010. handler.send('test', false);
  38011. return;
  38012. }
  38013. handler.send('test', {
  38014. supportTypedArray: true,
  38015. supportTransfers: supportTransfers
  38016. });
  38017. });
  38018. handler.on('GetDocRequest', function wphSetupDoc(data) {
  38019. var onSuccess = function(doc) {
  38020. handler.send('GetDoc', { pdfInfo: doc });
  38021. };
  38022. var onFailure = function(e) {
  38023. if (e instanceof PasswordException) {
  38024. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38025. handler.send('NeedPassword', e);
  38026. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38027. handler.send('IncorrectPassword', e);
  38028. }
  38029. } else if (e instanceof InvalidPDFException) {
  38030. handler.send('InvalidPDF', e);
  38031. } else if (e instanceof MissingPDFException) {
  38032. handler.send('MissingPDF', e);
  38033. } else if (e instanceof UnexpectedResponseException) {
  38034. handler.send('UnexpectedResponse', e);
  38035. } else {
  38036. handler.send('UnknownError',
  38037. new UnknownErrorException(e.message, e.toString()));
  38038. }
  38039. };
  38040. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38041. -1 : data.maxImageSize;
  38042. PDFJS.disableFontFace = data.disableFontFace;
  38043. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38044. PDFJS.verbosity = data.verbosity;
  38045. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38046. null : data.cMapUrl;
  38047. PDFJS.cMapPacked = data.cMapPacked === true;
  38048. getPdfManager(data).then(function () {
  38049. handler.send('PDFManagerReady', null);
  38050. pdfManager.onLoadedStream().then(function(stream) {
  38051. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38052. });
  38053. }).then(function pdfManagerReady() {
  38054. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38055. // Try again with recoveryMode == true
  38056. if (!(ex instanceof XRefParseException)) {
  38057. if (ex instanceof PasswordException) {
  38058. // after password exception prepare to receive a new password
  38059. // to repeat loading
  38060. pdfManager.passwordChanged().then(pdfManagerReady);
  38061. }
  38062. onFailure(ex);
  38063. return;
  38064. }
  38065. pdfManager.requestLoadedStream();
  38066. pdfManager.onLoadedStream().then(function() {
  38067. loadDocument(true).then(onSuccess, onFailure);
  38068. });
  38069. }, onFailure);
  38070. }, onFailure);
  38071. });
  38072. handler.on('GetPage', function wphSetupGetPage(data) {
  38073. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38074. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38075. var refPromise = pdfManager.ensure(page, 'ref');
  38076. var viewPromise = pdfManager.ensure(page, 'view');
  38077. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38078. function(results) {
  38079. return {
  38080. rotate: results[0],
  38081. ref: results[1],
  38082. view: results[2]
  38083. };
  38084. });
  38085. });
  38086. });
  38087. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38088. var ref = new Ref(data.ref.num, data.ref.gen);
  38089. var catalog = pdfManager.pdfDocument.catalog;
  38090. return catalog.getPageIndex(ref);
  38091. });
  38092. handler.on('GetDestinations',
  38093. function wphSetupGetDestinations(data) {
  38094. return pdfManager.ensureCatalog('destinations');
  38095. }
  38096. );
  38097. handler.on('GetDestination',
  38098. function wphSetupGetDestination(data) {
  38099. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  38100. }
  38101. );
  38102. handler.on('GetAttachments',
  38103. function wphSetupGetAttachments(data) {
  38104. return pdfManager.ensureCatalog('attachments');
  38105. }
  38106. );
  38107. handler.on('GetJavaScript',
  38108. function wphSetupGetJavaScript(data) {
  38109. return pdfManager.ensureCatalog('javaScript');
  38110. }
  38111. );
  38112. handler.on('GetOutline',
  38113. function wphSetupGetOutline(data) {
  38114. return pdfManager.ensureCatalog('documentOutline');
  38115. }
  38116. );
  38117. handler.on('GetMetadata',
  38118. function wphSetupGetMetadata(data) {
  38119. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38120. pdfManager.ensureCatalog('metadata')]);
  38121. }
  38122. );
  38123. handler.on('GetData', function wphSetupGetData(data) {
  38124. pdfManager.requestLoadedStream();
  38125. return pdfManager.onLoadedStream().then(function(stream) {
  38126. return stream.bytes;
  38127. });
  38128. });
  38129. handler.on('GetStats',
  38130. function wphSetupGetStats(data) {
  38131. return pdfManager.pdfDocument.xref.stats;
  38132. }
  38133. );
  38134. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38135. pdfManager.updatePassword(data);
  38136. });
  38137. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38138. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38139. return pdfManager.ensure(page, 'getAnnotationsData', []);
  38140. });
  38141. });
  38142. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38143. pdfManager.getPage(data.pageIndex).then(function(page) {
  38144. var pageNum = data.pageIndex + 1;
  38145. var start = Date.now();
  38146. // Pre compile the pdf page and fetch the fonts/images.
  38147. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  38148. info('page=' + pageNum + ' - getOperatorList: time=' +
  38149. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  38150. }, function(e) {
  38151. var minimumStackMessage =
  38152. 'worker.js: while trying to getPage() and getOperatorList()';
  38153. var wrappedException;
  38154. // Turn the error into an obj that can be serialized
  38155. if (typeof e === 'string') {
  38156. wrappedException = {
  38157. message: e,
  38158. stack: minimumStackMessage
  38159. };
  38160. } else if (typeof e === 'object') {
  38161. wrappedException = {
  38162. message: e.message || e.toString(),
  38163. stack: e.stack || minimumStackMessage
  38164. };
  38165. } else {
  38166. wrappedException = {
  38167. message: 'Unknown exception type: ' + (typeof e),
  38168. stack: minimumStackMessage
  38169. };
  38170. }
  38171. handler.send('PageError', {
  38172. pageNum: pageNum,
  38173. error: wrappedException,
  38174. intent: data.intent
  38175. });
  38176. });
  38177. });
  38178. }, this);
  38179. handler.on('GetTextContent', function wphExtractText(data) {
  38180. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38181. var pageNum = data.pageIndex + 1;
  38182. var start = Date.now();
  38183. return page.extractTextContent().then(function(textContent) {
  38184. info('text indexing: page=' + pageNum + ' - time=' +
  38185. (Date.now() - start) + 'ms');
  38186. return textContent;
  38187. });
  38188. });
  38189. });
  38190. handler.on('Cleanup', function wphCleanup(data) {
  38191. return pdfManager.cleanup();
  38192. });
  38193. handler.on('Terminate', function wphTerminate(data) {
  38194. pdfManager.terminate();
  38195. });
  38196. }
  38197. };
  38198. var consoleTimer = {};
  38199. var workerConsole = {
  38200. log: function log() {
  38201. var args = Array.prototype.slice.call(arguments);
  38202. globalScope.postMessage({
  38203. action: 'console_log',
  38204. data: args
  38205. });
  38206. },
  38207. error: function error() {
  38208. var args = Array.prototype.slice.call(arguments);
  38209. globalScope.postMessage({
  38210. action: 'console_error',
  38211. data: args
  38212. });
  38213. throw 'pdf.js execution error';
  38214. },
  38215. time: function time(name) {
  38216. consoleTimer[name] = Date.now();
  38217. },
  38218. timeEnd: function timeEnd(name) {
  38219. var time = consoleTimer[name];
  38220. if (!time) {
  38221. error('Unknown timer name ' + name);
  38222. }
  38223. this.log('Timer:', name, Date.now() - time);
  38224. }
  38225. };
  38226. // Worker thread?
  38227. if (typeof window === 'undefined') {
  38228. if (!('console' in globalScope)) {
  38229. globalScope.console = workerConsole;
  38230. }
  38231. // Listen for unsupported features so we can pass them on to the main thread.
  38232. PDFJS.UnsupportedManager.listen(function (msg) {
  38233. globalScope.postMessage({
  38234. action: '_unsupported_feature',
  38235. data: msg
  38236. });
  38237. });
  38238. var handler = new MessageHandler('worker_processor', this);
  38239. WorkerMessageHandler.setup(handler);
  38240. }
  38241. /* This class implements the QM Coder decoding as defined in
  38242. * JPEG 2000 Part I Final Committee Draft Version 1.0
  38243. * Annex C.3 Arithmetic decoding procedure
  38244. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  38245. *
  38246. * The arithmetic decoder is used in conjunction with context models to decode
  38247. * JPEG2000 and JBIG2 streams.
  38248. */
  38249. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  38250. // Table C-2
  38251. var QeTable = [
  38252. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  38253. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  38254. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  38255. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  38256. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  38257. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  38258. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  38259. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  38260. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  38261. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  38262. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  38263. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  38264. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  38265. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  38266. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  38267. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  38268. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  38269. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  38270. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  38271. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  38272. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  38273. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  38274. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  38275. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  38276. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  38277. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  38278. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  38279. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  38280. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  38281. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  38282. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  38283. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  38284. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  38285. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  38286. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  38287. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  38288. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  38289. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  38290. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  38291. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  38292. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  38293. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  38294. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  38295. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  38296. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  38297. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  38298. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  38299. ];
  38300. // C.3.5 Initialisation of the decoder (INITDEC)
  38301. function ArithmeticDecoder(data, start, end) {
  38302. this.data = data;
  38303. this.bp = start;
  38304. this.dataEnd = end;
  38305. this.chigh = data[start];
  38306. this.clow = 0;
  38307. this.byteIn();
  38308. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  38309. this.clow = (this.clow << 7) & 0xFFFF;
  38310. this.ct -= 7;
  38311. this.a = 0x8000;
  38312. }
  38313. ArithmeticDecoder.prototype = {
  38314. // C.3.4 Compressed data input (BYTEIN)
  38315. byteIn: function ArithmeticDecoder_byteIn() {
  38316. var data = this.data;
  38317. var bp = this.bp;
  38318. if (data[bp] === 0xFF) {
  38319. var b1 = data[bp + 1];
  38320. if (b1 > 0x8F) {
  38321. this.clow += 0xFF00;
  38322. this.ct = 8;
  38323. } else {
  38324. bp++;
  38325. this.clow += (data[bp] << 9);
  38326. this.ct = 7;
  38327. this.bp = bp;
  38328. }
  38329. } else {
  38330. bp++;
  38331. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  38332. this.ct = 8;
  38333. this.bp = bp;
  38334. }
  38335. if (this.clow > 0xFFFF) {
  38336. this.chigh += (this.clow >> 16);
  38337. this.clow &= 0xFFFF;
  38338. }
  38339. },
  38340. // C.3.2 Decoding a decision (DECODE)
  38341. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  38342. // contexts are packed into 1 byte:
  38343. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  38344. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  38345. var qeTableIcx = QeTable[cx_index];
  38346. var qeIcx = qeTableIcx.qe;
  38347. var d;
  38348. var a = this.a - qeIcx;
  38349. if (this.chigh < qeIcx) {
  38350. // exchangeLps
  38351. if (a < qeIcx) {
  38352. a = qeIcx;
  38353. d = cx_mps;
  38354. cx_index = qeTableIcx.nmps;
  38355. } else {
  38356. a = qeIcx;
  38357. d = 1 ^ cx_mps;
  38358. if (qeTableIcx.switchFlag === 1) {
  38359. cx_mps = d;
  38360. }
  38361. cx_index = qeTableIcx.nlps;
  38362. }
  38363. } else {
  38364. this.chigh -= qeIcx;
  38365. if ((a & 0x8000) !== 0) {
  38366. this.a = a;
  38367. return cx_mps;
  38368. }
  38369. // exchangeMps
  38370. if (a < qeIcx) {
  38371. d = 1 ^ cx_mps;
  38372. if (qeTableIcx.switchFlag === 1) {
  38373. cx_mps = d;
  38374. }
  38375. cx_index = qeTableIcx.nlps;
  38376. } else {
  38377. d = cx_mps;
  38378. cx_index = qeTableIcx.nmps;
  38379. }
  38380. }
  38381. // C.3.3 renormD;
  38382. do {
  38383. if (this.ct === 0) {
  38384. this.byteIn();
  38385. }
  38386. a <<= 1;
  38387. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  38388. this.clow = (this.clow << 1) & 0xFFFF;
  38389. this.ct--;
  38390. } while ((a & 0x8000) === 0);
  38391. this.a = a;
  38392. contexts[pos] = cx_index << 1 | cx_mps;
  38393. return d;
  38394. }
  38395. };
  38396. return ArithmeticDecoder;
  38397. })();
  38398. var JpegImage = (function jpegImage() {
  38399. var dctZigZag = new Uint8Array([
  38400. 0,
  38401. 1, 8,
  38402. 16, 9, 2,
  38403. 3, 10, 17, 24,
  38404. 32, 25, 18, 11, 4,
  38405. 5, 12, 19, 26, 33, 40,
  38406. 48, 41, 34, 27, 20, 13, 6,
  38407. 7, 14, 21, 28, 35, 42, 49, 56,
  38408. 57, 50, 43, 36, 29, 22, 15,
  38409. 23, 30, 37, 44, 51, 58,
  38410. 59, 52, 45, 38, 31,
  38411. 39, 46, 53, 60,
  38412. 61, 54, 47,
  38413. 55, 62,
  38414. 63
  38415. ]);
  38416. var dctCos1 = 4017; // cos(pi/16)
  38417. var dctSin1 = 799; // sin(pi/16)
  38418. var dctCos3 = 3406; // cos(3*pi/16)
  38419. var dctSin3 = 2276; // sin(3*pi/16)
  38420. var dctCos6 = 1567; // cos(6*pi/16)
  38421. var dctSin6 = 3784; // sin(6*pi/16)
  38422. var dctSqrt2 = 5793; // sqrt(2)
  38423. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  38424. function constructor() {
  38425. }
  38426. function buildHuffmanTable(codeLengths, values) {
  38427. var k = 0, code = [], i, j, length = 16;
  38428. while (length > 0 && !codeLengths[length - 1]) {
  38429. length--;
  38430. }
  38431. code.push({children: [], index: 0});
  38432. var p = code[0], q;
  38433. for (i = 0; i < length; i++) {
  38434. for (j = 0; j < codeLengths[i]; j++) {
  38435. p = code.pop();
  38436. p.children[p.index] = values[k];
  38437. while (p.index > 0) {
  38438. p = code.pop();
  38439. }
  38440. p.index++;
  38441. code.push(p);
  38442. while (code.length <= i) {
  38443. code.push(q = {children: [], index: 0});
  38444. p.children[p.index] = q.children;
  38445. p = q;
  38446. }
  38447. k++;
  38448. }
  38449. if (i + 1 < length) {
  38450. // p here points to last code
  38451. code.push(q = {children: [], index: 0});
  38452. p.children[p.index] = q.children;
  38453. p = q;
  38454. }
  38455. }
  38456. return code[0].children;
  38457. }
  38458. function getBlockBufferOffset(component, row, col) {
  38459. return 64 * ((component.blocksPerLine + 1) * row + col);
  38460. }
  38461. function decodeScan(data, offset, frame, components, resetInterval,
  38462. spectralStart, spectralEnd, successivePrev, successive) {
  38463. var precision = frame.precision;
  38464. var samplesPerLine = frame.samplesPerLine;
  38465. var scanLines = frame.scanLines;
  38466. var mcusPerLine = frame.mcusPerLine;
  38467. var progressive = frame.progressive;
  38468. var maxH = frame.maxH, maxV = frame.maxV;
  38469. var startOffset = offset, bitsData = 0, bitsCount = 0;
  38470. function readBit() {
  38471. if (bitsCount > 0) {
  38472. bitsCount--;
  38473. return (bitsData >> bitsCount) & 1;
  38474. }
  38475. bitsData = data[offset++];
  38476. if (bitsData === 0xFF) {
  38477. var nextByte = data[offset++];
  38478. if (nextByte) {
  38479. throw 'unexpected marker: ' +
  38480. ((bitsData << 8) | nextByte).toString(16);
  38481. }
  38482. // unstuff 0
  38483. }
  38484. bitsCount = 7;
  38485. return bitsData >>> 7;
  38486. }
  38487. function decodeHuffman(tree) {
  38488. var node = tree;
  38489. while (true) {
  38490. node = node[readBit()];
  38491. if (typeof node === 'number') {
  38492. return node;
  38493. }
  38494. if (typeof node !== 'object') {
  38495. throw 'invalid huffman sequence';
  38496. }
  38497. }
  38498. }
  38499. function receive(length) {
  38500. var n = 0;
  38501. while (length > 0) {
  38502. n = (n << 1) | readBit();
  38503. length--;
  38504. }
  38505. return n;
  38506. }
  38507. function receiveAndExtend(length) {
  38508. if (length === 1) {
  38509. return readBit() === 1 ? 1 : -1;
  38510. }
  38511. var n = receive(length);
  38512. if (n >= 1 << (length - 1)) {
  38513. return n;
  38514. }
  38515. return n + (-1 << length) + 1;
  38516. }
  38517. function decodeBaseline(component, offset) {
  38518. var t = decodeHuffman(component.huffmanTableDC);
  38519. var diff = t === 0 ? 0 : receiveAndExtend(t);
  38520. component.blockData[offset] = (component.pred += diff);
  38521. var k = 1;
  38522. while (k < 64) {
  38523. var rs = decodeHuffman(component.huffmanTableAC);
  38524. var s = rs & 15, r = rs >> 4;
  38525. if (s === 0) {
  38526. if (r < 15) {
  38527. break;
  38528. }
  38529. k += 16;
  38530. continue;
  38531. }
  38532. k += r;
  38533. var z = dctZigZag[k];
  38534. component.blockData[offset + z] = receiveAndExtend(s);
  38535. k++;
  38536. }
  38537. }
  38538. function decodeDCFirst(component, offset) {
  38539. var t = decodeHuffman(component.huffmanTableDC);
  38540. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  38541. component.blockData[offset] = (component.pred += diff);
  38542. }
  38543. function decodeDCSuccessive(component, offset) {
  38544. component.blockData[offset] |= readBit() << successive;
  38545. }
  38546. var eobrun = 0;
  38547. function decodeACFirst(component, offset) {
  38548. if (eobrun > 0) {
  38549. eobrun--;
  38550. return;
  38551. }
  38552. var k = spectralStart, e = spectralEnd;
  38553. while (k <= e) {
  38554. var rs = decodeHuffman(component.huffmanTableAC);
  38555. var s = rs & 15, r = rs >> 4;
  38556. if (s === 0) {
  38557. if (r < 15) {
  38558. eobrun = receive(r) + (1 << r) - 1;
  38559. break;
  38560. }
  38561. k += 16;
  38562. continue;
  38563. }
  38564. k += r;
  38565. var z = dctZigZag[k];
  38566. component.blockData[offset + z] =
  38567. receiveAndExtend(s) * (1 << successive);
  38568. k++;
  38569. }
  38570. }
  38571. var successiveACState = 0, successiveACNextValue;
  38572. function decodeACSuccessive(component, offset) {
  38573. var k = spectralStart;
  38574. var e = spectralEnd;
  38575. var r = 0;
  38576. var s;
  38577. var rs;
  38578. while (k <= e) {
  38579. var z = dctZigZag[k];
  38580. switch (successiveACState) {
  38581. case 0: // initial state
  38582. rs = decodeHuffman(component.huffmanTableAC);
  38583. s = rs & 15;
  38584. r = rs >> 4;
  38585. if (s === 0) {
  38586. if (r < 15) {
  38587. eobrun = receive(r) + (1 << r);
  38588. successiveACState = 4;
  38589. } else {
  38590. r = 16;
  38591. successiveACState = 1;
  38592. }
  38593. } else {
  38594. if (s !== 1) {
  38595. throw 'invalid ACn encoding';
  38596. }
  38597. successiveACNextValue = receiveAndExtend(s);
  38598. successiveACState = r ? 2 : 3;
  38599. }
  38600. continue;
  38601. case 1: // skipping r zero items
  38602. case 2:
  38603. if (component.blockData[offset + z]) {
  38604. component.blockData[offset + z] += (readBit() << successive);
  38605. } else {
  38606. r--;
  38607. if (r === 0) {
  38608. successiveACState = successiveACState === 2 ? 3 : 0;
  38609. }
  38610. }
  38611. break;
  38612. case 3: // set value for a zero item
  38613. if (component.blockData[offset + z]) {
  38614. component.blockData[offset + z] += (readBit() << successive);
  38615. } else {
  38616. component.blockData[offset + z] =
  38617. successiveACNextValue << successive;
  38618. successiveACState = 0;
  38619. }
  38620. break;
  38621. case 4: // eob
  38622. if (component.blockData[offset + z]) {
  38623. component.blockData[offset + z] += (readBit() << successive);
  38624. }
  38625. break;
  38626. }
  38627. k++;
  38628. }
  38629. if (successiveACState === 4) {
  38630. eobrun--;
  38631. if (eobrun === 0) {
  38632. successiveACState = 0;
  38633. }
  38634. }
  38635. }
  38636. function decodeMcu(component, decode, mcu, row, col) {
  38637. var mcuRow = (mcu / mcusPerLine) | 0;
  38638. var mcuCol = mcu % mcusPerLine;
  38639. var blockRow = mcuRow * component.v + row;
  38640. var blockCol = mcuCol * component.h + col;
  38641. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38642. decode(component, offset);
  38643. }
  38644. function decodeBlock(component, decode, mcu) {
  38645. var blockRow = (mcu / component.blocksPerLine) | 0;
  38646. var blockCol = mcu % component.blocksPerLine;
  38647. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38648. decode(component, offset);
  38649. }
  38650. var componentsLength = components.length;
  38651. var component, i, j, k, n;
  38652. var decodeFn;
  38653. if (progressive) {
  38654. if (spectralStart === 0) {
  38655. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38656. } else {
  38657. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38658. }
  38659. } else {
  38660. decodeFn = decodeBaseline;
  38661. }
  38662. var mcu = 0, marker;
  38663. var mcuExpected;
  38664. if (componentsLength === 1) {
  38665. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38666. } else {
  38667. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38668. }
  38669. if (!resetInterval) {
  38670. resetInterval = mcuExpected;
  38671. }
  38672. var h, v;
  38673. while (mcu < mcuExpected) {
  38674. // reset interval stuff
  38675. for (i = 0; i < componentsLength; i++) {
  38676. components[i].pred = 0;
  38677. }
  38678. eobrun = 0;
  38679. if (componentsLength === 1) {
  38680. component = components[0];
  38681. for (n = 0; n < resetInterval; n++) {
  38682. decodeBlock(component, decodeFn, mcu);
  38683. mcu++;
  38684. }
  38685. } else {
  38686. for (n = 0; n < resetInterval; n++) {
  38687. for (i = 0; i < componentsLength; i++) {
  38688. component = components[i];
  38689. h = component.h;
  38690. v = component.v;
  38691. for (j = 0; j < v; j++) {
  38692. for (k = 0; k < h; k++) {
  38693. decodeMcu(component, decodeFn, mcu, j, k);
  38694. }
  38695. }
  38696. }
  38697. mcu++;
  38698. }
  38699. }
  38700. // find marker
  38701. bitsCount = 0;
  38702. marker = (data[offset] << 8) | data[offset + 1];
  38703. if (marker <= 0xFF00) {
  38704. throw 'marker was not found';
  38705. }
  38706. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38707. offset += 2;
  38708. } else {
  38709. break;
  38710. }
  38711. }
  38712. return offset - startOffset;
  38713. }
  38714. // A port of poppler's IDCT method which in turn is taken from:
  38715. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38716. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38717. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38718. // 988-991.
  38719. function quantizeAndInverse(component, blockBufferOffset, p) {
  38720. var qt = component.quantizationTable, blockData = component.blockData;
  38721. var v0, v1, v2, v3, v4, v5, v6, v7;
  38722. var p0, p1, p2, p3, p4, p5, p6, p7;
  38723. var t;
  38724. // inverse DCT on rows
  38725. for (var row = 0; row < 64; row += 8) {
  38726. // gather block data
  38727. p0 = blockData[blockBufferOffset + row];
  38728. p1 = blockData[blockBufferOffset + row + 1];
  38729. p2 = blockData[blockBufferOffset + row + 2];
  38730. p3 = blockData[blockBufferOffset + row + 3];
  38731. p4 = blockData[blockBufferOffset + row + 4];
  38732. p5 = blockData[blockBufferOffset + row + 5];
  38733. p6 = blockData[blockBufferOffset + row + 6];
  38734. p7 = blockData[blockBufferOffset + row + 7];
  38735. // dequant p0
  38736. p0 *= qt[row];
  38737. // check for all-zero AC coefficients
  38738. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38739. t = (dctSqrt2 * p0 + 512) >> 10;
  38740. p[row] = t;
  38741. p[row + 1] = t;
  38742. p[row + 2] = t;
  38743. p[row + 3] = t;
  38744. p[row + 4] = t;
  38745. p[row + 5] = t;
  38746. p[row + 6] = t;
  38747. p[row + 7] = t;
  38748. continue;
  38749. }
  38750. // dequant p1 ... p7
  38751. p1 *= qt[row + 1];
  38752. p2 *= qt[row + 2];
  38753. p3 *= qt[row + 3];
  38754. p4 *= qt[row + 4];
  38755. p5 *= qt[row + 5];
  38756. p6 *= qt[row + 6];
  38757. p7 *= qt[row + 7];
  38758. // stage 4
  38759. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38760. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38761. v2 = p2;
  38762. v3 = p6;
  38763. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38764. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38765. v5 = p3 << 4;
  38766. v6 = p5 << 4;
  38767. // stage 3
  38768. v0 = (v0 + v1 + 1) >> 1;
  38769. v1 = v0 - v1;
  38770. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38771. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38772. v3 = t;
  38773. v4 = (v4 + v6 + 1) >> 1;
  38774. v6 = v4 - v6;
  38775. v7 = (v7 + v5 + 1) >> 1;
  38776. v5 = v7 - v5;
  38777. // stage 2
  38778. v0 = (v0 + v3 + 1) >> 1;
  38779. v3 = v0 - v3;
  38780. v1 = (v1 + v2 + 1) >> 1;
  38781. v2 = v1 - v2;
  38782. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38783. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38784. v7 = t;
  38785. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38786. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38787. v6 = t;
  38788. // stage 1
  38789. p[row] = v0 + v7;
  38790. p[row + 7] = v0 - v7;
  38791. p[row + 1] = v1 + v6;
  38792. p[row + 6] = v1 - v6;
  38793. p[row + 2] = v2 + v5;
  38794. p[row + 5] = v2 - v5;
  38795. p[row + 3] = v3 + v4;
  38796. p[row + 4] = v3 - v4;
  38797. }
  38798. // inverse DCT on columns
  38799. for (var col = 0; col < 8; ++col) {
  38800. p0 = p[col];
  38801. p1 = p[col + 8];
  38802. p2 = p[col + 16];
  38803. p3 = p[col + 24];
  38804. p4 = p[col + 32];
  38805. p5 = p[col + 40];
  38806. p6 = p[col + 48];
  38807. p7 = p[col + 56];
  38808. // check for all-zero AC coefficients
  38809. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38810. t = (dctSqrt2 * p0 + 8192) >> 14;
  38811. // convert to 8 bit
  38812. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38813. blockData[blockBufferOffset + col] = t;
  38814. blockData[blockBufferOffset + col + 8] = t;
  38815. blockData[blockBufferOffset + col + 16] = t;
  38816. blockData[blockBufferOffset + col + 24] = t;
  38817. blockData[blockBufferOffset + col + 32] = t;
  38818. blockData[blockBufferOffset + col + 40] = t;
  38819. blockData[blockBufferOffset + col + 48] = t;
  38820. blockData[blockBufferOffset + col + 56] = t;
  38821. continue;
  38822. }
  38823. // stage 4
  38824. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38825. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38826. v2 = p2;
  38827. v3 = p6;
  38828. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38829. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38830. v5 = p3;
  38831. v6 = p5;
  38832. // stage 3
  38833. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38834. // converting to UInt8 range later.
  38835. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38836. v1 = v0 - v1;
  38837. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38838. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38839. v3 = t;
  38840. v4 = (v4 + v6 + 1) >> 1;
  38841. v6 = v4 - v6;
  38842. v7 = (v7 + v5 + 1) >> 1;
  38843. v5 = v7 - v5;
  38844. // stage 2
  38845. v0 = (v0 + v3 + 1) >> 1;
  38846. v3 = v0 - v3;
  38847. v1 = (v1 + v2 + 1) >> 1;
  38848. v2 = v1 - v2;
  38849. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38850. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38851. v7 = t;
  38852. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38853. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38854. v6 = t;
  38855. // stage 1
  38856. p0 = v0 + v7;
  38857. p7 = v0 - v7;
  38858. p1 = v1 + v6;
  38859. p6 = v1 - v6;
  38860. p2 = v2 + v5;
  38861. p5 = v2 - v5;
  38862. p3 = v3 + v4;
  38863. p4 = v3 - v4;
  38864. // convert to 8-bit integers
  38865. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38866. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38867. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38868. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38869. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38870. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38871. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38872. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38873. // store block data
  38874. blockData[blockBufferOffset + col] = p0;
  38875. blockData[blockBufferOffset + col + 8] = p1;
  38876. blockData[blockBufferOffset + col + 16] = p2;
  38877. blockData[blockBufferOffset + col + 24] = p3;
  38878. blockData[blockBufferOffset + col + 32] = p4;
  38879. blockData[blockBufferOffset + col + 40] = p5;
  38880. blockData[blockBufferOffset + col + 48] = p6;
  38881. blockData[blockBufferOffset + col + 56] = p7;
  38882. }
  38883. }
  38884. function buildComponentData(frame, component) {
  38885. var blocksPerLine = component.blocksPerLine;
  38886. var blocksPerColumn = component.blocksPerColumn;
  38887. var computationBuffer = new Int16Array(64);
  38888. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38889. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38890. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38891. quantizeAndInverse(component, offset, computationBuffer);
  38892. }
  38893. }
  38894. return component.blockData;
  38895. }
  38896. function clamp0to255(a) {
  38897. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38898. }
  38899. constructor.prototype = {
  38900. parse: function parse(data) {
  38901. function readUint16() {
  38902. var value = (data[offset] << 8) | data[offset + 1];
  38903. offset += 2;
  38904. return value;
  38905. }
  38906. function readDataBlock() {
  38907. var length = readUint16();
  38908. var array = data.subarray(offset, offset + length - 2);
  38909. offset += array.length;
  38910. return array;
  38911. }
  38912. function prepareComponents(frame) {
  38913. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38914. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38915. for (var i = 0; i < frame.components.length; i++) {
  38916. component = frame.components[i];
  38917. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38918. component.h / frame.maxH);
  38919. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38920. component.v / frame.maxV);
  38921. var blocksPerLineForMcu = mcusPerLine * component.h;
  38922. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38923. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38924. (blocksPerLineForMcu + 1);
  38925. component.blockData = new Int16Array(blocksBufferSize);
  38926. component.blocksPerLine = blocksPerLine;
  38927. component.blocksPerColumn = blocksPerColumn;
  38928. }
  38929. frame.mcusPerLine = mcusPerLine;
  38930. frame.mcusPerColumn = mcusPerColumn;
  38931. }
  38932. var offset = 0, length = data.length;
  38933. var jfif = null;
  38934. var adobe = null;
  38935. var pixels = null;
  38936. var frame, resetInterval;
  38937. var quantizationTables = [];
  38938. var huffmanTablesAC = [], huffmanTablesDC = [];
  38939. var fileMarker = readUint16();
  38940. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38941. throw 'SOI not found';
  38942. }
  38943. fileMarker = readUint16();
  38944. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38945. var i, j, l;
  38946. switch(fileMarker) {
  38947. case 0xFFE0: // APP0 (Application Specific)
  38948. case 0xFFE1: // APP1
  38949. case 0xFFE2: // APP2
  38950. case 0xFFE3: // APP3
  38951. case 0xFFE4: // APP4
  38952. case 0xFFE5: // APP5
  38953. case 0xFFE6: // APP6
  38954. case 0xFFE7: // APP7
  38955. case 0xFFE8: // APP8
  38956. case 0xFFE9: // APP9
  38957. case 0xFFEA: // APP10
  38958. case 0xFFEB: // APP11
  38959. case 0xFFEC: // APP12
  38960. case 0xFFED: // APP13
  38961. case 0xFFEE: // APP14
  38962. case 0xFFEF: // APP15
  38963. case 0xFFFE: // COM (Comment)
  38964. var appData = readDataBlock();
  38965. if (fileMarker === 0xFFE0) {
  38966. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38967. appData[2] === 0x49 && appData[3] === 0x46 &&
  38968. appData[4] === 0) { // 'JFIF\x00'
  38969. jfif = {
  38970. version: { major: appData[5], minor: appData[6] },
  38971. densityUnits: appData[7],
  38972. xDensity: (appData[8] << 8) | appData[9],
  38973. yDensity: (appData[10] << 8) | appData[11],
  38974. thumbWidth: appData[12],
  38975. thumbHeight: appData[13],
  38976. thumbData: appData.subarray(14, 14 +
  38977. 3 * appData[12] * appData[13])
  38978. };
  38979. }
  38980. }
  38981. // TODO APP1 - Exif
  38982. if (fileMarker === 0xFFEE) {
  38983. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38984. appData[2] === 0x6F && appData[3] === 0x62 &&
  38985. appData[4] === 0x65) { // 'Adobe'
  38986. adobe = {
  38987. version: (appData[5] << 8) | appData[6],
  38988. flags0: (appData[7] << 8) | appData[8],
  38989. flags1: (appData[9] << 8) | appData[10],
  38990. transformCode: appData[11]
  38991. };
  38992. }
  38993. }
  38994. break;
  38995. case 0xFFDB: // DQT (Define Quantization Tables)
  38996. var quantizationTablesLength = readUint16();
  38997. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38998. var z;
  38999. while (offset < quantizationTablesEnd) {
  39000. var quantizationTableSpec = data[offset++];
  39001. var tableData = new Uint16Array(64);
  39002. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  39003. for (j = 0; j < 64; j++) {
  39004. z = dctZigZag[j];
  39005. tableData[z] = data[offset++];
  39006. }
  39007. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  39008. for (j = 0; j < 64; j++) {
  39009. z = dctZigZag[j];
  39010. tableData[z] = readUint16();
  39011. }
  39012. } else {
  39013. throw 'DQT: invalid table spec';
  39014. }
  39015. quantizationTables[quantizationTableSpec & 15] = tableData;
  39016. }
  39017. break;
  39018. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  39019. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  39020. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  39021. if (frame) {
  39022. throw 'Only single frame JPEGs supported';
  39023. }
  39024. readUint16(); // skip data length
  39025. frame = {};
  39026. frame.extended = (fileMarker === 0xFFC1);
  39027. frame.progressive = (fileMarker === 0xFFC2);
  39028. frame.precision = data[offset++];
  39029. frame.scanLines = readUint16();
  39030. frame.samplesPerLine = readUint16();
  39031. frame.components = [];
  39032. frame.componentIds = {};
  39033. var componentsCount = data[offset++], componentId;
  39034. var maxH = 0, maxV = 0;
  39035. for (i = 0; i < componentsCount; i++) {
  39036. componentId = data[offset];
  39037. var h = data[offset + 1] >> 4;
  39038. var v = data[offset + 1] & 15;
  39039. if (maxH < h) {
  39040. maxH = h;
  39041. }
  39042. if (maxV < v) {
  39043. maxV = v;
  39044. }
  39045. var qId = data[offset + 2];
  39046. l = frame.components.push({
  39047. h: h,
  39048. v: v,
  39049. quantizationTable: quantizationTables[qId]
  39050. });
  39051. frame.componentIds[componentId] = l - 1;
  39052. offset += 3;
  39053. }
  39054. frame.maxH = maxH;
  39055. frame.maxV = maxV;
  39056. prepareComponents(frame);
  39057. break;
  39058. case 0xFFC4: // DHT (Define Huffman Tables)
  39059. var huffmanLength = readUint16();
  39060. for (i = 2; i < huffmanLength;) {
  39061. var huffmanTableSpec = data[offset++];
  39062. var codeLengths = new Uint8Array(16);
  39063. var codeLengthSum = 0;
  39064. for (j = 0; j < 16; j++, offset++) {
  39065. codeLengthSum += (codeLengths[j] = data[offset]);
  39066. }
  39067. var huffmanValues = new Uint8Array(codeLengthSum);
  39068. for (j = 0; j < codeLengthSum; j++, offset++) {
  39069. huffmanValues[j] = data[offset];
  39070. }
  39071. i += 17 + codeLengthSum;
  39072. ((huffmanTableSpec >> 4) === 0 ?
  39073. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  39074. buildHuffmanTable(codeLengths, huffmanValues);
  39075. }
  39076. break;
  39077. case 0xFFDD: // DRI (Define Restart Interval)
  39078. readUint16(); // skip data length
  39079. resetInterval = readUint16();
  39080. break;
  39081. case 0xFFDA: // SOS (Start of Scan)
  39082. var scanLength = readUint16();
  39083. var selectorsCount = data[offset++];
  39084. var components = [], component;
  39085. for (i = 0; i < selectorsCount; i++) {
  39086. var componentIndex = frame.componentIds[data[offset++]];
  39087. component = frame.components[componentIndex];
  39088. var tableSpec = data[offset++];
  39089. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  39090. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  39091. components.push(component);
  39092. }
  39093. var spectralStart = data[offset++];
  39094. var spectralEnd = data[offset++];
  39095. var successiveApproximation = data[offset++];
  39096. var processed = decodeScan(data, offset,
  39097. frame, components, resetInterval,
  39098. spectralStart, spectralEnd,
  39099. successiveApproximation >> 4, successiveApproximation & 15);
  39100. offset += processed;
  39101. break;
  39102. case 0xFFFF: // Fill bytes
  39103. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  39104. offset--;
  39105. }
  39106. break;
  39107. default:
  39108. if (data[offset - 3] === 0xFF &&
  39109. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  39110. // could be incorrect encoding -- last 0xFF byte of the previous
  39111. // block was eaten by the encoder
  39112. offset -= 3;
  39113. break;
  39114. }
  39115. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  39116. }
  39117. fileMarker = readUint16();
  39118. }
  39119. this.width = frame.samplesPerLine;
  39120. this.height = frame.scanLines;
  39121. this.jfif = jfif;
  39122. this.adobe = adobe;
  39123. this.components = [];
  39124. for (i = 0; i < frame.components.length; i++) {
  39125. component = frame.components[i];
  39126. this.components.push({
  39127. output: buildComponentData(frame, component),
  39128. scaleX: component.h / frame.maxH,
  39129. scaleY: component.v / frame.maxV,
  39130. blocksPerLine: component.blocksPerLine,
  39131. blocksPerColumn: component.blocksPerColumn
  39132. });
  39133. }
  39134. this.numComponents = this.components.length;
  39135. },
  39136. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  39137. var scaleX = this.width / width, scaleY = this.height / height;
  39138. var component, componentScaleX, componentScaleY, blocksPerScanline;
  39139. var x, y, i, j, k;
  39140. var index;
  39141. var offset = 0;
  39142. var output;
  39143. var numComponents = this.components.length;
  39144. var dataLength = width * height * numComponents;
  39145. var data = new Uint8Array(dataLength);
  39146. var xScaleBlockOffset = new Uint32Array(width);
  39147. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  39148. for (i = 0; i < numComponents; i++) {
  39149. component = this.components[i];
  39150. componentScaleX = component.scaleX * scaleX;
  39151. componentScaleY = component.scaleY * scaleY;
  39152. offset = i;
  39153. output = component.output;
  39154. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  39155. // precalculate the xScaleBlockOffset
  39156. for (x = 0; x < width; x++) {
  39157. j = 0 | (x * componentScaleX);
  39158. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  39159. }
  39160. // linearize the blocks of the component
  39161. for (y = 0; y < height; y++) {
  39162. j = 0 | (y * componentScaleY);
  39163. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  39164. for (x = 0; x < width; x++) {
  39165. data[offset] = output[index + xScaleBlockOffset[x]];
  39166. offset += numComponents;
  39167. }
  39168. }
  39169. }
  39170. // decodeTransform contains pairs of multiplier (-256..256) and additive
  39171. var transform = this.decodeTransform;
  39172. if (transform) {
  39173. for (i = 0; i < dataLength;) {
  39174. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  39175. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  39176. }
  39177. }
  39178. }
  39179. return data;
  39180. },
  39181. _isColorConversionNeeded: function isColorConversionNeeded() {
  39182. if (this.adobe && this.adobe.transformCode) {
  39183. // The adobe transform marker overrides any previous setting
  39184. return true;
  39185. } else if (this.numComponents === 3) {
  39186. return true;
  39187. } else {
  39188. return false;
  39189. }
  39190. },
  39191. _convertYccToRgb: function convertYccToRgb(data) {
  39192. var Y, Cb, Cr;
  39193. for (var i = 0, length = data.length; i < length; i += 3) {
  39194. Y = data[i ];
  39195. Cb = data[i + 1];
  39196. Cr = data[i + 2];
  39197. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  39198. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  39199. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  39200. }
  39201. return data;
  39202. },
  39203. _convertYcckToRgb: function convertYcckToRgb(data) {
  39204. var Y, Cb, Cr, k;
  39205. var offset = 0;
  39206. for (var i = 0, length = data.length; i < length; i += 4) {
  39207. Y = data[i];
  39208. Cb = data[i + 1];
  39209. Cr = data[i + 2];
  39210. k = data[i + 3];
  39211. var r = -122.67195406894 +
  39212. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  39213. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  39214. 0.154362151871126) +
  39215. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  39216. 0.00477271405408747 * k + 1.53380253221734) +
  39217. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  39218. 0.48357088451265) +
  39219. k * (-0.000336197177618394 * k + 0.484791561490776);
  39220. var g = 107.268039397724 +
  39221. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  39222. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  39223. 0.176491792462875) +
  39224. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  39225. 0.000770482631801132 * k - 0.151051492775562) +
  39226. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  39227. 0.25802910206845) +
  39228. k * (-0.000318913117588328 * k - 0.213742400323665);
  39229. var b = -20.810012546947 +
  39230. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  39231. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  39232. 0.814272968359295) +
  39233. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  39234. 0.000560833691242812 * k - 0.195152027534049) +
  39235. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  39236. 0.116935020465145) +
  39237. k * (-0.000343531996510555 * k + 0.24165260232407);
  39238. data[offset++] = clamp0to255(r);
  39239. data[offset++] = clamp0to255(g);
  39240. data[offset++] = clamp0to255(b);
  39241. }
  39242. return data;
  39243. },
  39244. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  39245. var Y, Cb, Cr;
  39246. for (var i = 0, length = data.length; i < length; i += 4) {
  39247. Y = data[i];
  39248. Cb = data[i + 1];
  39249. Cr = data[i + 2];
  39250. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  39251. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  39252. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  39253. // K in data[i + 3] is unchanged
  39254. }
  39255. return data;
  39256. },
  39257. _convertCmykToRgb: function convertCmykToRgb(data) {
  39258. var c, m, y, k;
  39259. var offset = 0;
  39260. var min = -255 * 255 * 255;
  39261. var scale = 1 / 255 / 255;
  39262. for (var i = 0, length = data.length; i < length; i += 4) {
  39263. c = data[i];
  39264. m = data[i + 1];
  39265. y = data[i + 2];
  39266. k = data[i + 3];
  39267. var r =
  39268. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39269. 18.82290502165302 * y + 212.25662451639585 * k -
  39270. 72734.4411664936) +
  39271. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  39272. 17.873870861415444 * k - 1401.7366389350734) +
  39273. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39274. 4465.541406466231) -
  39275. k * (21.86122147463605 * k + 48317.86113160301);
  39276. var g =
  39277. c * (8.841041422036149 * c + 60.118027045597366 * m +
  39278. 6.871425592049007 * y + 31.159100130055922 * k -
  39279. 20220.756542821975) +
  39280. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39281. 131.35250912493976 * k - 48691.05921601825) +
  39282. y * (4.444339102852739 * y + 9.8632861493405 * k -
  39283. 6341.191035517494) -
  39284. k * (20.737325471181034 * k + 47890.15695978492);
  39285. var b =
  39286. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39287. 30.89978309703729 * y - 0.23883238689178934 * k -
  39288. 3616.812083916688) +
  39289. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39290. 50.606957656360734 * k - 28620.90484698408) +
  39291. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  39292. 49363.43385999684) -
  39293. k * (22.33816807309886 * k + 45932.16563550634);
  39294. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  39295. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  39296. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  39297. }
  39298. return data;
  39299. },
  39300. getData: function getData(width, height, forceRGBoutput) {
  39301. if (this.numComponents > 4) {
  39302. throw 'Unsupported color mode';
  39303. }
  39304. // type of data: Uint8Array(width * height * numComponents)
  39305. var data = this._getLinearizedBlockData(width, height);
  39306. if (this.numComponents === 3) {
  39307. return this._convertYccToRgb(data);
  39308. } else if (this.numComponents === 4) {
  39309. if (this._isColorConversionNeeded()) {
  39310. if (forceRGBoutput) {
  39311. return this._convertYcckToRgb(data);
  39312. } else {
  39313. return this._convertYcckToCmyk(data);
  39314. }
  39315. } else if (forceRGBoutput) {
  39316. return this._convertCmykToRgb(data);
  39317. }
  39318. }
  39319. return data;
  39320. }
  39321. };
  39322. return constructor;
  39323. })();
  39324. var JpxImage = (function JpxImageClosure() {
  39325. // Table E.1
  39326. var SubbandsGainLog2 = {
  39327. 'LL': 0,
  39328. 'LH': 1,
  39329. 'HL': 1,
  39330. 'HH': 2
  39331. };
  39332. function JpxImage() {
  39333. this.failOnCorruptedImage = false;
  39334. }
  39335. JpxImage.prototype = {
  39336. parse: function JpxImage_parse(data) {
  39337. var head = readUint16(data, 0);
  39338. // No box header, immediate start of codestream (SOC)
  39339. if (head === 0xFF4F) {
  39340. this.parseCodestream(data, 0, data.length);
  39341. return;
  39342. }
  39343. var position = 0, length = data.length;
  39344. while (position < length) {
  39345. var headerSize = 8;
  39346. var lbox = readUint32(data, position);
  39347. var tbox = readUint32(data, position + 4);
  39348. position += headerSize;
  39349. if (lbox === 1) {
  39350. // XLBox: read UInt64 according to spec.
  39351. // JavaScript's int precision of 53 bit should be sufficient here.
  39352. lbox = readUint32(data, position) * 4294967296 +
  39353. readUint32(data, position + 4);
  39354. position += 8;
  39355. headerSize += 8;
  39356. }
  39357. if (lbox === 0) {
  39358. lbox = length - position + headerSize;
  39359. }
  39360. if (lbox < headerSize) {
  39361. throw new Error('JPX Error: Invalid box field size');
  39362. }
  39363. var dataLength = lbox - headerSize;
  39364. var jumpDataLength = true;
  39365. switch (tbox) {
  39366. case 0x6A703268: // 'jp2h'
  39367. jumpDataLength = false; // parsing child boxes
  39368. break;
  39369. case 0x636F6C72: // 'colr'
  39370. // Colorspaces are not used, the CS from the PDF is used.
  39371. var method = data[position];
  39372. var precedence = data[position + 1];
  39373. var approximation = data[position + 2];
  39374. if (method === 1) {
  39375. // enumerated colorspace
  39376. var colorspace = readUint32(data, position + 3);
  39377. switch (colorspace) {
  39378. case 16: // this indicates a sRGB colorspace
  39379. case 17: // this indicates a grayscale colorspace
  39380. case 18: // this indicates a YUV colorspace
  39381. break;
  39382. default:
  39383. warn('Unknown colorspace ' + colorspace);
  39384. break;
  39385. }
  39386. } else if (method === 2) {
  39387. info('ICC profile not supported');
  39388. }
  39389. break;
  39390. case 0x6A703263: // 'jp2c'
  39391. this.parseCodestream(data, position, position + dataLength);
  39392. break;
  39393. case 0x6A502020: // 'jP\024\024'
  39394. if (0x0d0a870a !== readUint32(data, position)) {
  39395. warn('Invalid JP2 signature');
  39396. }
  39397. break;
  39398. // The following header types are valid but currently not used:
  39399. case 0x6A501A1A: // 'jP\032\032'
  39400. case 0x66747970: // 'ftyp'
  39401. case 0x72726571: // 'rreq'
  39402. case 0x72657320: // 'res '
  39403. case 0x69686472: // 'ihdr'
  39404. break;
  39405. default:
  39406. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  39407. (tbox >> 16) & 0xFF,
  39408. (tbox >> 8) & 0xFF,
  39409. tbox & 0xFF);
  39410. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  39411. break;
  39412. }
  39413. if (jumpDataLength) {
  39414. position += dataLength;
  39415. }
  39416. }
  39417. },
  39418. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  39419. var newByte = stream.getByte();
  39420. while (newByte >= 0) {
  39421. var oldByte = newByte;
  39422. newByte = stream.getByte();
  39423. var code = (oldByte << 8) | newByte;
  39424. // Image and tile size (SIZ)
  39425. if (code === 0xFF51) {
  39426. stream.skip(4);
  39427. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  39428. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  39429. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  39430. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  39431. stream.skip(16);
  39432. var Csiz = stream.getUint16(); // Byte 36
  39433. this.width = Xsiz - XOsiz;
  39434. this.height = Ysiz - YOsiz;
  39435. this.componentsCount = Csiz;
  39436. // Results are always returned as Uint8Arrays
  39437. this.bitsPerComponent = 8;
  39438. return;
  39439. }
  39440. }
  39441. throw new Error('JPX Error: No size marker found in JPX stream');
  39442. },
  39443. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  39444. var context = {};
  39445. try {
  39446. var doNotRecover = false;
  39447. var position = start;
  39448. while (position + 1 < end) {
  39449. var code = readUint16(data, position);
  39450. position += 2;
  39451. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  39452. switch (code) {
  39453. case 0xFF4F: // Start of codestream (SOC)
  39454. context.mainHeader = true;
  39455. break;
  39456. case 0xFFD9: // End of codestream (EOC)
  39457. break;
  39458. case 0xFF51: // Image and tile size (SIZ)
  39459. length = readUint16(data, position);
  39460. var siz = {};
  39461. siz.Xsiz = readUint32(data, position + 4);
  39462. siz.Ysiz = readUint32(data, position + 8);
  39463. siz.XOsiz = readUint32(data, position + 12);
  39464. siz.YOsiz = readUint32(data, position + 16);
  39465. siz.XTsiz = readUint32(data, position + 20);
  39466. siz.YTsiz = readUint32(data, position + 24);
  39467. siz.XTOsiz = readUint32(data, position + 28);
  39468. siz.YTOsiz = readUint32(data, position + 32);
  39469. var componentsCount = readUint16(data, position + 36);
  39470. siz.Csiz = componentsCount;
  39471. var components = [];
  39472. j = position + 38;
  39473. for (var i = 0; i < componentsCount; i++) {
  39474. var component = {
  39475. precision: (data[j] & 0x7F) + 1,
  39476. isSigned: !!(data[j] & 0x80),
  39477. XRsiz: data[j + 1],
  39478. YRsiz: data[j + 1]
  39479. };
  39480. calculateComponentDimensions(component, siz);
  39481. components.push(component);
  39482. }
  39483. context.SIZ = siz;
  39484. context.components = components;
  39485. calculateTileGrids(context, components);
  39486. context.QCC = [];
  39487. context.COC = [];
  39488. break;
  39489. case 0xFF5C: // Quantization default (QCD)
  39490. length = readUint16(data, position);
  39491. var qcd = {};
  39492. j = position + 2;
  39493. sqcd = data[j++];
  39494. switch (sqcd & 0x1F) {
  39495. case 0:
  39496. spqcdSize = 8;
  39497. scalarExpounded = true;
  39498. break;
  39499. case 1:
  39500. spqcdSize = 16;
  39501. scalarExpounded = false;
  39502. break;
  39503. case 2:
  39504. spqcdSize = 16;
  39505. scalarExpounded = true;
  39506. break;
  39507. default:
  39508. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39509. }
  39510. qcd.noQuantization = (spqcdSize === 8);
  39511. qcd.scalarExpounded = scalarExpounded;
  39512. qcd.guardBits = sqcd >> 5;
  39513. spqcds = [];
  39514. while (j < length + position) {
  39515. var spqcd = {};
  39516. if (spqcdSize === 8) {
  39517. spqcd.epsilon = data[j++] >> 3;
  39518. spqcd.mu = 0;
  39519. } else {
  39520. spqcd.epsilon = data[j] >> 3;
  39521. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39522. j += 2;
  39523. }
  39524. spqcds.push(spqcd);
  39525. }
  39526. qcd.SPqcds = spqcds;
  39527. if (context.mainHeader) {
  39528. context.QCD = qcd;
  39529. } else {
  39530. context.currentTile.QCD = qcd;
  39531. context.currentTile.QCC = [];
  39532. }
  39533. break;
  39534. case 0xFF5D: // Quantization component (QCC)
  39535. length = readUint16(data, position);
  39536. var qcc = {};
  39537. j = position + 2;
  39538. var cqcc;
  39539. if (context.SIZ.Csiz < 257) {
  39540. cqcc = data[j++];
  39541. } else {
  39542. cqcc = readUint16(data, j);
  39543. j += 2;
  39544. }
  39545. sqcd = data[j++];
  39546. switch (sqcd & 0x1F) {
  39547. case 0:
  39548. spqcdSize = 8;
  39549. scalarExpounded = true;
  39550. break;
  39551. case 1:
  39552. spqcdSize = 16;
  39553. scalarExpounded = false;
  39554. break;
  39555. case 2:
  39556. spqcdSize = 16;
  39557. scalarExpounded = true;
  39558. break;
  39559. default:
  39560. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39561. }
  39562. qcc.noQuantization = (spqcdSize === 8);
  39563. qcc.scalarExpounded = scalarExpounded;
  39564. qcc.guardBits = sqcd >> 5;
  39565. spqcds = [];
  39566. while (j < (length + position)) {
  39567. spqcd = {};
  39568. if (spqcdSize === 8) {
  39569. spqcd.epsilon = data[j++] >> 3;
  39570. spqcd.mu = 0;
  39571. } else {
  39572. spqcd.epsilon = data[j] >> 3;
  39573. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39574. j += 2;
  39575. }
  39576. spqcds.push(spqcd);
  39577. }
  39578. qcc.SPqcds = spqcds;
  39579. if (context.mainHeader) {
  39580. context.QCC[cqcc] = qcc;
  39581. } else {
  39582. context.currentTile.QCC[cqcc] = qcc;
  39583. }
  39584. break;
  39585. case 0xFF52: // Coding style default (COD)
  39586. length = readUint16(data, position);
  39587. var cod = {};
  39588. j = position + 2;
  39589. var scod = data[j++];
  39590. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39591. cod.sopMarkerUsed = !!(scod & 2);
  39592. cod.ephMarkerUsed = !!(scod & 4);
  39593. cod.progressionOrder = data[j++];
  39594. cod.layersCount = readUint16(data, j);
  39595. j += 2;
  39596. cod.multipleComponentTransform = data[j++];
  39597. cod.decompositionLevelsCount = data[j++];
  39598. cod.xcb = (data[j++] & 0xF) + 2;
  39599. cod.ycb = (data[j++] & 0xF) + 2;
  39600. var blockStyle = data[j++];
  39601. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39602. cod.resetContextProbabilities = !!(blockStyle & 2);
  39603. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39604. cod.verticalyStripe = !!(blockStyle & 8);
  39605. cod.predictableTermination = !!(blockStyle & 16);
  39606. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39607. cod.reversibleTransformation = data[j++];
  39608. if (cod.entropyCoderWithCustomPrecincts) {
  39609. var precinctsSizes = [];
  39610. while (j < length + position) {
  39611. var precinctsSize = data[j++];
  39612. precinctsSizes.push({
  39613. PPx: precinctsSize & 0xF,
  39614. PPy: precinctsSize >> 4
  39615. });
  39616. }
  39617. cod.precinctsSizes = precinctsSizes;
  39618. }
  39619. var unsupported = [];
  39620. if (cod.selectiveArithmeticCodingBypass) {
  39621. unsupported.push('selectiveArithmeticCodingBypass');
  39622. }
  39623. if (cod.resetContextProbabilities) {
  39624. unsupported.push('resetContextProbabilities');
  39625. }
  39626. if (cod.terminationOnEachCodingPass) {
  39627. unsupported.push('terminationOnEachCodingPass');
  39628. }
  39629. if (cod.verticalyStripe) {
  39630. unsupported.push('verticalyStripe');
  39631. }
  39632. if (cod.predictableTermination) {
  39633. unsupported.push('predictableTermination');
  39634. }
  39635. if (unsupported.length > 0) {
  39636. doNotRecover = true;
  39637. throw new Error('JPX Error: Unsupported COD options (' +
  39638. unsupported.join(', ') + ')');
  39639. }
  39640. if (context.mainHeader) {
  39641. context.COD = cod;
  39642. } else {
  39643. context.currentTile.COD = cod;
  39644. context.currentTile.COC = [];
  39645. }
  39646. break;
  39647. case 0xFF90: // Start of tile-part (SOT)
  39648. length = readUint16(data, position);
  39649. tile = {};
  39650. tile.index = readUint16(data, position + 2);
  39651. tile.length = readUint32(data, position + 4);
  39652. tile.dataEnd = tile.length + position - 2;
  39653. tile.partIndex = data[position + 8];
  39654. tile.partsCount = data[position + 9];
  39655. context.mainHeader = false;
  39656. if (tile.partIndex === 0) {
  39657. // reset component specific settings
  39658. tile.COD = context.COD;
  39659. tile.COC = context.COC.slice(0); // clone of the global COC
  39660. tile.QCD = context.QCD;
  39661. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39662. }
  39663. context.currentTile = tile;
  39664. break;
  39665. case 0xFF93: // Start of data (SOD)
  39666. tile = context.currentTile;
  39667. if (tile.partIndex === 0) {
  39668. initializeTile(context, tile.index);
  39669. buildPackets(context);
  39670. }
  39671. // moving to the end of the data
  39672. length = tile.dataEnd - position;
  39673. parseTilePackets(context, data, position, length);
  39674. break;
  39675. case 0xFF55: // Tile-part lengths, main header (TLM)
  39676. case 0xFF57: // Packet length, main header (PLM)
  39677. case 0xFF58: // Packet length, tile-part header (PLT)
  39678. case 0xFF64: // Comment (COM)
  39679. length = readUint16(data, position);
  39680. // skipping content
  39681. break;
  39682. case 0xFF53: // Coding style component (COC)
  39683. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39684. 'not implemented');
  39685. default:
  39686. throw new Error('JPX Error: Unknown codestream code: ' +
  39687. code.toString(16));
  39688. }
  39689. position += length;
  39690. }
  39691. } catch (e) {
  39692. if (doNotRecover || this.failOnCorruptedImage) {
  39693. throw e;
  39694. } else {
  39695. warn('Trying to recover from ' + e.message);
  39696. }
  39697. }
  39698. this.tiles = transformComponents(context);
  39699. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39700. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39701. this.componentsCount = context.SIZ.Csiz;
  39702. }
  39703. };
  39704. function calculateComponentDimensions(component, siz) {
  39705. // Section B.2 Component mapping
  39706. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39707. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39708. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39709. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39710. component.width = component.x1 - component.x0;
  39711. component.height = component.y1 - component.y0;
  39712. }
  39713. function calculateTileGrids(context, components) {
  39714. var siz = context.SIZ;
  39715. // Section B.3 Division into tile and tile-components
  39716. var tile, tiles = [];
  39717. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39718. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39719. for (var q = 0; q < numYtiles; q++) {
  39720. for (var p = 0; p < numXtiles; p++) {
  39721. tile = {};
  39722. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39723. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39724. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39725. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39726. tile.width = tile.tx1 - tile.tx0;
  39727. tile.height = tile.ty1 - tile.ty0;
  39728. tile.components = [];
  39729. tiles.push(tile);
  39730. }
  39731. }
  39732. context.tiles = tiles;
  39733. var componentsCount = siz.Csiz;
  39734. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39735. var component = components[i];
  39736. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39737. var tileComponent = {};
  39738. tile = tiles[j];
  39739. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39740. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39741. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39742. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39743. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39744. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39745. tile.components[i] = tileComponent;
  39746. }
  39747. }
  39748. }
  39749. function getBlocksDimensions(context, component, r) {
  39750. var codOrCoc = component.codingStyleParameters;
  39751. var result = {};
  39752. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39753. result.PPx = 15;
  39754. result.PPy = 15;
  39755. } else {
  39756. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39757. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39758. }
  39759. // calculate codeblock size as described in section B.7
  39760. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39761. Math.min(codOrCoc.xcb, result.PPx));
  39762. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39763. Math.min(codOrCoc.ycb, result.PPy));
  39764. return result;
  39765. }
  39766. function buildPrecincts(context, resolution, dimensions) {
  39767. // Section B.6 Division resolution to precincts
  39768. var precinctWidth = 1 << dimensions.PPx;
  39769. var precinctHeight = 1 << dimensions.PPy;
  39770. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39771. // to precincts. Precinct partition divides a resolution according to width
  39772. // and height parameters. The subband that belongs to the resolution level
  39773. // has a different size than the level, unless it is the zero resolution.
  39774. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39775. // The precinct partitioning for a particular subband is derived from a
  39776. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39777. // resolution level)... The LL band associated with each resolution level is
  39778. // divided into precincts... Each of the resulting precinct regions is then
  39779. // mapped into its child subbands (if any) at the next lower resolution
  39780. // level. This is accomplished by using the coordinate transformation
  39781. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39782. // coordinates of a point in the LL band and child subband, respectively.
  39783. var isZeroRes = resolution.resLevel === 0;
  39784. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39785. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39786. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39787. Math.ceil(resolution.trx1 / precinctWidth) -
  39788. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39789. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39790. Math.ceil(resolution.try1 / precinctHeight) -
  39791. Math.floor(resolution.try0 / precinctHeight) : 0);
  39792. var numprecincts = numprecinctswide * numprecinctshigh;
  39793. resolution.precinctParameters = {
  39794. precinctWidth: precinctWidth,
  39795. precinctHeight: precinctHeight,
  39796. numprecinctswide: numprecinctswide,
  39797. numprecinctshigh: numprecinctshigh,
  39798. numprecincts: numprecincts,
  39799. precinctWidthInSubband: precinctWidthInSubband,
  39800. precinctHeightInSubband: precinctHeightInSubband
  39801. };
  39802. }
  39803. function buildCodeblocks(context, subband, dimensions) {
  39804. // Section B.7 Division sub-band into code-blocks
  39805. var xcb_ = dimensions.xcb_;
  39806. var ycb_ = dimensions.ycb_;
  39807. var codeblockWidth = 1 << xcb_;
  39808. var codeblockHeight = 1 << ycb_;
  39809. var cbx0 = subband.tbx0 >> xcb_;
  39810. var cby0 = subband.tby0 >> ycb_;
  39811. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39812. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39813. var precinctParameters = subband.resolution.precinctParameters;
  39814. var codeblocks = [];
  39815. var precincts = [];
  39816. var i, j, codeblock, precinctNumber;
  39817. for (j = cby0; j < cby1; j++) {
  39818. for (i = cbx0; i < cbx1; i++) {
  39819. codeblock = {
  39820. cbx: i,
  39821. cby: j,
  39822. tbx0: codeblockWidth * i,
  39823. tby0: codeblockHeight * j,
  39824. tbx1: codeblockWidth * (i + 1),
  39825. tby1: codeblockHeight * (j + 1)
  39826. };
  39827. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39828. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39829. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39830. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39831. // Calculate precinct number for this codeblock, codeblock position
  39832. // should be relative to its subband, use actual dimension and position
  39833. // See comment about codeblock group width and height
  39834. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39835. precinctParameters.precinctWidthInSubband);
  39836. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39837. precinctParameters.precinctHeightInSubband);
  39838. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39839. codeblock.precinctNumber = precinctNumber;
  39840. codeblock.subbandType = subband.type;
  39841. codeblock.Lblock = 3;
  39842. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39843. codeblock.tby1_ <= codeblock.tby0_) {
  39844. continue;
  39845. }
  39846. codeblocks.push(codeblock);
  39847. // building precinct for the sub-band
  39848. var precinct = precincts[precinctNumber];
  39849. if (precinct !== undefined) {
  39850. if (i < precinct.cbxMin) {
  39851. precinct.cbxMin = i;
  39852. } else if (i > precinct.cbxMax) {
  39853. precinct.cbxMax = i;
  39854. }
  39855. if (j < precinct.cbyMin) {
  39856. precinct.cbxMin = j;
  39857. } else if (j > precinct.cbyMax) {
  39858. precinct.cbyMax = j;
  39859. }
  39860. } else {
  39861. precincts[precinctNumber] = precinct = {
  39862. cbxMin: i,
  39863. cbyMin: j,
  39864. cbxMax: i,
  39865. cbyMax: j
  39866. };
  39867. }
  39868. codeblock.precinct = precinct;
  39869. }
  39870. }
  39871. subband.codeblockParameters = {
  39872. codeblockWidth: xcb_,
  39873. codeblockHeight: ycb_,
  39874. numcodeblockwide: cbx1 - cbx0 + 1,
  39875. numcodeblockhigh: cby1 - cby0 + 1
  39876. };
  39877. subband.codeblocks = codeblocks;
  39878. subband.precincts = precincts;
  39879. }
  39880. function createPacket(resolution, precinctNumber, layerNumber) {
  39881. var precinctCodeblocks = [];
  39882. // Section B.10.8 Order of info in packet
  39883. var subbands = resolution.subbands;
  39884. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39885. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39886. var subband = subbands[i];
  39887. var codeblocks = subband.codeblocks;
  39888. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39889. var codeblock = codeblocks[j];
  39890. if (codeblock.precinctNumber !== precinctNumber) {
  39891. continue;
  39892. }
  39893. precinctCodeblocks.push(codeblock);
  39894. }
  39895. }
  39896. return {
  39897. layerNumber: layerNumber,
  39898. codeblocks: precinctCodeblocks
  39899. };
  39900. }
  39901. function LayerResolutionComponentPositionIterator(context) {
  39902. var siz = context.SIZ;
  39903. var tileIndex = context.currentTile.index;
  39904. var tile = context.tiles[tileIndex];
  39905. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39906. var componentsCount = siz.Csiz;
  39907. var maxDecompositionLevelsCount = 0;
  39908. for (var q = 0; q < componentsCount; q++) {
  39909. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39910. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39911. }
  39912. var l = 0, r = 0, i = 0, k = 0;
  39913. this.nextPacket = function JpxImage_nextPacket() {
  39914. // Section B.12.1.1 Layer-resolution-component-position
  39915. for (; l < layersCount; l++) {
  39916. for (; r <= maxDecompositionLevelsCount; r++) {
  39917. for (; i < componentsCount; i++) {
  39918. var component = tile.components[i];
  39919. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39920. continue;
  39921. }
  39922. var resolution = component.resolutions[r];
  39923. var numprecincts = resolution.precinctParameters.numprecincts;
  39924. for (; k < numprecincts;) {
  39925. var packet = createPacket(resolution, k, l);
  39926. k++;
  39927. return packet;
  39928. }
  39929. k = 0;
  39930. }
  39931. i = 0;
  39932. }
  39933. r = 0;
  39934. }
  39935. throw new Error('JPX Error: Out of packets');
  39936. };
  39937. }
  39938. function ResolutionLayerComponentPositionIterator(context) {
  39939. var siz = context.SIZ;
  39940. var tileIndex = context.currentTile.index;
  39941. var tile = context.tiles[tileIndex];
  39942. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39943. var componentsCount = siz.Csiz;
  39944. var maxDecompositionLevelsCount = 0;
  39945. for (var q = 0; q < componentsCount; q++) {
  39946. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39947. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39948. }
  39949. var r = 0, l = 0, i = 0, k = 0;
  39950. this.nextPacket = function JpxImage_nextPacket() {
  39951. // Section B.12.1.2 Resolution-layer-component-position
  39952. for (; r <= maxDecompositionLevelsCount; r++) {
  39953. for (; l < layersCount; l++) {
  39954. for (; i < componentsCount; i++) {
  39955. var component = tile.components[i];
  39956. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39957. continue;
  39958. }
  39959. var resolution = component.resolutions[r];
  39960. var numprecincts = resolution.precinctParameters.numprecincts;
  39961. for (; k < numprecincts;) {
  39962. var packet = createPacket(resolution, k, l);
  39963. k++;
  39964. return packet;
  39965. }
  39966. k = 0;
  39967. }
  39968. i = 0;
  39969. }
  39970. l = 0;
  39971. }
  39972. throw new Error('JPX Error: Out of packets');
  39973. };
  39974. }
  39975. function ResolutionPositionComponentLayerIterator(context) {
  39976. var siz = context.SIZ;
  39977. var tileIndex = context.currentTile.index;
  39978. var tile = context.tiles[tileIndex];
  39979. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39980. var componentsCount = siz.Csiz;
  39981. var l, r, c, p;
  39982. var maxDecompositionLevelsCount = 0;
  39983. for (c = 0; c < componentsCount; c++) {
  39984. var component = tile.components[c];
  39985. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39986. component.codingStyleParameters.decompositionLevelsCount);
  39987. }
  39988. var maxNumPrecinctsInLevel = new Int32Array(
  39989. maxDecompositionLevelsCount + 1);
  39990. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39991. var maxNumPrecincts = 0;
  39992. for (c = 0; c < componentsCount; ++c) {
  39993. var resolutions = tile.components[c].resolutions;
  39994. if (r < resolutions.length) {
  39995. maxNumPrecincts = Math.max(maxNumPrecincts,
  39996. resolutions[r].precinctParameters.numprecincts);
  39997. }
  39998. }
  39999. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  40000. }
  40001. l = 0;
  40002. r = 0;
  40003. c = 0;
  40004. p = 0;
  40005. this.nextPacket = function JpxImage_nextPacket() {
  40006. // Section B.12.1.3 Resolution-position-component-layer
  40007. for (; r <= maxDecompositionLevelsCount; r++) {
  40008. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  40009. for (; c < componentsCount; c++) {
  40010. var component = tile.components[c];
  40011. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  40012. continue;
  40013. }
  40014. var resolution = component.resolutions[r];
  40015. var numprecincts = resolution.precinctParameters.numprecincts;
  40016. if (p >= numprecincts) {
  40017. continue;
  40018. }
  40019. for (; l < layersCount;) {
  40020. var packet = createPacket(resolution, p, l);
  40021. l++;
  40022. return packet;
  40023. }
  40024. l = 0;
  40025. }
  40026. c = 0;
  40027. }
  40028. p = 0;
  40029. }
  40030. throw new Error('JPX Error: Out of packets');
  40031. };
  40032. }
  40033. function PositionComponentResolutionLayerIterator(context) {
  40034. var siz = context.SIZ;
  40035. var tileIndex = context.currentTile.index;
  40036. var tile = context.tiles[tileIndex];
  40037. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40038. var componentsCount = siz.Csiz;
  40039. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  40040. var precinctsIterationSizes = precinctsSizes;
  40041. var l = 0, r = 0, c = 0, px = 0, py = 0;
  40042. this.nextPacket = function JpxImage_nextPacket() {
  40043. // Section B.12.1.4 Position-component-resolution-layer
  40044. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  40045. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  40046. for (; c < componentsCount; c++) {
  40047. var component = tile.components[c];
  40048. var decompositionLevelsCount =
  40049. component.codingStyleParameters.decompositionLevelsCount;
  40050. for (; r <= decompositionLevelsCount; r++) {
  40051. var resolution = component.resolutions[r];
  40052. var sizeInImageScale =
  40053. precinctsSizes.components[c].resolutions[r];
  40054. var k = getPrecinctIndexIfExist(
  40055. px,
  40056. py,
  40057. sizeInImageScale,
  40058. precinctsIterationSizes,
  40059. resolution);
  40060. if (k === null) {
  40061. continue;
  40062. }
  40063. for (; l < layersCount;) {
  40064. var packet = createPacket(resolution, k, l);
  40065. l++;
  40066. return packet;
  40067. }
  40068. l = 0;
  40069. }
  40070. r = 0;
  40071. }
  40072. c = 0;
  40073. }
  40074. px = 0;
  40075. }
  40076. throw new Error('JPX Error: Out of packets');
  40077. };
  40078. }
  40079. function ComponentPositionResolutionLayerIterator(context) {
  40080. var siz = context.SIZ;
  40081. var tileIndex = context.currentTile.index;
  40082. var tile = context.tiles[tileIndex];
  40083. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40084. var componentsCount = siz.Csiz;
  40085. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  40086. var l = 0, r = 0, c = 0, px = 0, py = 0;
  40087. this.nextPacket = function JpxImage_nextPacket() {
  40088. // Section B.12.1.5 Component-position-resolution-layer
  40089. for (; c < componentsCount; ++c) {
  40090. var component = tile.components[c];
  40091. var precinctsIterationSizes = precinctsSizes.components[c];
  40092. var decompositionLevelsCount =
  40093. component.codingStyleParameters.decompositionLevelsCount;
  40094. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  40095. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  40096. for (; r <= decompositionLevelsCount; r++) {
  40097. var resolution = component.resolutions[r];
  40098. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  40099. var k = getPrecinctIndexIfExist(
  40100. px,
  40101. py,
  40102. sizeInImageScale,
  40103. precinctsIterationSizes,
  40104. resolution);
  40105. if (k === null) {
  40106. continue;
  40107. }
  40108. for (; l < layersCount;) {
  40109. var packet = createPacket(resolution, k, l);
  40110. l++;
  40111. return packet;
  40112. }
  40113. l = 0;
  40114. }
  40115. r = 0;
  40116. }
  40117. px = 0;
  40118. }
  40119. py = 0;
  40120. }
  40121. throw new Error('JPX Error: Out of packets');
  40122. };
  40123. }
  40124. function getPrecinctIndexIfExist(
  40125. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  40126. var posX = pxIndex * precinctIterationSizes.minWidth;
  40127. var posY = pyIndex * precinctIterationSizes.minHeight;
  40128. if (posX % sizeInImageScale.width !== 0 ||
  40129. posY % sizeInImageScale.height !== 0) {
  40130. return null;
  40131. }
  40132. var startPrecinctRowIndex =
  40133. (posY / sizeInImageScale.width) *
  40134. resolution.precinctParameters.numprecinctswide;
  40135. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  40136. }
  40137. function getPrecinctSizesInImageScale(tile) {
  40138. var componentsCount = tile.components.length;
  40139. var minWidth = Number.MAX_VALUE;
  40140. var minHeight = Number.MAX_VALUE;
  40141. var maxNumWide = 0;
  40142. var maxNumHigh = 0;
  40143. var sizePerComponent = new Array(componentsCount);
  40144. for (var c = 0; c < componentsCount; c++) {
  40145. var component = tile.components[c];
  40146. var decompositionLevelsCount =
  40147. component.codingStyleParameters.decompositionLevelsCount;
  40148. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  40149. var minWidthCurrentComponent = Number.MAX_VALUE;
  40150. var minHeightCurrentComponent = Number.MAX_VALUE;
  40151. var maxNumWideCurrentComponent = 0;
  40152. var maxNumHighCurrentComponent = 0;
  40153. var scale = 1;
  40154. for (var r = decompositionLevelsCount; r >= 0; --r) {
  40155. var resolution = component.resolutions[r];
  40156. var widthCurrentResolution =
  40157. scale * resolution.precinctParameters.precinctWidth;
  40158. var heightCurrentResolution =
  40159. scale * resolution.precinctParameters.precinctHeight;
  40160. minWidthCurrentComponent = Math.min(
  40161. minWidthCurrentComponent,
  40162. widthCurrentResolution);
  40163. minHeightCurrentComponent = Math.min(
  40164. minHeightCurrentComponent,
  40165. heightCurrentResolution);
  40166. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  40167. resolution.precinctParameters.numprecinctswide);
  40168. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  40169. resolution.precinctParameters.numprecinctshigh);
  40170. sizePerResolution[r] = {
  40171. width: widthCurrentResolution,
  40172. height: heightCurrentResolution
  40173. };
  40174. scale <<= 1;
  40175. }
  40176. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  40177. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  40178. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  40179. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  40180. sizePerComponent[c] = {
  40181. resolutions: sizePerResolution,
  40182. minWidth: minWidthCurrentComponent,
  40183. minHeight: minHeightCurrentComponent,
  40184. maxNumWide: maxNumWideCurrentComponent,
  40185. maxNumHigh: maxNumHighCurrentComponent
  40186. };
  40187. }
  40188. return {
  40189. components: sizePerComponent,
  40190. minWidth: minWidth,
  40191. minHeight: minHeight,
  40192. maxNumWide: maxNumWide,
  40193. maxNumHigh: maxNumHigh
  40194. };
  40195. }
  40196. function buildPackets(context) {
  40197. var siz = context.SIZ;
  40198. var tileIndex = context.currentTile.index;
  40199. var tile = context.tiles[tileIndex];
  40200. var componentsCount = siz.Csiz;
  40201. // Creating resolutions and sub-bands for each component
  40202. for (var c = 0; c < componentsCount; c++) {
  40203. var component = tile.components[c];
  40204. var decompositionLevelsCount =
  40205. component.codingStyleParameters.decompositionLevelsCount;
  40206. // Section B.5 Resolution levels and sub-bands
  40207. var resolutions = [];
  40208. var subbands = [];
  40209. for (var r = 0; r <= decompositionLevelsCount; r++) {
  40210. var blocksDimensions = getBlocksDimensions(context, component, r);
  40211. var resolution = {};
  40212. var scale = 1 << (decompositionLevelsCount - r);
  40213. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  40214. resolution.try0 = Math.ceil(component.tcy0 / scale);
  40215. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  40216. resolution.try1 = Math.ceil(component.tcy1 / scale);
  40217. resolution.resLevel = r;
  40218. buildPrecincts(context, resolution, blocksDimensions);
  40219. resolutions.push(resolution);
  40220. var subband;
  40221. if (r === 0) {
  40222. // one sub-band (LL) with last decomposition
  40223. subband = {};
  40224. subband.type = 'LL';
  40225. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  40226. subband.tby0 = Math.ceil(component.tcy0 / scale);
  40227. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  40228. subband.tby1 = Math.ceil(component.tcy1 / scale);
  40229. subband.resolution = resolution;
  40230. buildCodeblocks(context, subband, blocksDimensions);
  40231. subbands.push(subband);
  40232. resolution.subbands = [subband];
  40233. } else {
  40234. var bscale = 1 << (decompositionLevelsCount - r + 1);
  40235. var resolutionSubbands = [];
  40236. // three sub-bands (HL, LH and HH) with rest of decompositions
  40237. subband = {};
  40238. subband.type = 'HL';
  40239. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  40240. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  40241. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  40242. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  40243. subband.resolution = resolution;
  40244. buildCodeblocks(context, subband, blocksDimensions);
  40245. subbands.push(subband);
  40246. resolutionSubbands.push(subband);
  40247. subband = {};
  40248. subband.type = 'LH';
  40249. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  40250. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  40251. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  40252. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  40253. subband.resolution = resolution;
  40254. buildCodeblocks(context, subband, blocksDimensions);
  40255. subbands.push(subband);
  40256. resolutionSubbands.push(subband);
  40257. subband = {};
  40258. subband.type = 'HH';
  40259. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  40260. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  40261. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  40262. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  40263. subband.resolution = resolution;
  40264. buildCodeblocks(context, subband, blocksDimensions);
  40265. subbands.push(subband);
  40266. resolutionSubbands.push(subband);
  40267. resolution.subbands = resolutionSubbands;
  40268. }
  40269. }
  40270. component.resolutions = resolutions;
  40271. component.subbands = subbands;
  40272. }
  40273. // Generate the packets sequence
  40274. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  40275. switch (progressionOrder) {
  40276. case 0:
  40277. tile.packetsIterator =
  40278. new LayerResolutionComponentPositionIterator(context);
  40279. break;
  40280. case 1:
  40281. tile.packetsIterator =
  40282. new ResolutionLayerComponentPositionIterator(context);
  40283. break;
  40284. case 2:
  40285. tile.packetsIterator =
  40286. new ResolutionPositionComponentLayerIterator(context);
  40287. break;
  40288. case 3:
  40289. tile.packetsIterator =
  40290. new PositionComponentResolutionLayerIterator(context);
  40291. break;
  40292. case 4:
  40293. tile.packetsIterator =
  40294. new ComponentPositionResolutionLayerIterator(context);
  40295. break;
  40296. default:
  40297. throw new Error('JPX Error: Unsupported progression order ' +
  40298. progressionOrder);
  40299. }
  40300. }
  40301. function parseTilePackets(context, data, offset, dataLength) {
  40302. var position = 0;
  40303. var buffer, bufferSize = 0, skipNextBit = false;
  40304. function readBits(count) {
  40305. while (bufferSize < count) {
  40306. var b = data[offset + position];
  40307. position++;
  40308. if (skipNextBit) {
  40309. buffer = (buffer << 7) | b;
  40310. bufferSize += 7;
  40311. skipNextBit = false;
  40312. } else {
  40313. buffer = (buffer << 8) | b;
  40314. bufferSize += 8;
  40315. }
  40316. if (b === 0xFF) {
  40317. skipNextBit = true;
  40318. }
  40319. }
  40320. bufferSize -= count;
  40321. return (buffer >>> bufferSize) & ((1 << count) - 1);
  40322. }
  40323. function skipMarkerIfEqual(value) {
  40324. if (data[offset + position - 1] === 0xFF &&
  40325. data[offset + position] === value) {
  40326. skipBytes(1);
  40327. return true;
  40328. } else if (data[offset + position] === 0xFF &&
  40329. data[offset + position + 1] === value) {
  40330. skipBytes(2);
  40331. return true;
  40332. }
  40333. return false;
  40334. }
  40335. function skipBytes(count) {
  40336. position += count;
  40337. }
  40338. function alignToByte() {
  40339. bufferSize = 0;
  40340. if (skipNextBit) {
  40341. position++;
  40342. skipNextBit = false;
  40343. }
  40344. }
  40345. function readCodingpasses() {
  40346. if (readBits(1) === 0) {
  40347. return 1;
  40348. }
  40349. if (readBits(1) === 0) {
  40350. return 2;
  40351. }
  40352. var value = readBits(2);
  40353. if (value < 3) {
  40354. return value + 3;
  40355. }
  40356. value = readBits(5);
  40357. if (value < 31) {
  40358. return value + 6;
  40359. }
  40360. value = readBits(7);
  40361. return value + 37;
  40362. }
  40363. var tileIndex = context.currentTile.index;
  40364. var tile = context.tiles[tileIndex];
  40365. var sopMarkerUsed = context.COD.sopMarkerUsed;
  40366. var ephMarkerUsed = context.COD.ephMarkerUsed;
  40367. var packetsIterator = tile.packetsIterator;
  40368. while (position < dataLength) {
  40369. alignToByte();
  40370. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  40371. // Skip also marker segment length and packet sequence ID
  40372. skipBytes(4);
  40373. }
  40374. var packet = packetsIterator.nextPacket();
  40375. if (!readBits(1)) {
  40376. continue;
  40377. }
  40378. var layerNumber = packet.layerNumber;
  40379. var queue = [], codeblock;
  40380. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  40381. codeblock = packet.codeblocks[i];
  40382. var precinct = codeblock.precinct;
  40383. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  40384. var codeblockRow = codeblock.cby - precinct.cbyMin;
  40385. var codeblockIncluded = false;
  40386. var firstTimeInclusion = false;
  40387. var valueReady;
  40388. if (codeblock['included'] !== undefined) {
  40389. codeblockIncluded = !!readBits(1);
  40390. } else {
  40391. // reading inclusion tree
  40392. precinct = codeblock.precinct;
  40393. var inclusionTree, zeroBitPlanesTree;
  40394. if (precinct['inclusionTree'] !== undefined) {
  40395. inclusionTree = precinct.inclusionTree;
  40396. } else {
  40397. // building inclusion and zero bit-planes trees
  40398. var width = precinct.cbxMax - precinct.cbxMin + 1;
  40399. var height = precinct.cbyMax - precinct.cbyMin + 1;
  40400. inclusionTree = new InclusionTree(width, height, layerNumber);
  40401. zeroBitPlanesTree = new TagTree(width, height);
  40402. precinct.inclusionTree = inclusionTree;
  40403. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  40404. }
  40405. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  40406. while (true) {
  40407. if (readBits(1)) {
  40408. valueReady = !inclusionTree.nextLevel();
  40409. if (valueReady) {
  40410. codeblock.included = true;
  40411. codeblockIncluded = firstTimeInclusion = true;
  40412. break;
  40413. }
  40414. } else {
  40415. inclusionTree.incrementValue(layerNumber);
  40416. break;
  40417. }
  40418. }
  40419. }
  40420. }
  40421. if (!codeblockIncluded) {
  40422. continue;
  40423. }
  40424. if (firstTimeInclusion) {
  40425. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  40426. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  40427. while (true) {
  40428. if (readBits(1)) {
  40429. valueReady = !zeroBitPlanesTree.nextLevel();
  40430. if (valueReady) {
  40431. break;
  40432. }
  40433. } else {
  40434. zeroBitPlanesTree.incrementValue();
  40435. }
  40436. }
  40437. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  40438. }
  40439. var codingpasses = readCodingpasses();
  40440. while (readBits(1)) {
  40441. codeblock.Lblock++;
  40442. }
  40443. var codingpassesLog2 = log2(codingpasses);
  40444. // rounding down log2
  40445. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  40446. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  40447. var codedDataLength = readBits(bits);
  40448. queue.push({
  40449. codeblock: codeblock,
  40450. codingpasses: codingpasses,
  40451. dataLength: codedDataLength
  40452. });
  40453. }
  40454. alignToByte();
  40455. if (ephMarkerUsed) {
  40456. skipMarkerIfEqual(0x92);
  40457. }
  40458. while (queue.length > 0) {
  40459. var packetItem = queue.shift();
  40460. codeblock = packetItem.codeblock;
  40461. if (codeblock['data'] === undefined) {
  40462. codeblock.data = [];
  40463. }
  40464. codeblock.data.push({
  40465. data: data,
  40466. start: offset + position,
  40467. end: offset + position + packetItem.dataLength,
  40468. codingpasses: packetItem.codingpasses
  40469. });
  40470. position += packetItem.dataLength;
  40471. }
  40472. }
  40473. return position;
  40474. }
  40475. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  40476. delta, mb, reversible, segmentationSymbolUsed) {
  40477. var x0 = subband.tbx0;
  40478. var y0 = subband.tby0;
  40479. var width = subband.tbx1 - subband.tbx0;
  40480. var codeblocks = subband.codeblocks;
  40481. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  40482. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  40483. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  40484. var codeblock = codeblocks[i];
  40485. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  40486. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  40487. if (blockWidth === 0 || blockHeight === 0) {
  40488. continue;
  40489. }
  40490. if (codeblock['data'] === undefined) {
  40491. continue;
  40492. }
  40493. var bitModel, currentCodingpassType;
  40494. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  40495. codeblock.zeroBitPlanes, mb);
  40496. currentCodingpassType = 2; // first bit plane starts from cleanup
  40497. // collect data
  40498. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  40499. var j, jj, dataItem;
  40500. for (j = 0, jj = data.length; j < jj; j++) {
  40501. dataItem = data[j];
  40502. totalLength += dataItem.end - dataItem.start;
  40503. codingpasses += dataItem.codingpasses;
  40504. }
  40505. var encodedData = new Uint8Array(totalLength);
  40506. var position = 0;
  40507. for (j = 0, jj = data.length; j < jj; j++) {
  40508. dataItem = data[j];
  40509. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  40510. encodedData.set(chunk, position);
  40511. position += chunk.length;
  40512. }
  40513. // decoding the item
  40514. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  40515. bitModel.setDecoder(decoder);
  40516. for (j = 0; j < codingpasses; j++) {
  40517. switch (currentCodingpassType) {
  40518. case 0:
  40519. bitModel.runSignificancePropogationPass();
  40520. break;
  40521. case 1:
  40522. bitModel.runMagnitudeRefinementPass();
  40523. break;
  40524. case 2:
  40525. bitModel.runCleanupPass();
  40526. if (segmentationSymbolUsed) {
  40527. bitModel.checkSegmentationSymbol();
  40528. }
  40529. break;
  40530. }
  40531. currentCodingpassType = (currentCodingpassType + 1) % 3;
  40532. }
  40533. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  40534. var sign = bitModel.coefficentsSign;
  40535. var magnitude = bitModel.coefficentsMagnitude;
  40536. var bitsDecoded = bitModel.bitsDecoded;
  40537. var magnitudeCorrection = reversible ? 0 : 0.5;
  40538. var k, n, nb;
  40539. position = 0;
  40540. // Do the interleaving of Section F.3.3 here, so we do not need
  40541. // to copy later. LL level is not interleaved, just copied.
  40542. var interleave = (subband.type !== 'LL');
  40543. for (j = 0; j < blockHeight; j++) {
  40544. var row = (offset / width) | 0; // row in the non-interleaved subband
  40545. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  40546. for (k = 0; k < blockWidth; k++) {
  40547. n = magnitude[position];
  40548. if (n !== 0) {
  40549. n = (n + magnitudeCorrection) * delta;
  40550. if (sign[position] !== 0) {
  40551. n = -n;
  40552. }
  40553. nb = bitsDecoded[position];
  40554. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  40555. if (reversible && (nb >= mb)) {
  40556. coefficients[pos] = n;
  40557. } else {
  40558. coefficients[pos] = n * (1 << (mb - nb));
  40559. }
  40560. }
  40561. offset++;
  40562. position++;
  40563. }
  40564. offset += width - blockWidth;
  40565. }
  40566. }
  40567. }
  40568. function transformTile(context, tile, c) {
  40569. var component = tile.components[c];
  40570. var codingStyleParameters = component.codingStyleParameters;
  40571. var quantizationParameters = component.quantizationParameters;
  40572. var decompositionLevelsCount =
  40573. codingStyleParameters.decompositionLevelsCount;
  40574. var spqcds = quantizationParameters.SPqcds;
  40575. var scalarExpounded = quantizationParameters.scalarExpounded;
  40576. var guardBits = quantizationParameters.guardBits;
  40577. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40578. var precision = context.components[c].precision;
  40579. var reversible = codingStyleParameters.reversibleTransformation;
  40580. var transform = (reversible ? new ReversibleTransform() :
  40581. new IrreversibleTransform());
  40582. var subbandCoefficients = [];
  40583. var b = 0;
  40584. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40585. var resolution = component.resolutions[i];
  40586. var width = resolution.trx1 - resolution.trx0;
  40587. var height = resolution.try1 - resolution.try0;
  40588. // Allocate space for the whole sublevel.
  40589. var coefficients = new Float32Array(width * height);
  40590. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40591. var mu, epsilon;
  40592. if (!scalarExpounded) {
  40593. // formula E-5
  40594. mu = spqcds[0].mu;
  40595. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40596. } else {
  40597. mu = spqcds[b].mu;
  40598. epsilon = spqcds[b].epsilon;
  40599. b++;
  40600. }
  40601. var subband = resolution.subbands[j];
  40602. var gainLog2 = SubbandsGainLog2[subband.type];
  40603. // calulate quantization coefficient (Section E.1.1.1)
  40604. var delta = (reversible ? 1 :
  40605. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40606. var mb = (guardBits + epsilon - 1);
  40607. // In the first resolution level, copyCoefficients will fill the
  40608. // whole array with coefficients. In the succeding passes,
  40609. // copyCoefficients will consecutively fill in the values that belong
  40610. // to the interleaved positions of the HL, LH, and HH coefficients.
  40611. // The LL coefficients will then be interleaved in Transform.iterate().
  40612. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40613. reversible, segmentationSymbolUsed);
  40614. }
  40615. subbandCoefficients.push({
  40616. width: width,
  40617. height: height,
  40618. items: coefficients
  40619. });
  40620. }
  40621. var result = transform.calculate(subbandCoefficients,
  40622. component.tcx0, component.tcy0);
  40623. return {
  40624. left: component.tcx0,
  40625. top: component.tcy0,
  40626. width: result.width,
  40627. height: result.height,
  40628. items: result.items
  40629. };
  40630. }
  40631. function transformComponents(context) {
  40632. var siz = context.SIZ;
  40633. var components = context.components;
  40634. var componentsCount = siz.Csiz;
  40635. var resultImages = [];
  40636. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40637. var tile = context.tiles[i];
  40638. var transformedTiles = [];
  40639. var c;
  40640. for (c = 0; c < componentsCount; c++) {
  40641. transformedTiles[c] = transformTile(context, tile, c);
  40642. }
  40643. var tile0 = transformedTiles[0];
  40644. var out = new Uint8Array(tile0.items.length * componentsCount);
  40645. var result = {
  40646. left: tile0.left,
  40647. top: tile0.top,
  40648. width: tile0.width,
  40649. height: tile0.height,
  40650. items: out
  40651. };
  40652. // Section G.2.2 Inverse multi component transform
  40653. var shift, offset, max, min, maxK;
  40654. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40655. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40656. var fourComponents = componentsCount === 4;
  40657. var y0items = transformedTiles[0].items;
  40658. var y1items = transformedTiles[1].items;
  40659. var y2items = transformedTiles[2].items;
  40660. var y3items = fourComponents ? transformedTiles[3].items : null;
  40661. // HACK: The multiple component transform formulas below assume that
  40662. // all components have the same precision. With this in mind, we
  40663. // compute shift and offset only once.
  40664. shift = components[0].precision - 8;
  40665. offset = (128 << shift) + 0.5;
  40666. max = 255 * (1 << shift);
  40667. maxK = max * 0.5;
  40668. min = -maxK;
  40669. var component0 = tile.components[0];
  40670. var alpha01 = componentsCount - 3;
  40671. jj = y0items.length;
  40672. if (!component0.codingStyleParameters.reversibleTransformation) {
  40673. // inverse irreversible multiple component transform
  40674. for (j = 0; j < jj; j++, pos += alpha01) {
  40675. y0 = y0items[j] + offset;
  40676. y1 = y1items[j];
  40677. y2 = y2items[j];
  40678. r = y0 + 1.402 * y2;
  40679. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40680. b = y0 + 1.772 * y1;
  40681. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40682. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40683. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40684. }
  40685. } else {
  40686. // inverse reversible multiple component transform
  40687. for (j = 0; j < jj; j++, pos += alpha01) {
  40688. y0 = y0items[j] + offset;
  40689. y1 = y1items[j];
  40690. y2 = y2items[j];
  40691. g = y0 - ((y2 + y1) >> 2);
  40692. r = g + y2;
  40693. b = g + y1;
  40694. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40695. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40696. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40697. }
  40698. }
  40699. if (fourComponents) {
  40700. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40701. k = y3items[j];
  40702. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40703. }
  40704. }
  40705. } else { // no multi-component transform
  40706. for (c = 0; c < componentsCount; c++) {
  40707. var items = transformedTiles[c].items;
  40708. shift = components[c].precision - 8;
  40709. offset = (128 << shift) + 0.5;
  40710. max = (127.5 * (1 << shift));
  40711. min = -max;
  40712. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40713. val = items[j];
  40714. out[pos] = val <= min ? 0 :
  40715. val >= max ? 255 : (val + offset) >> shift;
  40716. pos += componentsCount;
  40717. }
  40718. }
  40719. }
  40720. resultImages.push(result);
  40721. }
  40722. return resultImages;
  40723. }
  40724. function initializeTile(context, tileIndex) {
  40725. var siz = context.SIZ;
  40726. var componentsCount = siz.Csiz;
  40727. var tile = context.tiles[tileIndex];
  40728. for (var c = 0; c < componentsCount; c++) {
  40729. var component = tile.components[c];
  40730. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40731. context.currentTile.QCC[c] : context.currentTile.QCD);
  40732. component.quantizationParameters = qcdOrQcc;
  40733. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40734. context.currentTile.COC[c] : context.currentTile.COD);
  40735. component.codingStyleParameters = codOrCoc;
  40736. }
  40737. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40738. }
  40739. // Section B.10.2 Tag trees
  40740. var TagTree = (function TagTreeClosure() {
  40741. function TagTree(width, height) {
  40742. var levelsLength = log2(Math.max(width, height)) + 1;
  40743. this.levels = [];
  40744. for (var i = 0; i < levelsLength; i++) {
  40745. var level = {
  40746. width: width,
  40747. height: height,
  40748. items: []
  40749. };
  40750. this.levels.push(level);
  40751. width = Math.ceil(width / 2);
  40752. height = Math.ceil(height / 2);
  40753. }
  40754. }
  40755. TagTree.prototype = {
  40756. reset: function TagTree_reset(i, j) {
  40757. var currentLevel = 0, value = 0, level;
  40758. while (currentLevel < this.levels.length) {
  40759. level = this.levels[currentLevel];
  40760. var index = i + j * level.width;
  40761. if (level.items[index] !== undefined) {
  40762. value = level.items[index];
  40763. break;
  40764. }
  40765. level.index = index;
  40766. i >>= 1;
  40767. j >>= 1;
  40768. currentLevel++;
  40769. }
  40770. currentLevel--;
  40771. level = this.levels[currentLevel];
  40772. level.items[level.index] = value;
  40773. this.currentLevel = currentLevel;
  40774. delete this.value;
  40775. },
  40776. incrementValue: function TagTree_incrementValue() {
  40777. var level = this.levels[this.currentLevel];
  40778. level.items[level.index]++;
  40779. },
  40780. nextLevel: function TagTree_nextLevel() {
  40781. var currentLevel = this.currentLevel;
  40782. var level = this.levels[currentLevel];
  40783. var value = level.items[level.index];
  40784. currentLevel--;
  40785. if (currentLevel < 0) {
  40786. this.value = value;
  40787. return false;
  40788. }
  40789. this.currentLevel = currentLevel;
  40790. level = this.levels[currentLevel];
  40791. level.items[level.index] = value;
  40792. return true;
  40793. }
  40794. };
  40795. return TagTree;
  40796. })();
  40797. var InclusionTree = (function InclusionTreeClosure() {
  40798. function InclusionTree(width, height, defaultValue) {
  40799. var levelsLength = log2(Math.max(width, height)) + 1;
  40800. this.levels = [];
  40801. for (var i = 0; i < levelsLength; i++) {
  40802. var items = new Uint8Array(width * height);
  40803. for (var j = 0, jj = items.length; j < jj; j++) {
  40804. items[j] = defaultValue;
  40805. }
  40806. var level = {
  40807. width: width,
  40808. height: height,
  40809. items: items
  40810. };
  40811. this.levels.push(level);
  40812. width = Math.ceil(width / 2);
  40813. height = Math.ceil(height / 2);
  40814. }
  40815. }
  40816. InclusionTree.prototype = {
  40817. reset: function InclusionTree_reset(i, j, stopValue) {
  40818. var currentLevel = 0;
  40819. while (currentLevel < this.levels.length) {
  40820. var level = this.levels[currentLevel];
  40821. var index = i + j * level.width;
  40822. level.index = index;
  40823. var value = level.items[index];
  40824. if (value === 0xFF) {
  40825. break;
  40826. }
  40827. if (value > stopValue) {
  40828. this.currentLevel = currentLevel;
  40829. // already know about this one, propagating the value to top levels
  40830. this.propagateValues();
  40831. return false;
  40832. }
  40833. i >>= 1;
  40834. j >>= 1;
  40835. currentLevel++;
  40836. }
  40837. this.currentLevel = currentLevel - 1;
  40838. return true;
  40839. },
  40840. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40841. var level = this.levels[this.currentLevel];
  40842. level.items[level.index] = stopValue + 1;
  40843. this.propagateValues();
  40844. },
  40845. propagateValues: function InclusionTree_propagateValues() {
  40846. var levelIndex = this.currentLevel;
  40847. var level = this.levels[levelIndex];
  40848. var currentValue = level.items[level.index];
  40849. while (--levelIndex >= 0) {
  40850. level = this.levels[levelIndex];
  40851. level.items[level.index] = currentValue;
  40852. }
  40853. },
  40854. nextLevel: function InclusionTree_nextLevel() {
  40855. var currentLevel = this.currentLevel;
  40856. var level = this.levels[currentLevel];
  40857. var value = level.items[level.index];
  40858. level.items[level.index] = 0xFF;
  40859. currentLevel--;
  40860. if (currentLevel < 0) {
  40861. return false;
  40862. }
  40863. this.currentLevel = currentLevel;
  40864. level = this.levels[currentLevel];
  40865. level.items[level.index] = value;
  40866. return true;
  40867. }
  40868. };
  40869. return InclusionTree;
  40870. })();
  40871. // Section D. Coefficient bit modeling
  40872. var BitModel = (function BitModelClosure() {
  40873. var UNIFORM_CONTEXT = 17;
  40874. var RUNLENGTH_CONTEXT = 18;
  40875. // Table D-1
  40876. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40877. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40878. var LLAndLHContextsLabel = new Uint8Array([
  40879. 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,
  40880. 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,
  40881. 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
  40882. ]);
  40883. var HLContextLabel = new Uint8Array([
  40884. 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,
  40885. 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,
  40886. 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
  40887. ]);
  40888. var HHContextLabel = new Uint8Array([
  40889. 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,
  40890. 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,
  40891. 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
  40892. ]);
  40893. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40894. this.width = width;
  40895. this.height = height;
  40896. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40897. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40898. var coefficientCount = width * height;
  40899. // coefficients outside the encoding region treated as insignificant
  40900. // add border state cells for significanceState
  40901. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40902. this.coefficentsSign = new Uint8Array(coefficientCount);
  40903. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40904. mb > 6 ? new Uint16Array(coefficientCount) :
  40905. new Uint8Array(coefficientCount);
  40906. this.processingFlags = new Uint8Array(coefficientCount);
  40907. var bitsDecoded = new Uint8Array(coefficientCount);
  40908. if (zeroBitPlanes !== 0) {
  40909. for (var i = 0; i < coefficientCount; i++) {
  40910. bitsDecoded[i] = zeroBitPlanes;
  40911. }
  40912. }
  40913. this.bitsDecoded = bitsDecoded;
  40914. this.reset();
  40915. }
  40916. BitModel.prototype = {
  40917. setDecoder: function BitModel_setDecoder(decoder) {
  40918. this.decoder = decoder;
  40919. },
  40920. reset: function BitModel_reset() {
  40921. // We have 17 contexts that are accessed via context labels,
  40922. // plus the uniform and runlength context.
  40923. this.contexts = new Int8Array(19);
  40924. // Contexts are packed into 1 byte:
  40925. // highest 7 bits carry the index, lowest bit carries mps
  40926. this.contexts[0] = (4 << 1) | 0;
  40927. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40928. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40929. },
  40930. setNeighborsSignificance:
  40931. function BitModel_setNeighborsSignificance(row, column, index) {
  40932. var neighborsSignificance = this.neighborsSignificance;
  40933. var width = this.width, height = this.height;
  40934. var left = (column > 0);
  40935. var right = (column + 1 < width);
  40936. var i;
  40937. if (row > 0) {
  40938. i = index - width;
  40939. if (left) {
  40940. neighborsSignificance[i - 1] += 0x10;
  40941. }
  40942. if (right) {
  40943. neighborsSignificance[i + 1] += 0x10;
  40944. }
  40945. neighborsSignificance[i] += 0x04;
  40946. }
  40947. if (row + 1 < height) {
  40948. i = index + width;
  40949. if (left) {
  40950. neighborsSignificance[i - 1] += 0x10;
  40951. }
  40952. if (right) {
  40953. neighborsSignificance[i + 1] += 0x10;
  40954. }
  40955. neighborsSignificance[i] += 0x04;
  40956. }
  40957. if (left) {
  40958. neighborsSignificance[index - 1] += 0x01;
  40959. }
  40960. if (right) {
  40961. neighborsSignificance[index + 1] += 0x01;
  40962. }
  40963. neighborsSignificance[index] |= 0x80;
  40964. },
  40965. runSignificancePropogationPass:
  40966. function BitModel_runSignificancePropogationPass() {
  40967. var decoder = this.decoder;
  40968. var width = this.width, height = this.height;
  40969. var coefficentsMagnitude = this.coefficentsMagnitude;
  40970. var coefficentsSign = this.coefficentsSign;
  40971. var neighborsSignificance = this.neighborsSignificance;
  40972. var processingFlags = this.processingFlags;
  40973. var contexts = this.contexts;
  40974. var labels = this.contextLabelTable;
  40975. var bitsDecoded = this.bitsDecoded;
  40976. var processedInverseMask = ~1;
  40977. var processedMask = 1;
  40978. var firstMagnitudeBitMask = 2;
  40979. for (var i0 = 0; i0 < height; i0 += 4) {
  40980. for (var j = 0; j < width; j++) {
  40981. var index = i0 * width + j;
  40982. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40983. var i = i0 + i1;
  40984. if (i >= height) {
  40985. break;
  40986. }
  40987. // clear processed flag first
  40988. processingFlags[index] &= processedInverseMask;
  40989. if (coefficentsMagnitude[index] ||
  40990. !neighborsSignificance[index]) {
  40991. continue;
  40992. }
  40993. var contextLabel = labels[neighborsSignificance[index]];
  40994. var decision = decoder.readBit(contexts, contextLabel);
  40995. if (decision) {
  40996. var sign = this.decodeSignBit(i, j, index);
  40997. coefficentsSign[index] = sign;
  40998. coefficentsMagnitude[index] = 1;
  40999. this.setNeighborsSignificance(i, j, index);
  41000. processingFlags[index] |= firstMagnitudeBitMask;
  41001. }
  41002. bitsDecoded[index]++;
  41003. processingFlags[index] |= processedMask;
  41004. }
  41005. }
  41006. }
  41007. },
  41008. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  41009. var width = this.width, height = this.height;
  41010. var coefficentsMagnitude = this.coefficentsMagnitude;
  41011. var coefficentsSign = this.coefficentsSign;
  41012. var contribution, sign0, sign1, significance1;
  41013. var contextLabel, decoded;
  41014. // calculate horizontal contribution
  41015. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  41016. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  41017. sign1 = coefficentsSign[index + 1];
  41018. if (significance1) {
  41019. sign0 = coefficentsSign[index - 1];
  41020. contribution = 1 - sign1 - sign0;
  41021. } else {
  41022. contribution = 1 - sign1 - sign1;
  41023. }
  41024. } else if (significance1) {
  41025. sign0 = coefficentsSign[index - 1];
  41026. contribution = 1 - sign0 - sign0;
  41027. } else {
  41028. contribution = 0;
  41029. }
  41030. var horizontalContribution = 3 * contribution;
  41031. // calculate vertical contribution and combine with the horizontal
  41032. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  41033. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  41034. sign1 = coefficentsSign[index + width];
  41035. if (significance1) {
  41036. sign0 = coefficentsSign[index - width];
  41037. contribution = 1 - sign1 - sign0 + horizontalContribution;
  41038. } else {
  41039. contribution = 1 - sign1 - sign1 + horizontalContribution;
  41040. }
  41041. } else if (significance1) {
  41042. sign0 = coefficentsSign[index - width];
  41043. contribution = 1 - sign0 - sign0 + horizontalContribution;
  41044. } else {
  41045. contribution = horizontalContribution;
  41046. }
  41047. if (contribution >= 0) {
  41048. contextLabel = 9 + contribution;
  41049. decoded = this.decoder.readBit(this.contexts, contextLabel);
  41050. } else {
  41051. contextLabel = 9 - contribution;
  41052. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  41053. }
  41054. return decoded;
  41055. },
  41056. runMagnitudeRefinementPass:
  41057. function BitModel_runMagnitudeRefinementPass() {
  41058. var decoder = this.decoder;
  41059. var width = this.width, height = this.height;
  41060. var coefficentsMagnitude = this.coefficentsMagnitude;
  41061. var neighborsSignificance = this.neighborsSignificance;
  41062. var contexts = this.contexts;
  41063. var bitsDecoded = this.bitsDecoded;
  41064. var processingFlags = this.processingFlags;
  41065. var processedMask = 1;
  41066. var firstMagnitudeBitMask = 2;
  41067. var length = width * height;
  41068. var width4 = width * 4;
  41069. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  41070. indexNext = Math.min(length, index0 + width4);
  41071. for (var j = 0; j < width; j++) {
  41072. for (var index = index0 + j; index < indexNext; index += width) {
  41073. // significant but not those that have just become
  41074. if (!coefficentsMagnitude[index] ||
  41075. (processingFlags[index] & processedMask) !== 0) {
  41076. continue;
  41077. }
  41078. var contextLabel = 16;
  41079. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  41080. processingFlags[index] ^= firstMagnitudeBitMask;
  41081. // first refinement
  41082. var significance = neighborsSignificance[index] & 127;
  41083. contextLabel = significance === 0 ? 15 : 14;
  41084. }
  41085. var bit = decoder.readBit(contexts, contextLabel);
  41086. coefficentsMagnitude[index] =
  41087. (coefficentsMagnitude[index] << 1) | bit;
  41088. bitsDecoded[index]++;
  41089. processingFlags[index] |= processedMask;
  41090. }
  41091. }
  41092. }
  41093. },
  41094. runCleanupPass: function BitModel_runCleanupPass() {
  41095. var decoder = this.decoder;
  41096. var width = this.width, height = this.height;
  41097. var neighborsSignificance = this.neighborsSignificance;
  41098. var coefficentsMagnitude = this.coefficentsMagnitude;
  41099. var coefficentsSign = this.coefficentsSign;
  41100. var contexts = this.contexts;
  41101. var labels = this.contextLabelTable;
  41102. var bitsDecoded = this.bitsDecoded;
  41103. var processingFlags = this.processingFlags;
  41104. var processedMask = 1;
  41105. var firstMagnitudeBitMask = 2;
  41106. var oneRowDown = width;
  41107. var twoRowsDown = width * 2;
  41108. var threeRowsDown = width * 3;
  41109. var iNext;
  41110. for (var i0 = 0; i0 < height; i0 = iNext) {
  41111. iNext = Math.min(i0 + 4, height);
  41112. var indexBase = i0 * width;
  41113. var checkAllEmpty = i0 + 3 < height;
  41114. for (var j = 0; j < width; j++) {
  41115. var index0 = indexBase + j;
  41116. // using the property: labels[neighborsSignificance[index]] === 0
  41117. // when neighborsSignificance[index] === 0
  41118. var allEmpty = (checkAllEmpty &&
  41119. processingFlags[index0] === 0 &&
  41120. processingFlags[index0 + oneRowDown] === 0 &&
  41121. processingFlags[index0 + twoRowsDown] === 0 &&
  41122. processingFlags[index0 + threeRowsDown] === 0 &&
  41123. neighborsSignificance[index0] === 0 &&
  41124. neighborsSignificance[index0 + oneRowDown] === 0 &&
  41125. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  41126. neighborsSignificance[index0 + threeRowsDown] === 0);
  41127. var i1 = 0, index = index0;
  41128. var i = i0, sign;
  41129. if (allEmpty) {
  41130. var hasSignificantCoefficent =
  41131. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  41132. if (!hasSignificantCoefficent) {
  41133. bitsDecoded[index0]++;
  41134. bitsDecoded[index0 + oneRowDown]++;
  41135. bitsDecoded[index0 + twoRowsDown]++;
  41136. bitsDecoded[index0 + threeRowsDown]++;
  41137. continue; // next column
  41138. }
  41139. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  41140. decoder.readBit(contexts, UNIFORM_CONTEXT);
  41141. if (i1 !== 0) {
  41142. i = i0 + i1;
  41143. index += i1 * width;
  41144. }
  41145. sign = this.decodeSignBit(i, j, index);
  41146. coefficentsSign[index] = sign;
  41147. coefficentsMagnitude[index] = 1;
  41148. this.setNeighborsSignificance(i, j, index);
  41149. processingFlags[index] |= firstMagnitudeBitMask;
  41150. index = index0;
  41151. for (var i2 = i0; i2 <= i; i2++, index += width) {
  41152. bitsDecoded[index]++;
  41153. }
  41154. i1++;
  41155. }
  41156. for (i = i0 + i1; i < iNext; i++, index += width) {
  41157. if (coefficentsMagnitude[index] ||
  41158. (processingFlags[index] & processedMask) !== 0) {
  41159. continue;
  41160. }
  41161. var contextLabel = labels[neighborsSignificance[index]];
  41162. var decision = decoder.readBit(contexts, contextLabel);
  41163. if (decision === 1) {
  41164. sign = this.decodeSignBit(i, j, index);
  41165. coefficentsSign[index] = sign;
  41166. coefficentsMagnitude[index] = 1;
  41167. this.setNeighborsSignificance(i, j, index);
  41168. processingFlags[index] |= firstMagnitudeBitMask;
  41169. }
  41170. bitsDecoded[index]++;
  41171. }
  41172. }
  41173. }
  41174. },
  41175. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  41176. var decoder = this.decoder;
  41177. var contexts = this.contexts;
  41178. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  41179. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  41180. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  41181. decoder.readBit(contexts, UNIFORM_CONTEXT);
  41182. if (symbol !== 0xA) {
  41183. throw new Error('JPX Error: Invalid segmentation symbol');
  41184. }
  41185. }
  41186. };
  41187. return BitModel;
  41188. })();
  41189. // Section F, Discrete wavelet transformation
  41190. var Transform = (function TransformClosure() {
  41191. function Transform() {}
  41192. Transform.prototype.calculate =
  41193. function transformCalculate(subbands, u0, v0) {
  41194. var ll = subbands[0];
  41195. for (var i = 1, ii = subbands.length; i < ii; i++) {
  41196. ll = this.iterate(ll, subbands[i], u0, v0);
  41197. }
  41198. return ll;
  41199. };
  41200. Transform.prototype.extend = function extend(buffer, offset, size) {
  41201. // Section F.3.7 extending... using max extension of 4
  41202. var i1 = offset - 1, j1 = offset + 1;
  41203. var i2 = offset + size - 2, j2 = offset + size;
  41204. buffer[i1--] = buffer[j1++];
  41205. buffer[j2++] = buffer[i2--];
  41206. buffer[i1--] = buffer[j1++];
  41207. buffer[j2++] = buffer[i2--];
  41208. buffer[i1--] = buffer[j1++];
  41209. buffer[j2++] = buffer[i2--];
  41210. buffer[i1] = buffer[j1];
  41211. buffer[j2] = buffer[i2];
  41212. };
  41213. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  41214. u0, v0) {
  41215. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  41216. var width = hl_lh_hh.width;
  41217. var height = hl_lh_hh.height;
  41218. var items = hl_lh_hh.items;
  41219. var i, j, k, l, u, v;
  41220. // Interleave LL according to Section F.3.3
  41221. for (k = 0, i = 0; i < llHeight; i++) {
  41222. l = i * 2 * width;
  41223. for (j = 0; j < llWidth; j++, k++, l += 2) {
  41224. items[l] = llItems[k];
  41225. }
  41226. }
  41227. // The LL band is not needed anymore.
  41228. llItems = ll.items = null;
  41229. var bufferPadding = 4;
  41230. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  41231. // Section F.3.4 HOR_SR
  41232. if (width === 1) {
  41233. // if width = 1, when u0 even keep items as is, when odd divide by 2
  41234. if ((u0 & 1) !== 0) {
  41235. for (v = 0, k = 0; v < height; v++, k += width) {
  41236. items[k] *= 0.5;
  41237. }
  41238. }
  41239. } else {
  41240. for (v = 0, k = 0; v < height; v++, k += width) {
  41241. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  41242. this.extend(rowBuffer, bufferPadding, width);
  41243. this.filter(rowBuffer, bufferPadding, width);
  41244. items.set(
  41245. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  41246. k);
  41247. }
  41248. }
  41249. // Accesses to the items array can take long, because it may not fit into
  41250. // CPU cache and has to be fetched from main memory. Since subsequent
  41251. // accesses to the items array are not local when reading columns, we
  41252. // have a cache miss every time. To reduce cache misses, get up to
  41253. // 'numBuffers' items at a time and store them into the individual
  41254. // buffers. The colBuffers should be small enough to fit into CPU cache.
  41255. var numBuffers = 16;
  41256. var colBuffers = [];
  41257. for (i = 0; i < numBuffers; i++) {
  41258. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  41259. }
  41260. var b, currentBuffer = 0;
  41261. ll = bufferPadding + height;
  41262. // Section F.3.5 VER_SR
  41263. if (height === 1) {
  41264. // if height = 1, when v0 even keep items as is, when odd divide by 2
  41265. if ((v0 & 1) !== 0) {
  41266. for (u = 0; u < width; u++) {
  41267. items[u] *= 0.5;
  41268. }
  41269. }
  41270. } else {
  41271. for (u = 0; u < width; u++) {
  41272. // if we ran out of buffers, copy several image columns at once
  41273. if (currentBuffer === 0) {
  41274. numBuffers = Math.min(width - u, numBuffers);
  41275. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  41276. for (b = 0; b < numBuffers; b++) {
  41277. colBuffers[b][l] = items[k + b];
  41278. }
  41279. }
  41280. currentBuffer = numBuffers;
  41281. }
  41282. currentBuffer--;
  41283. var buffer = colBuffers[currentBuffer];
  41284. this.extend(buffer, bufferPadding, height);
  41285. this.filter(buffer, bufferPadding, height);
  41286. // If this is last buffer in this group of buffers, flush all buffers.
  41287. if (currentBuffer === 0) {
  41288. k = u - numBuffers + 1;
  41289. for (l = bufferPadding; l < ll; k += width, l++) {
  41290. for (b = 0; b < numBuffers; b++) {
  41291. items[k + b] = colBuffers[b][l];
  41292. }
  41293. }
  41294. }
  41295. }
  41296. }
  41297. return {
  41298. width: width,
  41299. height: height,
  41300. items: items
  41301. };
  41302. };
  41303. return Transform;
  41304. })();
  41305. // Section 3.8.2 Irreversible 9-7 filter
  41306. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  41307. function IrreversibleTransform() {
  41308. Transform.call(this);
  41309. }
  41310. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  41311. IrreversibleTransform.prototype.filter =
  41312. function irreversibleTransformFilter(x, offset, length) {
  41313. var len = length >> 1;
  41314. offset = offset | 0;
  41315. var j, n, current, next;
  41316. var alpha = -1.586134342059924;
  41317. var beta = -0.052980118572961;
  41318. var gamma = 0.882911075530934;
  41319. var delta = 0.443506852043971;
  41320. var K = 1.230174104914001;
  41321. var K_ = 1 / K;
  41322. // step 1 is combined with step 3
  41323. // step 2
  41324. j = offset - 3;
  41325. for (n = len + 4; n--; j += 2) {
  41326. x[j] *= K_;
  41327. }
  41328. // step 1 & 3
  41329. j = offset - 2;
  41330. current = delta * x[j -1];
  41331. for (n = len + 3; n--; j += 2) {
  41332. next = delta * x[j + 1];
  41333. x[j] = K * x[j] - current - next;
  41334. if (n--) {
  41335. j += 2;
  41336. current = delta * x[j + 1];
  41337. x[j] = K * x[j] - current - next;
  41338. } else {
  41339. break;
  41340. }
  41341. }
  41342. // step 4
  41343. j = offset - 1;
  41344. current = gamma * x[j - 1];
  41345. for (n = len + 2; n--; j += 2) {
  41346. next = gamma * x[j + 1];
  41347. x[j] -= current + next;
  41348. if (n--) {
  41349. j += 2;
  41350. current = gamma * x[j + 1];
  41351. x[j] -= current + next;
  41352. } else {
  41353. break;
  41354. }
  41355. }
  41356. // step 5
  41357. j = offset;
  41358. current = beta * x[j - 1];
  41359. for (n = len + 1; n--; j += 2) {
  41360. next = beta * x[j + 1];
  41361. x[j] -= current + next;
  41362. if (n--) {
  41363. j += 2;
  41364. current = beta * x[j + 1];
  41365. x[j] -= current + next;
  41366. } else {
  41367. break;
  41368. }
  41369. }
  41370. // step 6
  41371. if (len !== 0) {
  41372. j = offset + 1;
  41373. current = alpha * x[j - 1];
  41374. for (n = len; n--; j += 2) {
  41375. next = alpha * x[j + 1];
  41376. x[j] -= current + next;
  41377. if (n--) {
  41378. j += 2;
  41379. current = alpha * x[j + 1];
  41380. x[j] -= current + next;
  41381. } else {
  41382. break;
  41383. }
  41384. }
  41385. }
  41386. };
  41387. return IrreversibleTransform;
  41388. })();
  41389. // Section 3.8.1 Reversible 5-3 filter
  41390. var ReversibleTransform = (function ReversibleTransformClosure() {
  41391. function ReversibleTransform() {
  41392. Transform.call(this);
  41393. }
  41394. ReversibleTransform.prototype = Object.create(Transform.prototype);
  41395. ReversibleTransform.prototype.filter =
  41396. function reversibleTransformFilter(x, offset, length) {
  41397. var len = length >> 1;
  41398. offset = offset | 0;
  41399. var j, n;
  41400. for (j = offset, n = len + 1; n--; j += 2) {
  41401. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  41402. }
  41403. for (j = offset + 1, n = len; n--; j += 2) {
  41404. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  41405. }
  41406. };
  41407. return ReversibleTransform;
  41408. })();
  41409. return JpxImage;
  41410. })();
  41411. var Jbig2Image = (function Jbig2ImageClosure() {
  41412. // Utility data structures
  41413. function ContextCache() {}
  41414. ContextCache.prototype = {
  41415. getContexts: function(id) {
  41416. if (id in this) {
  41417. return this[id];
  41418. }
  41419. return (this[id] = new Int8Array(1 << 16));
  41420. }
  41421. };
  41422. function DecodingContext(data, start, end) {
  41423. this.data = data;
  41424. this.start = start;
  41425. this.end = end;
  41426. }
  41427. DecodingContext.prototype = {
  41428. get decoder() {
  41429. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  41430. return shadow(this, 'decoder', decoder);
  41431. },
  41432. get contextCache() {
  41433. var cache = new ContextCache();
  41434. return shadow(this, 'contextCache', cache);
  41435. }
  41436. };
  41437. // Annex A. Arithmetic Integer Decoding Procedure
  41438. // A.2 Procedure for decoding values
  41439. function decodeInteger(contextCache, procedure, decoder) {
  41440. var contexts = contextCache.getContexts(procedure);
  41441. var prev = 1;
  41442. function readBits(length) {
  41443. var v = 0;
  41444. for (var i = 0; i < length; i++) {
  41445. var bit = decoder.readBit(contexts, prev);
  41446. prev = (prev < 256 ? (prev << 1) | bit :
  41447. (((prev << 1) | bit) & 511) | 256);
  41448. v = (v << 1) | bit;
  41449. }
  41450. return v >>> 0;
  41451. }
  41452. var sign = readBits(1);
  41453. var value = readBits(1) ?
  41454. (readBits(1) ?
  41455. (readBits(1) ?
  41456. (readBits(1) ?
  41457. (readBits(1) ?
  41458. (readBits(32) + 4436) :
  41459. readBits(12) + 340) :
  41460. readBits(8) + 84) :
  41461. readBits(6) + 20) :
  41462. readBits(4) + 4) :
  41463. readBits(2);
  41464. return (sign === 0 ? value : (value > 0 ? -value : null));
  41465. }
  41466. // A.3 The IAID decoding procedure
  41467. function decodeIAID(contextCache, decoder, codeLength) {
  41468. var contexts = contextCache.getContexts('IAID');
  41469. var prev = 1;
  41470. for (var i = 0; i < codeLength; i++) {
  41471. var bit = decoder.readBit(contexts, prev);
  41472. prev = (prev << 1) | bit;
  41473. }
  41474. if (codeLength < 31) {
  41475. return prev & ((1 << codeLength) - 1);
  41476. }
  41477. return prev & 0x7FFFFFFF;
  41478. }
  41479. // 7.3 Segment types
  41480. var SegmentTypes = [
  41481. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  41482. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  41483. null, null, null, null, null, 'patternDictionary', null, null, null,
  41484. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  41485. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  41486. null, null, null, null, null, 'IntermediateGenericRegion', null,
  41487. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  41488. 'IntermediateGenericRefinementRegion', null,
  41489. 'ImmediateGenericRefinementRegion',
  41490. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  41491. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  41492. 'Tables', null, null, null, null, null, null, null, null,
  41493. 'Extension'
  41494. ];
  41495. var CodingTemplates = [
  41496. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41497. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  41498. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41499. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  41500. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  41501. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41502. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41503. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  41504. {x: -1, y: 0}],
  41505. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  41506. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  41507. ];
  41508. var RefinementTemplates = [
  41509. {
  41510. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41511. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  41512. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  41513. },
  41514. {
  41515. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41516. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  41517. {x: 0, y: 1}, {x: 1, y: 1}]
  41518. }
  41519. ];
  41520. // See 6.2.5.7 Decoding the bitmap.
  41521. var ReusedContexts = [
  41522. 0x9B25, // 10011 0110010 0101
  41523. 0x0795, // 0011 110010 101
  41524. 0x00E5, // 001 11001 01
  41525. 0x0195 // 011001 0101
  41526. ];
  41527. var RefinementReusedContexts = [
  41528. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  41529. 0x0008 // '0000' + '001000'
  41530. ];
  41531. function decodeBitmapTemplate0(width, height, decodingContext) {
  41532. var decoder = decodingContext.decoder;
  41533. var contexts = decodingContext.contextCache.getContexts('GB');
  41534. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  41535. // ...ooooo....
  41536. // ..ooooooo... Context template for current pixel (X)
  41537. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  41538. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  41539. for (i = 0; i < height; i++) {
  41540. row = bitmap[i] = new Uint8Array(width);
  41541. row1 = (i < 1) ? row : bitmap[i - 1];
  41542. row2 = (i < 2) ? row : bitmap[i - 2];
  41543. // At the beginning of each row:
  41544. // Fill contextLabel with pixels that are above/right of (X)
  41545. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  41546. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  41547. (row1[3] << 4);
  41548. for (j = 0; j < width; j++) {
  41549. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  41550. // At each pixel: Clear contextLabel pixels that are shifted
  41551. // out of the context, then add new ones.
  41552. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  41553. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  41554. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  41555. }
  41556. }
  41557. return bitmap;
  41558. }
  41559. // 6.2 Generic Region Decoding Procedure
  41560. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  41561. decodingContext) {
  41562. if (mmr) {
  41563. error('JBIG2 error: MMR encoding is not supported');
  41564. }
  41565. // Use optimized version for the most common case
  41566. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41567. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41568. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41569. return decodeBitmapTemplate0(width, height, decodingContext);
  41570. }
  41571. var useskip = !!skip;
  41572. var template = CodingTemplates[templateIndex].concat(at);
  41573. // Sorting is non-standard, and it is not required. But sorting increases
  41574. // the number of template bits that can be reused from the previous
  41575. // contextLabel in the main loop.
  41576. template.sort(function (a, b) {
  41577. return (a.y - b.y) || (a.x - b.x);
  41578. });
  41579. var templateLength = template.length;
  41580. var templateX = new Int8Array(templateLength);
  41581. var templateY = new Int8Array(templateLength);
  41582. var changingTemplateEntries = [];
  41583. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41584. var c, k;
  41585. for (k = 0; k < templateLength; k++) {
  41586. templateX[k] = template[k].x;
  41587. templateY[k] = template[k].y;
  41588. minX = Math.min(minX, template[k].x);
  41589. maxX = Math.max(maxX, template[k].x);
  41590. minY = Math.min(minY, template[k].y);
  41591. // Check if the template pixel appears in two consecutive context labels,
  41592. // so it can be reused. Otherwise, we add it to the list of changing
  41593. // template entries.
  41594. if (k < templateLength - 1 &&
  41595. template[k].y === template[k + 1].y &&
  41596. template[k].x === template[k + 1].x - 1) {
  41597. reuseMask |= 1 << (templateLength - 1 - k);
  41598. } else {
  41599. changingTemplateEntries.push(k);
  41600. }
  41601. }
  41602. var changingEntriesLength = changingTemplateEntries.length;
  41603. var changingTemplateX = new Int8Array(changingEntriesLength);
  41604. var changingTemplateY = new Int8Array(changingEntriesLength);
  41605. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41606. for (c = 0; c < changingEntriesLength; c++) {
  41607. k = changingTemplateEntries[c];
  41608. changingTemplateX[c] = template[k].x;
  41609. changingTemplateY[c] = template[k].y;
  41610. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41611. }
  41612. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41613. var sbb_left = -minX;
  41614. var sbb_top = -minY;
  41615. var sbb_right = width - maxX;
  41616. var pseudoPixelContext = ReusedContexts[templateIndex];
  41617. var row = new Uint8Array(width);
  41618. var bitmap = [];
  41619. var decoder = decodingContext.decoder;
  41620. var contexts = decodingContext.contextCache.getContexts('GB');
  41621. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41622. for (var i = 0; i < height; i++) {
  41623. if (prediction) {
  41624. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41625. ltp ^= sltp;
  41626. if (ltp) {
  41627. bitmap.push(row); // duplicate previous row
  41628. continue;
  41629. }
  41630. }
  41631. row = new Uint8Array(row);
  41632. bitmap.push(row);
  41633. for (j = 0; j < width; j++) {
  41634. if (useskip && skip[i][j]) {
  41635. row[j] = 0;
  41636. continue;
  41637. }
  41638. // Are we in the middle of a scanline, so we can reuse contextLabel
  41639. // bits?
  41640. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41641. // If yes, we can just shift the bits that are reusable and only
  41642. // fetch the remaining ones.
  41643. contextLabel = (contextLabel << 1) & reuseMask;
  41644. for (k = 0; k < changingEntriesLength; k++) {
  41645. i0 = i + changingTemplateY[k];
  41646. j0 = j + changingTemplateX[k];
  41647. bit = bitmap[i0][j0];
  41648. if (bit) {
  41649. bit = changingTemplateBit[k];
  41650. contextLabel |= bit;
  41651. }
  41652. }
  41653. } else {
  41654. // compute the contextLabel from scratch
  41655. contextLabel = 0;
  41656. shift = templateLength - 1;
  41657. for (k = 0; k < templateLength; k++, shift--) {
  41658. j0 = j + templateX[k];
  41659. if (j0 >= 0 && j0 < width) {
  41660. i0 = i + templateY[k];
  41661. if (i0 >= 0) {
  41662. bit = bitmap[i0][j0];
  41663. if (bit) {
  41664. contextLabel |= bit << shift;
  41665. }
  41666. }
  41667. }
  41668. }
  41669. }
  41670. var pixel = decoder.readBit(contexts, contextLabel);
  41671. row[j] = pixel;
  41672. }
  41673. }
  41674. return bitmap;
  41675. }
  41676. // 6.3.2 Generic Refinement Region Decoding Procedure
  41677. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41678. offsetX, offsetY, prediction, at,
  41679. decodingContext) {
  41680. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41681. if (templateIndex === 0) {
  41682. codingTemplate = codingTemplate.concat([at[0]]);
  41683. }
  41684. var codingTemplateLength = codingTemplate.length;
  41685. var codingTemplateX = new Int32Array(codingTemplateLength);
  41686. var codingTemplateY = new Int32Array(codingTemplateLength);
  41687. var k;
  41688. for (k = 0; k < codingTemplateLength; k++) {
  41689. codingTemplateX[k] = codingTemplate[k].x;
  41690. codingTemplateY[k] = codingTemplate[k].y;
  41691. }
  41692. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41693. if (templateIndex === 0) {
  41694. referenceTemplate = referenceTemplate.concat([at[1]]);
  41695. }
  41696. var referenceTemplateLength = referenceTemplate.length;
  41697. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41698. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41699. for (k = 0; k < referenceTemplateLength; k++) {
  41700. referenceTemplateX[k] = referenceTemplate[k].x;
  41701. referenceTemplateY[k] = referenceTemplate[k].y;
  41702. }
  41703. var referenceWidth = referenceBitmap[0].length;
  41704. var referenceHeight = referenceBitmap.length;
  41705. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41706. var bitmap = [];
  41707. var decoder = decodingContext.decoder;
  41708. var contexts = decodingContext.contextCache.getContexts('GR');
  41709. var ltp = 0;
  41710. for (var i = 0; i < height; i++) {
  41711. if (prediction) {
  41712. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41713. ltp ^= sltp;
  41714. if (ltp) {
  41715. error('JBIG2 error: prediction is not supported');
  41716. }
  41717. }
  41718. var row = new Uint8Array(width);
  41719. bitmap.push(row);
  41720. for (var j = 0; j < width; j++) {
  41721. var i0, j0;
  41722. var contextLabel = 0;
  41723. for (k = 0; k < codingTemplateLength; k++) {
  41724. i0 = i + codingTemplateY[k];
  41725. j0 = j + codingTemplateX[k];
  41726. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41727. contextLabel <<= 1; // out of bound pixel
  41728. } else {
  41729. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41730. }
  41731. }
  41732. for (k = 0; k < referenceTemplateLength; k++) {
  41733. i0 = i + referenceTemplateY[k] + offsetY;
  41734. j0 = j + referenceTemplateX[k] + offsetX;
  41735. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41736. j0 >= referenceWidth) {
  41737. contextLabel <<= 1; // out of bound pixel
  41738. } else {
  41739. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41740. }
  41741. }
  41742. var pixel = decoder.readBit(contexts, contextLabel);
  41743. row[j] = pixel;
  41744. }
  41745. }
  41746. return bitmap;
  41747. }
  41748. // 6.5.5 Decoding the symbol dictionary
  41749. function decodeSymbolDictionary(huffman, refinement, symbols,
  41750. numberOfNewSymbols, numberOfExportedSymbols,
  41751. huffmanTables, templateIndex, at,
  41752. refinementTemplateIndex, refinementAt,
  41753. decodingContext) {
  41754. if (huffman) {
  41755. error('JBIG2 error: huffman is not supported');
  41756. }
  41757. var newSymbols = [];
  41758. var currentHeight = 0;
  41759. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41760. var decoder = decodingContext.decoder;
  41761. var contextCache = decodingContext.contextCache;
  41762. while (newSymbols.length < numberOfNewSymbols) {
  41763. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41764. currentHeight += deltaHeight;
  41765. var currentWidth = 0;
  41766. var totalWidth = 0;
  41767. while (true) {
  41768. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41769. if (deltaWidth === null) {
  41770. break; // OOB
  41771. }
  41772. currentWidth += deltaWidth;
  41773. totalWidth += currentWidth;
  41774. var bitmap;
  41775. if (refinement) {
  41776. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41777. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41778. if (numberOfInstances > 1) {
  41779. bitmap = decodeTextRegion(huffman, refinement,
  41780. currentWidth, currentHeight, 0,
  41781. numberOfInstances, 1, //strip size
  41782. symbols.concat(newSymbols),
  41783. symbolCodeLength,
  41784. 0, //transposed
  41785. 0, //ds offset
  41786. 1, //top left 7.4.3.1.1
  41787. 0, //OR operator
  41788. huffmanTables,
  41789. refinementTemplateIndex, refinementAt,
  41790. decodingContext);
  41791. } else {
  41792. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41793. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41794. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41795. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41796. newSymbols[symbolId - symbols.length]);
  41797. bitmap = decodeRefinement(currentWidth, currentHeight,
  41798. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41799. decodingContext);
  41800. }
  41801. } else {
  41802. // 6.5.8.1 Direct-coded symbol bitmap
  41803. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41804. templateIndex, false, null, at, decodingContext);
  41805. }
  41806. newSymbols.push(bitmap);
  41807. }
  41808. }
  41809. // 6.5.10 Exported symbols
  41810. var exportedSymbols = [];
  41811. var flags = [], currentFlag = false;
  41812. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41813. while (flags.length < totalSymbolsLength) {
  41814. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41815. while (runLength--) {
  41816. flags.push(currentFlag);
  41817. }
  41818. currentFlag = !currentFlag;
  41819. }
  41820. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41821. if (flags[i]) {
  41822. exportedSymbols.push(symbols[i]);
  41823. }
  41824. }
  41825. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41826. if (flags[i]) {
  41827. exportedSymbols.push(newSymbols[j]);
  41828. }
  41829. }
  41830. return exportedSymbols;
  41831. }
  41832. function decodeTextRegion(huffman, refinement, width, height,
  41833. defaultPixelValue, numberOfSymbolInstances,
  41834. stripSize, inputSymbols, symbolCodeLength,
  41835. transposed, dsOffset, referenceCorner,
  41836. combinationOperator, huffmanTables,
  41837. refinementTemplateIndex, refinementAt,
  41838. decodingContext) {
  41839. if (huffman) {
  41840. error('JBIG2 error: huffman is not supported');
  41841. }
  41842. // Prepare bitmap
  41843. var bitmap = [];
  41844. var i, row;
  41845. for (i = 0; i < height; i++) {
  41846. row = new Uint8Array(width);
  41847. if (defaultPixelValue) {
  41848. for (var j = 0; j < width; j++) {
  41849. row[j] = defaultPixelValue;
  41850. }
  41851. }
  41852. bitmap.push(row);
  41853. }
  41854. var decoder = decodingContext.decoder;
  41855. var contextCache = decodingContext.contextCache;
  41856. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41857. var firstS = 0;
  41858. i = 0;
  41859. while (i < numberOfSymbolInstances) {
  41860. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41861. stripT += deltaT;
  41862. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41863. firstS += deltaFirstS;
  41864. var currentS = firstS;
  41865. do {
  41866. var currentT = (stripSize === 1 ? 0 :
  41867. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41868. var t = stripSize * stripT + currentT;
  41869. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41870. var applyRefinement = (refinement &&
  41871. decodeInteger(contextCache, 'IARI', decoder));
  41872. var symbolBitmap = inputSymbols[symbolId];
  41873. var symbolWidth = symbolBitmap[0].length;
  41874. var symbolHeight = symbolBitmap.length;
  41875. if (applyRefinement) {
  41876. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41877. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41878. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41879. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41880. symbolWidth += rdw;
  41881. symbolHeight += rdh;
  41882. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41883. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41884. (rdh >> 1) + rdy, false, refinementAt,
  41885. decodingContext);
  41886. }
  41887. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41888. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41889. var s2, t2, symbolRow;
  41890. if (transposed) {
  41891. // Place Symbol Bitmap from T1,S1
  41892. for (s2 = 0; s2 < symbolHeight; s2++) {
  41893. row = bitmap[offsetS + s2];
  41894. if (!row) {
  41895. continue;
  41896. }
  41897. symbolRow = symbolBitmap[s2];
  41898. // To ignore Parts of Symbol bitmap which goes
  41899. // outside bitmap region
  41900. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41901. switch (combinationOperator) {
  41902. case 0: // OR
  41903. for (t2 = 0; t2 < maxWidth; t2++) {
  41904. row[offsetT + t2] |= symbolRow[t2];
  41905. }
  41906. break;
  41907. case 2: // XOR
  41908. for (t2 = 0; t2 < maxWidth; t2++) {
  41909. row[offsetT + t2] ^= symbolRow[t2];
  41910. }
  41911. break;
  41912. default:
  41913. error('JBIG2 error: operator ' + combinationOperator +
  41914. ' is not supported');
  41915. }
  41916. }
  41917. currentS += symbolHeight - 1;
  41918. } else {
  41919. for (t2 = 0; t2 < symbolHeight; t2++) {
  41920. row = bitmap[offsetT + t2];
  41921. if (!row) {
  41922. continue;
  41923. }
  41924. symbolRow = symbolBitmap[t2];
  41925. switch (combinationOperator) {
  41926. case 0: // OR
  41927. for (s2 = 0; s2 < symbolWidth; s2++) {
  41928. row[offsetS + s2] |= symbolRow[s2];
  41929. }
  41930. break;
  41931. case 2: // XOR
  41932. for (s2 = 0; s2 < symbolWidth; s2++) {
  41933. row[offsetS + s2] ^= symbolRow[s2];
  41934. }
  41935. break;
  41936. default:
  41937. error('JBIG2 error: operator ' + combinationOperator +
  41938. ' is not supported');
  41939. }
  41940. }
  41941. currentS += symbolWidth - 1;
  41942. }
  41943. i++;
  41944. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41945. if (deltaS === null) {
  41946. break; // OOB
  41947. }
  41948. currentS += deltaS + dsOffset;
  41949. } while (true);
  41950. }
  41951. return bitmap;
  41952. }
  41953. function readSegmentHeader(data, start) {
  41954. var segmentHeader = {};
  41955. segmentHeader.number = readUint32(data, start);
  41956. var flags = data[start + 4];
  41957. var segmentType = flags & 0x3F;
  41958. if (!SegmentTypes[segmentType]) {
  41959. error('JBIG2 error: invalid segment type: ' + segmentType);
  41960. }
  41961. segmentHeader.type = segmentType;
  41962. segmentHeader.typeName = SegmentTypes[segmentType];
  41963. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41964. var pageAssociationFieldSize = !!(flags & 0x40);
  41965. var referredFlags = data[start + 5];
  41966. var referredToCount = (referredFlags >> 5) & 7;
  41967. var retainBits = [referredFlags & 31];
  41968. var position = start + 6;
  41969. if (referredFlags === 7) {
  41970. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41971. position += 3;
  41972. var bytes = (referredToCount + 7) >> 3;
  41973. retainBits[0] = data[position++];
  41974. while (--bytes > 0) {
  41975. retainBits.push(data[position++]);
  41976. }
  41977. } else if (referredFlags === 5 || referredFlags === 6) {
  41978. error('JBIG2 error: invalid referred-to flags');
  41979. }
  41980. segmentHeader.retainBits = retainBits;
  41981. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41982. (segmentHeader.number <= 65536 ? 2 : 4));
  41983. var referredTo = [];
  41984. var i, ii;
  41985. for (i = 0; i < referredToCount; i++) {
  41986. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41987. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41988. readUint32(data, position)));
  41989. referredTo.push(number);
  41990. position += referredToSegmentNumberSize;
  41991. }
  41992. segmentHeader.referredTo = referredTo;
  41993. if (!pageAssociationFieldSize) {
  41994. segmentHeader.pageAssociation = data[position++];
  41995. } else {
  41996. segmentHeader.pageAssociation = readUint32(data, position);
  41997. position += 4;
  41998. }
  41999. segmentHeader.length = readUint32(data, position);
  42000. position += 4;
  42001. if (segmentHeader.length === 0xFFFFFFFF) {
  42002. // 7.2.7 Segment data length, unknown segment length
  42003. if (segmentType === 38) { // ImmediateGenericRegion
  42004. var genericRegionInfo = readRegionSegmentInformation(data, position);
  42005. var genericRegionSegmentFlags = data[position +
  42006. RegionSegmentInformationFieldLength];
  42007. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  42008. // searching for the segment end
  42009. var searchPatternLength = 6;
  42010. var searchPattern = new Uint8Array(searchPatternLength);
  42011. if (!genericRegionMmr) {
  42012. searchPattern[0] = 0xFF;
  42013. searchPattern[1] = 0xAC;
  42014. }
  42015. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  42016. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  42017. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  42018. searchPattern[5] = genericRegionInfo.height & 0xFF;
  42019. for (i = position, ii = data.length; i < ii; i++) {
  42020. var j = 0;
  42021. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  42022. j++;
  42023. }
  42024. if (j === searchPatternLength) {
  42025. segmentHeader.length = i + searchPatternLength;
  42026. break;
  42027. }
  42028. }
  42029. if (segmentHeader.length === 0xFFFFFFFF) {
  42030. error('JBIG2 error: segment end was not found');
  42031. }
  42032. } else {
  42033. error('JBIG2 error: invalid unknown segment length');
  42034. }
  42035. }
  42036. segmentHeader.headerEnd = position;
  42037. return segmentHeader;
  42038. }
  42039. function readSegments(header, data, start, end) {
  42040. var segments = [];
  42041. var position = start;
  42042. while (position < end) {
  42043. var segmentHeader = readSegmentHeader(data, position);
  42044. position = segmentHeader.headerEnd;
  42045. var segment = {
  42046. header: segmentHeader,
  42047. data: data
  42048. };
  42049. if (!header.randomAccess) {
  42050. segment.start = position;
  42051. position += segmentHeader.length;
  42052. segment.end = position;
  42053. }
  42054. segments.push(segment);
  42055. if (segmentHeader.type === 51) {
  42056. break; // end of file is found
  42057. }
  42058. }
  42059. if (header.randomAccess) {
  42060. for (var i = 0, ii = segments.length; i < ii; i++) {
  42061. segments[i].start = position;
  42062. position += segments[i].header.length;
  42063. segments[i].end = position;
  42064. }
  42065. }
  42066. return segments;
  42067. }
  42068. // 7.4.1 Region segment information field
  42069. function readRegionSegmentInformation(data, start) {
  42070. return {
  42071. width: readUint32(data, start),
  42072. height: readUint32(data, start + 4),
  42073. x: readUint32(data, start + 8),
  42074. y: readUint32(data, start + 12),
  42075. combinationOperator: data[start + 16] & 7
  42076. };
  42077. }
  42078. var RegionSegmentInformationFieldLength = 17;
  42079. function processSegment(segment, visitor) {
  42080. var header = segment.header;
  42081. var data = segment.data, position = segment.start, end = segment.end;
  42082. var args, at, i, atLength;
  42083. switch (header.type) {
  42084. case 0: // SymbolDictionary
  42085. // 7.4.2 Symbol dictionary segment syntax
  42086. var dictionary = {};
  42087. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  42088. dictionary.huffman = !!(dictionaryFlags & 1);
  42089. dictionary.refinement = !!(dictionaryFlags & 2);
  42090. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  42091. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  42092. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  42093. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  42094. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  42095. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  42096. dictionary.template = (dictionaryFlags >> 10) & 3;
  42097. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  42098. position += 2;
  42099. if (!dictionary.huffman) {
  42100. atLength = dictionary.template === 0 ? 4 : 1;
  42101. at = [];
  42102. for (i = 0; i < atLength; i++) {
  42103. at.push({
  42104. x: readInt8(data, position),
  42105. y: readInt8(data, position + 1)
  42106. });
  42107. position += 2;
  42108. }
  42109. dictionary.at = at;
  42110. }
  42111. if (dictionary.refinement && !dictionary.refinementTemplate) {
  42112. at = [];
  42113. for (i = 0; i < 2; i++) {
  42114. at.push({
  42115. x: readInt8(data, position),
  42116. y: readInt8(data, position + 1)
  42117. });
  42118. position += 2;
  42119. }
  42120. dictionary.refinementAt = at;
  42121. }
  42122. dictionary.numberOfExportedSymbols = readUint32(data, position);
  42123. position += 4;
  42124. dictionary.numberOfNewSymbols = readUint32(data, position);
  42125. position += 4;
  42126. args = [dictionary, header.number, header.referredTo,
  42127. data, position, end];
  42128. break;
  42129. case 6: // ImmediateTextRegion
  42130. case 7: // ImmediateLosslessTextRegion
  42131. var textRegion = {};
  42132. textRegion.info = readRegionSegmentInformation(data, position);
  42133. position += RegionSegmentInformationFieldLength;
  42134. var textRegionSegmentFlags = readUint16(data, position);
  42135. position += 2;
  42136. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  42137. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  42138. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  42139. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  42140. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  42141. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  42142. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  42143. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  42144. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  42145. if (textRegion.huffman) {
  42146. var textRegionHuffmanFlags = readUint16(data, position);
  42147. position += 2;
  42148. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  42149. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  42150. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  42151. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  42152. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  42153. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  42154. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  42155. textRegion.huffmanRefinementSizeSelector =
  42156. !!(textRegionHuffmanFlags & 14);
  42157. }
  42158. if (textRegion.refinement && !textRegion.refinementTemplate) {
  42159. at = [];
  42160. for (i = 0; i < 2; i++) {
  42161. at.push({
  42162. x: readInt8(data, position),
  42163. y: readInt8(data, position + 1)
  42164. });
  42165. position += 2;
  42166. }
  42167. textRegion.refinementAt = at;
  42168. }
  42169. textRegion.numberOfSymbolInstances = readUint32(data, position);
  42170. position += 4;
  42171. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  42172. if (textRegion.huffman) {
  42173. error('JBIG2 error: huffman is not supported');
  42174. }
  42175. args = [textRegion, header.referredTo, data, position, end];
  42176. break;
  42177. case 38: // ImmediateGenericRegion
  42178. case 39: // ImmediateLosslessGenericRegion
  42179. var genericRegion = {};
  42180. genericRegion.info = readRegionSegmentInformation(data, position);
  42181. position += RegionSegmentInformationFieldLength;
  42182. var genericRegionSegmentFlags = data[position++];
  42183. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  42184. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  42185. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  42186. if (!genericRegion.mmr) {
  42187. atLength = genericRegion.template === 0 ? 4 : 1;
  42188. at = [];
  42189. for (i = 0; i < atLength; i++) {
  42190. at.push({
  42191. x: readInt8(data, position),
  42192. y: readInt8(data, position + 1)
  42193. });
  42194. position += 2;
  42195. }
  42196. genericRegion.at = at;
  42197. }
  42198. args = [genericRegion, data, position, end];
  42199. break;
  42200. case 48: // PageInformation
  42201. var pageInfo = {
  42202. width: readUint32(data, position),
  42203. height: readUint32(data, position + 4),
  42204. resolutionX: readUint32(data, position + 8),
  42205. resolutionY: readUint32(data, position + 12)
  42206. };
  42207. if (pageInfo.height === 0xFFFFFFFF) {
  42208. delete pageInfo.height;
  42209. }
  42210. var pageSegmentFlags = data[position + 16];
  42211. var pageStripingInformatiom = readUint16(data, position + 17);
  42212. pageInfo.lossless = !!(pageSegmentFlags & 1);
  42213. pageInfo.refinement = !!(pageSegmentFlags & 2);
  42214. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  42215. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  42216. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  42217. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  42218. args = [pageInfo];
  42219. break;
  42220. case 49: // EndOfPage
  42221. break;
  42222. case 50: // EndOfStripe
  42223. break;
  42224. case 51: // EndOfFile
  42225. break;
  42226. case 62: // 7.4.15 defines 2 extension types which
  42227. // are comments and can be ignored.
  42228. break;
  42229. default:
  42230. error('JBIG2 error: segment type ' + header.typeName + '(' +
  42231. header.type + ') is not implemented');
  42232. }
  42233. var callbackName = 'on' + header.typeName;
  42234. if (callbackName in visitor) {
  42235. visitor[callbackName].apply(visitor, args);
  42236. }
  42237. }
  42238. function processSegments(segments, visitor) {
  42239. for (var i = 0, ii = segments.length; i < ii; i++) {
  42240. processSegment(segments[i], visitor);
  42241. }
  42242. }
  42243. function parseJbig2(data, start, end) {
  42244. var position = start;
  42245. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  42246. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  42247. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  42248. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  42249. error('JBIG2 error: invalid header');
  42250. }
  42251. var header = {};
  42252. position += 8;
  42253. var flags = data[position++];
  42254. header.randomAccess = !(flags & 1);
  42255. if (!(flags & 2)) {
  42256. header.numberOfPages = readUint32(data, position);
  42257. position += 4;
  42258. }
  42259. var segments = readSegments(header, data, position, end);
  42260. error('Not implemented');
  42261. // processSegments(segments, new SimpleSegmentVisitor());
  42262. }
  42263. function parseJbig2Chunks(chunks) {
  42264. var visitor = new SimpleSegmentVisitor();
  42265. for (var i = 0, ii = chunks.length; i < ii; i++) {
  42266. var chunk = chunks[i];
  42267. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  42268. processSegments(segments, visitor);
  42269. }
  42270. return visitor.buffer;
  42271. }
  42272. function SimpleSegmentVisitor() {}
  42273. SimpleSegmentVisitor.prototype = {
  42274. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  42275. this.currentPageInfo = info;
  42276. var rowSize = (info.width + 7) >> 3;
  42277. var buffer = new Uint8Array(rowSize * info.height);
  42278. // The contents of ArrayBuffers are initialized to 0.
  42279. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  42280. if (info.defaultPixelValue) {
  42281. for (var i = 0, ii = buffer.length; i < ii; i++) {
  42282. buffer[i] = 0xFF;
  42283. }
  42284. }
  42285. this.buffer = buffer;
  42286. },
  42287. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  42288. var pageInfo = this.currentPageInfo;
  42289. var width = regionInfo.width, height = regionInfo.height;
  42290. var rowSize = (pageInfo.width + 7) >> 3;
  42291. var combinationOperator = pageInfo.combinationOperatorOverride ?
  42292. regionInfo.combinationOperator : pageInfo.combinationOperator;
  42293. var buffer = this.buffer;
  42294. var mask0 = 128 >> (regionInfo.x & 7);
  42295. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  42296. var i, j, mask, offset;
  42297. switch (combinationOperator) {
  42298. case 0: // OR
  42299. for (i = 0; i < height; i++) {
  42300. mask = mask0;
  42301. offset = offset0;
  42302. for (j = 0; j < width; j++) {
  42303. if (bitmap[i][j]) {
  42304. buffer[offset] |= mask;
  42305. }
  42306. mask >>= 1;
  42307. if (!mask) {
  42308. mask = 128;
  42309. offset++;
  42310. }
  42311. }
  42312. offset0 += rowSize;
  42313. }
  42314. break;
  42315. case 2: // XOR
  42316. for (i = 0; i < height; i++) {
  42317. mask = mask0;
  42318. offset = offset0;
  42319. for (j = 0; j < width; j++) {
  42320. if (bitmap[i][j]) {
  42321. buffer[offset] ^= mask;
  42322. }
  42323. mask >>= 1;
  42324. if (!mask) {
  42325. mask = 128;
  42326. offset++;
  42327. }
  42328. }
  42329. offset0 += rowSize;
  42330. }
  42331. break;
  42332. default:
  42333. error('JBIG2 error: operator ' + combinationOperator +
  42334. ' is not supported');
  42335. }
  42336. },
  42337. onImmediateGenericRegion:
  42338. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  42339. start, end) {
  42340. var regionInfo = region.info;
  42341. var decodingContext = new DecodingContext(data, start, end);
  42342. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  42343. region.template, region.prediction, null,
  42344. region.at, decodingContext);
  42345. this.drawBitmap(regionInfo, bitmap);
  42346. },
  42347. onImmediateLosslessGenericRegion:
  42348. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  42349. this.onImmediateGenericRegion.apply(this, arguments);
  42350. },
  42351. onSymbolDictionary:
  42352. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  42353. currentSegment,
  42354. referredSegments,
  42355. data, start, end) {
  42356. var huffmanTables;
  42357. if (dictionary.huffman) {
  42358. error('JBIG2 error: huffman is not supported');
  42359. }
  42360. // Combines exported symbols from all referred segments
  42361. var symbols = this.symbols;
  42362. if (!symbols) {
  42363. this.symbols = symbols = {};
  42364. }
  42365. var inputSymbols = [];
  42366. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  42367. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  42368. }
  42369. var decodingContext = new DecodingContext(data, start, end);
  42370. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  42371. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  42372. dictionary.numberOfExportedSymbols, huffmanTables,
  42373. dictionary.template, dictionary.at,
  42374. dictionary.refinementTemplate, dictionary.refinementAt,
  42375. decodingContext);
  42376. },
  42377. onImmediateTextRegion:
  42378. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  42379. referredSegments,
  42380. data, start, end) {
  42381. var regionInfo = region.info;
  42382. var huffmanTables;
  42383. // Combines exported symbols from all referred segments
  42384. var symbols = this.symbols;
  42385. var inputSymbols = [];
  42386. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  42387. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  42388. }
  42389. var symbolCodeLength = log2(inputSymbols.length);
  42390. var decodingContext = new DecodingContext(data, start, end);
  42391. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  42392. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  42393. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  42394. symbolCodeLength, region.transposed, region.dsOffset,
  42395. region.referenceCorner, region.combinationOperator, huffmanTables,
  42396. region.refinementTemplate, region.refinementAt, decodingContext);
  42397. this.drawBitmap(regionInfo, bitmap);
  42398. },
  42399. onImmediateLosslessTextRegion:
  42400. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  42401. this.onImmediateTextRegion.apply(this, arguments);
  42402. }
  42403. };
  42404. function Jbig2Image() {}
  42405. Jbig2Image.prototype = {
  42406. parseChunks: function Jbig2Image_parseChunks(chunks) {
  42407. return parseJbig2Chunks(chunks);
  42408. }
  42409. };
  42410. return Jbig2Image;
  42411. })();
  42412. var bidi = PDFJS.bidi = (function bidiClosure() {
  42413. // Character types for symbols from 0000 to 00FF.
  42414. var baseTypes = [
  42415. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  42416. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42417. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  42418. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  42419. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  42420. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42421. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  42422. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42423. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42424. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  42425. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42426. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42427. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  42428. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  42429. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42430. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42431. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42432. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42433. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  42434. ];
  42435. // Character types for symbols from 0600 to 06FF
  42436. var arabicTypes = [
  42437. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42438. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  42439. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42440. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42441. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42442. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42443. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  42444. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  42445. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  42446. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  42447. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42448. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42449. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42450. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42451. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42452. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42453. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42454. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42455. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  42456. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  42457. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42458. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  42459. ];
  42460. function isOdd(i) {
  42461. return (i & 1) !== 0;
  42462. }
  42463. function isEven(i) {
  42464. return (i & 1) === 0;
  42465. }
  42466. function findUnequal(arr, start, value) {
  42467. for (var j = start, jj = arr.length; j < jj; ++j) {
  42468. if (arr[j] !== value) {
  42469. return j;
  42470. }
  42471. }
  42472. return j;
  42473. }
  42474. function setValues(arr, start, end, value) {
  42475. for (var j = start; j < end; ++j) {
  42476. arr[j] = value;
  42477. }
  42478. }
  42479. function reverseValues(arr, start, end) {
  42480. for (var i = start, j = end - 1; i < j; ++i, --j) {
  42481. var temp = arr[i];
  42482. arr[i] = arr[j];
  42483. arr[j] = temp;
  42484. }
  42485. }
  42486. function createBidiText(str, isLTR, vertical) {
  42487. return {
  42488. str: str,
  42489. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  42490. };
  42491. }
  42492. // These are used in bidi(), which is called frequently. We re-use them on
  42493. // each call to avoid unnecessary allocations.
  42494. var chars = [];
  42495. var types = [];
  42496. function bidi(str, startLevel, vertical) {
  42497. var isLTR = true;
  42498. var strLength = str.length;
  42499. if (strLength === 0 || vertical) {
  42500. return createBidiText(str, isLTR, vertical);
  42501. }
  42502. // Get types and fill arrays
  42503. chars.length = strLength;
  42504. types.length = strLength;
  42505. var numBidi = 0;
  42506. var i, ii;
  42507. for (i = 0; i < strLength; ++i) {
  42508. chars[i] = str.charAt(i);
  42509. var charCode = str.charCodeAt(i);
  42510. var charType = 'L';
  42511. if (charCode <= 0x00ff) {
  42512. charType = baseTypes[charCode];
  42513. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  42514. charType = 'R';
  42515. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  42516. charType = arabicTypes[charCode & 0xff];
  42517. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  42518. charType = 'AL';
  42519. }
  42520. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  42521. numBidi++;
  42522. }
  42523. types[i] = charType;
  42524. }
  42525. // Detect the bidi method
  42526. // - If there are no rtl characters then no bidi needed
  42527. // - If less than 30% chars are rtl then string is primarily ltr
  42528. // - If more than 30% chars are rtl then string is primarily rtl
  42529. if (numBidi === 0) {
  42530. isLTR = true;
  42531. return createBidiText(str, isLTR);
  42532. }
  42533. if (startLevel === -1) {
  42534. if ((strLength / numBidi) < 0.3) {
  42535. isLTR = true;
  42536. startLevel = 0;
  42537. } else {
  42538. isLTR = false;
  42539. startLevel = 1;
  42540. }
  42541. }
  42542. var levels = [];
  42543. for (i = 0; i < strLength; ++i) {
  42544. levels[i] = startLevel;
  42545. }
  42546. /*
  42547. X1-X10: skip most of this, since we are NOT doing the embeddings.
  42548. */
  42549. var e = (isOdd(startLevel) ? 'R' : 'L');
  42550. var sor = e;
  42551. var eor = sor;
  42552. /*
  42553. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  42554. type of the NSM to the type of the previous character. If the NSM is at the
  42555. start of the level run, it will get the type of sor.
  42556. */
  42557. var lastType = sor;
  42558. for (i = 0; i < strLength; ++i) {
  42559. if (types[i] === 'NSM') {
  42560. types[i] = lastType;
  42561. } else {
  42562. lastType = types[i];
  42563. }
  42564. }
  42565. /*
  42566. W2. Search backwards from each instance of a European number until the
  42567. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42568. the type of the European number to Arabic number.
  42569. */
  42570. lastType = sor;
  42571. var t;
  42572. for (i = 0; i < strLength; ++i) {
  42573. t = types[i];
  42574. if (t === 'EN') {
  42575. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42576. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42577. lastType = t;
  42578. }
  42579. }
  42580. /*
  42581. W3. Change all ALs to R.
  42582. */
  42583. for (i = 0; i < strLength; ++i) {
  42584. t = types[i];
  42585. if (t === 'AL') {
  42586. types[i] = 'R';
  42587. }
  42588. }
  42589. /*
  42590. W4. A single European separator between two European numbers changes to a
  42591. European number. A single common separator between two numbers of the same
  42592. type changes to that type:
  42593. */
  42594. for (i = 1; i < strLength - 1; ++i) {
  42595. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42596. types[i] = 'EN';
  42597. }
  42598. if (types[i] === 'CS' &&
  42599. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42600. types[i + 1] === types[i - 1]) {
  42601. types[i] = types[i - 1];
  42602. }
  42603. }
  42604. /*
  42605. W5. A sequence of European terminators adjacent to European numbers changes
  42606. to all European numbers:
  42607. */
  42608. for (i = 0; i < strLength; ++i) {
  42609. if (types[i] === 'EN') {
  42610. // do before
  42611. var j;
  42612. for (j = i - 1; j >= 0; --j) {
  42613. if (types[j] !== 'ET') {
  42614. break;
  42615. }
  42616. types[j] = 'EN';
  42617. }
  42618. // do after
  42619. for (j = i + 1; j < strLength; --j) {
  42620. if (types[j] !== 'ET') {
  42621. break;
  42622. }
  42623. types[j] = 'EN';
  42624. }
  42625. }
  42626. }
  42627. /*
  42628. W6. Otherwise, separators and terminators change to Other Neutral:
  42629. */
  42630. for (i = 0; i < strLength; ++i) {
  42631. t = types[i];
  42632. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42633. types[i] = 'ON';
  42634. }
  42635. }
  42636. /*
  42637. W7. Search backwards from each instance of a European number until the
  42638. first strong type (R, L, or sor) is found. If an L is found, then change
  42639. the type of the European number to L.
  42640. */
  42641. lastType = sor;
  42642. for (i = 0; i < strLength; ++i) {
  42643. t = types[i];
  42644. if (t === 'EN') {
  42645. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42646. } else if (t === 'R' || t === 'L') {
  42647. lastType = t;
  42648. }
  42649. }
  42650. /*
  42651. N1. A sequence of neutrals takes the direction of the surrounding strong
  42652. text if the text on both sides has the same direction. European and Arabic
  42653. numbers are treated as though they were R. Start-of-level-run (sor) and
  42654. end-of-level-run (eor) are used at level run boundaries.
  42655. */
  42656. for (i = 0; i < strLength; ++i) {
  42657. if (types[i] === 'ON') {
  42658. var end = findUnequal(types, i + 1, 'ON');
  42659. var before = sor;
  42660. if (i > 0) {
  42661. before = types[i - 1];
  42662. }
  42663. var after = eor;
  42664. if (end + 1 < strLength) {
  42665. after = types[end + 1];
  42666. }
  42667. if (before !== 'L') {
  42668. before = 'R';
  42669. }
  42670. if (after !== 'L') {
  42671. after = 'R';
  42672. }
  42673. if (before === after) {
  42674. setValues(types, i, end, before);
  42675. }
  42676. i = end - 1; // reset to end (-1 so next iteration is ok)
  42677. }
  42678. }
  42679. /*
  42680. N2. Any remaining neutrals take the embedding direction.
  42681. */
  42682. for (i = 0; i < strLength; ++i) {
  42683. if (types[i] === 'ON') {
  42684. types[i] = e;
  42685. }
  42686. }
  42687. /*
  42688. I1. For all characters with an even (left-to-right) embedding direction,
  42689. those of type R go up one level and those of type AN or EN go up two
  42690. levels.
  42691. I2. For all characters with an odd (right-to-left) embedding direction,
  42692. those of type L, EN or AN go up one level.
  42693. */
  42694. for (i = 0; i < strLength; ++i) {
  42695. t = types[i];
  42696. if (isEven(levels[i])) {
  42697. if (t === 'R') {
  42698. levels[i] += 1;
  42699. } else if (t === 'AN' || t === 'EN') {
  42700. levels[i] += 2;
  42701. }
  42702. } else { // isOdd
  42703. if (t === 'L' || t === 'AN' || t === 'EN') {
  42704. levels[i] += 1;
  42705. }
  42706. }
  42707. }
  42708. /*
  42709. L1. On each line, reset the embedding level of the following characters to
  42710. the paragraph embedding level:
  42711. segment separators,
  42712. paragraph separators,
  42713. any sequence of whitespace characters preceding a segment separator or
  42714. paragraph separator, and any sequence of white space characters at the end
  42715. of the line.
  42716. */
  42717. // don't bother as text is only single line
  42718. /*
  42719. L2. From the highest level found in the text to the lowest odd level on
  42720. each line, reverse any contiguous sequence of characters that are at that
  42721. level or higher.
  42722. */
  42723. // find highest level & lowest odd level
  42724. var highestLevel = -1;
  42725. var lowestOddLevel = 99;
  42726. var level;
  42727. for (i = 0, ii = levels.length; i < ii; ++i) {
  42728. level = levels[i];
  42729. if (highestLevel < level) {
  42730. highestLevel = level;
  42731. }
  42732. if (lowestOddLevel > level && isOdd(level)) {
  42733. lowestOddLevel = level;
  42734. }
  42735. }
  42736. // now reverse between those limits
  42737. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42738. // find segments to reverse
  42739. var start = -1;
  42740. for (i = 0, ii = levels.length; i < ii; ++i) {
  42741. if (levels[i] < level) {
  42742. if (start >= 0) {
  42743. reverseValues(chars, start, i);
  42744. start = -1;
  42745. }
  42746. } else if (start < 0) {
  42747. start = i;
  42748. }
  42749. }
  42750. if (start >= 0) {
  42751. reverseValues(chars, start, levels.length);
  42752. }
  42753. }
  42754. /*
  42755. L3. Combining marks applied to a right-to-left base character will at this
  42756. point precede their base character. If the rendering engine expects them to
  42757. follow the base characters in the final display process, then the ordering
  42758. of the marks and the base character must be reversed.
  42759. */
  42760. // don't bother for now
  42761. /*
  42762. L4. A character that possesses the mirrored property as specified by
  42763. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42764. directionality of that character is R.
  42765. */
  42766. // don't mirror as characters are already mirrored in the pdf
  42767. // Finally, return string
  42768. for (i = 0, ii = chars.length; i < ii; ++i) {
  42769. var ch = chars[i];
  42770. if (ch === '<' || ch === '>') {
  42771. chars[i] = '';
  42772. }
  42773. }
  42774. return createBidiText(chars.join(''), isLTR);
  42775. }
  42776. return bidi;
  42777. })();
  42778. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42779. // Workaround for missing math precison in JS.
  42780. var MASK_HIGH = 0xffff0000;
  42781. var MASK_LOW = 0xffff;
  42782. function MurmurHash3_64 (seed) {
  42783. var SEED = 0xc3d2e1f0;
  42784. this.h1 = seed ? seed & 0xffffffff : SEED;
  42785. this.h2 = seed ? seed & 0xffffffff : SEED;
  42786. }
  42787. var alwaysUseUint32ArrayView = false;
  42788. // old webkits have issues with non-aligned arrays
  42789. try {
  42790. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42791. } catch (e) {
  42792. alwaysUseUint32ArrayView = true;
  42793. }
  42794. MurmurHash3_64.prototype = {
  42795. update: function MurmurHash3_64_update(input) {
  42796. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42797. var i;
  42798. if (typeof input === 'string') {
  42799. var data = new Uint8Array(input.length * 2);
  42800. var length = 0;
  42801. for (i = 0; i < input.length; i++) {
  42802. var code = input.charCodeAt(i);
  42803. if (code <= 0xff) {
  42804. data[length++] = code;
  42805. }
  42806. else {
  42807. data[length++] = code >>> 8;
  42808. data[length++] = code & 0xff;
  42809. }
  42810. }
  42811. } else if (input instanceof Uint8Array) {
  42812. data = input;
  42813. length = data.length;
  42814. } else if (typeof input === 'object' && ('length' in input)) {
  42815. // processing regular arrays as well, e.g. for IE9
  42816. data = input;
  42817. length = data.length;
  42818. useUint32ArrayView = true;
  42819. } else {
  42820. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42821. 'Input must be a string or array.');
  42822. }
  42823. var blockCounts = length >> 2;
  42824. var tailLength = length - blockCounts * 4;
  42825. // we don't care about endianness here
  42826. var dataUint32 = useUint32ArrayView ?
  42827. new Uint32ArrayView(data, blockCounts) :
  42828. new Uint32Array(data.buffer, 0, blockCounts);
  42829. var k1 = 0;
  42830. var k2 = 0;
  42831. var h1 = this.h1;
  42832. var h2 = this.h2;
  42833. var C1 = 0xcc9e2d51;
  42834. var C2 = 0x1b873593;
  42835. var C1_LOW = C1 & MASK_LOW;
  42836. var C2_LOW = C2 & MASK_LOW;
  42837. for (i = 0; i < blockCounts; i++) {
  42838. if (i & 1) {
  42839. k1 = dataUint32[i];
  42840. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42841. k1 = k1 << 15 | k1 >>> 17;
  42842. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42843. h1 ^= k1;
  42844. h1 = h1 << 13 | h1 >>> 19;
  42845. h1 = h1 * 5 + 0xe6546b64;
  42846. } else {
  42847. k2 = dataUint32[i];
  42848. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42849. k2 = k2 << 15 | k2 >>> 17;
  42850. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42851. h2 ^= k2;
  42852. h2 = h2 << 13 | h2 >>> 19;
  42853. h2 = h2 * 5 + 0xe6546b64;
  42854. }
  42855. }
  42856. k1 = 0;
  42857. switch (tailLength) {
  42858. case 3:
  42859. k1 ^= data[blockCounts * 4 + 2] << 16;
  42860. /* falls through */
  42861. case 2:
  42862. k1 ^= data[blockCounts * 4 + 1] << 8;
  42863. /* falls through */
  42864. case 1:
  42865. k1 ^= data[blockCounts * 4];
  42866. /* falls through */
  42867. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42868. k1 = k1 << 15 | k1 >>> 17;
  42869. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42870. if (blockCounts & 1) {
  42871. h1 ^= k1;
  42872. } else {
  42873. h2 ^= k1;
  42874. }
  42875. }
  42876. this.h1 = h1;
  42877. this.h2 = h2;
  42878. return this;
  42879. },
  42880. hexdigest: function MurmurHash3_64_hexdigest () {
  42881. var h1 = this.h1;
  42882. var h2 = this.h2;
  42883. h1 ^= h2 >>> 1;
  42884. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42885. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42886. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42887. h1 ^= h2 >>> 1;
  42888. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42889. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42890. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42891. h1 ^= h2 >>> 1;
  42892. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42893. var hex = (arr[i] >>> 0).toString(16);
  42894. while (hex.length < 8) {
  42895. hex = '0' + hex;
  42896. }
  42897. str += hex;
  42898. }
  42899. return str;
  42900. }
  42901. };
  42902. return MurmurHash3_64;
  42903. })();
  42904. }).call((typeof window === 'undefined') ? this : window);
  42905. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42906. // workerSrc is not set -- using last script url to define default location
  42907. PDFJS.workerSrc = (function () {
  42908. 'use strict';
  42909. var scriptTagContainer = document.body ||
  42910. document.getElementsByTagName('head')[0];
  42911. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42912. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42913. })();
  42914. }