pdf.combined.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566
  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.0.1209';
  24. PDFJS.build = 'f7b3852';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgant support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  847. 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,
  848. 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,
  849. 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,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function isEmptyObj(obj) {
  875. for (var key in obj) {
  876. return false;
  877. }
  878. return true;
  879. }
  880. function isBool(v) {
  881. return typeof v === 'boolean';
  882. }
  883. function isInt(v) {
  884. return typeof v === 'number' && ((v | 0) === v);
  885. }
  886. function isNum(v) {
  887. return typeof v === 'number';
  888. }
  889. function isString(v) {
  890. return typeof v === 'string';
  891. }
  892. function isName(v) {
  893. return v instanceof Name;
  894. }
  895. function isCmd(v, cmd) {
  896. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  897. }
  898. function isDict(v, type) {
  899. if (!(v instanceof Dict)) {
  900. return false;
  901. }
  902. if (!type) {
  903. return true;
  904. }
  905. var dictType = v.get('Type');
  906. return isName(dictType) && dictType.name === type;
  907. }
  908. function isArray(v) {
  909. return v instanceof Array;
  910. }
  911. function isStream(v) {
  912. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  913. }
  914. function isArrayBuffer(v) {
  915. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  916. }
  917. function isRef(v) {
  918. return v instanceof Ref;
  919. }
  920. /**
  921. * Promise Capability object.
  922. *
  923. * @typedef {Object} PromiseCapability
  924. * @property {Promise} promise - A promise object.
  925. * @property {function} resolve - Fullfills the promise.
  926. * @property {function} reject - Rejects the promise.
  927. */
  928. /**
  929. * Creates a promise capability object.
  930. * @alias PDFJS.createPromiseCapability
  931. *
  932. * @return {PromiseCapability} A capability object contains:
  933. * - a Promise, resolve and reject methods.
  934. */
  935. function createPromiseCapability() {
  936. var capability = {};
  937. capability.promise = new Promise(function (resolve, reject) {
  938. capability.resolve = resolve;
  939. capability.reject = reject;
  940. });
  941. return capability;
  942. }
  943. PDFJS.createPromiseCapability = createPromiseCapability;
  944. /**
  945. * Polyfill for Promises:
  946. * The following promise implementation tries to generally implement the
  947. * Promise/A+ spec. Some notable differences from other promise libaries are:
  948. * - There currently isn't a seperate deferred and promise object.
  949. * - Unhandled rejections eventually show an error if they aren't handled.
  950. *
  951. * Based off of the work in:
  952. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  953. */
  954. (function PromiseClosure() {
  955. if (globalScope.Promise) {
  956. // Promises existing in the DOM/Worker, checking presence of all/resolve
  957. if (typeof globalScope.Promise.all !== 'function') {
  958. globalScope.Promise.all = function (iterable) {
  959. var count = 0, results = [], resolve, reject;
  960. var promise = new globalScope.Promise(function (resolve_, reject_) {
  961. resolve = resolve_;
  962. reject = reject_;
  963. });
  964. iterable.forEach(function (p, i) {
  965. count++;
  966. p.then(function (result) {
  967. results[i] = result;
  968. count--;
  969. if (count === 0) {
  970. resolve(results);
  971. }
  972. }, reject);
  973. });
  974. if (count === 0) {
  975. resolve(results);
  976. }
  977. return promise;
  978. };
  979. }
  980. if (typeof globalScope.Promise.resolve !== 'function') {
  981. globalScope.Promise.resolve = function (value) {
  982. return new globalScope.Promise(function (resolve) { resolve(value); });
  983. };
  984. }
  985. if (typeof globalScope.Promise.reject !== 'function') {
  986. globalScope.Promise.reject = function (reason) {
  987. return new globalScope.Promise(function (resolve, reject) {
  988. reject(reason);
  989. });
  990. };
  991. }
  992. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  993. globalScope.Promise.prototype.catch = function (onReject) {
  994. return globalScope.Promise.prototype.then(undefined, onReject);
  995. };
  996. }
  997. return;
  998. }
  999. var STATUS_PENDING = 0;
  1000. var STATUS_RESOLVED = 1;
  1001. var STATUS_REJECTED = 2;
  1002. // In an attempt to avoid silent exceptions, unhandled rejections are
  1003. // tracked and if they aren't handled in a certain amount of time an
  1004. // error is logged.
  1005. var REJECTION_TIMEOUT = 500;
  1006. var HandlerManager = {
  1007. handlers: [],
  1008. running: false,
  1009. unhandledRejections: [],
  1010. pendingRejectionCheck: false,
  1011. scheduleHandlers: function scheduleHandlers(promise) {
  1012. if (promise._status === STATUS_PENDING) {
  1013. return;
  1014. }
  1015. this.handlers = this.handlers.concat(promise._handlers);
  1016. promise._handlers = [];
  1017. if (this.running) {
  1018. return;
  1019. }
  1020. this.running = true;
  1021. setTimeout(this.runHandlers.bind(this), 0);
  1022. },
  1023. runHandlers: function runHandlers() {
  1024. var RUN_TIMEOUT = 1; // ms
  1025. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1026. while (this.handlers.length > 0) {
  1027. var handler = this.handlers.shift();
  1028. var nextStatus = handler.thisPromise._status;
  1029. var nextValue = handler.thisPromise._value;
  1030. try {
  1031. if (nextStatus === STATUS_RESOLVED) {
  1032. if (typeof handler.onResolve === 'function') {
  1033. nextValue = handler.onResolve(nextValue);
  1034. }
  1035. } else if (typeof handler.onReject === 'function') {
  1036. nextValue = handler.onReject(nextValue);
  1037. nextStatus = STATUS_RESOLVED;
  1038. if (handler.thisPromise._unhandledRejection) {
  1039. this.removeUnhandeledRejection(handler.thisPromise);
  1040. }
  1041. }
  1042. } catch (ex) {
  1043. nextStatus = STATUS_REJECTED;
  1044. nextValue = ex;
  1045. }
  1046. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1047. if (Date.now() >= timeoutAt) {
  1048. break;
  1049. }
  1050. }
  1051. if (this.handlers.length > 0) {
  1052. setTimeout(this.runHandlers.bind(this), 0);
  1053. return;
  1054. }
  1055. this.running = false;
  1056. },
  1057. addUnhandledRejection: function addUnhandledRejection(promise) {
  1058. this.unhandledRejections.push({
  1059. promise: promise,
  1060. time: Date.now()
  1061. });
  1062. this.scheduleRejectionCheck();
  1063. },
  1064. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1065. promise._unhandledRejection = false;
  1066. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1067. if (this.unhandledRejections[i].promise === promise) {
  1068. this.unhandledRejections.splice(i);
  1069. i--;
  1070. }
  1071. }
  1072. },
  1073. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1074. if (this.pendingRejectionCheck) {
  1075. return;
  1076. }
  1077. this.pendingRejectionCheck = true;
  1078. setTimeout(function rejectionCheck() {
  1079. this.pendingRejectionCheck = false;
  1080. var now = Date.now();
  1081. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1082. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1083. var unhandled = this.unhandledRejections[i].promise._value;
  1084. var msg = 'Unhandled rejection: ' + unhandled;
  1085. if (unhandled.stack) {
  1086. msg += '\n' + unhandled.stack;
  1087. }
  1088. warn(msg);
  1089. this.unhandledRejections.splice(i);
  1090. i--;
  1091. }
  1092. }
  1093. if (this.unhandledRejections.length) {
  1094. this.scheduleRejectionCheck();
  1095. }
  1096. }.bind(this), REJECTION_TIMEOUT);
  1097. }
  1098. };
  1099. function Promise(resolver) {
  1100. this._status = STATUS_PENDING;
  1101. this._handlers = [];
  1102. try {
  1103. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1104. } catch (e) {
  1105. this._reject(e);
  1106. }
  1107. }
  1108. /**
  1109. * Builds a promise that is resolved when all the passed in promises are
  1110. * resolved.
  1111. * @param {array} array of data and/or promises to wait for.
  1112. * @return {Promise} New dependant promise.
  1113. */
  1114. Promise.all = function Promise_all(promises) {
  1115. var resolveAll, rejectAll;
  1116. var deferred = new Promise(function (resolve, reject) {
  1117. resolveAll = resolve;
  1118. rejectAll = reject;
  1119. });
  1120. var unresolved = promises.length;
  1121. var results = [];
  1122. if (unresolved === 0) {
  1123. resolveAll(results);
  1124. return deferred;
  1125. }
  1126. function reject(reason) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results = [];
  1131. rejectAll(reason);
  1132. }
  1133. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1134. var promise = promises[i];
  1135. var resolve = (function(i) {
  1136. return function(value) {
  1137. if (deferred._status === STATUS_REJECTED) {
  1138. return;
  1139. }
  1140. results[i] = value;
  1141. unresolved--;
  1142. if (unresolved === 0) {
  1143. resolveAll(results);
  1144. }
  1145. };
  1146. })(i);
  1147. if (Promise.isPromise(promise)) {
  1148. promise.then(resolve, reject);
  1149. } else {
  1150. resolve(promise);
  1151. }
  1152. }
  1153. return deferred;
  1154. };
  1155. /**
  1156. * Checks if the value is likely a promise (has a 'then' function).
  1157. * @return {boolean} true if value is thenable
  1158. */
  1159. Promise.isPromise = function Promise_isPromise(value) {
  1160. return value && typeof value.then === 'function';
  1161. };
  1162. /**
  1163. * Creates resolved promise
  1164. * @param value resolve value
  1165. * @returns {Promise}
  1166. */
  1167. Promise.resolve = function Promise_resolve(value) {
  1168. return new Promise(function (resolve) { resolve(value); });
  1169. };
  1170. /**
  1171. * Creates rejected promise
  1172. * @param reason rejection value
  1173. * @returns {Promise}
  1174. */
  1175. Promise.reject = function Promise_reject(reason) {
  1176. return new Promise(function (resolve, reject) { reject(reason); });
  1177. };
  1178. Promise.prototype = {
  1179. _status: null,
  1180. _value: null,
  1181. _handlers: null,
  1182. _unhandledRejection: null,
  1183. _updateStatus: function Promise__updateStatus(status, value) {
  1184. if (this._status === STATUS_RESOLVED ||
  1185. this._status === STATUS_REJECTED) {
  1186. return;
  1187. }
  1188. if (status === STATUS_RESOLVED &&
  1189. Promise.isPromise(value)) {
  1190. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1191. this._updateStatus.bind(this, STATUS_REJECTED));
  1192. return;
  1193. }
  1194. this._status = status;
  1195. this._value = value;
  1196. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1197. this._unhandledRejection = true;
  1198. HandlerManager.addUnhandledRejection(this);
  1199. }
  1200. HandlerManager.scheduleHandlers(this);
  1201. },
  1202. _resolve: function Promise_resolve(value) {
  1203. this._updateStatus(STATUS_RESOLVED, value);
  1204. },
  1205. _reject: function Promise_reject(reason) {
  1206. this._updateStatus(STATUS_REJECTED, reason);
  1207. },
  1208. then: function Promise_then(onResolve, onReject) {
  1209. var nextPromise = new Promise(function (resolve, reject) {
  1210. this.resolve = resolve;
  1211. this.reject = reject;
  1212. });
  1213. this._handlers.push({
  1214. thisPromise: this,
  1215. onResolve: onResolve,
  1216. onReject: onReject,
  1217. nextPromise: nextPromise
  1218. });
  1219. HandlerManager.scheduleHandlers(this);
  1220. return nextPromise;
  1221. },
  1222. catch: function Promise_catch(onReject) {
  1223. return this.then(undefined, onReject);
  1224. }
  1225. };
  1226. globalScope.Promise = Promise;
  1227. })();
  1228. var StatTimer = (function StatTimerClosure() {
  1229. function rpad(str, pad, length) {
  1230. while (str.length < length) {
  1231. str += pad;
  1232. }
  1233. return str;
  1234. }
  1235. function StatTimer() {
  1236. this.started = {};
  1237. this.times = [];
  1238. this.enabled = true;
  1239. }
  1240. StatTimer.prototype = {
  1241. time: function StatTimer_time(name) {
  1242. if (!this.enabled) {
  1243. return;
  1244. }
  1245. if (name in this.started) {
  1246. warn('Timer is already running for ' + name);
  1247. }
  1248. this.started[name] = Date.now();
  1249. },
  1250. timeEnd: function StatTimer_timeEnd(name) {
  1251. if (!this.enabled) {
  1252. return;
  1253. }
  1254. if (!(name in this.started)) {
  1255. warn('Timer has not been started for ' + name);
  1256. }
  1257. this.times.push({
  1258. 'name': name,
  1259. 'start': this.started[name],
  1260. 'end': Date.now()
  1261. });
  1262. // Remove timer from started so it can be called again.
  1263. delete this.started[name];
  1264. },
  1265. toString: function StatTimer_toString() {
  1266. var i, ii;
  1267. var times = this.times;
  1268. var out = '';
  1269. // Find the longest name for padding purposes.
  1270. var longest = 0;
  1271. for (i = 0, ii = times.length; i < ii; ++i) {
  1272. var name = times[i]['name'];
  1273. if (name.length > longest) {
  1274. longest = name.length;
  1275. }
  1276. }
  1277. for (i = 0, ii = times.length; i < ii; ++i) {
  1278. var span = times[i];
  1279. var duration = span.end - span.start;
  1280. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1281. }
  1282. return out;
  1283. }
  1284. };
  1285. return StatTimer;
  1286. })();
  1287. PDFJS.createBlob = function createBlob(data, contentType) {
  1288. if (typeof Blob !== 'undefined') {
  1289. return new Blob([data], { type: contentType });
  1290. }
  1291. // Blob builder is deprecated in FF14 and removed in FF18.
  1292. var bb = new MozBlobBuilder();
  1293. bb.append(data);
  1294. return bb.getBlob(contentType);
  1295. };
  1296. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1297. // Blob/createObjectURL is not available, falling back to data schema.
  1298. var digits =
  1299. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1300. return function createObjectURL(data, contentType) {
  1301. if (!PDFJS.disableCreateObjectURL &&
  1302. typeof URL !== 'undefined' && URL.createObjectURL) {
  1303. var blob = PDFJS.createBlob(data, contentType);
  1304. return URL.createObjectURL(blob);
  1305. }
  1306. var buffer = 'data:' + contentType + ';base64,';
  1307. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1308. var b1 = data[i] & 0xFF;
  1309. var b2 = data[i + 1] & 0xFF;
  1310. var b3 = data[i + 2] & 0xFF;
  1311. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1312. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1313. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1314. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1315. }
  1316. return buffer;
  1317. };
  1318. })();
  1319. function MessageHandler(name, comObj) {
  1320. this.name = name;
  1321. this.comObj = comObj;
  1322. this.callbackIndex = 1;
  1323. this.postMessageTransfers = true;
  1324. var callbacksCapabilities = this.callbacksCapabilities = {};
  1325. var ah = this.actionHandler = {};
  1326. ah['console_log'] = [function ahConsoleLog(data) {
  1327. console.log.apply(console, data);
  1328. }];
  1329. ah['console_error'] = [function ahConsoleError(data) {
  1330. console.error.apply(console, data);
  1331. }];
  1332. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1333. UnsupportedManager.notify(data);
  1334. }];
  1335. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1336. var data = event.data;
  1337. if (data.isReply) {
  1338. var callbackId = data.callbackId;
  1339. if (data.callbackId in callbacksCapabilities) {
  1340. var callback = callbacksCapabilities[callbackId];
  1341. delete callbacksCapabilities[callbackId];
  1342. if ('error' in data) {
  1343. callback.reject(data.error);
  1344. } else {
  1345. callback.resolve(data.data);
  1346. }
  1347. } else {
  1348. error('Cannot resolve callback ' + callbackId);
  1349. }
  1350. } else if (data.action in ah) {
  1351. var action = ah[data.action];
  1352. if (data.callbackId) {
  1353. Promise.resolve().then(function () {
  1354. return action[0].call(action[1], data.data);
  1355. }).then(function (result) {
  1356. comObj.postMessage({
  1357. isReply: true,
  1358. callbackId: data.callbackId,
  1359. data: result
  1360. });
  1361. }, function (reason) {
  1362. comObj.postMessage({
  1363. isReply: true,
  1364. callbackId: data.callbackId,
  1365. error: reason
  1366. });
  1367. });
  1368. } else {
  1369. action[0].call(action[1], data.data);
  1370. }
  1371. } else {
  1372. error('Unknown action from worker: ' + data.action);
  1373. }
  1374. };
  1375. }
  1376. MessageHandler.prototype = {
  1377. on: function messageHandlerOn(actionName, handler, scope) {
  1378. var ah = this.actionHandler;
  1379. if (ah[actionName]) {
  1380. error('There is already an actionName called "' + actionName + '"');
  1381. }
  1382. ah[actionName] = [handler, scope];
  1383. },
  1384. /**
  1385. * Sends a message to the comObj to invoke the action with the supplied data.
  1386. * @param {String} actionName Action to call.
  1387. * @param {JSON} data JSON data to send.
  1388. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1389. */
  1390. send: function messageHandlerSend(actionName, data, transfers) {
  1391. var message = {
  1392. action: actionName,
  1393. data: data
  1394. };
  1395. this.postMessage(message, transfers);
  1396. },
  1397. /**
  1398. * Sends a message to the comObj to invoke the action with the supplied data.
  1399. * Expects that other side will callback with the response.
  1400. * @param {String} actionName Action to call.
  1401. * @param {JSON} data JSON data to send.
  1402. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1403. * @returns {Promise} Promise to be resolved with response data.
  1404. */
  1405. sendWithPromise:
  1406. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1407. var callbackId = this.callbackIndex++;
  1408. var message = {
  1409. action: actionName,
  1410. data: data,
  1411. callbackId: callbackId
  1412. };
  1413. var capability = createPromiseCapability();
  1414. this.callbacksCapabilities[callbackId] = capability;
  1415. try {
  1416. this.postMessage(message, transfers);
  1417. } catch (e) {
  1418. capability.reject(e);
  1419. }
  1420. return capability.promise;
  1421. },
  1422. /**
  1423. * Sends raw message to the comObj.
  1424. * @private
  1425. * @param message {Object} Raw message.
  1426. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1427. */
  1428. postMessage: function (message, transfers) {
  1429. if (transfers && this.postMessageTransfers) {
  1430. this.comObj.postMessage(message, transfers);
  1431. } else {
  1432. this.comObj.postMessage(message);
  1433. }
  1434. }
  1435. };
  1436. function loadJpegStream(id, imageUrl, objs) {
  1437. var img = new Image();
  1438. img.onload = (function loadJpegStream_onloadClosure() {
  1439. objs.resolve(id, img);
  1440. });
  1441. img.onerror = (function loadJpegStream_onerrorClosure() {
  1442. objs.resolve(id, null);
  1443. warn('Error during JPEG image loading');
  1444. });
  1445. img.src = imageUrl;
  1446. }
  1447. /**
  1448. * The maximum allowed image size in total pixels e.g. width * height. Images
  1449. * above this value will not be drawn. Use -1 for no limit.
  1450. * @var {number}
  1451. */
  1452. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1453. -1 : PDFJS.maxImageSize);
  1454. /**
  1455. * The url of where the predefined Adobe CMaps are located. Include trailing
  1456. * slash.
  1457. * @var {string}
  1458. */
  1459. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1460. /**
  1461. * Specifies if CMaps are binary packed.
  1462. * @var {boolean}
  1463. */
  1464. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1465. /**
  1466. * By default fonts are converted to OpenType fonts and loaded via font face
  1467. * rules. If disabled, the font will be rendered using a built in font renderer
  1468. * that constructs the glyphs with primitive path commands.
  1469. * @var {boolean}
  1470. */
  1471. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1472. false : PDFJS.disableFontFace);
  1473. /**
  1474. * Path for image resources, mainly for annotation icons. Include trailing
  1475. * slash.
  1476. * @var {string}
  1477. */
  1478. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1479. '' : PDFJS.imageResourcesPath);
  1480. /**
  1481. * Disable the web worker and run all code on the main thread. This will happen
  1482. * automatically if the browser doesn't support workers or sending typed arrays
  1483. * to workers.
  1484. * @var {boolean}
  1485. */
  1486. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1487. false : PDFJS.disableWorker);
  1488. /**
  1489. * Path and filename of the worker file. Required when the worker is enabled in
  1490. * development mode. If unspecified in the production build, the worker will be
  1491. * loaded based on the location of the pdf.js file.
  1492. * @var {string}
  1493. */
  1494. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1495. /**
  1496. * Disable range request loading of PDF files. When enabled and if the server
  1497. * supports partial content requests then the PDF will be fetched in chunks.
  1498. * Enabled (false) by default.
  1499. * @var {boolean}
  1500. */
  1501. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1502. false : PDFJS.disableRange);
  1503. /**
  1504. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1505. * in chunks. This default behavior can be disabled.
  1506. * @var {boolean}
  1507. */
  1508. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1509. false : PDFJS.disableStream);
  1510. /**
  1511. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1512. * will automatically keep fetching more data even if it isn't needed to display
  1513. * the current page. This default behavior can be disabled.
  1514. *
  1515. * NOTE: It is also necessary to disable streaming, see above,
  1516. * in order for disabling of pre-fetching to work correctly.
  1517. * @var {boolean}
  1518. */
  1519. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1520. false : PDFJS.disableAutoFetch);
  1521. /**
  1522. * Enables special hooks for debugging PDF.js.
  1523. * @var {boolean}
  1524. */
  1525. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1526. /**
  1527. * Enables transfer usage in postMessage for ArrayBuffers.
  1528. * @var {boolean}
  1529. */
  1530. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1531. true : PDFJS.postMessageTransfers);
  1532. /**
  1533. * Disables URL.createObjectURL usage.
  1534. * @var {boolean}
  1535. */
  1536. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1537. false : PDFJS.disableCreateObjectURL);
  1538. /**
  1539. * Disables WebGL usage.
  1540. * @var {boolean}
  1541. */
  1542. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1543. true : PDFJS.disableWebGL);
  1544. /**
  1545. * Disables fullscreen support, and by extension Presentation Mode,
  1546. * in browsers which support the fullscreen API.
  1547. * @var {boolean}
  1548. */
  1549. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1550. false : PDFJS.disableFullscreen);
  1551. /**
  1552. * Enables CSS only zooming.
  1553. * @var {boolean}
  1554. */
  1555. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1556. false : PDFJS.useOnlyCssZoom);
  1557. /**
  1558. * Controls the logging level.
  1559. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1560. * - errors
  1561. * - warnings [default]
  1562. * - infos
  1563. * @var {number}
  1564. */
  1565. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1566. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1567. /**
  1568. * The maximum supported canvas size in total pixels e.g. width * height.
  1569. * The default value is 4096 * 4096. Use -1 for no limit.
  1570. * @var {number}
  1571. */
  1572. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1573. 16777216 : PDFJS.maxCanvasPixels);
  1574. /**
  1575. * Opens external links in a new window if enabled. The default behavior opens
  1576. * external links in the PDF.js window.
  1577. * @var {boolean}
  1578. */
  1579. PDFJS.openExternalLinksInNewWindow = (
  1580. PDFJS.openExternalLinksInNewWindow === undefined ?
  1581. false : PDFJS.openExternalLinksInNewWindow);
  1582. /**
  1583. * Document initialization / loading parameters object.
  1584. *
  1585. * @typedef {Object} DocumentInitParameters
  1586. * @property {string} url - The URL of the PDF.
  1587. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1588. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1589. * use atob() to convert it to a binary string first.
  1590. * @property {Object} httpHeaders - Basic authentication headers.
  1591. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1592. * Access-Control requests should be made using credentials such as cookies
  1593. * or authorization headers. The default is false.
  1594. * @property {string} password - For decrypting password-protected PDFs.
  1595. * @property {TypedArray} initialData - A typed array with the first portion or
  1596. * all of the pdf data. Used by the extension since some data is already
  1597. * loaded before the switch to range requests.
  1598. * @property {number} length - The PDF file length. It's used for progress
  1599. * reports and range requests operations.
  1600. * @property {PDFDataRangeTransport} range
  1601. */
  1602. /**
  1603. * @typedef {Object} PDFDocumentStats
  1604. * @property {Array} streamTypes - Used stream types in the document (an item
  1605. * is set to true if specific stream ID was used in the document).
  1606. * @property {Array} fontTypes - Used font type in the document (an item is set
  1607. * to true if specific font ID was used in the document).
  1608. */
  1609. /**
  1610. * This is the main entry point for loading a PDF and interacting with it.
  1611. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1612. * is used, which means it must follow the same origin rules that any XHR does
  1613. * e.g. No cross domain requests without CORS.
  1614. *
  1615. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1616. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1617. * already populated with data or parameter object.
  1618. *
  1619. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1620. * if you want to manually serve range requests for data in the PDF.
  1621. *
  1622. * @param {function} passwordCallback (deprecated) It is used to request a
  1623. * password if wrong or no password was provided. The callback receives two
  1624. * parameters: function that needs to be called with new password and reason
  1625. * (see {PasswordResponses}).
  1626. *
  1627. * @param {function} progressCallback (deprecated) It is used to be able to
  1628. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1629. * a loading bar). The callback receives an {Object} with the properties:
  1630. * {number} loaded and {number} total.
  1631. *
  1632. * @return {PDFDocumentLoadingTask}
  1633. */
  1634. PDFJS.getDocument = function getDocument(src,
  1635. pdfDataRangeTransport,
  1636. passwordCallback,
  1637. progressCallback) {
  1638. var task = new PDFDocumentLoadingTask();
  1639. // Support of the obsolete arguments (for compatibility with API v1.0)
  1640. if (pdfDataRangeTransport) {
  1641. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1642. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1643. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1644. pdfDataRangeTransport.length = src.length;
  1645. pdfDataRangeTransport.initialData = src.initialData;
  1646. }
  1647. src = Object.create(src);
  1648. src.range = pdfDataRangeTransport;
  1649. }
  1650. task.onPassword = passwordCallback || null;
  1651. task.onProgress = progressCallback || null;
  1652. var workerInitializedCapability, transport;
  1653. var source;
  1654. if (typeof src === 'string') {
  1655. source = { url: src };
  1656. } else if (isArrayBuffer(src)) {
  1657. source = { data: src };
  1658. } else if (src instanceof PDFDataRangeTransport) {
  1659. source = { range: src };
  1660. } else {
  1661. if (typeof src !== 'object') {
  1662. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1663. 'string or a parameter object');
  1664. }
  1665. if (!src.url && !src.data && !src.range) {
  1666. error('Invalid parameter object: need either .data, .range or .url');
  1667. }
  1668. source = src;
  1669. }
  1670. var params = {};
  1671. for (var key in source) {
  1672. if (key === 'url' && typeof window !== 'undefined') {
  1673. // The full path is required in the 'url' field.
  1674. params[key] = combineUrl(window.location.href, source[key]);
  1675. continue;
  1676. } else if (key === 'range') {
  1677. continue;
  1678. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1679. // Converting string or array-like data to Uint8Array.
  1680. var pdfBytes = source[key];
  1681. if (typeof pdfBytes === 'string') {
  1682. params[key] = stringToBytes(pdfBytes);
  1683. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1684. !isNaN(pdfBytes.length)) {
  1685. params[key] = new Uint8Array(pdfBytes);
  1686. } else {
  1687. error('Invalid PDF binary data: either typed array, string or ' +
  1688. 'array-like object is expected in the data property.');
  1689. }
  1690. continue;
  1691. }
  1692. params[key] = source[key];
  1693. }
  1694. workerInitializedCapability = createPromiseCapability();
  1695. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1696. workerInitializedCapability.promise.then(function transportInitialized() {
  1697. transport.fetchDocument(task, params);
  1698. });
  1699. return task;
  1700. };
  1701. /**
  1702. * PDF document loading operation.
  1703. * @class
  1704. */
  1705. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1706. /** @constructs PDFDocumentLoadingTask */
  1707. function PDFDocumentLoadingTask() {
  1708. this._capability = createPromiseCapability();
  1709. /**
  1710. * Callback to request a password if wrong or no password was provided.
  1711. * The callback receives two parameters: function that needs to be called
  1712. * with new password and reason (see {PasswordResponses}).
  1713. */
  1714. this.onPassword = null;
  1715. /**
  1716. * Callback to be able to monitor the loading progress of the PDF file
  1717. * (necessary to implement e.g. a loading bar). The callback receives
  1718. * an {Object} with the properties: {number} loaded and {number} total.
  1719. */
  1720. this.onProgress = null;
  1721. }
  1722. PDFDocumentLoadingTask.prototype =
  1723. /** @lends PDFDocumentLoadingTask.prototype */ {
  1724. /**
  1725. * @return {Promise}
  1726. */
  1727. get promise() {
  1728. return this._capability.promise;
  1729. },
  1730. // TODO add cancel or abort method
  1731. /**
  1732. * Registers callbacks to indicate the document loading completion.
  1733. *
  1734. * @param {function} onFulfilled The callback for the loading completion.
  1735. * @param {function} onRejected The callback for the loading failure.
  1736. * @return {Promise} A promise that is resolved after the onFulfilled or
  1737. * onRejected callback.
  1738. */
  1739. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1740. return this.promise.then.apply(this.promise, arguments);
  1741. }
  1742. };
  1743. return PDFDocumentLoadingTask;
  1744. })();
  1745. /**
  1746. * Abstract class to support range requests file loading.
  1747. * @class
  1748. */
  1749. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1750. /**
  1751. * @constructs PDFDataRangeTransport
  1752. * @param {number} length
  1753. * @param {Uint8Array} initialData
  1754. */
  1755. function PDFDataRangeTransport(length, initialData) {
  1756. this.length = length;
  1757. this.initialData = initialData;
  1758. this._rangeListeners = [];
  1759. this._progressListeners = [];
  1760. this._progressiveReadListeners = [];
  1761. this._readyCapability = createPromiseCapability();
  1762. }
  1763. PDFDataRangeTransport.prototype =
  1764. /** @lends PDFDataRangeTransport.prototype */ {
  1765. addRangeListener:
  1766. function PDFDataRangeTransport_addRangeListener(listener) {
  1767. this._rangeListeners.push(listener);
  1768. },
  1769. addProgressListener:
  1770. function PDFDataRangeTransport_addProgressListener(listener) {
  1771. this._progressListeners.push(listener);
  1772. },
  1773. addProgressiveReadListener:
  1774. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1775. this._progressiveReadListeners.push(listener);
  1776. },
  1777. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1778. var listeners = this._rangeListeners;
  1779. for (var i = 0, n = listeners.length; i < n; ++i) {
  1780. listeners[i](begin, chunk);
  1781. }
  1782. },
  1783. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1784. this._readyCapability.promise.then(function () {
  1785. var listeners = this._progressListeners;
  1786. for (var i = 0, n = listeners.length; i < n; ++i) {
  1787. listeners[i](loaded);
  1788. }
  1789. }.bind(this));
  1790. },
  1791. onDataProgressiveRead:
  1792. function PDFDataRangeTransport_onDataProgress(chunk) {
  1793. this._readyCapability.promise.then(function () {
  1794. var listeners = this._progressiveReadListeners;
  1795. for (var i = 0, n = listeners.length; i < n; ++i) {
  1796. listeners[i](chunk);
  1797. }
  1798. }.bind(this));
  1799. },
  1800. transportReady: function PDFDataRangeTransport_transportReady() {
  1801. this._readyCapability.resolve();
  1802. },
  1803. requestDataRange:
  1804. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1805. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1806. }
  1807. };
  1808. return PDFDataRangeTransport;
  1809. })();
  1810. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1811. /**
  1812. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1813. * properties that can be read synchronously.
  1814. * @class
  1815. */
  1816. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1817. function PDFDocumentProxy(pdfInfo, transport) {
  1818. this.pdfInfo = pdfInfo;
  1819. this.transport = transport;
  1820. }
  1821. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1822. /**
  1823. * @return {number} Total number of pages the PDF contains.
  1824. */
  1825. get numPages() {
  1826. return this.pdfInfo.numPages;
  1827. },
  1828. /**
  1829. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1830. * unique.
  1831. */
  1832. get fingerprint() {
  1833. return this.pdfInfo.fingerprint;
  1834. },
  1835. /**
  1836. * @param {number} pageNumber The page number to get. The first page is 1.
  1837. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1838. * object.
  1839. */
  1840. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1841. return this.transport.getPage(pageNumber);
  1842. },
  1843. /**
  1844. * @param {{num: number, gen: number}} ref The page reference. Must have
  1845. * the 'num' and 'gen' properties.
  1846. * @return {Promise} A promise that is resolved with the page index that is
  1847. * associated with the reference.
  1848. */
  1849. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1850. return this.transport.getPageIndex(ref);
  1851. },
  1852. /**
  1853. * @return {Promise} A promise that is resolved with a lookup table for
  1854. * mapping named destinations to reference numbers.
  1855. *
  1856. * This can be slow for large documents: use getDestination instead
  1857. */
  1858. getDestinations: function PDFDocumentProxy_getDestinations() {
  1859. return this.transport.getDestinations();
  1860. },
  1861. /**
  1862. * @param {string} id The named destination to get.
  1863. * @return {Promise} A promise that is resolved with all information
  1864. * of the given named destination.
  1865. */
  1866. getDestination: function PDFDocumentProxy_getDestination(id) {
  1867. return this.transport.getDestination(id);
  1868. },
  1869. /**
  1870. * @return {Promise} A promise that is resolved with a lookup table for
  1871. * mapping named attachments to their content.
  1872. */
  1873. getAttachments: function PDFDocumentProxy_getAttachments() {
  1874. return this.transport.getAttachments();
  1875. },
  1876. /**
  1877. * @return {Promise} A promise that is resolved with an array of all the
  1878. * JavaScript strings in the name tree.
  1879. */
  1880. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1881. return this.transport.getJavaScript();
  1882. },
  1883. /**
  1884. * @return {Promise} A promise that is resolved with an {Array} that is a
  1885. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1886. * [
  1887. * {
  1888. * title: string,
  1889. * bold: boolean,
  1890. * italic: boolean,
  1891. * color: rgb array,
  1892. * dest: dest obj,
  1893. * items: array of more items like this
  1894. * },
  1895. * ...
  1896. * ].
  1897. */
  1898. getOutline: function PDFDocumentProxy_getOutline() {
  1899. return this.transport.getOutline();
  1900. },
  1901. /**
  1902. * @return {Promise} A promise that is resolved with an {Object} that has
  1903. * info and metadata properties. Info is an {Object} filled with anything
  1904. * available in the information dictionary and similarly metadata is a
  1905. * {Metadata} object with information from the metadata section of the PDF.
  1906. */
  1907. getMetadata: function PDFDocumentProxy_getMetadata() {
  1908. return this.transport.getMetadata();
  1909. },
  1910. /**
  1911. * @return {Promise} A promise that is resolved with a TypedArray that has
  1912. * the raw data from the PDF.
  1913. */
  1914. getData: function PDFDocumentProxy_getData() {
  1915. return this.transport.getData();
  1916. },
  1917. /**
  1918. * @return {Promise} A promise that is resolved when the document's data
  1919. * is loaded. It is resolved with an {Object} that contains the length
  1920. * property that indicates size of the PDF data in bytes.
  1921. */
  1922. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1923. return this.transport.downloadInfoCapability.promise;
  1924. },
  1925. /**
  1926. * @return {Promise} A promise this is resolved with current stats about
  1927. * document structures (see {@link PDFDocumentStats}).
  1928. */
  1929. getStats: function PDFDocumentProxy_getStats() {
  1930. return this.transport.getStats();
  1931. },
  1932. /**
  1933. * Cleans up resources allocated by the document, e.g. created @font-face.
  1934. */
  1935. cleanup: function PDFDocumentProxy_cleanup() {
  1936. this.transport.startCleanup();
  1937. },
  1938. /**
  1939. * Destroys current document instance and terminates worker.
  1940. */
  1941. destroy: function PDFDocumentProxy_destroy() {
  1942. this.transport.destroy();
  1943. }
  1944. };
  1945. return PDFDocumentProxy;
  1946. })();
  1947. /**
  1948. * Page text content.
  1949. *
  1950. * @typedef {Object} TextContent
  1951. * @property {array} items - array of {@link TextItem}
  1952. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1953. * name.
  1954. */
  1955. /**
  1956. * Page text content part.
  1957. *
  1958. * @typedef {Object} TextItem
  1959. * @property {string} str - text content.
  1960. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1961. * @property {array} transform - transformation matrix.
  1962. * @property {number} width - width in device space.
  1963. * @property {number} height - height in device space.
  1964. * @property {string} fontName - font name used by pdf.js for converted font.
  1965. */
  1966. /**
  1967. * Text style.
  1968. *
  1969. * @typedef {Object} TextStyle
  1970. * @property {number} ascent - font ascent.
  1971. * @property {number} descent - font descent.
  1972. * @property {boolean} vertical - text is in vertical mode.
  1973. * @property {string} fontFamily - possible font family
  1974. */
  1975. /**
  1976. * Page render parameters.
  1977. *
  1978. * @typedef {Object} RenderParameters
  1979. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1980. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1981. * calling of PDFPage.getViewport method.
  1982. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1983. * (default value is 'display').
  1984. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1985. * endLayout and appendImage functions.
  1986. * @property {function} continueCallback - (deprecated) A function that will be
  1987. * called each time the rendering is paused. To continue
  1988. * rendering call the function that is the first argument
  1989. * to the callback.
  1990. */
  1991. /**
  1992. * PDF page operator list.
  1993. *
  1994. * @typedef {Object} PDFOperatorList
  1995. * @property {Array} fnArray - Array containing the operator functions.
  1996. * @property {Array} argsArray - Array containing the arguments of the
  1997. * functions.
  1998. */
  1999. /**
  2000. * Proxy to a PDFPage in the worker thread.
  2001. * @class
  2002. */
  2003. var PDFPageProxy = (function PDFPageProxyClosure() {
  2004. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2005. this.pageIndex = pageIndex;
  2006. this.pageInfo = pageInfo;
  2007. this.transport = transport;
  2008. this.stats = new StatTimer();
  2009. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2010. this.commonObjs = transport.commonObjs;
  2011. this.objs = new PDFObjects();
  2012. this.cleanupAfterRender = false;
  2013. this.pendingDestroy = false;
  2014. this.intentStates = {};
  2015. }
  2016. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2017. /**
  2018. * @return {number} Page number of the page. First page is 1.
  2019. */
  2020. get pageNumber() {
  2021. return this.pageIndex + 1;
  2022. },
  2023. /**
  2024. * @return {number} The number of degrees the page is rotated clockwise.
  2025. */
  2026. get rotate() {
  2027. return this.pageInfo.rotate;
  2028. },
  2029. /**
  2030. * @return {Object} The reference that points to this page. It has 'num' and
  2031. * 'gen' properties.
  2032. */
  2033. get ref() {
  2034. return this.pageInfo.ref;
  2035. },
  2036. /**
  2037. * @return {Array} An array of the visible portion of the PDF page in the
  2038. * user space units - [x1, y1, x2, y2].
  2039. */
  2040. get view() {
  2041. return this.pageInfo.view;
  2042. },
  2043. /**
  2044. * @param {number} scale The desired scale of the viewport.
  2045. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2046. * defaults to the page rotation.
  2047. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2048. * along with transforms required for rendering.
  2049. */
  2050. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2051. if (arguments.length < 2) {
  2052. rotate = this.rotate;
  2053. }
  2054. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2055. },
  2056. /**
  2057. * @return {Promise} A promise that is resolved with an {Array} of the
  2058. * annotation objects.
  2059. */
  2060. getAnnotations: function PDFPageProxy_getAnnotations() {
  2061. if (this.annotationsPromise) {
  2062. return this.annotationsPromise;
  2063. }
  2064. var promise = this.transport.getAnnotations(this.pageIndex);
  2065. this.annotationsPromise = promise;
  2066. return promise;
  2067. },
  2068. /**
  2069. * Begins the process of rendering a page to the desired context.
  2070. * @param {RenderParameters} params Page render parameters.
  2071. * @return {RenderTask} An object that contains the promise, which
  2072. * is resolved when the page finishes rendering.
  2073. */
  2074. render: function PDFPageProxy_render(params) {
  2075. var stats = this.stats;
  2076. stats.time('Overall');
  2077. // If there was a pending destroy cancel it so no cleanup happens during
  2078. // this call to render.
  2079. this.pendingDestroy = false;
  2080. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2081. if (!this.intentStates[renderingIntent]) {
  2082. this.intentStates[renderingIntent] = {};
  2083. }
  2084. var intentState = this.intentStates[renderingIntent];
  2085. // If there's no displayReadyCapability yet, then the operatorList
  2086. // was never requested before. Make the request and create the promise.
  2087. if (!intentState.displayReadyCapability) {
  2088. intentState.receivingOperatorList = true;
  2089. intentState.displayReadyCapability = createPromiseCapability();
  2090. intentState.operatorList = {
  2091. fnArray: [],
  2092. argsArray: [],
  2093. lastChunk: false
  2094. };
  2095. this.stats.time('Page Request');
  2096. this.transport.messageHandler.send('RenderPageRequest', {
  2097. pageIndex: this.pageNumber - 1,
  2098. intent: renderingIntent
  2099. });
  2100. }
  2101. var internalRenderTask = new InternalRenderTask(complete, params,
  2102. this.objs,
  2103. this.commonObjs,
  2104. intentState.operatorList,
  2105. this.pageNumber);
  2106. if (!intentState.renderTasks) {
  2107. intentState.renderTasks = [];
  2108. }
  2109. intentState.renderTasks.push(internalRenderTask);
  2110. var renderTask = internalRenderTask.task;
  2111. // Obsolete parameter support
  2112. if (params.continueCallback) {
  2113. renderTask.onContinue = params.continueCallback;
  2114. }
  2115. var self = this;
  2116. intentState.displayReadyCapability.promise.then(
  2117. function pageDisplayReadyPromise(transparency) {
  2118. if (self.pendingDestroy) {
  2119. complete();
  2120. return;
  2121. }
  2122. stats.time('Rendering');
  2123. internalRenderTask.initalizeGraphics(transparency);
  2124. internalRenderTask.operatorListChanged();
  2125. },
  2126. function pageDisplayReadPromiseError(reason) {
  2127. complete(reason);
  2128. }
  2129. );
  2130. function complete(error) {
  2131. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2132. if (i >= 0) {
  2133. intentState.renderTasks.splice(i, 1);
  2134. }
  2135. if (self.cleanupAfterRender) {
  2136. self.pendingDestroy = true;
  2137. }
  2138. self._tryDestroy();
  2139. if (error) {
  2140. internalRenderTask.capability.reject(error);
  2141. } else {
  2142. internalRenderTask.capability.resolve();
  2143. }
  2144. stats.timeEnd('Rendering');
  2145. stats.timeEnd('Overall');
  2146. }
  2147. return renderTask;
  2148. },
  2149. /**
  2150. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2151. * object that represents page's operator list.
  2152. */
  2153. getOperatorList: function PDFPageProxy_getOperatorList() {
  2154. function operatorListChanged() {
  2155. if (intentState.operatorList.lastChunk) {
  2156. intentState.opListReadCapability.resolve(intentState.operatorList);
  2157. }
  2158. }
  2159. var renderingIntent = 'oplist';
  2160. if (!this.intentStates[renderingIntent]) {
  2161. this.intentStates[renderingIntent] = {};
  2162. }
  2163. var intentState = this.intentStates[renderingIntent];
  2164. if (!intentState.opListReadCapability) {
  2165. var opListTask = {};
  2166. opListTask.operatorListChanged = operatorListChanged;
  2167. intentState.receivingOperatorList = true;
  2168. intentState.opListReadCapability = createPromiseCapability();
  2169. intentState.renderTasks = [];
  2170. intentState.renderTasks.push(opListTask);
  2171. intentState.operatorList = {
  2172. fnArray: [],
  2173. argsArray: [],
  2174. lastChunk: false
  2175. };
  2176. this.transport.messageHandler.send('RenderPageRequest', {
  2177. pageIndex: this.pageIndex,
  2178. intent: renderingIntent
  2179. });
  2180. }
  2181. return intentState.opListReadCapability.promise;
  2182. },
  2183. /**
  2184. * @return {Promise} That is resolved a {@link TextContent}
  2185. * object that represent the page text content.
  2186. */
  2187. getTextContent: function PDFPageProxy_getTextContent() {
  2188. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2189. pageIndex: this.pageNumber - 1
  2190. });
  2191. },
  2192. /**
  2193. * Destroys resources allocated by the page.
  2194. */
  2195. destroy: function PDFPageProxy_destroy() {
  2196. this.pendingDestroy = true;
  2197. this._tryDestroy();
  2198. },
  2199. /**
  2200. * For internal use only. Attempts to clean up if rendering is in a state
  2201. * where that's possible.
  2202. * @ignore
  2203. */
  2204. _tryDestroy: function PDFPageProxy__destroy() {
  2205. if (!this.pendingDestroy ||
  2206. Object.keys(this.intentStates).some(function(intent) {
  2207. var intentState = this.intentStates[intent];
  2208. return (intentState.renderTasks.length !== 0 ||
  2209. intentState.receivingOperatorList);
  2210. }, this)) {
  2211. return;
  2212. }
  2213. Object.keys(this.intentStates).forEach(function(intent) {
  2214. delete this.intentStates[intent];
  2215. }, this);
  2216. this.objs.clear();
  2217. this.annotationsPromise = null;
  2218. this.pendingDestroy = false;
  2219. },
  2220. /**
  2221. * For internal use only.
  2222. * @ignore
  2223. */
  2224. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2225. intent) {
  2226. var intentState = this.intentStates[intent];
  2227. // TODO Refactor RenderPageRequest to separate rendering
  2228. // and operator list logic
  2229. if (intentState.displayReadyCapability) {
  2230. intentState.displayReadyCapability.resolve(transparency);
  2231. }
  2232. },
  2233. /**
  2234. * For internal use only.
  2235. * @ignore
  2236. */
  2237. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2238. intent) {
  2239. var intentState = this.intentStates[intent];
  2240. var i, ii;
  2241. // Add the new chunk to the current operator list.
  2242. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2243. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2244. intentState.operatorList.argsArray.push(
  2245. operatorListChunk.argsArray[i]);
  2246. }
  2247. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2248. // Notify all the rendering tasks there are more operators to be consumed.
  2249. for (i = 0; i < intentState.renderTasks.length; i++) {
  2250. intentState.renderTasks[i].operatorListChanged();
  2251. }
  2252. if (operatorListChunk.lastChunk) {
  2253. intentState.receivingOperatorList = false;
  2254. this._tryDestroy();
  2255. }
  2256. }
  2257. };
  2258. return PDFPageProxy;
  2259. })();
  2260. /**
  2261. * For internal use only.
  2262. * @ignore
  2263. */
  2264. var WorkerTransport = (function WorkerTransportClosure() {
  2265. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2266. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2267. this.workerInitializedCapability = workerInitializedCapability;
  2268. this.commonObjs = new PDFObjects();
  2269. this.loadingTask = null;
  2270. this.pageCache = [];
  2271. this.pagePromises = [];
  2272. this.downloadInfoCapability = createPromiseCapability();
  2273. // If worker support isn't disabled explicit and the browser has worker
  2274. // support, create a new web worker and test if it/the browser fullfills
  2275. // all requirements to run parts of pdf.js in a web worker.
  2276. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2277. // as it arrives on the worker. Chrome added this with version 15.
  2278. // Either workers are disabled, not supported or have thrown an exception.
  2279. // Thus, we fallback to a faked worker.
  2280. this.setupFakeWorker();
  2281. }
  2282. WorkerTransport.prototype = {
  2283. destroy: function WorkerTransport_destroy() {
  2284. this.pageCache = [];
  2285. this.pagePromises = [];
  2286. var self = this;
  2287. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2288. FontLoader.clear();
  2289. if (self.worker) {
  2290. self.worker.terminate();
  2291. }
  2292. });
  2293. },
  2294. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2295. globalScope.PDFJS.disableWorker = true;
  2296. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2297. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2298. // In the developer build load worker_loader which in turn loads all the
  2299. // other files and resolves the promise. In production only the
  2300. // pdf.worker.js file is needed.
  2301. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2302. }
  2303. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2304. warn('Setting up fake worker.');
  2305. // If we don't use a worker, just post/sendMessage to the main thread.
  2306. var fakeWorker = {
  2307. postMessage: function WorkerTransport_postMessage(obj) {
  2308. fakeWorker.onmessage({data: obj});
  2309. },
  2310. terminate: function WorkerTransport_terminate() {}
  2311. };
  2312. var messageHandler = new MessageHandler('main', fakeWorker);
  2313. this.setupMessageHandler(messageHandler);
  2314. // If the main thread is our worker, setup the handling for the messages
  2315. // the main thread sends to it self.
  2316. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2317. this.workerInitializedCapability.resolve();
  2318. }.bind(this));
  2319. },
  2320. setupMessageHandler:
  2321. function WorkerTransport_setupMessageHandler(messageHandler) {
  2322. this.messageHandler = messageHandler;
  2323. function updatePassword(password) {
  2324. messageHandler.send('UpdatePassword', password);
  2325. }
  2326. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2327. if (pdfDataRangeTransport) {
  2328. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2329. messageHandler.send('OnDataRange', {
  2330. begin: begin,
  2331. chunk: chunk
  2332. });
  2333. });
  2334. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2335. messageHandler.send('OnDataProgress', {
  2336. loaded: loaded
  2337. });
  2338. });
  2339. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2340. messageHandler.send('OnDataRange', {
  2341. chunk: chunk
  2342. });
  2343. });
  2344. messageHandler.on('RequestDataRange',
  2345. function transportDataRange(data) {
  2346. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2347. }, this);
  2348. }
  2349. messageHandler.on('GetDoc', function transportDoc(data) {
  2350. var pdfInfo = data.pdfInfo;
  2351. this.numPages = data.pdfInfo.numPages;
  2352. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2353. this.pdfDocument = pdfDocument;
  2354. this.loadingTask._capability.resolve(pdfDocument);
  2355. }, this);
  2356. messageHandler.on('NeedPassword',
  2357. function transportNeedPassword(exception) {
  2358. var loadingTask = this.loadingTask;
  2359. if (loadingTask.onPassword) {
  2360. return loadingTask.onPassword(updatePassword,
  2361. PasswordResponses.NEED_PASSWORD);
  2362. }
  2363. loadingTask._capability.reject(
  2364. new PasswordException(exception.message, exception.code));
  2365. }, this);
  2366. messageHandler.on('IncorrectPassword',
  2367. function transportIncorrectPassword(exception) {
  2368. var loadingTask = this.loadingTask;
  2369. if (loadingTask.onPassword) {
  2370. return loadingTask.onPassword(updatePassword,
  2371. PasswordResponses.INCORRECT_PASSWORD);
  2372. }
  2373. loadingTask._capability.reject(
  2374. new PasswordException(exception.message, exception.code));
  2375. }, this);
  2376. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2377. this.loadingTask._capability.reject(
  2378. new InvalidPDFException(exception.message));
  2379. }, this);
  2380. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2381. this.loadingTask._capability.reject(
  2382. new MissingPDFException(exception.message));
  2383. }, this);
  2384. messageHandler.on('UnexpectedResponse',
  2385. function transportUnexpectedResponse(exception) {
  2386. this.loadingTask._capability.reject(
  2387. new UnexpectedResponseException(exception.message, exception.status));
  2388. }, this);
  2389. messageHandler.on('UnknownError',
  2390. function transportUnknownError(exception) {
  2391. this.loadingTask._capability.reject(
  2392. new UnknownErrorException(exception.message, exception.details));
  2393. }, this);
  2394. messageHandler.on('DataLoaded', function transportPage(data) {
  2395. this.downloadInfoCapability.resolve(data);
  2396. }, this);
  2397. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2398. if (this.pdfDataRangeTransport) {
  2399. this.pdfDataRangeTransport.transportReady();
  2400. }
  2401. }, this);
  2402. messageHandler.on('StartRenderPage', function transportRender(data) {
  2403. var page = this.pageCache[data.pageIndex];
  2404. page.stats.timeEnd('Page Request');
  2405. page._startRenderPage(data.transparency, data.intent);
  2406. }, this);
  2407. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2408. var page = this.pageCache[data.pageIndex];
  2409. page._renderPageChunk(data.operatorList, data.intent);
  2410. }, this);
  2411. messageHandler.on('commonobj', function transportObj(data) {
  2412. var id = data[0];
  2413. var type = data[1];
  2414. if (this.commonObjs.hasData(id)) {
  2415. return;
  2416. }
  2417. switch (type) {
  2418. case 'Font':
  2419. var exportedData = data[2];
  2420. var font;
  2421. if ('error' in exportedData) {
  2422. var error = exportedData.error;
  2423. warn('Error during font loading: ' + error);
  2424. this.commonObjs.resolve(id, error);
  2425. break;
  2426. } else {
  2427. font = new FontFaceObject(exportedData);
  2428. }
  2429. FontLoader.bind(
  2430. [font],
  2431. function fontReady(fontObjs) {
  2432. this.commonObjs.resolve(id, font);
  2433. }.bind(this)
  2434. );
  2435. break;
  2436. case 'FontPath':
  2437. this.commonObjs.resolve(id, data[2]);
  2438. break;
  2439. default:
  2440. error('Got unknown common object type ' + type);
  2441. }
  2442. }, this);
  2443. messageHandler.on('obj', function transportObj(data) {
  2444. var id = data[0];
  2445. var pageIndex = data[1];
  2446. var type = data[2];
  2447. var pageProxy = this.pageCache[pageIndex];
  2448. var imageData;
  2449. if (pageProxy.objs.hasData(id)) {
  2450. return;
  2451. }
  2452. switch (type) {
  2453. case 'JpegStream':
  2454. imageData = data[3];
  2455. loadJpegStream(id, imageData, pageProxy.objs);
  2456. break;
  2457. case 'Image':
  2458. imageData = data[3];
  2459. pageProxy.objs.resolve(id, imageData);
  2460. // heuristics that will allow not to store large data
  2461. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2462. if (imageData && 'data' in imageData &&
  2463. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2464. pageProxy.cleanupAfterRender = true;
  2465. }
  2466. break;
  2467. default:
  2468. error('Got unknown object type ' + type);
  2469. }
  2470. }, this);
  2471. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2472. var loadingTask = this.loadingTask;
  2473. if (loadingTask.onProgress) {
  2474. loadingTask.onProgress({
  2475. loaded: data.loaded,
  2476. total: data.total
  2477. });
  2478. }
  2479. }, this);
  2480. messageHandler.on('PageError', function transportError(data) {
  2481. var page = this.pageCache[data.pageNum - 1];
  2482. var intentState = page.intentStates[data.intent];
  2483. if (intentState.displayReadyCapability) {
  2484. intentState.displayReadyCapability.reject(data.error);
  2485. } else {
  2486. error(data.error);
  2487. }
  2488. }, this);
  2489. messageHandler.on('JpegDecode', function(data) {
  2490. var imageUrl = data[0];
  2491. var components = data[1];
  2492. if (components !== 3 && components !== 1) {
  2493. return Promise.reject(
  2494. new Error('Only 3 components or 1 component can be returned'));
  2495. }
  2496. return new Promise(function (resolve, reject) {
  2497. var img = new Image();
  2498. img.onload = function () {
  2499. var width = img.width;
  2500. var height = img.height;
  2501. var size = width * height;
  2502. var rgbaLength = size * 4;
  2503. var buf = new Uint8Array(size * components);
  2504. var tmpCanvas = createScratchCanvas(width, height);
  2505. var tmpCtx = tmpCanvas.getContext('2d');
  2506. tmpCtx.drawImage(img, 0, 0);
  2507. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2508. var i, j;
  2509. if (components === 3) {
  2510. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2511. buf[j] = data[i];
  2512. buf[j + 1] = data[i + 1];
  2513. buf[j + 2] = data[i + 2];
  2514. }
  2515. } else if (components === 1) {
  2516. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2517. buf[j] = data[i];
  2518. }
  2519. }
  2520. resolve({ data: buf, width: width, height: height});
  2521. };
  2522. img.onerror = function () {
  2523. reject(new Error('JpegDecode failed to load image'));
  2524. };
  2525. img.src = imageUrl;
  2526. });
  2527. });
  2528. },
  2529. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2530. this.loadingTask = loadingTask;
  2531. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2532. source.disableStream = PDFJS.disableStream;
  2533. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2534. if (this.pdfDataRangeTransport) {
  2535. source.length = this.pdfDataRangeTransport.length;
  2536. source.initialData = this.pdfDataRangeTransport.initialData;
  2537. }
  2538. this.messageHandler.send('GetDocRequest', {
  2539. source: source,
  2540. disableRange: PDFJS.disableRange,
  2541. maxImageSize: PDFJS.maxImageSize,
  2542. cMapUrl: PDFJS.cMapUrl,
  2543. cMapPacked: PDFJS.cMapPacked,
  2544. disableFontFace: PDFJS.disableFontFace,
  2545. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2546. verbosity: PDFJS.verbosity
  2547. });
  2548. },
  2549. getData: function WorkerTransport_getData() {
  2550. return this.messageHandler.sendWithPromise('GetData', null);
  2551. },
  2552. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2553. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2554. (pageNumber|0) !== pageNumber) {
  2555. return Promise.reject(new Error('Invalid page request'));
  2556. }
  2557. var pageIndex = pageNumber - 1;
  2558. if (pageIndex in this.pagePromises) {
  2559. return this.pagePromises[pageIndex];
  2560. }
  2561. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2562. pageIndex: pageIndex
  2563. }).then(function (pageInfo) {
  2564. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2565. this.pageCache[pageIndex] = page;
  2566. return page;
  2567. }.bind(this));
  2568. this.pagePromises[pageIndex] = promise;
  2569. return promise;
  2570. },
  2571. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2572. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2573. },
  2574. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2575. return this.messageHandler.sendWithPromise('GetAnnotations',
  2576. { pageIndex: pageIndex });
  2577. },
  2578. getDestinations: function WorkerTransport_getDestinations() {
  2579. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2580. },
  2581. getDestination: function WorkerTransport_getDestination(id) {
  2582. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2583. },
  2584. getAttachments: function WorkerTransport_getAttachments() {
  2585. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2586. },
  2587. getJavaScript: function WorkerTransport_getJavaScript() {
  2588. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2589. },
  2590. getOutline: function WorkerTransport_getOutline() {
  2591. return this.messageHandler.sendWithPromise('GetOutline', null);
  2592. },
  2593. getMetadata: function WorkerTransport_getMetadata() {
  2594. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2595. then(function transportMetadata(results) {
  2596. return {
  2597. info: results[0],
  2598. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2599. };
  2600. });
  2601. },
  2602. getStats: function WorkerTransport_getStats() {
  2603. return this.messageHandler.sendWithPromise('GetStats', null);
  2604. },
  2605. startCleanup: function WorkerTransport_startCleanup() {
  2606. this.messageHandler.sendWithPromise('Cleanup', null).
  2607. then(function endCleanup() {
  2608. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2609. var page = this.pageCache[i];
  2610. if (page) {
  2611. page.destroy();
  2612. }
  2613. }
  2614. this.commonObjs.clear();
  2615. FontLoader.clear();
  2616. }.bind(this));
  2617. }
  2618. };
  2619. return WorkerTransport;
  2620. })();
  2621. /**
  2622. * A PDF document and page is built of many objects. E.g. there are objects
  2623. * for fonts, images, rendering code and such. These objects might get processed
  2624. * inside of a worker. The `PDFObjects` implements some basic functions to
  2625. * manage these objects.
  2626. * @ignore
  2627. */
  2628. var PDFObjects = (function PDFObjectsClosure() {
  2629. function PDFObjects() {
  2630. this.objs = {};
  2631. }
  2632. PDFObjects.prototype = {
  2633. /**
  2634. * Internal function.
  2635. * Ensures there is an object defined for `objId`.
  2636. */
  2637. ensureObj: function PDFObjects_ensureObj(objId) {
  2638. if (this.objs[objId]) {
  2639. return this.objs[objId];
  2640. }
  2641. var obj = {
  2642. capability: createPromiseCapability(),
  2643. data: null,
  2644. resolved: false
  2645. };
  2646. this.objs[objId] = obj;
  2647. return obj;
  2648. },
  2649. /**
  2650. * If called *without* callback, this returns the data of `objId` but the
  2651. * object needs to be resolved. If it isn't, this function throws.
  2652. *
  2653. * If called *with* a callback, the callback is called with the data of the
  2654. * object once the object is resolved. That means, if you call this
  2655. * function and the object is already resolved, the callback gets called
  2656. * right away.
  2657. */
  2658. get: function PDFObjects_get(objId, callback) {
  2659. // If there is a callback, then the get can be async and the object is
  2660. // not required to be resolved right now
  2661. if (callback) {
  2662. this.ensureObj(objId).capability.promise.then(callback);
  2663. return null;
  2664. }
  2665. // If there isn't a callback, the user expects to get the resolved data
  2666. // directly.
  2667. var obj = this.objs[objId];
  2668. // If there isn't an object yet or the object isn't resolved, then the
  2669. // data isn't ready yet!
  2670. if (!obj || !obj.resolved) {
  2671. error('Requesting object that isn\'t resolved yet ' + objId);
  2672. }
  2673. return obj.data;
  2674. },
  2675. /**
  2676. * Resolves the object `objId` with optional `data`.
  2677. */
  2678. resolve: function PDFObjects_resolve(objId, data) {
  2679. var obj = this.ensureObj(objId);
  2680. obj.resolved = true;
  2681. obj.data = data;
  2682. obj.capability.resolve(data);
  2683. },
  2684. isResolved: function PDFObjects_isResolved(objId) {
  2685. var objs = this.objs;
  2686. if (!objs[objId]) {
  2687. return false;
  2688. } else {
  2689. return objs[objId].resolved;
  2690. }
  2691. },
  2692. hasData: function PDFObjects_hasData(objId) {
  2693. return this.isResolved(objId);
  2694. },
  2695. /**
  2696. * Returns the data of `objId` if object exists, null otherwise.
  2697. */
  2698. getData: function PDFObjects_getData(objId) {
  2699. var objs = this.objs;
  2700. if (!objs[objId] || !objs[objId].resolved) {
  2701. return null;
  2702. } else {
  2703. return objs[objId].data;
  2704. }
  2705. },
  2706. clear: function PDFObjects_clear() {
  2707. this.objs = {};
  2708. }
  2709. };
  2710. return PDFObjects;
  2711. })();
  2712. /**
  2713. * Allows controlling of the rendering tasks.
  2714. * @class
  2715. */
  2716. var RenderTask = (function RenderTaskClosure() {
  2717. function RenderTask(internalRenderTask) {
  2718. this._internalRenderTask = internalRenderTask;
  2719. /**
  2720. * Callback for incremental rendering -- a function that will be called
  2721. * each time the rendering is paused. To continue rendering call the
  2722. * function that is the first argument to the callback.
  2723. * @type {function}
  2724. */
  2725. this.onContinue = null;
  2726. }
  2727. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2728. /**
  2729. * Promise for rendering task completion.
  2730. * @return {Promise}
  2731. */
  2732. get promise() {
  2733. return this._internalRenderTask.capability.promise;
  2734. },
  2735. /**
  2736. * Cancels the rendering task. If the task is currently rendering it will
  2737. * not be cancelled until graphics pauses with a timeout. The promise that
  2738. * this object extends will resolved when cancelled.
  2739. */
  2740. cancel: function RenderTask_cancel() {
  2741. this._internalRenderTask.cancel();
  2742. },
  2743. /**
  2744. * Registers callbacks to indicate the rendering task completion.
  2745. *
  2746. * @param {function} onFulfilled The callback for the rendering completion.
  2747. * @param {function} onRejected The callback for the rendering failure.
  2748. * @return {Promise} A promise that is resolved after the onFulfilled or
  2749. * onRejected callback.
  2750. */
  2751. then: function RenderTask_then(onFulfilled, onRejected) {
  2752. return this.promise.then.apply(this.promise, arguments);
  2753. }
  2754. };
  2755. return RenderTask;
  2756. })();
  2757. /**
  2758. * For internal use only.
  2759. * @ignore
  2760. */
  2761. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2762. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2763. pageNumber) {
  2764. this.callback = callback;
  2765. this.params = params;
  2766. this.objs = objs;
  2767. this.commonObjs = commonObjs;
  2768. this.operatorListIdx = null;
  2769. this.operatorList = operatorList;
  2770. this.pageNumber = pageNumber;
  2771. this.running = false;
  2772. this.graphicsReadyCallback = null;
  2773. this.graphicsReady = false;
  2774. this.cancelled = false;
  2775. this.capability = createPromiseCapability();
  2776. this.task = new RenderTask(this);
  2777. // caching this-bound methods
  2778. this._continueBound = this._continue.bind(this);
  2779. this._scheduleNextBound = this._scheduleNext.bind(this);
  2780. this._nextBound = this._next.bind(this);
  2781. }
  2782. InternalRenderTask.prototype = {
  2783. initalizeGraphics:
  2784. function InternalRenderTask_initalizeGraphics(transparency) {
  2785. if (this.cancelled) {
  2786. return;
  2787. }
  2788. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2789. globalScope.StepperManager.enabled) {
  2790. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2791. this.stepper.init(this.operatorList);
  2792. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2793. }
  2794. var params = this.params;
  2795. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2796. this.objs, params.imageLayer);
  2797. this.gfx.beginDrawing(params.viewport, transparency);
  2798. this.operatorListIdx = 0;
  2799. this.graphicsReady = true;
  2800. if (this.graphicsReadyCallback) {
  2801. this.graphicsReadyCallback();
  2802. }
  2803. },
  2804. cancel: function InternalRenderTask_cancel() {
  2805. this.running = false;
  2806. this.cancelled = true;
  2807. this.callback('cancelled');
  2808. },
  2809. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2810. if (!this.graphicsReady) {
  2811. if (!this.graphicsReadyCallback) {
  2812. this.graphicsReadyCallback = this._continueBound;
  2813. }
  2814. return;
  2815. }
  2816. if (this.stepper) {
  2817. this.stepper.updateOperatorList(this.operatorList);
  2818. }
  2819. if (this.running) {
  2820. return;
  2821. }
  2822. this._continue();
  2823. },
  2824. _continue: function InternalRenderTask__continue() {
  2825. this.running = true;
  2826. if (this.cancelled) {
  2827. return;
  2828. }
  2829. if (this.task.onContinue) {
  2830. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2831. } else {
  2832. this._scheduleNext();
  2833. }
  2834. },
  2835. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2836. window.requestAnimationFrame(this._nextBound);
  2837. },
  2838. _next: function InternalRenderTask__next() {
  2839. if (this.cancelled) {
  2840. return;
  2841. }
  2842. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2843. this.operatorListIdx,
  2844. this._continueBound,
  2845. this.stepper);
  2846. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2847. this.running = false;
  2848. if (this.operatorList.lastChunk) {
  2849. this.gfx.endDrawing();
  2850. this.callback();
  2851. }
  2852. }
  2853. }
  2854. };
  2855. return InternalRenderTask;
  2856. })();
  2857. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2858. function fixMetadata(meta) {
  2859. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2860. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2861. function(code, d1, d2, d3) {
  2862. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2863. });
  2864. var chars = '';
  2865. for (var i = 0; i < bytes.length; i += 2) {
  2866. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2867. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2868. code !== 38 && false ? String.fromCharCode(code) :
  2869. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2870. }
  2871. return '>' + chars;
  2872. });
  2873. }
  2874. function Metadata(meta) {
  2875. if (typeof meta === 'string') {
  2876. // Ghostscript produces invalid metadata
  2877. meta = fixMetadata(meta);
  2878. var parser = new DOMParser();
  2879. meta = parser.parseFromString(meta, 'application/xml');
  2880. } else if (!(meta instanceof Document)) {
  2881. error('Metadata: Invalid metadata object');
  2882. }
  2883. this.metaDocument = meta;
  2884. this.metadata = {};
  2885. this.parse();
  2886. }
  2887. Metadata.prototype = {
  2888. parse: function Metadata_parse() {
  2889. var doc = this.metaDocument;
  2890. var rdf = doc.documentElement;
  2891. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2892. rdf = rdf.firstChild;
  2893. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2894. rdf = rdf.nextSibling;
  2895. }
  2896. }
  2897. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2898. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2899. return;
  2900. }
  2901. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2902. for (i = 0, length = children.length; i < length; i++) {
  2903. desc = children[i];
  2904. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2905. continue;
  2906. }
  2907. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2908. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2909. entry = desc.childNodes[ii];
  2910. name = entry.nodeName.toLowerCase();
  2911. this.metadata[name] = entry.textContent.trim();
  2912. }
  2913. }
  2914. }
  2915. },
  2916. get: function Metadata_get(name) {
  2917. return this.metadata[name] || null;
  2918. },
  2919. has: function Metadata_has(name) {
  2920. return typeof this.metadata[name] !== 'undefined';
  2921. }
  2922. };
  2923. return Metadata;
  2924. })();
  2925. // <canvas> contexts store most of the state we need natively.
  2926. // However, PDF needs a bit more state, which we store here.
  2927. // Minimal font size that would be used during canvas fillText operations.
  2928. var MIN_FONT_SIZE = 16;
  2929. // Maximum font size that would be used during canvas fillText operations.
  2930. var MAX_FONT_SIZE = 100;
  2931. var MAX_GROUP_SIZE = 4096;
  2932. // Heuristic value used when enforcing minimum line widths.
  2933. var MIN_WIDTH_FACTOR = 0.65;
  2934. var COMPILE_TYPE3_GLYPHS = true;
  2935. var MAX_SIZE_TO_COMPILE = 1000;
  2936. var FULL_CHUNK_HEIGHT = 16;
  2937. function createScratchCanvas(width, height) {
  2938. var canvas = document.createElement('canvas');
  2939. canvas.width = width;
  2940. canvas.height = height;
  2941. return canvas;
  2942. }
  2943. function addContextCurrentTransform(ctx) {
  2944. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2945. if (!ctx.mozCurrentTransform) {
  2946. // Store the original context
  2947. ctx._scaleX = ctx._scaleX || 1.0;
  2948. ctx._scaleY = ctx._scaleY || 1.0;
  2949. ctx._originalSave = ctx.save;
  2950. ctx._originalRestore = ctx.restore;
  2951. ctx._originalRotate = ctx.rotate;
  2952. ctx._originalScale = ctx.scale;
  2953. ctx._originalTranslate = ctx.translate;
  2954. ctx._originalTransform = ctx.transform;
  2955. ctx._originalSetTransform = ctx.setTransform;
  2956. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2957. ctx._transformStack = [];
  2958. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2959. get: function getCurrentTransform() {
  2960. return this._transformMatrix;
  2961. }
  2962. });
  2963. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2964. get: function getCurrentTransformInverse() {
  2965. // Calculation done using WolframAlpha:
  2966. // http://www.wolframalpha.com/input/?
  2967. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2968. var m = this._transformMatrix;
  2969. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2970. var ad_bc = a * d - b * c;
  2971. var bc_ad = b * c - a * d;
  2972. return [
  2973. d / ad_bc,
  2974. b / bc_ad,
  2975. c / bc_ad,
  2976. a / ad_bc,
  2977. (d * e - c * f) / bc_ad,
  2978. (b * e - a * f) / ad_bc
  2979. ];
  2980. }
  2981. });
  2982. ctx.save = function ctxSave() {
  2983. var old = this._transformMatrix;
  2984. this._transformStack.push(old);
  2985. this._transformMatrix = old.slice(0, 6);
  2986. this._originalSave();
  2987. };
  2988. ctx.restore = function ctxRestore() {
  2989. var prev = this._transformStack.pop();
  2990. if (prev) {
  2991. this._transformMatrix = prev;
  2992. this._originalRestore();
  2993. }
  2994. };
  2995. ctx.translate = function ctxTranslate(x, y) {
  2996. var m = this._transformMatrix;
  2997. m[4] = m[0] * x + m[2] * y + m[4];
  2998. m[5] = m[1] * x + m[3] * y + m[5];
  2999. this._originalTranslate(x, y);
  3000. };
  3001. ctx.scale = function ctxScale(x, y) {
  3002. var m = this._transformMatrix;
  3003. m[0] = m[0] * x;
  3004. m[1] = m[1] * x;
  3005. m[2] = m[2] * y;
  3006. m[3] = m[3] * y;
  3007. this._originalScale(x, y);
  3008. };
  3009. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3010. var m = this._transformMatrix;
  3011. this._transformMatrix = [
  3012. m[0] * a + m[2] * b,
  3013. m[1] * a + m[3] * b,
  3014. m[0] * c + m[2] * d,
  3015. m[1] * c + m[3] * d,
  3016. m[0] * e + m[2] * f + m[4],
  3017. m[1] * e + m[3] * f + m[5]
  3018. ];
  3019. ctx._originalTransform(a, b, c, d, e, f);
  3020. };
  3021. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3022. this._transformMatrix = [a, b, c, d, e, f];
  3023. ctx._originalSetTransform(a, b, c, d, e, f);
  3024. };
  3025. ctx.rotate = function ctxRotate(angle) {
  3026. var cosValue = Math.cos(angle);
  3027. var sinValue = Math.sin(angle);
  3028. var m = this._transformMatrix;
  3029. this._transformMatrix = [
  3030. m[0] * cosValue + m[2] * sinValue,
  3031. m[1] * cosValue + m[3] * sinValue,
  3032. m[0] * (-sinValue) + m[2] * cosValue,
  3033. m[1] * (-sinValue) + m[3] * cosValue,
  3034. m[4],
  3035. m[5]
  3036. ];
  3037. this._originalRotate(angle);
  3038. };
  3039. }
  3040. }
  3041. var CachedCanvases = (function CachedCanvasesClosure() {
  3042. var cache = {};
  3043. return {
  3044. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3045. trackTransform) {
  3046. var canvasEntry;
  3047. if (cache[id] !== undefined) {
  3048. canvasEntry = cache[id];
  3049. canvasEntry.canvas.width = width;
  3050. canvasEntry.canvas.height = height;
  3051. // reset canvas transform for emulated mozCurrentTransform, if needed
  3052. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3053. } else {
  3054. var canvas = createScratchCanvas(width, height);
  3055. var ctx = canvas.getContext('2d');
  3056. if (trackTransform) {
  3057. addContextCurrentTransform(ctx);
  3058. }
  3059. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3060. }
  3061. return canvasEntry;
  3062. },
  3063. clear: function () {
  3064. for (var id in cache) {
  3065. var canvasEntry = cache[id];
  3066. // Zeroing the width and height causes Firefox to release graphics
  3067. // resources immediately, which can greatly reduce memory consumption.
  3068. canvasEntry.canvas.width = 0;
  3069. canvasEntry.canvas.height = 0;
  3070. delete cache[id];
  3071. }
  3072. }
  3073. };
  3074. })();
  3075. function compileType3Glyph(imgData) {
  3076. var POINT_TO_PROCESS_LIMIT = 1000;
  3077. var width = imgData.width, height = imgData.height;
  3078. var i, j, j0, width1 = width + 1;
  3079. var points = new Uint8Array(width1 * (height + 1));
  3080. var POINT_TYPES =
  3081. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3082. // decodes bit-packed mask data
  3083. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3084. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3085. for (i = 0, ii = data0.length; i < ii; i++) {
  3086. var mask = 128, elem = data0[i];
  3087. while (mask > 0) {
  3088. data[pos++] = (elem & mask) ? 0 : 255;
  3089. mask >>= 1;
  3090. }
  3091. }
  3092. // finding iteresting points: every point is located between mask pixels,
  3093. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3094. // will have flags assigned based on neighboring mask pixels:
  3095. // 4 | 8
  3096. // --P--
  3097. // 2 | 1
  3098. // We are interested only in points with the flags:
  3099. // - outside corners: 1, 2, 4, 8;
  3100. // - inside corners: 7, 11, 13, 14;
  3101. // - and, intersections: 5, 10.
  3102. var count = 0;
  3103. pos = 0;
  3104. if (data[pos] !== 0) {
  3105. points[0] = 1;
  3106. ++count;
  3107. }
  3108. for (j = 1; j < width; j++) {
  3109. if (data[pos] !== data[pos + 1]) {
  3110. points[j] = data[pos] ? 2 : 1;
  3111. ++count;
  3112. }
  3113. pos++;
  3114. }
  3115. if (data[pos] !== 0) {
  3116. points[j] = 2;
  3117. ++count;
  3118. }
  3119. for (i = 1; i < height; i++) {
  3120. pos = i * lineSize;
  3121. j0 = i * width1;
  3122. if (data[pos - lineSize] !== data[pos]) {
  3123. points[j0] = data[pos] ? 1 : 8;
  3124. ++count;
  3125. }
  3126. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3127. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3128. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3129. for (j = 1; j < width; j++) {
  3130. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3131. (data[pos - lineSize + 1] ? 8 : 0);
  3132. if (POINT_TYPES[sum]) {
  3133. points[j0 + j] = POINT_TYPES[sum];
  3134. ++count;
  3135. }
  3136. pos++;
  3137. }
  3138. if (data[pos - lineSize] !== data[pos]) {
  3139. points[j0 + j] = data[pos] ? 2 : 4;
  3140. ++count;
  3141. }
  3142. if (count > POINT_TO_PROCESS_LIMIT) {
  3143. return null;
  3144. }
  3145. }
  3146. pos = lineSize * (height - 1);
  3147. j0 = i * width1;
  3148. if (data[pos] !== 0) {
  3149. points[j0] = 8;
  3150. ++count;
  3151. }
  3152. for (j = 1; j < width; j++) {
  3153. if (data[pos] !== data[pos + 1]) {
  3154. points[j0 + j] = data[pos] ? 4 : 8;
  3155. ++count;
  3156. }
  3157. pos++;
  3158. }
  3159. if (data[pos] !== 0) {
  3160. points[j0 + j] = 4;
  3161. ++count;
  3162. }
  3163. if (count > POINT_TO_PROCESS_LIMIT) {
  3164. return null;
  3165. }
  3166. // building outlines
  3167. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3168. var outlines = [];
  3169. for (i = 0; count && i <= height; i++) {
  3170. var p = i * width1;
  3171. var end = p + width;
  3172. while (p < end && !points[p]) {
  3173. p++;
  3174. }
  3175. if (p === end) {
  3176. continue;
  3177. }
  3178. var coords = [p % width1, i];
  3179. var type = points[p], p0 = p, pp;
  3180. do {
  3181. var step = steps[type];
  3182. do {
  3183. p += step;
  3184. } while (!points[p]);
  3185. pp = points[p];
  3186. if (pp !== 5 && pp !== 10) {
  3187. // set new direction
  3188. type = pp;
  3189. // delete mark
  3190. points[p] = 0;
  3191. } else { // type is 5 or 10, ie, a crossing
  3192. // set new direction
  3193. type = pp & ((0x33 * type) >> 4);
  3194. // set new type for "future hit"
  3195. points[p] &= (type >> 2 | type << 2);
  3196. }
  3197. coords.push(p % width1);
  3198. coords.push((p / width1) | 0);
  3199. --count;
  3200. } while (p0 !== p);
  3201. outlines.push(coords);
  3202. --i;
  3203. }
  3204. var drawOutline = function(c) {
  3205. c.save();
  3206. // the path shall be painted in [0..1]x[0..1] space
  3207. c.scale(1 / width, -1 / height);
  3208. c.translate(0, -height);
  3209. c.beginPath();
  3210. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3211. var o = outlines[i];
  3212. c.moveTo(o[0], o[1]);
  3213. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3214. c.lineTo(o[j], o[j+1]);
  3215. }
  3216. }
  3217. c.fill();
  3218. c.beginPath();
  3219. c.restore();
  3220. };
  3221. return drawOutline;
  3222. }
  3223. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3224. function CanvasExtraState(old) {
  3225. // Are soft masks and alpha values shapes or opacities?
  3226. this.alphaIsShape = false;
  3227. this.fontSize = 0;
  3228. this.fontSizeScale = 1;
  3229. this.textMatrix = IDENTITY_MATRIX;
  3230. this.textMatrixScale = 1;
  3231. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3232. this.leading = 0;
  3233. // Current point (in user coordinates)
  3234. this.x = 0;
  3235. this.y = 0;
  3236. // Start of text line (in text coordinates)
  3237. this.lineX = 0;
  3238. this.lineY = 0;
  3239. // Character and word spacing
  3240. this.charSpacing = 0;
  3241. this.wordSpacing = 0;
  3242. this.textHScale = 1;
  3243. this.textRenderingMode = TextRenderingMode.FILL;
  3244. this.textRise = 0;
  3245. // Default fore and background colors
  3246. this.fillColor = '#000000';
  3247. this.strokeColor = '#000000';
  3248. this.patternFill = false;
  3249. // Note: fill alpha applies to all non-stroking operations
  3250. this.fillAlpha = 1;
  3251. this.strokeAlpha = 1;
  3252. this.lineWidth = 1;
  3253. this.activeSMask = null; // nonclonable field (see the save method below)
  3254. this.old = old;
  3255. }
  3256. CanvasExtraState.prototype = {
  3257. clone: function CanvasExtraState_clone() {
  3258. return Object.create(this);
  3259. },
  3260. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3261. this.x = x;
  3262. this.y = y;
  3263. }
  3264. };
  3265. return CanvasExtraState;
  3266. })();
  3267. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3268. // Defines the time the executeOperatorList is going to be executing
  3269. // before it stops and shedules a continue of execution.
  3270. var EXECUTION_TIME = 15;
  3271. // Defines the number of steps before checking the execution time
  3272. var EXECUTION_STEPS = 10;
  3273. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3274. this.ctx = canvasCtx;
  3275. this.current = new CanvasExtraState();
  3276. this.stateStack = [];
  3277. this.pendingClip = null;
  3278. this.pendingEOFill = false;
  3279. this.res = null;
  3280. this.xobjs = null;
  3281. this.commonObjs = commonObjs;
  3282. this.objs = objs;
  3283. this.imageLayer = imageLayer;
  3284. this.groupStack = [];
  3285. this.processingType3 = null;
  3286. // Patterns are painted relative to the initial page/form transform, see pdf
  3287. // spec 8.7.2 NOTE 1.
  3288. this.baseTransform = null;
  3289. this.baseTransformStack = [];
  3290. this.groupLevel = 0;
  3291. this.smaskStack = [];
  3292. this.smaskCounter = 0;
  3293. this.tempSMask = null;
  3294. if (canvasCtx) {
  3295. addContextCurrentTransform(canvasCtx);
  3296. }
  3297. this.cachedGetSinglePixelWidth = null;
  3298. }
  3299. function putBinaryImageData(ctx, imgData) {
  3300. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3301. ctx.putImageData(imgData, 0, 0);
  3302. return;
  3303. }
  3304. // Put the image data to the canvas in chunks, rather than putting the
  3305. // whole image at once. This saves JS memory, because the ImageData object
  3306. // is smaller. It also possibly saves C++ memory within the implementation
  3307. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3308. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3309. // because too many putImageData() calls will slow things down.
  3310. //
  3311. // Note: as written, if the last chunk is partial, the putImageData() call
  3312. // will (conceptually) put pixels past the bounds of the canvas. But
  3313. // that's ok; any such pixels are ignored.
  3314. var height = imgData.height, width = imgData.width;
  3315. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3316. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3317. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3318. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3319. var srcPos = 0, destPos;
  3320. var src = imgData.data;
  3321. var dest = chunkImgData.data;
  3322. var i, j, thisChunkHeight, elemsInThisChunk;
  3323. // There are multiple forms in which the pixel data can be passed, and
  3324. // imgData.kind tells us which one this is.
  3325. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3326. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3327. var srcLength = src.byteLength;
  3328. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3329. new Uint32ArrayView(dest);
  3330. var dest32DataLength = dest32.length;
  3331. var fullSrcDiff = (width + 7) >> 3;
  3332. var white = 0xFFFFFFFF;
  3333. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3334. 0xFF000000 : 0x000000FF;
  3335. for (i = 0; i < totalChunks; i++) {
  3336. thisChunkHeight =
  3337. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3338. destPos = 0;
  3339. for (j = 0; j < thisChunkHeight; j++) {
  3340. var srcDiff = srcLength - srcPos;
  3341. var k = 0;
  3342. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3343. var kEndUnrolled = kEnd & ~7;
  3344. var mask = 0;
  3345. var srcByte = 0;
  3346. for (; k < kEndUnrolled; k += 8) {
  3347. srcByte = src[srcPos++];
  3348. dest32[destPos++] = (srcByte & 128) ? white : black;
  3349. dest32[destPos++] = (srcByte & 64) ? white : black;
  3350. dest32[destPos++] = (srcByte & 32) ? white : black;
  3351. dest32[destPos++] = (srcByte & 16) ? white : black;
  3352. dest32[destPos++] = (srcByte & 8) ? white : black;
  3353. dest32[destPos++] = (srcByte & 4) ? white : black;
  3354. dest32[destPos++] = (srcByte & 2) ? white : black;
  3355. dest32[destPos++] = (srcByte & 1) ? white : black;
  3356. }
  3357. for (; k < kEnd; k++) {
  3358. if (mask === 0) {
  3359. srcByte = src[srcPos++];
  3360. mask = 128;
  3361. }
  3362. dest32[destPos++] = (srcByte & mask) ? white : black;
  3363. mask >>= 1;
  3364. }
  3365. }
  3366. // We ran out of input. Make all remaining pixels transparent.
  3367. while (destPos < dest32DataLength) {
  3368. dest32[destPos++] = 0;
  3369. }
  3370. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3371. }
  3372. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3373. // RGBA, 32-bits per pixel.
  3374. j = 0;
  3375. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3376. for (i = 0; i < fullChunks; i++) {
  3377. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3378. srcPos += elemsInThisChunk;
  3379. ctx.putImageData(chunkImgData, 0, j);
  3380. j += FULL_CHUNK_HEIGHT;
  3381. }
  3382. if (i < totalChunks) {
  3383. elemsInThisChunk = width * partialChunkHeight * 4;
  3384. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3385. ctx.putImageData(chunkImgData, 0, j);
  3386. }
  3387. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3388. // RGB, 24-bits per pixel.
  3389. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3390. elemsInThisChunk = width * thisChunkHeight;
  3391. for (i = 0; i < totalChunks; i++) {
  3392. if (i >= fullChunks) {
  3393. thisChunkHeight = partialChunkHeight;
  3394. elemsInThisChunk = width * thisChunkHeight;
  3395. }
  3396. destPos = 0;
  3397. for (j = elemsInThisChunk; j--;) {
  3398. dest[destPos++] = src[srcPos++];
  3399. dest[destPos++] = src[srcPos++];
  3400. dest[destPos++] = src[srcPos++];
  3401. dest[destPos++] = 255;
  3402. }
  3403. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3404. }
  3405. } else {
  3406. error('bad image kind: ' + imgData.kind);
  3407. }
  3408. }
  3409. function putBinaryImageMask(ctx, imgData) {
  3410. var height = imgData.height, width = imgData.width;
  3411. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3412. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3413. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3414. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3415. var srcPos = 0;
  3416. var src = imgData.data;
  3417. var dest = chunkImgData.data;
  3418. for (var i = 0; i < totalChunks; i++) {
  3419. var thisChunkHeight =
  3420. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3421. // Expand the mask so it can be used by the canvas. Any required
  3422. // inversion has already been handled.
  3423. var destPos = 3; // alpha component offset
  3424. for (var j = 0; j < thisChunkHeight; j++) {
  3425. var mask = 0;
  3426. for (var k = 0; k < width; k++) {
  3427. if (!mask) {
  3428. var elem = src[srcPos++];
  3429. mask = 128;
  3430. }
  3431. dest[destPos] = (elem & mask) ? 0 : 255;
  3432. destPos += 4;
  3433. mask >>= 1;
  3434. }
  3435. }
  3436. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3437. }
  3438. }
  3439. function copyCtxState(sourceCtx, destCtx) {
  3440. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3441. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3442. 'globalCompositeOperation', 'font'];
  3443. for (var i = 0, ii = properties.length; i < ii; i++) {
  3444. var property = properties[i];
  3445. if (sourceCtx[property] !== undefined) {
  3446. destCtx[property] = sourceCtx[property];
  3447. }
  3448. }
  3449. if (sourceCtx.setLineDash !== undefined) {
  3450. destCtx.setLineDash(sourceCtx.getLineDash());
  3451. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3452. } else if (sourceCtx.mozDashOffset !== undefined) {
  3453. destCtx.mozDash = sourceCtx.mozDash;
  3454. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3455. }
  3456. }
  3457. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3458. var length = bytes.length;
  3459. for (var i = 3; i < length; i += 4) {
  3460. var alpha = bytes[i];
  3461. if (alpha === 0) {
  3462. bytes[i - 3] = r0;
  3463. bytes[i - 2] = g0;
  3464. bytes[i - 1] = b0;
  3465. } else if (alpha < 255) {
  3466. var alpha_ = 255 - alpha;
  3467. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3468. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3469. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3470. }
  3471. }
  3472. }
  3473. function composeSMaskAlpha(maskData, layerData) {
  3474. var length = maskData.length;
  3475. var scale = 1 / 255;
  3476. for (var i = 3; i < length; i += 4) {
  3477. var alpha = maskData[i];
  3478. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3479. }
  3480. }
  3481. function composeSMaskLuminosity(maskData, layerData) {
  3482. var length = maskData.length;
  3483. for (var i = 3; i < length; i += 4) {
  3484. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3485. (maskData[i - 2] * 152) + // * 0.59 ....
  3486. (maskData[i - 1] * 28); // * 0.11 ....
  3487. layerData[i] = (layerData[i] * y) >> 16;
  3488. }
  3489. }
  3490. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3491. subtype, backdrop) {
  3492. var hasBackdrop = !!backdrop;
  3493. var r0 = hasBackdrop ? backdrop[0] : 0;
  3494. var g0 = hasBackdrop ? backdrop[1] : 0;
  3495. var b0 = hasBackdrop ? backdrop[2] : 0;
  3496. var composeFn;
  3497. if (subtype === 'Luminosity') {
  3498. composeFn = composeSMaskLuminosity;
  3499. } else {
  3500. composeFn = composeSMaskAlpha;
  3501. }
  3502. // processing image in chunks to save memory
  3503. var PIXELS_TO_PROCESS = 1048576;
  3504. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3505. for (var row = 0; row < height; row += chunkSize) {
  3506. var chunkHeight = Math.min(chunkSize, height - row);
  3507. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3508. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3509. if (hasBackdrop) {
  3510. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3511. }
  3512. composeFn(maskData.data, layerData.data);
  3513. maskCtx.putImageData(layerData, 0, row);
  3514. }
  3515. }
  3516. function composeSMask(ctx, smask, layerCtx) {
  3517. var mask = smask.canvas;
  3518. var maskCtx = smask.context;
  3519. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3520. smask.offsetX, smask.offsetY);
  3521. var backdrop = smask.backdrop || null;
  3522. if (WebGLUtils.isEnabled) {
  3523. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3524. {subtype: smask.subtype, backdrop: backdrop});
  3525. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3526. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3527. return;
  3528. }
  3529. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3530. smask.subtype, backdrop);
  3531. ctx.drawImage(mask, 0, 0);
  3532. }
  3533. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3534. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3535. var NORMAL_CLIP = {};
  3536. var EO_CLIP = {};
  3537. CanvasGraphics.prototype = {
  3538. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3539. // For pdfs that use blend modes we have to clear the canvas else certain
  3540. // blend modes can look wrong since we'd be blending with a white
  3541. // backdrop. The problem with a transparent backdrop though is we then
  3542. // don't get sub pixel anti aliasing on text, so we fill with white if
  3543. // we can.
  3544. var width = this.ctx.canvas.width;
  3545. var height = this.ctx.canvas.height;
  3546. if (transparency) {
  3547. this.ctx.clearRect(0, 0, width, height);
  3548. } else {
  3549. this.ctx.mozOpaque = true;
  3550. this.ctx.save();
  3551. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3552. this.ctx.fillRect(0, 0, width, height);
  3553. this.ctx.restore();
  3554. }
  3555. var transform = viewport.transform;
  3556. this.ctx.save();
  3557. this.ctx.transform.apply(this.ctx, transform);
  3558. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3559. if (this.imageLayer) {
  3560. this.imageLayer.beginLayout();
  3561. }
  3562. },
  3563. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3564. operatorList,
  3565. executionStartIdx, continueCallback,
  3566. stepper) {
  3567. var argsArray = operatorList.argsArray;
  3568. var fnArray = operatorList.fnArray;
  3569. var i = executionStartIdx || 0;
  3570. var argsArrayLen = argsArray.length;
  3571. // Sometimes the OperatorList to execute is empty.
  3572. if (argsArrayLen === i) {
  3573. return i;
  3574. }
  3575. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3576. typeof continueCallback === 'function');
  3577. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3578. var steps = 0;
  3579. var commonObjs = this.commonObjs;
  3580. var objs = this.objs;
  3581. var fnId;
  3582. while (true) {
  3583. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3584. stepper.breakIt(i, continueCallback);
  3585. return i;
  3586. }
  3587. fnId = fnArray[i];
  3588. if (fnId !== OPS.dependency) {
  3589. this[fnId].apply(this, argsArray[i]);
  3590. } else {
  3591. var deps = argsArray[i];
  3592. for (var n = 0, nn = deps.length; n < nn; n++) {
  3593. var depObjId = deps[n];
  3594. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3595. var objsPool = common ? commonObjs : objs;
  3596. // If the promise isn't resolved yet, add the continueCallback
  3597. // to the promise and bail out.
  3598. if (!objsPool.isResolved(depObjId)) {
  3599. objsPool.get(depObjId, continueCallback);
  3600. return i;
  3601. }
  3602. }
  3603. }
  3604. i++;
  3605. // If the entire operatorList was executed, stop as were done.
  3606. if (i === argsArrayLen) {
  3607. return i;
  3608. }
  3609. // If the execution took longer then a certain amount of time and
  3610. // `continueCallback` is specified, interrupt the execution.
  3611. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3612. if (Date.now() > endTime) {
  3613. continueCallback();
  3614. return i;
  3615. }
  3616. steps = 0;
  3617. }
  3618. // If the operatorList isn't executed completely yet OR the execution
  3619. // time was short enough, do another execution round.
  3620. }
  3621. },
  3622. endDrawing: function CanvasGraphics_endDrawing() {
  3623. this.ctx.restore();
  3624. CachedCanvases.clear();
  3625. WebGLUtils.clear();
  3626. if (this.imageLayer) {
  3627. this.imageLayer.endLayout();
  3628. }
  3629. },
  3630. // Graphics state
  3631. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3632. this.current.lineWidth = width;
  3633. this.ctx.lineWidth = width;
  3634. },
  3635. setLineCap: function CanvasGraphics_setLineCap(style) {
  3636. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3637. },
  3638. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3639. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3640. },
  3641. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3642. this.ctx.miterLimit = limit;
  3643. },
  3644. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3645. var ctx = this.ctx;
  3646. if (ctx.setLineDash !== undefined) {
  3647. ctx.setLineDash(dashArray);
  3648. ctx.lineDashOffset = dashPhase;
  3649. } else {
  3650. ctx.mozDash = dashArray;
  3651. ctx.mozDashOffset = dashPhase;
  3652. }
  3653. },
  3654. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3655. // Maybe if we one day fully support color spaces this will be important
  3656. // for now we can ignore.
  3657. // TODO set rendering intent?
  3658. },
  3659. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3660. // There's no way to control this with canvas, but we can safely ignore.
  3661. // TODO set flatness?
  3662. },
  3663. setGState: function CanvasGraphics_setGState(states) {
  3664. for (var i = 0, ii = states.length; i < ii; i++) {
  3665. var state = states[i];
  3666. var key = state[0];
  3667. var value = state[1];
  3668. switch (key) {
  3669. case 'LW':
  3670. this.setLineWidth(value);
  3671. break;
  3672. case 'LC':
  3673. this.setLineCap(value);
  3674. break;
  3675. case 'LJ':
  3676. this.setLineJoin(value);
  3677. break;
  3678. case 'ML':
  3679. this.setMiterLimit(value);
  3680. break;
  3681. case 'D':
  3682. this.setDash(value[0], value[1]);
  3683. break;
  3684. case 'RI':
  3685. this.setRenderingIntent(value);
  3686. break;
  3687. case 'FL':
  3688. this.setFlatness(value);
  3689. break;
  3690. case 'Font':
  3691. this.setFont(value[0], value[1]);
  3692. break;
  3693. case 'CA':
  3694. this.current.strokeAlpha = state[1];
  3695. break;
  3696. case 'ca':
  3697. this.current.fillAlpha = state[1];
  3698. this.ctx.globalAlpha = state[1];
  3699. break;
  3700. case 'BM':
  3701. if (value && value.name && (value.name !== 'Normal')) {
  3702. var mode = value.name.replace(/([A-Z])/g,
  3703. function(c) {
  3704. return '-' + c.toLowerCase();
  3705. }
  3706. ).substring(1);
  3707. this.ctx.globalCompositeOperation = mode;
  3708. if (this.ctx.globalCompositeOperation !== mode) {
  3709. warn('globalCompositeOperation "' + mode +
  3710. '" is not supported');
  3711. }
  3712. } else {
  3713. this.ctx.globalCompositeOperation = 'source-over';
  3714. }
  3715. break;
  3716. case 'SMask':
  3717. if (this.current.activeSMask) {
  3718. this.endSMaskGroup();
  3719. }
  3720. this.current.activeSMask = value ? this.tempSMask : null;
  3721. if (this.current.activeSMask) {
  3722. this.beginSMaskGroup();
  3723. }
  3724. this.tempSMask = null;
  3725. break;
  3726. }
  3727. }
  3728. },
  3729. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3730. var activeSMask = this.current.activeSMask;
  3731. var drawnWidth = activeSMask.canvas.width;
  3732. var drawnHeight = activeSMask.canvas.height;
  3733. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3734. var scratchCanvas = CachedCanvases.getCanvas(
  3735. cacheId, drawnWidth, drawnHeight, true);
  3736. var currentCtx = this.ctx;
  3737. var currentTransform = currentCtx.mozCurrentTransform;
  3738. this.ctx.save();
  3739. var groupCtx = scratchCanvas.context;
  3740. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3741. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3742. groupCtx.transform.apply(groupCtx, currentTransform);
  3743. copyCtxState(currentCtx, groupCtx);
  3744. this.ctx = groupCtx;
  3745. this.setGState([
  3746. ['BM', 'Normal'],
  3747. ['ca', 1],
  3748. ['CA', 1]
  3749. ]);
  3750. this.groupStack.push(currentCtx);
  3751. this.groupLevel++;
  3752. },
  3753. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3754. var groupCtx = this.ctx;
  3755. this.groupLevel--;
  3756. this.ctx = this.groupStack.pop();
  3757. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3758. this.ctx.restore();
  3759. },
  3760. save: function CanvasGraphics_save() {
  3761. this.ctx.save();
  3762. var old = this.current;
  3763. this.stateStack.push(old);
  3764. this.current = old.clone();
  3765. this.current.activeSMask = null;
  3766. },
  3767. restore: function CanvasGraphics_restore() {
  3768. if (this.stateStack.length !== 0) {
  3769. if (this.current.activeSMask !== null) {
  3770. this.endSMaskGroup();
  3771. }
  3772. this.current = this.stateStack.pop();
  3773. this.ctx.restore();
  3774. this.cachedGetSinglePixelWidth = null;
  3775. }
  3776. },
  3777. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3778. this.ctx.transform(a, b, c, d, e, f);
  3779. this.cachedGetSinglePixelWidth = null;
  3780. },
  3781. // Path
  3782. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3783. var ctx = this.ctx;
  3784. var current = this.current;
  3785. var x = current.x, y = current.y;
  3786. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3787. switch (ops[i] | 0) {
  3788. case OPS.rectangle:
  3789. x = args[j++];
  3790. y = args[j++];
  3791. var width = args[j++];
  3792. var height = args[j++];
  3793. if (width === 0) {
  3794. width = this.getSinglePixelWidth();
  3795. }
  3796. if (height === 0) {
  3797. height = this.getSinglePixelWidth();
  3798. }
  3799. var xw = x + width;
  3800. var yh = y + height;
  3801. this.ctx.moveTo(x, y);
  3802. this.ctx.lineTo(xw, y);
  3803. this.ctx.lineTo(xw, yh);
  3804. this.ctx.lineTo(x, yh);
  3805. this.ctx.lineTo(x, y);
  3806. this.ctx.closePath();
  3807. break;
  3808. case OPS.moveTo:
  3809. x = args[j++];
  3810. y = args[j++];
  3811. ctx.moveTo(x, y);
  3812. break;
  3813. case OPS.lineTo:
  3814. x = args[j++];
  3815. y = args[j++];
  3816. ctx.lineTo(x, y);
  3817. break;
  3818. case OPS.curveTo:
  3819. x = args[j + 4];
  3820. y = args[j + 5];
  3821. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3822. x, y);
  3823. j += 6;
  3824. break;
  3825. case OPS.curveTo2:
  3826. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3827. args[j + 2], args[j + 3]);
  3828. x = args[j + 2];
  3829. y = args[j + 3];
  3830. j += 4;
  3831. break;
  3832. case OPS.curveTo3:
  3833. x = args[j + 2];
  3834. y = args[j + 3];
  3835. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3836. j += 4;
  3837. break;
  3838. case OPS.closePath:
  3839. ctx.closePath();
  3840. break;
  3841. }
  3842. }
  3843. current.setCurrentPoint(x, y);
  3844. },
  3845. closePath: function CanvasGraphics_closePath() {
  3846. this.ctx.closePath();
  3847. },
  3848. stroke: function CanvasGraphics_stroke(consumePath) {
  3849. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3850. var ctx = this.ctx;
  3851. var strokeColor = this.current.strokeColor;
  3852. // Prevent drawing too thin lines by enforcing a minimum line width.
  3853. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3854. this.current.lineWidth);
  3855. // For stroke we want to temporarily change the global alpha to the
  3856. // stroking alpha.
  3857. ctx.globalAlpha = this.current.strokeAlpha;
  3858. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3859. strokeColor.type === 'Pattern') {
  3860. // for patterns, we transform to pattern space, calculate
  3861. // the pattern, call stroke, and restore to user space
  3862. ctx.save();
  3863. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3864. ctx.stroke();
  3865. ctx.restore();
  3866. } else {
  3867. ctx.stroke();
  3868. }
  3869. if (consumePath) {
  3870. this.consumePath();
  3871. }
  3872. // Restore the global alpha to the fill alpha
  3873. ctx.globalAlpha = this.current.fillAlpha;
  3874. },
  3875. closeStroke: function CanvasGraphics_closeStroke() {
  3876. this.closePath();
  3877. this.stroke();
  3878. },
  3879. fill: function CanvasGraphics_fill(consumePath) {
  3880. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3881. var ctx = this.ctx;
  3882. var fillColor = this.current.fillColor;
  3883. var isPatternFill = this.current.patternFill;
  3884. var needRestore = false;
  3885. if (isPatternFill) {
  3886. ctx.save();
  3887. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3888. needRestore = true;
  3889. }
  3890. if (this.pendingEOFill) {
  3891. if (ctx.mozFillRule !== undefined) {
  3892. ctx.mozFillRule = 'evenodd';
  3893. ctx.fill();
  3894. ctx.mozFillRule = 'nonzero';
  3895. } else {
  3896. try {
  3897. ctx.fill('evenodd');
  3898. } catch (ex) {
  3899. // shouldn't really happen, but browsers might think differently
  3900. ctx.fill();
  3901. }
  3902. }
  3903. this.pendingEOFill = false;
  3904. } else {
  3905. ctx.fill();
  3906. }
  3907. if (needRestore) {
  3908. ctx.restore();
  3909. }
  3910. if (consumePath) {
  3911. this.consumePath();
  3912. }
  3913. },
  3914. eoFill: function CanvasGraphics_eoFill() {
  3915. this.pendingEOFill = true;
  3916. this.fill();
  3917. },
  3918. fillStroke: function CanvasGraphics_fillStroke() {
  3919. this.fill(false);
  3920. this.stroke(false);
  3921. this.consumePath();
  3922. },
  3923. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3924. this.pendingEOFill = true;
  3925. this.fillStroke();
  3926. },
  3927. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3928. this.closePath();
  3929. this.fillStroke();
  3930. },
  3931. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3932. this.pendingEOFill = true;
  3933. this.closePath();
  3934. this.fillStroke();
  3935. },
  3936. endPath: function CanvasGraphics_endPath() {
  3937. this.consumePath();
  3938. },
  3939. // Clipping
  3940. clip: function CanvasGraphics_clip() {
  3941. this.pendingClip = NORMAL_CLIP;
  3942. },
  3943. eoClip: function CanvasGraphics_eoClip() {
  3944. this.pendingClip = EO_CLIP;
  3945. },
  3946. // Text
  3947. beginText: function CanvasGraphics_beginText() {
  3948. this.current.textMatrix = IDENTITY_MATRIX;
  3949. this.current.textMatrixScale = 1;
  3950. this.current.x = this.current.lineX = 0;
  3951. this.current.y = this.current.lineY = 0;
  3952. },
  3953. endText: function CanvasGraphics_endText() {
  3954. var paths = this.pendingTextPaths;
  3955. var ctx = this.ctx;
  3956. if (paths === undefined) {
  3957. ctx.beginPath();
  3958. return;
  3959. }
  3960. ctx.save();
  3961. ctx.beginPath();
  3962. for (var i = 0; i < paths.length; i++) {
  3963. var path = paths[i];
  3964. ctx.setTransform.apply(ctx, path.transform);
  3965. ctx.translate(path.x, path.y);
  3966. path.addToPath(ctx, path.fontSize);
  3967. }
  3968. ctx.restore();
  3969. ctx.clip();
  3970. ctx.beginPath();
  3971. delete this.pendingTextPaths;
  3972. },
  3973. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3974. this.current.charSpacing = spacing;
  3975. },
  3976. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3977. this.current.wordSpacing = spacing;
  3978. },
  3979. setHScale: function CanvasGraphics_setHScale(scale) {
  3980. this.current.textHScale = scale / 100;
  3981. },
  3982. setLeading: function CanvasGraphics_setLeading(leading) {
  3983. this.current.leading = -leading;
  3984. },
  3985. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3986. var fontObj = this.commonObjs.get(fontRefName);
  3987. var current = this.current;
  3988. if (!fontObj) {
  3989. error('Can\'t find font for ' + fontRefName);
  3990. }
  3991. current.fontMatrix = (fontObj.fontMatrix ?
  3992. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3993. // A valid matrix needs all main diagonal elements to be non-zero
  3994. // This also ensures we bypass FF bugzilla bug #719844.
  3995. if (current.fontMatrix[0] === 0 ||
  3996. current.fontMatrix[3] === 0) {
  3997. warn('Invalid font matrix for font ' + fontRefName);
  3998. }
  3999. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4000. // and in some docs this can be negative (inverted x-y axes).
  4001. if (size < 0) {
  4002. size = -size;
  4003. current.fontDirection = -1;
  4004. } else {
  4005. current.fontDirection = 1;
  4006. }
  4007. this.current.font = fontObj;
  4008. this.current.fontSize = size;
  4009. if (fontObj.isType3Font) {
  4010. return; // we don't need ctx.font for Type3 fonts
  4011. }
  4012. var name = fontObj.loadedName || 'sans-serif';
  4013. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  4014. (fontObj.bold ? 'bold' : 'normal');
  4015. var italic = fontObj.italic ? 'italic' : 'normal';
  4016. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4017. // Some font backends cannot handle fonts below certain size.
  4018. // Keeping the font at minimal size and using the fontSizeScale to change
  4019. // the current transformation matrix before the fillText/strokeText.
  4020. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4021. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4022. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4023. this.current.fontSizeScale = size / browserFontSize;
  4024. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4025. this.ctx.font = rule;
  4026. },
  4027. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4028. this.current.textRenderingMode = mode;
  4029. },
  4030. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4031. this.current.textRise = rise;
  4032. },
  4033. moveText: function CanvasGraphics_moveText(x, y) {
  4034. this.current.x = this.current.lineX += x;
  4035. this.current.y = this.current.lineY += y;
  4036. },
  4037. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4038. this.setLeading(-y);
  4039. this.moveText(x, y);
  4040. },
  4041. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4042. this.current.textMatrix = [a, b, c, d, e, f];
  4043. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4044. this.current.x = this.current.lineX = 0;
  4045. this.current.y = this.current.lineY = 0;
  4046. },
  4047. nextLine: function CanvasGraphics_nextLine() {
  4048. this.moveText(0, this.current.leading);
  4049. },
  4050. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4051. var ctx = this.ctx;
  4052. var current = this.current;
  4053. var font = current.font;
  4054. var textRenderingMode = current.textRenderingMode;
  4055. var fontSize = current.fontSize / current.fontSizeScale;
  4056. var fillStrokeMode = textRenderingMode &
  4057. TextRenderingMode.FILL_STROKE_MASK;
  4058. var isAddToPathSet = !!(textRenderingMode &
  4059. TextRenderingMode.ADD_TO_PATH_FLAG);
  4060. var addToPath;
  4061. if (font.disableFontFace || isAddToPathSet) {
  4062. addToPath = font.getPathGenerator(this.commonObjs, character);
  4063. }
  4064. if (font.disableFontFace) {
  4065. ctx.save();
  4066. ctx.translate(x, y);
  4067. ctx.beginPath();
  4068. addToPath(ctx, fontSize);
  4069. if (fillStrokeMode === TextRenderingMode.FILL ||
  4070. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4071. ctx.fill();
  4072. }
  4073. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4074. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4075. ctx.stroke();
  4076. }
  4077. ctx.restore();
  4078. } else {
  4079. if (fillStrokeMode === TextRenderingMode.FILL ||
  4080. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4081. ctx.fillText(character, x, y);
  4082. }
  4083. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4084. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4085. ctx.strokeText(character, x, y);
  4086. }
  4087. }
  4088. if (isAddToPathSet) {
  4089. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4090. paths.push({
  4091. transform: ctx.mozCurrentTransform,
  4092. x: x,
  4093. y: y,
  4094. fontSize: fontSize,
  4095. addToPath: addToPath
  4096. });
  4097. }
  4098. },
  4099. get isFontSubpixelAAEnabled() {
  4100. // Checks if anti-aliasing is enabled when scaled text is painted.
  4101. // On Windows GDI scaled fonts looks bad.
  4102. var ctx = document.createElement('canvas').getContext('2d');
  4103. ctx.scale(1.5, 1);
  4104. ctx.fillText('I', 0, 10);
  4105. var data = ctx.getImageData(0, 0, 10, 10).data;
  4106. var enabled = false;
  4107. for (var i = 3; i < data.length; i += 4) {
  4108. if (data[i] > 0 && data[i] < 255) {
  4109. enabled = true;
  4110. break;
  4111. }
  4112. }
  4113. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4114. },
  4115. showText: function CanvasGraphics_showText(glyphs) {
  4116. var current = this.current;
  4117. var font = current.font;
  4118. if (font.isType3Font) {
  4119. return this.showType3Text(glyphs);
  4120. }
  4121. var fontSize = current.fontSize;
  4122. if (fontSize === 0) {
  4123. return;
  4124. }
  4125. var ctx = this.ctx;
  4126. var fontSizeScale = current.fontSizeScale;
  4127. var charSpacing = current.charSpacing;
  4128. var wordSpacing = current.wordSpacing;
  4129. var fontDirection = current.fontDirection;
  4130. var textHScale = current.textHScale * fontDirection;
  4131. var glyphsLength = glyphs.length;
  4132. var vertical = font.vertical;
  4133. var defaultVMetrics = font.defaultVMetrics;
  4134. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4135. var simpleFillText =
  4136. current.textRenderingMode === TextRenderingMode.FILL &&
  4137. !font.disableFontFace;
  4138. ctx.save();
  4139. ctx.transform.apply(ctx, current.textMatrix);
  4140. ctx.translate(current.x, current.y + current.textRise);
  4141. if (fontDirection > 0) {
  4142. ctx.scale(textHScale, -1);
  4143. } else {
  4144. ctx.scale(textHScale, 1);
  4145. }
  4146. var lineWidth = current.lineWidth;
  4147. var scale = current.textMatrixScale;
  4148. if (scale === 0 || lineWidth === 0) {
  4149. var fillStrokeMode = current.textRenderingMode &
  4150. TextRenderingMode.FILL_STROKE_MASK;
  4151. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4152. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4153. this.cachedGetSinglePixelWidth = null;
  4154. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4155. }
  4156. } else {
  4157. lineWidth /= scale;
  4158. }
  4159. if (fontSizeScale !== 1.0) {
  4160. ctx.scale(fontSizeScale, fontSizeScale);
  4161. lineWidth /= fontSizeScale;
  4162. }
  4163. ctx.lineWidth = lineWidth;
  4164. var x = 0, i;
  4165. for (i = 0; i < glyphsLength; ++i) {
  4166. var glyph = glyphs[i];
  4167. if (glyph === null) {
  4168. // word break
  4169. x += fontDirection * wordSpacing;
  4170. continue;
  4171. } else if (isNum(glyph)) {
  4172. x += -glyph * fontSize * 0.001;
  4173. continue;
  4174. }
  4175. var restoreNeeded = false;
  4176. var character = glyph.fontChar;
  4177. var accent = glyph.accent;
  4178. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4179. var width = glyph.width;
  4180. if (vertical) {
  4181. var vmetric, vx, vy;
  4182. vmetric = glyph.vmetric || defaultVMetrics;
  4183. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4184. vx = -vx * widthAdvanceScale;
  4185. vy = vmetric[2] * widthAdvanceScale;
  4186. width = vmetric ? -vmetric[0] : width;
  4187. scaledX = vx / fontSizeScale;
  4188. scaledY = (x + vy) / fontSizeScale;
  4189. } else {
  4190. scaledX = x / fontSizeScale;
  4191. scaledY = 0;
  4192. }
  4193. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4194. // some standard fonts may not have the exact width, trying to
  4195. // rescale per character
  4196. var measuredWidth = ctx.measureText(character).width * 1000 /
  4197. fontSize * fontSizeScale;
  4198. var characterScaleX = width / measuredWidth;
  4199. restoreNeeded = true;
  4200. ctx.save();
  4201. ctx.scale(characterScaleX, 1);
  4202. scaledX /= characterScaleX;
  4203. }
  4204. if (simpleFillText && !accent) {
  4205. // common case
  4206. ctx.fillText(character, scaledX, scaledY);
  4207. } else {
  4208. this.paintChar(character, scaledX, scaledY);
  4209. if (accent) {
  4210. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4211. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4212. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4213. }
  4214. }
  4215. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4216. x += charWidth;
  4217. if (restoreNeeded) {
  4218. ctx.restore();
  4219. }
  4220. }
  4221. if (vertical) {
  4222. current.y -= x * textHScale;
  4223. } else {
  4224. current.x += x * textHScale;
  4225. }
  4226. ctx.restore();
  4227. },
  4228. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4229. // Type3 fonts - each glyph is a "mini-PDF"
  4230. var ctx = this.ctx;
  4231. var current = this.current;
  4232. var font = current.font;
  4233. var fontSize = current.fontSize;
  4234. var fontDirection = current.fontDirection;
  4235. var charSpacing = current.charSpacing;
  4236. var wordSpacing = current.wordSpacing;
  4237. var textHScale = current.textHScale * fontDirection;
  4238. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4239. var glyphsLength = glyphs.length;
  4240. var isTextInvisible =
  4241. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4242. var i, glyph, width;
  4243. if (isTextInvisible || fontSize === 0) {
  4244. return;
  4245. }
  4246. ctx.save();
  4247. ctx.transform.apply(ctx, current.textMatrix);
  4248. ctx.translate(current.x, current.y);
  4249. ctx.scale(textHScale, fontDirection);
  4250. for (i = 0; i < glyphsLength; ++i) {
  4251. glyph = glyphs[i];
  4252. if (glyph === null) {
  4253. // word break
  4254. this.ctx.translate(wordSpacing, 0);
  4255. current.x += wordSpacing * textHScale;
  4256. continue;
  4257. } else if (isNum(glyph)) {
  4258. var spacingLength = -glyph * 0.001 * fontSize;
  4259. this.ctx.translate(spacingLength, 0);
  4260. current.x += spacingLength * textHScale;
  4261. continue;
  4262. }
  4263. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4264. if (!operatorList) {
  4265. warn('Type3 character \"' + glyph.operatorListId +
  4266. '\" is not available');
  4267. continue;
  4268. }
  4269. this.processingType3 = glyph;
  4270. this.save();
  4271. ctx.scale(fontSize, fontSize);
  4272. ctx.transform.apply(ctx, fontMatrix);
  4273. this.executeOperatorList(operatorList);
  4274. this.restore();
  4275. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4276. width = transformed[0] * fontSize + charSpacing;
  4277. ctx.translate(width, 0);
  4278. current.x += width * textHScale;
  4279. }
  4280. ctx.restore();
  4281. this.processingType3 = null;
  4282. },
  4283. // Type3 fonts
  4284. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4285. // We can safely ignore this since the width should be the same
  4286. // as the width in the Widths array.
  4287. },
  4288. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4289. yWidth,
  4290. llx,
  4291. lly,
  4292. urx,
  4293. ury) {
  4294. // TODO According to the spec we're also suppose to ignore any operators
  4295. // that set color or include images while processing this type3 font.
  4296. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4297. this.clip();
  4298. this.endPath();
  4299. },
  4300. // Color
  4301. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4302. var pattern;
  4303. if (IR[0] === 'TilingPattern') {
  4304. var color = IR[1];
  4305. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4306. this.commonObjs, this.baseTransform);
  4307. } else {
  4308. pattern = getShadingPatternFromIR(IR);
  4309. }
  4310. return pattern;
  4311. },
  4312. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4313. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4314. },
  4315. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4316. this.current.fillColor = this.getColorN_Pattern(arguments);
  4317. this.current.patternFill = true;
  4318. },
  4319. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4320. var color = Util.makeCssRgb(r, g, b);
  4321. this.ctx.strokeStyle = color;
  4322. this.current.strokeColor = color;
  4323. },
  4324. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4325. var color = Util.makeCssRgb(r, g, b);
  4326. this.ctx.fillStyle = color;
  4327. this.current.fillColor = color;
  4328. this.current.patternFill = false;
  4329. },
  4330. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4331. var ctx = this.ctx;
  4332. this.save();
  4333. var pattern = getShadingPatternFromIR(patternIR);
  4334. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4335. var inv = ctx.mozCurrentTransformInverse;
  4336. if (inv) {
  4337. var canvas = ctx.canvas;
  4338. var width = canvas.width;
  4339. var height = canvas.height;
  4340. var bl = Util.applyTransform([0, 0], inv);
  4341. var br = Util.applyTransform([0, height], inv);
  4342. var ul = Util.applyTransform([width, 0], inv);
  4343. var ur = Util.applyTransform([width, height], inv);
  4344. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4345. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4346. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4347. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4348. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4349. } else {
  4350. // HACK to draw the gradient onto an infinite rectangle.
  4351. // PDF gradients are drawn across the entire image while
  4352. // Canvas only allows gradients to be drawn in a rectangle
  4353. // The following bug should allow us to remove this.
  4354. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4355. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4356. }
  4357. this.restore();
  4358. },
  4359. // Images
  4360. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4361. error('Should not call beginInlineImage');
  4362. },
  4363. beginImageData: function CanvasGraphics_beginImageData() {
  4364. error('Should not call beginImageData');
  4365. },
  4366. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4367. bbox) {
  4368. this.save();
  4369. this.baseTransformStack.push(this.baseTransform);
  4370. if (isArray(matrix) && 6 === matrix.length) {
  4371. this.transform.apply(this, matrix);
  4372. }
  4373. this.baseTransform = this.ctx.mozCurrentTransform;
  4374. if (isArray(bbox) && 4 === bbox.length) {
  4375. var width = bbox[2] - bbox[0];
  4376. var height = bbox[3] - bbox[1];
  4377. this.ctx.rect(bbox[0], bbox[1], width, height);
  4378. this.clip();
  4379. this.endPath();
  4380. }
  4381. },
  4382. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4383. this.restore();
  4384. this.baseTransform = this.baseTransformStack.pop();
  4385. },
  4386. beginGroup: function CanvasGraphics_beginGroup(group) {
  4387. this.save();
  4388. var currentCtx = this.ctx;
  4389. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4390. // group results aren't usually that different and they even have tools
  4391. // that ignore this setting. Notes from Rik on implmenting:
  4392. // - When you encounter an transparency group, create a new canvas with
  4393. // the dimensions of the bbox
  4394. // - copy the content from the previous canvas to the new canvas
  4395. // - draw as usual
  4396. // - remove the backdrop alpha:
  4397. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4398. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4399. // backdrop
  4400. // - remove background color:
  4401. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4402. if (!group.isolated) {
  4403. info('TODO: Support non-isolated groups.');
  4404. }
  4405. // TODO knockout - supposedly possible with the clever use of compositing
  4406. // modes.
  4407. if (group.knockout) {
  4408. warn('Knockout groups not supported.');
  4409. }
  4410. var currentTransform = currentCtx.mozCurrentTransform;
  4411. if (group.matrix) {
  4412. currentCtx.transform.apply(currentCtx, group.matrix);
  4413. }
  4414. assert(group.bbox, 'Bounding box is required.');
  4415. // Based on the current transform figure out how big the bounding box
  4416. // will actually be.
  4417. var bounds = Util.getAxialAlignedBoundingBox(
  4418. group.bbox,
  4419. currentCtx.mozCurrentTransform);
  4420. // Clip the bounding box to the current canvas.
  4421. var canvasBounds = [0,
  4422. 0,
  4423. currentCtx.canvas.width,
  4424. currentCtx.canvas.height];
  4425. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4426. // Use ceil in case we're between sizes so we don't create canvas that is
  4427. // too small and make the canvas at least 1x1 pixels.
  4428. var offsetX = Math.floor(bounds[0]);
  4429. var offsetY = Math.floor(bounds[1]);
  4430. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4431. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4432. var scaleX = 1, scaleY = 1;
  4433. if (drawnWidth > MAX_GROUP_SIZE) {
  4434. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4435. drawnWidth = MAX_GROUP_SIZE;
  4436. }
  4437. if (drawnHeight > MAX_GROUP_SIZE) {
  4438. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4439. drawnHeight = MAX_GROUP_SIZE;
  4440. }
  4441. var cacheId = 'groupAt' + this.groupLevel;
  4442. if (group.smask) {
  4443. // Using two cache entries is case if masks are used one after another.
  4444. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4445. }
  4446. var scratchCanvas = CachedCanvases.getCanvas(
  4447. cacheId, drawnWidth, drawnHeight, true);
  4448. var groupCtx = scratchCanvas.context;
  4449. // Since we created a new canvas that is just the size of the bounding box
  4450. // we have to translate the group ctx.
  4451. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4452. groupCtx.translate(-offsetX, -offsetY);
  4453. groupCtx.transform.apply(groupCtx, currentTransform);
  4454. if (group.smask) {
  4455. // Saving state and cached mask to be used in setGState.
  4456. this.smaskStack.push({
  4457. canvas: scratchCanvas.canvas,
  4458. context: groupCtx,
  4459. offsetX: offsetX,
  4460. offsetY: offsetY,
  4461. scaleX: scaleX,
  4462. scaleY: scaleY,
  4463. subtype: group.smask.subtype,
  4464. backdrop: group.smask.backdrop
  4465. });
  4466. } else {
  4467. // Setup the current ctx so when the group is popped we draw it at the
  4468. // right location.
  4469. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4470. currentCtx.translate(offsetX, offsetY);
  4471. currentCtx.scale(scaleX, scaleY);
  4472. }
  4473. // The transparency group inherits all off the current graphics state
  4474. // except the blend mode, soft mask, and alpha constants.
  4475. copyCtxState(currentCtx, groupCtx);
  4476. this.ctx = groupCtx;
  4477. this.setGState([
  4478. ['BM', 'Normal'],
  4479. ['ca', 1],
  4480. ['CA', 1]
  4481. ]);
  4482. this.groupStack.push(currentCtx);
  4483. this.groupLevel++;
  4484. },
  4485. endGroup: function CanvasGraphics_endGroup(group) {
  4486. this.groupLevel--;
  4487. var groupCtx = this.ctx;
  4488. this.ctx = this.groupStack.pop();
  4489. // Turn off image smoothing to avoid sub pixel interpolation which can
  4490. // look kind of blurry for some pdfs.
  4491. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4492. this.ctx.imageSmoothingEnabled = false;
  4493. } else {
  4494. this.ctx.mozImageSmoothingEnabled = false;
  4495. }
  4496. if (group.smask) {
  4497. this.tempSMask = this.smaskStack.pop();
  4498. } else {
  4499. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4500. }
  4501. this.restore();
  4502. },
  4503. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4504. this.save();
  4505. this.current = new CanvasExtraState();
  4506. },
  4507. endAnnotations: function CanvasGraphics_endAnnotations() {
  4508. this.restore();
  4509. },
  4510. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4511. matrix) {
  4512. this.save();
  4513. if (isArray(rect) && 4 === rect.length) {
  4514. var width = rect[2] - rect[0];
  4515. var height = rect[3] - rect[1];
  4516. this.ctx.rect(rect[0], rect[1], width, height);
  4517. this.clip();
  4518. this.endPath();
  4519. }
  4520. this.transform.apply(this, transform);
  4521. this.transform.apply(this, matrix);
  4522. },
  4523. endAnnotation: function CanvasGraphics_endAnnotation() {
  4524. this.restore();
  4525. },
  4526. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4527. var domImage = this.objs.get(objId);
  4528. if (!domImage) {
  4529. warn('Dependent image isn\'t ready yet');
  4530. return;
  4531. }
  4532. this.save();
  4533. var ctx = this.ctx;
  4534. // scale the image to the unit square
  4535. ctx.scale(1 / w, -1 / h);
  4536. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4537. 0, -h, w, h);
  4538. if (this.imageLayer) {
  4539. var currentTransform = ctx.mozCurrentTransformInverse;
  4540. var position = this.getCanvasPosition(0, 0);
  4541. this.imageLayer.appendImage({
  4542. objId: objId,
  4543. left: position[0],
  4544. top: position[1],
  4545. width: w / currentTransform[0],
  4546. height: h / currentTransform[3]
  4547. });
  4548. }
  4549. this.restore();
  4550. },
  4551. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4552. var ctx = this.ctx;
  4553. var width = img.width, height = img.height;
  4554. var fillColor = this.current.fillColor;
  4555. var isPatternFill = this.current.patternFill;
  4556. var glyph = this.processingType3;
  4557. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4558. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4559. glyph.compiled =
  4560. compileType3Glyph({data: img.data, width: width, height: height});
  4561. } else {
  4562. glyph.compiled = null;
  4563. }
  4564. }
  4565. if (glyph && glyph.compiled) {
  4566. glyph.compiled(ctx);
  4567. return;
  4568. }
  4569. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4570. var maskCtx = maskCanvas.context;
  4571. maskCtx.save();
  4572. putBinaryImageMask(maskCtx, img);
  4573. maskCtx.globalCompositeOperation = 'source-in';
  4574. maskCtx.fillStyle = isPatternFill ?
  4575. fillColor.getPattern(maskCtx, this) : fillColor;
  4576. maskCtx.fillRect(0, 0, width, height);
  4577. maskCtx.restore();
  4578. this.paintInlineImageXObject(maskCanvas.canvas);
  4579. },
  4580. paintImageMaskXObjectRepeat:
  4581. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4582. scaleY, positions) {
  4583. var width = imgData.width;
  4584. var height = imgData.height;
  4585. var fillColor = this.current.fillColor;
  4586. var isPatternFill = this.current.patternFill;
  4587. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4588. var maskCtx = maskCanvas.context;
  4589. maskCtx.save();
  4590. putBinaryImageMask(maskCtx, imgData);
  4591. maskCtx.globalCompositeOperation = 'source-in';
  4592. maskCtx.fillStyle = isPatternFill ?
  4593. fillColor.getPattern(maskCtx, this) : fillColor;
  4594. maskCtx.fillRect(0, 0, width, height);
  4595. maskCtx.restore();
  4596. var ctx = this.ctx;
  4597. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4598. ctx.save();
  4599. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4600. ctx.scale(1, -1);
  4601. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4602. 0, -1, 1, 1);
  4603. ctx.restore();
  4604. }
  4605. },
  4606. paintImageMaskXObjectGroup:
  4607. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4608. var ctx = this.ctx;
  4609. var fillColor = this.current.fillColor;
  4610. var isPatternFill = this.current.patternFill;
  4611. for (var i = 0, ii = images.length; i < ii; i++) {
  4612. var image = images[i];
  4613. var width = image.width, height = image.height;
  4614. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4615. var maskCtx = maskCanvas.context;
  4616. maskCtx.save();
  4617. putBinaryImageMask(maskCtx, image);
  4618. maskCtx.globalCompositeOperation = 'source-in';
  4619. maskCtx.fillStyle = isPatternFill ?
  4620. fillColor.getPattern(maskCtx, this) : fillColor;
  4621. maskCtx.fillRect(0, 0, width, height);
  4622. maskCtx.restore();
  4623. ctx.save();
  4624. ctx.transform.apply(ctx, image.transform);
  4625. ctx.scale(1, -1);
  4626. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4627. 0, -1, 1, 1);
  4628. ctx.restore();
  4629. }
  4630. },
  4631. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4632. var imgData = this.objs.get(objId);
  4633. if (!imgData) {
  4634. warn('Dependent image isn\'t ready yet');
  4635. return;
  4636. }
  4637. this.paintInlineImageXObject(imgData);
  4638. },
  4639. paintImageXObjectRepeat:
  4640. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4641. positions) {
  4642. var imgData = this.objs.get(objId);
  4643. if (!imgData) {
  4644. warn('Dependent image isn\'t ready yet');
  4645. return;
  4646. }
  4647. var width = imgData.width;
  4648. var height = imgData.height;
  4649. var map = [];
  4650. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4651. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4652. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4653. }
  4654. this.paintInlineImageXObjectGroup(imgData, map);
  4655. },
  4656. paintInlineImageXObject:
  4657. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4658. var width = imgData.width;
  4659. var height = imgData.height;
  4660. var ctx = this.ctx;
  4661. this.save();
  4662. // scale the image to the unit square
  4663. ctx.scale(1 / width, -1 / height);
  4664. var currentTransform = ctx.mozCurrentTransformInverse;
  4665. var a = currentTransform[0], b = currentTransform[1];
  4666. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4667. var c = currentTransform[2], d = currentTransform[3];
  4668. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4669. var imgToPaint, tmpCanvas;
  4670. // instanceof HTMLElement does not work in jsdom node.js module
  4671. if (imgData instanceof HTMLElement || !imgData.data) {
  4672. imgToPaint = imgData;
  4673. } else {
  4674. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4675. var tmpCtx = tmpCanvas.context;
  4676. putBinaryImageData(tmpCtx, imgData);
  4677. imgToPaint = tmpCanvas.canvas;
  4678. }
  4679. var paintWidth = width, paintHeight = height;
  4680. var tmpCanvasId = 'prescale1';
  4681. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4682. // pixels during drawImage operation, painting on the temporary canvas(es)
  4683. // that are twice smaller in size
  4684. while ((widthScale > 2 && paintWidth > 1) ||
  4685. (heightScale > 2 && paintHeight > 1)) {
  4686. var newWidth = paintWidth, newHeight = paintHeight;
  4687. if (widthScale > 2 && paintWidth > 1) {
  4688. newWidth = Math.ceil(paintWidth / 2);
  4689. widthScale /= paintWidth / newWidth;
  4690. }
  4691. if (heightScale > 2 && paintHeight > 1) {
  4692. newHeight = Math.ceil(paintHeight / 2);
  4693. heightScale /= paintHeight / newHeight;
  4694. }
  4695. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4696. tmpCtx = tmpCanvas.context;
  4697. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4698. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4699. 0, 0, newWidth, newHeight);
  4700. imgToPaint = tmpCanvas.canvas;
  4701. paintWidth = newWidth;
  4702. paintHeight = newHeight;
  4703. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4704. }
  4705. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4706. 0, -height, width, height);
  4707. if (this.imageLayer) {
  4708. var position = this.getCanvasPosition(0, -height);
  4709. this.imageLayer.appendImage({
  4710. imgData: imgData,
  4711. left: position[0],
  4712. top: position[1],
  4713. width: width / currentTransform[0],
  4714. height: height / currentTransform[3]
  4715. });
  4716. }
  4717. this.restore();
  4718. },
  4719. paintInlineImageXObjectGroup:
  4720. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4721. var ctx = this.ctx;
  4722. var w = imgData.width;
  4723. var h = imgData.height;
  4724. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4725. var tmpCtx = tmpCanvas.context;
  4726. putBinaryImageData(tmpCtx, imgData);
  4727. for (var i = 0, ii = map.length; i < ii; i++) {
  4728. var entry = map[i];
  4729. ctx.save();
  4730. ctx.transform.apply(ctx, entry.transform);
  4731. ctx.scale(1, -1);
  4732. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4733. 0, -1, 1, 1);
  4734. if (this.imageLayer) {
  4735. var position = this.getCanvasPosition(entry.x, entry.y);
  4736. this.imageLayer.appendImage({
  4737. imgData: imgData,
  4738. left: position[0],
  4739. top: position[1],
  4740. width: w,
  4741. height: h
  4742. });
  4743. }
  4744. ctx.restore();
  4745. }
  4746. },
  4747. paintSolidColorImageMask:
  4748. function CanvasGraphics_paintSolidColorImageMask() {
  4749. this.ctx.fillRect(0, 0, 1, 1);
  4750. },
  4751. // Marked content
  4752. markPoint: function CanvasGraphics_markPoint(tag) {
  4753. // TODO Marked content.
  4754. },
  4755. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4756. // TODO Marked content.
  4757. },
  4758. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4759. // TODO Marked content.
  4760. },
  4761. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4762. tag, properties) {
  4763. // TODO Marked content.
  4764. },
  4765. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4766. // TODO Marked content.
  4767. },
  4768. // Compatibility
  4769. beginCompat: function CanvasGraphics_beginCompat() {
  4770. // TODO ignore undefined operators (should we do that anyway?)
  4771. },
  4772. endCompat: function CanvasGraphics_endCompat() {
  4773. // TODO stop ignoring undefined operators
  4774. },
  4775. // Helper functions
  4776. consumePath: function CanvasGraphics_consumePath() {
  4777. var ctx = this.ctx;
  4778. if (this.pendingClip) {
  4779. if (this.pendingClip === EO_CLIP) {
  4780. if (ctx.mozFillRule !== undefined) {
  4781. ctx.mozFillRule = 'evenodd';
  4782. ctx.clip();
  4783. ctx.mozFillRule = 'nonzero';
  4784. } else {
  4785. try {
  4786. ctx.clip('evenodd');
  4787. } catch (ex) {
  4788. // shouldn't really happen, but browsers might think differently
  4789. ctx.clip();
  4790. }
  4791. }
  4792. } else {
  4793. ctx.clip();
  4794. }
  4795. this.pendingClip = null;
  4796. }
  4797. ctx.beginPath();
  4798. },
  4799. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4800. if (this.cachedGetSinglePixelWidth === null) {
  4801. var inverse = this.ctx.mozCurrentTransformInverse;
  4802. // max of the current horizontal and vertical scale
  4803. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4804. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4805. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4806. }
  4807. return this.cachedGetSinglePixelWidth;
  4808. },
  4809. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4810. var transform = this.ctx.mozCurrentTransform;
  4811. return [
  4812. transform[0] * x + transform[2] * y + transform[4],
  4813. transform[1] * x + transform[3] * y + transform[5]
  4814. ];
  4815. }
  4816. };
  4817. for (var op in OPS) {
  4818. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4819. }
  4820. return CanvasGraphics;
  4821. })();
  4822. var WebGLUtils = (function WebGLUtilsClosure() {
  4823. function loadShader(gl, code, shaderType) {
  4824. var shader = gl.createShader(shaderType);
  4825. gl.shaderSource(shader, code);
  4826. gl.compileShader(shader);
  4827. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4828. if (!compiled) {
  4829. var errorMsg = gl.getShaderInfoLog(shader);
  4830. throw new Error('Error during shader compilation: ' + errorMsg);
  4831. }
  4832. return shader;
  4833. }
  4834. function createVertexShader(gl, code) {
  4835. return loadShader(gl, code, gl.VERTEX_SHADER);
  4836. }
  4837. function createFragmentShader(gl, code) {
  4838. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4839. }
  4840. function createProgram(gl, shaders) {
  4841. var program = gl.createProgram();
  4842. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4843. gl.attachShader(program, shaders[i]);
  4844. }
  4845. gl.linkProgram(program);
  4846. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4847. if (!linked) {
  4848. var errorMsg = gl.getProgramInfoLog(program);
  4849. throw new Error('Error during program linking: ' + errorMsg);
  4850. }
  4851. return program;
  4852. }
  4853. function createTexture(gl, image, textureId) {
  4854. gl.activeTexture(textureId);
  4855. var texture = gl.createTexture();
  4856. gl.bindTexture(gl.TEXTURE_2D, texture);
  4857. // Set the parameters so we can render any size image.
  4858. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4859. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4860. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4861. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4862. // Upload the image into the texture.
  4863. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4864. return texture;
  4865. }
  4866. var currentGL, currentCanvas;
  4867. function generateGL() {
  4868. if (currentGL) {
  4869. return;
  4870. }
  4871. currentCanvas = document.createElement('canvas');
  4872. currentGL = currentCanvas.getContext('webgl',
  4873. { premultipliedalpha: false });
  4874. }
  4875. var smaskVertexShaderCode = '\
  4876. attribute vec2 a_position; \
  4877. attribute vec2 a_texCoord; \
  4878. \
  4879. uniform vec2 u_resolution; \
  4880. \
  4881. varying vec2 v_texCoord; \
  4882. \
  4883. void main() { \
  4884. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4885. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4886. \
  4887. v_texCoord = a_texCoord; \
  4888. } ';
  4889. var smaskFragmentShaderCode = '\
  4890. precision mediump float; \
  4891. \
  4892. uniform vec4 u_backdrop; \
  4893. uniform int u_subtype; \
  4894. uniform sampler2D u_image; \
  4895. uniform sampler2D u_mask; \
  4896. \
  4897. varying vec2 v_texCoord; \
  4898. \
  4899. void main() { \
  4900. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4901. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4902. if (u_backdrop.a > 0.0) { \
  4903. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4904. u_backdrop.rgb * (1.0 - maskColor.a); \
  4905. } \
  4906. float lum; \
  4907. if (u_subtype == 0) { \
  4908. lum = maskColor.a; \
  4909. } else { \
  4910. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4911. maskColor.b * 0.11; \
  4912. } \
  4913. imageColor.a *= lum; \
  4914. imageColor.rgb *= imageColor.a; \
  4915. gl_FragColor = imageColor; \
  4916. } ';
  4917. var smaskCache = null;
  4918. function initSmaskGL() {
  4919. var canvas, gl;
  4920. generateGL();
  4921. canvas = currentCanvas;
  4922. currentCanvas = null;
  4923. gl = currentGL;
  4924. currentGL = null;
  4925. // setup a GLSL program
  4926. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4927. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4928. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4929. gl.useProgram(program);
  4930. var cache = {};
  4931. cache.gl = gl;
  4932. cache.canvas = canvas;
  4933. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4934. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4935. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4936. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4937. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4938. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4939. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4940. // provide texture coordinates for the rectangle.
  4941. var texCoordBuffer = gl.createBuffer();
  4942. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4943. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4944. 0.0, 0.0,
  4945. 1.0, 0.0,
  4946. 0.0, 1.0,
  4947. 0.0, 1.0,
  4948. 1.0, 0.0,
  4949. 1.0, 1.0]), gl.STATIC_DRAW);
  4950. gl.enableVertexAttribArray(texCoordLocation);
  4951. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4952. gl.uniform1i(texLayerLocation, 0);
  4953. gl.uniform1i(texMaskLocation, 1);
  4954. smaskCache = cache;
  4955. }
  4956. function composeSMask(layer, mask, properties) {
  4957. var width = layer.width, height = layer.height;
  4958. if (!smaskCache) {
  4959. initSmaskGL();
  4960. }
  4961. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4962. canvas.width = width;
  4963. canvas.height = height;
  4964. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4965. gl.uniform2f(cache.resolutionLocation, width, height);
  4966. if (properties.backdrop) {
  4967. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4968. properties.backdrop[1], properties.backdrop[2], 1);
  4969. } else {
  4970. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4971. }
  4972. gl.uniform1i(cache.subtypeLocation,
  4973. properties.subtype === 'Luminosity' ? 1 : 0);
  4974. // Create a textures
  4975. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4976. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4977. // Create a buffer and put a single clipspace rectangle in
  4978. // it (2 triangles)
  4979. var buffer = gl.createBuffer();
  4980. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4981. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4982. 0, 0,
  4983. width, 0,
  4984. 0, height,
  4985. 0, height,
  4986. width, 0,
  4987. width, height]), gl.STATIC_DRAW);
  4988. gl.enableVertexAttribArray(cache.positionLocation);
  4989. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4990. // draw
  4991. gl.clearColor(0, 0, 0, 0);
  4992. gl.enable(gl.BLEND);
  4993. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4994. gl.clear(gl.COLOR_BUFFER_BIT);
  4995. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4996. gl.flush();
  4997. gl.deleteTexture(texture);
  4998. gl.deleteTexture(maskTexture);
  4999. gl.deleteBuffer(buffer);
  5000. return canvas;
  5001. }
  5002. var figuresVertexShaderCode = '\
  5003. attribute vec2 a_position; \
  5004. attribute vec3 a_color; \
  5005. \
  5006. uniform vec2 u_resolution; \
  5007. uniform vec2 u_scale; \
  5008. uniform vec2 u_offset; \
  5009. \
  5010. varying vec4 v_color; \
  5011. \
  5012. void main() { \
  5013. vec2 position = (a_position + u_offset) * u_scale; \
  5014. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5015. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5016. \
  5017. v_color = vec4(a_color / 255.0, 1.0); \
  5018. } ';
  5019. var figuresFragmentShaderCode = '\
  5020. precision mediump float; \
  5021. \
  5022. varying vec4 v_color; \
  5023. \
  5024. void main() { \
  5025. gl_FragColor = v_color; \
  5026. } ';
  5027. var figuresCache = null;
  5028. function initFiguresGL() {
  5029. var canvas, gl;
  5030. generateGL();
  5031. canvas = currentCanvas;
  5032. currentCanvas = null;
  5033. gl = currentGL;
  5034. currentGL = null;
  5035. // setup a GLSL program
  5036. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5037. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5038. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5039. gl.useProgram(program);
  5040. var cache = {};
  5041. cache.gl = gl;
  5042. cache.canvas = canvas;
  5043. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5044. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5045. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5046. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5047. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5048. figuresCache = cache;
  5049. }
  5050. function drawFigures(width, height, backgroundColor, figures, context) {
  5051. if (!figuresCache) {
  5052. initFiguresGL();
  5053. }
  5054. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5055. canvas.width = width;
  5056. canvas.height = height;
  5057. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5058. gl.uniform2f(cache.resolutionLocation, width, height);
  5059. // count triangle points
  5060. var count = 0;
  5061. var i, ii, rows;
  5062. for (i = 0, ii = figures.length; i < ii; i++) {
  5063. switch (figures[i].type) {
  5064. case 'lattice':
  5065. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5066. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5067. break;
  5068. case 'triangles':
  5069. count += figures[i].coords.length;
  5070. break;
  5071. }
  5072. }
  5073. // transfer data
  5074. var coords = new Float32Array(count * 2);
  5075. var colors = new Uint8Array(count * 3);
  5076. var coordsMap = context.coords, colorsMap = context.colors;
  5077. var pIndex = 0, cIndex = 0;
  5078. for (i = 0, ii = figures.length; i < ii; i++) {
  5079. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5080. switch (figure.type) {
  5081. case 'lattice':
  5082. var cols = figure.verticesPerRow;
  5083. rows = (ps.length / cols) | 0;
  5084. for (var row = 1; row < rows; row++) {
  5085. var offset = row * cols + 1;
  5086. for (var col = 1; col < cols; col++, offset++) {
  5087. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5088. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5089. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5090. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5091. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5092. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5093. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5094. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5095. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5096. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5097. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5098. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5099. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5100. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5101. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5102. coords[pIndex + 6] = coords[pIndex + 2];
  5103. coords[pIndex + 7] = coords[pIndex + 3];
  5104. coords[pIndex + 8] = coords[pIndex + 4];
  5105. coords[pIndex + 9] = coords[pIndex + 5];
  5106. coords[pIndex + 10] = coordsMap[ps[offset]];
  5107. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5108. colors[cIndex + 9] = colors[cIndex + 3];
  5109. colors[cIndex + 10] = colors[cIndex + 4];
  5110. colors[cIndex + 11] = colors[cIndex + 5];
  5111. colors[cIndex + 12] = colors[cIndex + 6];
  5112. colors[cIndex + 13] = colors[cIndex + 7];
  5113. colors[cIndex + 14] = colors[cIndex + 8];
  5114. colors[cIndex + 15] = colorsMap[cs[offset]];
  5115. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5116. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5117. pIndex += 12;
  5118. cIndex += 18;
  5119. }
  5120. }
  5121. break;
  5122. case 'triangles':
  5123. for (var j = 0, jj = ps.length; j < jj; j++) {
  5124. coords[pIndex] = coordsMap[ps[j]];
  5125. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5126. colors[cIndex] = colorsMap[cs[i]];
  5127. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5128. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5129. pIndex += 2;
  5130. cIndex += 3;
  5131. }
  5132. break;
  5133. }
  5134. }
  5135. // draw
  5136. if (backgroundColor) {
  5137. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5138. backgroundColor[2] / 255, 1.0);
  5139. } else {
  5140. gl.clearColor(0, 0, 0, 0);
  5141. }
  5142. gl.clear(gl.COLOR_BUFFER_BIT);
  5143. var coordsBuffer = gl.createBuffer();
  5144. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5145. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5146. gl.enableVertexAttribArray(cache.positionLocation);
  5147. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5148. var colorsBuffer = gl.createBuffer();
  5149. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5150. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5151. gl.enableVertexAttribArray(cache.colorLocation);
  5152. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5153. 0, 0);
  5154. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5155. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5156. gl.drawArrays(gl.TRIANGLES, 0, count);
  5157. gl.flush();
  5158. gl.deleteBuffer(coordsBuffer);
  5159. gl.deleteBuffer(colorsBuffer);
  5160. return canvas;
  5161. }
  5162. function cleanup() {
  5163. if (smaskCache && smaskCache.canvas) {
  5164. smaskCache.canvas.width = 0;
  5165. smaskCache.canvas.height = 0;
  5166. }
  5167. if (figuresCache && figuresCache.canvas) {
  5168. figuresCache.canvas.width = 0;
  5169. figuresCache.canvas.height = 0;
  5170. }
  5171. smaskCache = null;
  5172. figuresCache = null;
  5173. }
  5174. return {
  5175. get isEnabled() {
  5176. if (PDFJS.disableWebGL) {
  5177. return false;
  5178. }
  5179. var enabled = false;
  5180. try {
  5181. generateGL();
  5182. enabled = !!currentGL;
  5183. } catch (e) { }
  5184. return shadow(this, 'isEnabled', enabled);
  5185. },
  5186. composeSMask: composeSMask,
  5187. drawFigures: drawFigures,
  5188. clear: cleanup
  5189. };
  5190. })();
  5191. var ShadingIRs = {};
  5192. ShadingIRs.RadialAxial = {
  5193. fromIR: function RadialAxial_fromIR(raw) {
  5194. var type = raw[1];
  5195. var colorStops = raw[2];
  5196. var p0 = raw[3];
  5197. var p1 = raw[4];
  5198. var r0 = raw[5];
  5199. var r1 = raw[6];
  5200. return {
  5201. type: 'Pattern',
  5202. getPattern: function RadialAxial_getPattern(ctx) {
  5203. var grad;
  5204. if (type === 'axial') {
  5205. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5206. } else if (type === 'radial') {
  5207. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5208. }
  5209. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5210. var c = colorStops[i];
  5211. grad.addColorStop(c[0], c[1]);
  5212. }
  5213. return grad;
  5214. }
  5215. };
  5216. }
  5217. };
  5218. var createMeshCanvas = (function createMeshCanvasClosure() {
  5219. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5220. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5221. var coords = context.coords, colors = context.colors;
  5222. var bytes = data.data, rowSize = data.width * 4;
  5223. var tmp;
  5224. if (coords[p1 + 1] > coords[p2 + 1]) {
  5225. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5226. }
  5227. if (coords[p2 + 1] > coords[p3 + 1]) {
  5228. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5229. }
  5230. if (coords[p1 + 1] > coords[p2 + 1]) {
  5231. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5232. }
  5233. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5234. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5235. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5236. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5237. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5238. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5239. if (y1 >= y3) {
  5240. return;
  5241. }
  5242. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5243. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5244. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5245. var minY = Math.round(y1), maxY = Math.round(y3);
  5246. var xa, car, cag, cab;
  5247. var xb, cbr, cbg, cbb;
  5248. var k;
  5249. for (var y = minY; y <= maxY; y++) {
  5250. if (y < y2) {
  5251. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5252. xa = x1 - (x1 - x2) * k;
  5253. car = c1r - (c1r - c2r) * k;
  5254. cag = c1g - (c1g - c2g) * k;
  5255. cab = c1b - (c1b - c2b) * k;
  5256. } else {
  5257. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5258. xa = x2 - (x2 - x3) * k;
  5259. car = c2r - (c2r - c3r) * k;
  5260. cag = c2g - (c2g - c3g) * k;
  5261. cab = c2b - (c2b - c3b) * k;
  5262. }
  5263. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5264. xb = x1 - (x1 - x3) * k;
  5265. cbr = c1r - (c1r - c3r) * k;
  5266. cbg = c1g - (c1g - c3g) * k;
  5267. cbb = c1b - (c1b - c3b) * k;
  5268. var x1_ = Math.round(Math.min(xa, xb));
  5269. var x2_ = Math.round(Math.max(xa, xb));
  5270. var j = rowSize * y + x1_ * 4;
  5271. for (var x = x1_; x <= x2_; x++) {
  5272. k = (xa - x) / (xa - xb);
  5273. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5274. bytes[j++] = (car - (car - cbr) * k) | 0;
  5275. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5276. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5277. bytes[j++] = 255;
  5278. }
  5279. }
  5280. }
  5281. function drawFigure(data, figure, context) {
  5282. var ps = figure.coords;
  5283. var cs = figure.colors;
  5284. var i, ii;
  5285. switch (figure.type) {
  5286. case 'lattice':
  5287. var verticesPerRow = figure.verticesPerRow;
  5288. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5289. var cols = verticesPerRow - 1;
  5290. for (i = 0; i < rows; i++) {
  5291. var q = i * verticesPerRow;
  5292. for (var j = 0; j < cols; j++, q++) {
  5293. drawTriangle(data, context,
  5294. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5295. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5296. drawTriangle(data, context,
  5297. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5298. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5299. }
  5300. }
  5301. break;
  5302. case 'triangles':
  5303. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5304. drawTriangle(data, context,
  5305. ps[i], ps[i + 1], ps[i + 2],
  5306. cs[i], cs[i + 1], cs[i + 2]);
  5307. }
  5308. break;
  5309. default:
  5310. error('illigal figure');
  5311. break;
  5312. }
  5313. }
  5314. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5315. backgroundColor) {
  5316. // we will increase scale on some weird factor to let antialiasing take
  5317. // care of "rough" edges
  5318. var EXPECTED_SCALE = 1.1;
  5319. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5320. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5321. var offsetX = Math.floor(bounds[0]);
  5322. var offsetY = Math.floor(bounds[1]);
  5323. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5324. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5325. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5326. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5327. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5328. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5329. var scaleX = boundsWidth / width;
  5330. var scaleY = boundsHeight / height;
  5331. var context = {
  5332. coords: coords,
  5333. colors: colors,
  5334. offsetX: -offsetX,
  5335. offsetY: -offsetY,
  5336. scaleX: 1 / scaleX,
  5337. scaleY: 1 / scaleY
  5338. };
  5339. var canvas, tmpCanvas, i, ii;
  5340. if (WebGLUtils.isEnabled) {
  5341. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5342. figures, context);
  5343. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5344. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5345. tmpCanvas.context.drawImage(canvas, 0, 0);
  5346. canvas = tmpCanvas.canvas;
  5347. } else {
  5348. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5349. var tmpCtx = tmpCanvas.context;
  5350. var data = tmpCtx.createImageData(width, height);
  5351. if (backgroundColor) {
  5352. var bytes = data.data;
  5353. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5354. bytes[i] = backgroundColor[0];
  5355. bytes[i + 1] = backgroundColor[1];
  5356. bytes[i + 2] = backgroundColor[2];
  5357. bytes[i + 3] = 255;
  5358. }
  5359. }
  5360. for (i = 0; i < figures.length; i++) {
  5361. drawFigure(data, figures[i], context);
  5362. }
  5363. tmpCtx.putImageData(data, 0, 0);
  5364. canvas = tmpCanvas.canvas;
  5365. }
  5366. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5367. scaleX: scaleX, scaleY: scaleY};
  5368. }
  5369. return createMeshCanvas;
  5370. })();
  5371. ShadingIRs.Mesh = {
  5372. fromIR: function Mesh_fromIR(raw) {
  5373. //var type = raw[1];
  5374. var coords = raw[2];
  5375. var colors = raw[3];
  5376. var figures = raw[4];
  5377. var bounds = raw[5];
  5378. var matrix = raw[6];
  5379. //var bbox = raw[7];
  5380. var background = raw[8];
  5381. return {
  5382. type: 'Pattern',
  5383. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5384. var scale;
  5385. if (shadingFill) {
  5386. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5387. } else {
  5388. // Obtain scale from matrix and current transformation matrix.
  5389. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5390. if (matrix) {
  5391. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5392. scale = [scale[0] * matrixScale[0],
  5393. scale[1] * matrixScale[1]];
  5394. }
  5395. }
  5396. // Rasterizing on the main thread since sending/queue large canvases
  5397. // might cause OOM.
  5398. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5399. colors, figures, shadingFill ? null : background);
  5400. if (!shadingFill) {
  5401. ctx.setTransform.apply(ctx, owner.baseTransform);
  5402. if (matrix) {
  5403. ctx.transform.apply(ctx, matrix);
  5404. }
  5405. }
  5406. ctx.translate(temporaryPatternCanvas.offsetX,
  5407. temporaryPatternCanvas.offsetY);
  5408. ctx.scale(temporaryPatternCanvas.scaleX,
  5409. temporaryPatternCanvas.scaleY);
  5410. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5411. }
  5412. };
  5413. }
  5414. };
  5415. ShadingIRs.Dummy = {
  5416. fromIR: function Dummy_fromIR() {
  5417. return {
  5418. type: 'Pattern',
  5419. getPattern: function Dummy_fromIR_getPattern() {
  5420. return 'hotpink';
  5421. }
  5422. };
  5423. }
  5424. };
  5425. function getShadingPatternFromIR(raw) {
  5426. var shadingIR = ShadingIRs[raw[0]];
  5427. if (!shadingIR) {
  5428. error('Unknown IR type: ' + raw[0]);
  5429. }
  5430. return shadingIR.fromIR(raw);
  5431. }
  5432. var TilingPattern = (function TilingPatternClosure() {
  5433. var PaintType = {
  5434. COLORED: 1,
  5435. UNCOLORED: 2
  5436. };
  5437. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5438. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5439. this.operatorList = IR[2];
  5440. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5441. this.bbox = IR[4];
  5442. this.xstep = IR[5];
  5443. this.ystep = IR[6];
  5444. this.paintType = IR[7];
  5445. this.tilingType = IR[8];
  5446. this.color = color;
  5447. this.objs = objs;
  5448. this.commonObjs = commonObjs;
  5449. this.baseTransform = baseTransform;
  5450. this.type = 'Pattern';
  5451. this.ctx = ctx;
  5452. }
  5453. TilingPattern.prototype = {
  5454. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5455. var operatorList = this.operatorList;
  5456. var bbox = this.bbox;
  5457. var xstep = this.xstep;
  5458. var ystep = this.ystep;
  5459. var paintType = this.paintType;
  5460. var tilingType = this.tilingType;
  5461. var color = this.color;
  5462. var objs = this.objs;
  5463. var commonObjs = this.commonObjs;
  5464. info('TilingType: ' + tilingType);
  5465. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5466. var topLeft = [x0, y0];
  5467. // we want the canvas to be as large as the step size
  5468. var botRight = [x0 + xstep, y0 + ystep];
  5469. var width = botRight[0] - topLeft[0];
  5470. var height = botRight[1] - topLeft[1];
  5471. // Obtain scale from matrix and current transformation matrix.
  5472. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5473. var curMatrixScale = Util.singularValueDecompose2dScale(
  5474. this.baseTransform);
  5475. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5476. matrixScale[1] * curMatrixScale[1]];
  5477. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5478. // Use width and height values that are as close as possible to the end
  5479. // result when the pattern is used. Too low value makes the pattern look
  5480. // blurry. Too large value makes it look too crispy.
  5481. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5482. MAX_PATTERN_SIZE);
  5483. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5484. MAX_PATTERN_SIZE);
  5485. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5486. var tmpCtx = tmpCanvas.context;
  5487. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5488. graphics.groupLevel = owner.groupLevel;
  5489. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5490. this.setScale(width, height, xstep, ystep);
  5491. this.transformToScale(graphics);
  5492. // transform coordinates to pattern space
  5493. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5494. graphics.transform.apply(graphics, tmpTranslate);
  5495. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5496. graphics.executeOperatorList(operatorList);
  5497. return tmpCanvas.canvas;
  5498. },
  5499. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5500. this.scale = [width / xstep, height / ystep];
  5501. },
  5502. transformToScale: function TilingPattern_transformToScale(graphics) {
  5503. var scale = this.scale;
  5504. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5505. graphics.transform.apply(graphics, tmpScale);
  5506. },
  5507. scaleToContext: function TilingPattern_scaleToContext() {
  5508. var scale = this.scale;
  5509. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5510. },
  5511. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5512. if (bbox && isArray(bbox) && bbox.length === 4) {
  5513. var bboxWidth = x1 - x0;
  5514. var bboxHeight = y1 - y0;
  5515. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5516. graphics.clip();
  5517. graphics.endPath();
  5518. }
  5519. },
  5520. setFillAndStrokeStyleToContext:
  5521. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5522. switch (paintType) {
  5523. case PaintType.COLORED:
  5524. var ctx = this.ctx;
  5525. context.fillStyle = ctx.fillStyle;
  5526. context.strokeStyle = ctx.strokeStyle;
  5527. break;
  5528. case PaintType.UNCOLORED:
  5529. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5530. context.fillStyle = cssColor;
  5531. context.strokeStyle = cssColor;
  5532. break;
  5533. default:
  5534. error('Unsupported paint type: ' + paintType);
  5535. }
  5536. },
  5537. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5538. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5539. ctx = this.ctx;
  5540. ctx.setTransform.apply(ctx, this.baseTransform);
  5541. ctx.transform.apply(ctx, this.matrix);
  5542. this.scaleToContext();
  5543. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5544. }
  5545. };
  5546. return TilingPattern;
  5547. })();
  5548. PDFJS.disableFontFace = false;
  5549. var FontLoader = {
  5550. insertRule: function fontLoaderInsertRule(rule) {
  5551. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5552. if (!styleElement) {
  5553. styleElement = document.createElement('style');
  5554. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5555. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5556. styleElement);
  5557. }
  5558. var styleSheet = styleElement.sheet;
  5559. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5560. },
  5561. clear: function fontLoaderClear() {
  5562. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5563. if (styleElement) {
  5564. styleElement.parentNode.removeChild(styleElement);
  5565. }
  5566. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5567. document.fonts.delete(nativeFontFace);
  5568. });
  5569. this.nativeFontFaces.length = 0;
  5570. },
  5571. get loadTestFont() {
  5572. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5573. // height.
  5574. return shadow(this, 'loadTestFont', atob(
  5575. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5576. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5577. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5578. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5579. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5580. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5581. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5582. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5583. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5584. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5585. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5586. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5587. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5588. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5589. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5590. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5591. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5592. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5593. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5594. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5595. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5596. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5597. ));
  5598. },
  5599. loadTestFontId: 0,
  5600. loadingContext: {
  5601. requests: [],
  5602. nextRequestId: 0
  5603. },
  5604. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5605. if (isWorker) {
  5606. return false;
  5607. }
  5608. // User agent string sniffing is bad, but there is no reliable way to tell
  5609. // if font is fully loaded and ready to be used with canvas.
  5610. var userAgent = window.navigator.userAgent;
  5611. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5612. if (m && m[1] >= 14) {
  5613. return true;
  5614. }
  5615. // TODO other browsers
  5616. if (userAgent === 'node') {
  5617. return true;
  5618. }
  5619. return false;
  5620. })(),
  5621. nativeFontFaces: [],
  5622. isFontLoadingAPISupported: !isWorker && !!document.fonts,
  5623. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5624. this.nativeFontFaces.push(nativeFontFace);
  5625. document.fonts.add(nativeFontFace);
  5626. },
  5627. bind: function fontLoaderBind(fonts, callback) {
  5628. assert(!isWorker, 'bind() shall be called from main thread');
  5629. var rules = [];
  5630. var fontsToLoad = [];
  5631. var fontLoadPromises = [];
  5632. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5633. var font = fonts[i];
  5634. // Add the font to the DOM only once or skip if the font
  5635. // is already loaded.
  5636. if (font.attached || font.loading === false) {
  5637. continue;
  5638. }
  5639. font.attached = true;
  5640. if (this.isFontLoadingAPISupported) {
  5641. var nativeFontFace = font.createNativeFontFace();
  5642. if (nativeFontFace) {
  5643. fontLoadPromises.push(nativeFontFace.loaded);
  5644. }
  5645. } else {
  5646. var rule = font.bindDOM();
  5647. if (rule) {
  5648. rules.push(rule);
  5649. fontsToLoad.push(font);
  5650. }
  5651. }
  5652. }
  5653. var request = FontLoader.queueLoadingCallback(callback);
  5654. if (this.isFontLoadingAPISupported) {
  5655. Promise.all(fontsToLoad).then(function() {
  5656. request.complete();
  5657. });
  5658. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5659. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5660. } else {
  5661. request.complete();
  5662. }
  5663. },
  5664. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5665. function LoadLoader_completeRequest() {
  5666. assert(!request.end, 'completeRequest() cannot be called twice');
  5667. request.end = Date.now();
  5668. // sending all completed requests in order how they were queued
  5669. while (context.requests.length > 0 && context.requests[0].end) {
  5670. var otherRequest = context.requests.shift();
  5671. setTimeout(otherRequest.callback, 0);
  5672. }
  5673. }
  5674. var context = FontLoader.loadingContext;
  5675. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5676. var request = {
  5677. id: requestId,
  5678. complete: LoadLoader_completeRequest,
  5679. callback: callback,
  5680. started: Date.now()
  5681. };
  5682. context.requests.push(request);
  5683. return request;
  5684. },
  5685. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5686. fonts,
  5687. request) {
  5688. /** Hack begin */
  5689. // There's currently no event when a font has finished downloading so the
  5690. // following code is a dirty hack to 'guess' when a font is
  5691. // ready. It's assumed fonts are loaded in order, so add a known test
  5692. // font after the desired fonts and then test for the loading of that
  5693. // test font.
  5694. function int32(data, offset) {
  5695. return (data.charCodeAt(offset) << 24) |
  5696. (data.charCodeAt(offset + 1) << 16) |
  5697. (data.charCodeAt(offset + 2) << 8) |
  5698. (data.charCodeAt(offset + 3) & 0xff);
  5699. }
  5700. function spliceString(s, offset, remove, insert) {
  5701. var chunk1 = s.substr(0, offset);
  5702. var chunk2 = s.substr(offset + remove);
  5703. return chunk1 + insert + chunk2;
  5704. }
  5705. var i, ii;
  5706. var canvas = document.createElement('canvas');
  5707. canvas.width = 1;
  5708. canvas.height = 1;
  5709. var ctx = canvas.getContext('2d');
  5710. var called = 0;
  5711. function isFontReady(name, callback) {
  5712. called++;
  5713. // With setTimeout clamping this gives the font ~100ms to load.
  5714. if(called > 30) {
  5715. warn('Load test font never loaded.');
  5716. callback();
  5717. return;
  5718. }
  5719. ctx.font = '30px ' + name;
  5720. ctx.fillText('.', 0, 20);
  5721. var imageData = ctx.getImageData(0, 0, 1, 1);
  5722. if (imageData.data[3] > 0) {
  5723. callback();
  5724. return;
  5725. }
  5726. setTimeout(isFontReady.bind(null, name, callback));
  5727. }
  5728. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5729. // Chromium seems to cache fonts based on a hash of the actual font data,
  5730. // so the font must be modified for each load test else it will appear to
  5731. // be loaded already.
  5732. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5733. // font by splitting it in chunks before hand and padding the font id.
  5734. var data = this.loadTestFont;
  5735. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5736. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5737. loadTestFontId);
  5738. // CFF checksum is important for IE, adjusting it
  5739. var CFF_CHECKSUM_OFFSET = 16;
  5740. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5741. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5742. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5743. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5744. }
  5745. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5746. checksum = (checksum - XXXX_VALUE +
  5747. int32(loadTestFontId + 'XXX', i)) | 0;
  5748. }
  5749. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5750. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5751. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5752. url + '}';
  5753. FontLoader.insertRule(rule);
  5754. var names = [];
  5755. for (i = 0, ii = fonts.length; i < ii; i++) {
  5756. names.push(fonts[i].loadedName);
  5757. }
  5758. names.push(loadTestFontId);
  5759. var div = document.createElement('div');
  5760. div.setAttribute('style',
  5761. 'visibility: hidden;' +
  5762. 'width: 10px; height: 10px;' +
  5763. 'position: absolute; top: 0px; left: 0px;');
  5764. for (i = 0, ii = names.length; i < ii; ++i) {
  5765. var span = document.createElement('span');
  5766. span.textContent = 'Hi';
  5767. span.style.fontFamily = names[i];
  5768. div.appendChild(span);
  5769. }
  5770. document.body.appendChild(div);
  5771. isFontReady(loadTestFontId, function() {
  5772. document.body.removeChild(div);
  5773. request.complete();
  5774. });
  5775. /** Hack end */
  5776. }
  5777. };
  5778. var FontFaceObject = (function FontFaceObjectClosure() {
  5779. function FontFaceObject(name, file, properties) {
  5780. this.compiledGlyphs = {};
  5781. if (arguments.length === 1) {
  5782. // importing translated data
  5783. var data = arguments[0];
  5784. for (var i in data) {
  5785. this[i] = data[i];
  5786. }
  5787. return;
  5788. }
  5789. }
  5790. FontFaceObject.prototype = {
  5791. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5792. if (!this.data) {
  5793. return null;
  5794. }
  5795. if (PDFJS.disableFontFace) {
  5796. this.disableFontFace = true;
  5797. return null;
  5798. }
  5799. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5800. FontLoader.addNativeFontFace(nativeFontFace);
  5801. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5802. globalScope['FontInspector'].enabled) {
  5803. globalScope['FontInspector'].fontAdded(this);
  5804. }
  5805. return nativeFontFace;
  5806. },
  5807. bindDOM: function FontFaceObject_bindDOM() {
  5808. if (!this.data) {
  5809. return null;
  5810. }
  5811. if (PDFJS.disableFontFace) {
  5812. this.disableFontFace = true;
  5813. return null;
  5814. }
  5815. var data = bytesToString(new Uint8Array(this.data));
  5816. var fontName = this.loadedName;
  5817. // Add the font-face rule to the document
  5818. var url = ('url(data:' + this.mimetype + ';base64,' +
  5819. window.btoa(data) + ');');
  5820. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5821. FontLoader.insertRule(rule);
  5822. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5823. globalScope['FontInspector'].enabled) {
  5824. globalScope['FontInspector'].fontAdded(this, url);
  5825. }
  5826. return rule;
  5827. },
  5828. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5829. if (!(character in this.compiledGlyphs)) {
  5830. var js = objs.get(this.loadedName + '_path_' + character);
  5831. /*jshint -W054 */
  5832. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5833. }
  5834. return this.compiledGlyphs[character];
  5835. }
  5836. };
  5837. return FontFaceObject;
  5838. })();
  5839. var ANNOT_MIN_SIZE = 10; // px
  5840. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5841. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5842. function setTextStyles(element, item, fontObj) {
  5843. var style = element.style;
  5844. style.fontSize = item.fontSize + 'px';
  5845. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5846. if (!fontObj) {
  5847. return;
  5848. }
  5849. style.fontWeight = fontObj.black ?
  5850. (fontObj.bold ? 'bolder' : 'bold') :
  5851. (fontObj.bold ? 'bold' : 'normal');
  5852. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5853. var fontName = fontObj.loadedName;
  5854. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5855. // Use a reasonable default font if the font doesn't specify a fallback
  5856. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5857. style.fontFamily = fontFamily + fallbackName;
  5858. }
  5859. function initContainer(item, drawBorder) {
  5860. var container = document.createElement('section');
  5861. var cstyle = container.style;
  5862. var width = item.rect[2] - item.rect[0];
  5863. var height = item.rect[3] - item.rect[1];
  5864. var bWidth = item.borderWidth || 0;
  5865. if (bWidth) {
  5866. width = width - 2 * bWidth;
  5867. height = height - 2 * bWidth;
  5868. cstyle.borderWidth = bWidth + 'px';
  5869. var color = item.color;
  5870. if (drawBorder && color) {
  5871. cstyle.borderStyle = 'solid';
  5872. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5873. Math.round(color[1] * 255),
  5874. Math.round(color[2] * 255));
  5875. }
  5876. }
  5877. cstyle.width = width + 'px';
  5878. cstyle.height = height + 'px';
  5879. return container;
  5880. }
  5881. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5882. var element = document.createElement('div');
  5883. var width = item.rect[2] - item.rect[0];
  5884. var height = item.rect[3] - item.rect[1];
  5885. element.style.width = width + 'px';
  5886. element.style.height = height + 'px';
  5887. element.style.display = 'table';
  5888. var content = document.createElement('div');
  5889. content.textContent = item.fieldValue;
  5890. var textAlignment = item.textAlignment;
  5891. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5892. content.style.verticalAlign = 'middle';
  5893. content.style.display = 'table-cell';
  5894. var fontObj = item.fontRefName ?
  5895. commonObjs.getData(item.fontRefName) : null;
  5896. setTextStyles(content, item, fontObj);
  5897. element.appendChild(content);
  5898. return element;
  5899. }
  5900. function getHtmlElementForTextAnnotation(item) {
  5901. var rect = item.rect;
  5902. // sanity check because of OOo-generated PDFs
  5903. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5904. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5905. }
  5906. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5907. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5908. }
  5909. var container = initContainer(item, false);
  5910. container.className = 'annotText';
  5911. var image = document.createElement('img');
  5912. image.style.height = container.style.height;
  5913. image.style.width = container.style.width;
  5914. var iconName = item.name;
  5915. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5916. iconName.toLowerCase() + '.svg';
  5917. image.alt = '[{{type}} Annotation]';
  5918. image.dataset.l10nId = 'text_annotation_type';
  5919. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5920. var contentWrapper = document.createElement('div');
  5921. contentWrapper.className = 'annotTextContentWrapper';
  5922. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5923. contentWrapper.style.top = '-10px';
  5924. var content = document.createElement('div');
  5925. content.className = 'annotTextContent';
  5926. content.setAttribute('hidden', true);
  5927. var i, ii;
  5928. if (item.hasBgColor) {
  5929. var color = item.color;
  5930. // Enlighten the color (70%)
  5931. var BACKGROUND_ENLIGHT = 0.7;
  5932. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5933. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5934. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5935. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5936. (g * 255) | 0,
  5937. (b * 255) | 0);
  5938. }
  5939. var title = document.createElement('h1');
  5940. var text = document.createElement('p');
  5941. title.textContent = item.title;
  5942. if (!item.content && !item.title) {
  5943. content.setAttribute('hidden', true);
  5944. } else {
  5945. var e = document.createElement('span');
  5946. var lines = item.content.split(/(?:\r\n?|\n)/);
  5947. for (i = 0, ii = lines.length; i < ii; ++i) {
  5948. var line = lines[i];
  5949. e.appendChild(document.createTextNode(line));
  5950. if (i < (ii - 1)) {
  5951. e.appendChild(document.createElement('br'));
  5952. }
  5953. }
  5954. text.appendChild(e);
  5955. var pinned = false;
  5956. var showAnnotation = function showAnnotation(pin) {
  5957. if (pin) {
  5958. pinned = true;
  5959. }
  5960. if (content.hasAttribute('hidden')) {
  5961. container.style.zIndex += 1;
  5962. content.removeAttribute('hidden');
  5963. }
  5964. };
  5965. var hideAnnotation = function hideAnnotation(unpin) {
  5966. if (unpin) {
  5967. pinned = false;
  5968. }
  5969. if (!content.hasAttribute('hidden') && !pinned) {
  5970. container.style.zIndex -= 1;
  5971. content.setAttribute('hidden', true);
  5972. }
  5973. };
  5974. var toggleAnnotation = function toggleAnnotation() {
  5975. if (pinned) {
  5976. hideAnnotation(true);
  5977. } else {
  5978. showAnnotation(true);
  5979. }
  5980. };
  5981. image.addEventListener('click', function image_clickHandler() {
  5982. toggleAnnotation();
  5983. }, false);
  5984. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5985. showAnnotation();
  5986. }, false);
  5987. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5988. hideAnnotation();
  5989. }, false);
  5990. content.addEventListener('click', function content_clickHandler() {
  5991. hideAnnotation(true);
  5992. }, false);
  5993. }
  5994. content.appendChild(title);
  5995. content.appendChild(text);
  5996. contentWrapper.appendChild(content);
  5997. container.appendChild(image);
  5998. container.appendChild(contentWrapper);
  5999. return container;
  6000. }
  6001. function getHtmlElementForLinkAnnotation(item) {
  6002. var container = initContainer(item, true);
  6003. container.className = 'annotLink';
  6004. var link = document.createElement('a');
  6005. link.href = link.title = item.url || '';
  6006. if (item.url && PDFJS.openExternalLinksInNewWindow) {
  6007. link.target = '_blank';
  6008. }
  6009. container.appendChild(link);
  6010. return container;
  6011. }
  6012. function getHtmlElement(data, objs) {
  6013. switch (data.annotationType) {
  6014. case AnnotationType.WIDGET:
  6015. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6016. case AnnotationType.TEXT:
  6017. return getHtmlElementForTextAnnotation(data);
  6018. case AnnotationType.LINK:
  6019. return getHtmlElementForLinkAnnotation(data);
  6020. default:
  6021. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6022. }
  6023. }
  6024. return {
  6025. getHtmlElement: getHtmlElement
  6026. };
  6027. })();
  6028. PDFJS.AnnotationUtils = AnnotationUtils;
  6029. var SVG_DEFAULTS = {
  6030. fontStyle: 'normal',
  6031. fontWeight: 'normal',
  6032. fillColor: '#000000'
  6033. };
  6034. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6035. var PNG_HEADER =
  6036. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6037. var CHUNK_WRAPPER_SIZE = 12;
  6038. var crcTable = new Int32Array(256);
  6039. for (var i = 0; i < 256; i++) {
  6040. var c = i;
  6041. for (var h = 0; h < 8; h++) {
  6042. if (c & 1) {
  6043. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6044. } else {
  6045. c = (c >> 1) & 0x7fffffff;
  6046. }
  6047. }
  6048. crcTable[i] = c;
  6049. }
  6050. function crc32(data, start, end) {
  6051. var crc = -1;
  6052. for (var i = start; i < end; i++) {
  6053. var a = (crc ^ data[i]) & 0xff;
  6054. var b = crcTable[a];
  6055. crc = (crc >>> 8) ^ b;
  6056. }
  6057. return crc ^ -1;
  6058. }
  6059. function writePngChunk(type, body, data, offset) {
  6060. var p = offset;
  6061. var len = body.length;
  6062. data[p] = len >> 24 & 0xff;
  6063. data[p + 1] = len >> 16 & 0xff;
  6064. data[p + 2] = len >> 8 & 0xff;
  6065. data[p + 3] = len & 0xff;
  6066. p += 4;
  6067. data[p] = type.charCodeAt(0) & 0xff;
  6068. data[p + 1] = type.charCodeAt(1) & 0xff;
  6069. data[p + 2] = type.charCodeAt(2) & 0xff;
  6070. data[p + 3] = type.charCodeAt(3) & 0xff;
  6071. p += 4;
  6072. data.set(body, p);
  6073. p += body.length;
  6074. var crc = crc32(data, offset + 4, p);
  6075. data[p] = crc >> 24 & 0xff;
  6076. data[p + 1] = crc >> 16 & 0xff;
  6077. data[p + 2] = crc >> 8 & 0xff;
  6078. data[p + 3] = crc & 0xff;
  6079. }
  6080. function adler32(data, start, end) {
  6081. var a = 1;
  6082. var b = 0;
  6083. for (var i = start; i < end; ++i) {
  6084. a = (a + (data[i] & 0xff)) % 65521;
  6085. b = (b + a) % 65521;
  6086. }
  6087. return (b << 16) | a;
  6088. }
  6089. function encode(imgData, kind) {
  6090. var width = imgData.width;
  6091. var height = imgData.height;
  6092. var bitDepth, colorType, lineSize;
  6093. var bytes = imgData.data;
  6094. switch (kind) {
  6095. case ImageKind.GRAYSCALE_1BPP:
  6096. colorType = 0;
  6097. bitDepth = 1;
  6098. lineSize = (width + 7) >> 3;
  6099. break;
  6100. case ImageKind.RGB_24BPP:
  6101. colorType = 2;
  6102. bitDepth = 8;
  6103. lineSize = width * 3;
  6104. break;
  6105. case ImageKind.RGBA_32BPP:
  6106. colorType = 6;
  6107. bitDepth = 8;
  6108. lineSize = width * 4;
  6109. break;
  6110. default:
  6111. throw new Error('invalid format');
  6112. }
  6113. // prefix every row with predictor 0
  6114. var literals = new Uint8Array((1 + lineSize) * height);
  6115. var offsetLiterals = 0, offsetBytes = 0;
  6116. var y, i;
  6117. for (y = 0; y < height; ++y) {
  6118. literals[offsetLiterals++] = 0; // no prediction
  6119. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6120. offsetLiterals);
  6121. offsetBytes += lineSize;
  6122. offsetLiterals += lineSize;
  6123. }
  6124. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6125. // inverting for B/W
  6126. offsetLiterals = 0;
  6127. for (y = 0; y < height; y++) {
  6128. offsetLiterals++; // skipping predictor
  6129. for (i = 0; i < lineSize; i++) {
  6130. literals[offsetLiterals++] ^= 0xFF;
  6131. }
  6132. }
  6133. }
  6134. var ihdr = new Uint8Array([
  6135. width >> 24 & 0xff,
  6136. width >> 16 & 0xff,
  6137. width >> 8 & 0xff,
  6138. width & 0xff,
  6139. height >> 24 & 0xff,
  6140. height >> 16 & 0xff,
  6141. height >> 8 & 0xff,
  6142. height & 0xff,
  6143. bitDepth, // bit depth
  6144. colorType, // color type
  6145. 0x00, // compression method
  6146. 0x00, // filter method
  6147. 0x00 // interlace method
  6148. ]);
  6149. var len = literals.length;
  6150. var maxBlockLength = 0xFFFF;
  6151. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6152. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6153. var pi = 0;
  6154. idat[pi++] = 0x78; // compression method and flags
  6155. idat[pi++] = 0x9c; // flags
  6156. var pos = 0;
  6157. while (len > maxBlockLength) {
  6158. // writing non-final DEFLATE blocks type 0 and length of 65535
  6159. idat[pi++] = 0x00;
  6160. idat[pi++] = 0xff;
  6161. idat[pi++] = 0xff;
  6162. idat[pi++] = 0x00;
  6163. idat[pi++] = 0x00;
  6164. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6165. pi += maxBlockLength;
  6166. pos += maxBlockLength;
  6167. len -= maxBlockLength;
  6168. }
  6169. // writing non-final DEFLATE blocks type 0
  6170. idat[pi++] = 0x01;
  6171. idat[pi++] = len & 0xff;
  6172. idat[pi++] = len >> 8 & 0xff;
  6173. idat[pi++] = (~len & 0xffff) & 0xff;
  6174. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6175. idat.set(literals.subarray(pos), pi);
  6176. pi += literals.length - pos;
  6177. var adler = adler32(literals, 0, literals.length); // checksum
  6178. idat[pi++] = adler >> 24 & 0xff;
  6179. idat[pi++] = adler >> 16 & 0xff;
  6180. idat[pi++] = adler >> 8 & 0xff;
  6181. idat[pi++] = adler & 0xff;
  6182. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6183. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6184. ihdr.length + idat.length;
  6185. var data = new Uint8Array(pngLength);
  6186. var offset = 0;
  6187. data.set(PNG_HEADER, offset);
  6188. offset += PNG_HEADER.length;
  6189. writePngChunk('IHDR', ihdr, data, offset);
  6190. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6191. writePngChunk('IDATA', idat, data, offset);
  6192. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6193. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6194. return PDFJS.createObjectURL(data, 'image/png');
  6195. }
  6196. return function convertImgDataToPng(imgData) {
  6197. var kind = (imgData.kind === undefined ?
  6198. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6199. return encode(imgData, kind);
  6200. };
  6201. })();
  6202. var SVGExtraState = (function SVGExtraStateClosure() {
  6203. function SVGExtraState() {
  6204. this.fontSizeScale = 1;
  6205. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6206. this.fontSize = 0;
  6207. this.textMatrix = IDENTITY_MATRIX;
  6208. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6209. this.leading = 0;
  6210. // Current point (in user coordinates)
  6211. this.x = 0;
  6212. this.y = 0;
  6213. // Start of text line (in text coordinates)
  6214. this.lineX = 0;
  6215. this.lineY = 0;
  6216. // Character and word spacing
  6217. this.charSpacing = 0;
  6218. this.wordSpacing = 0;
  6219. this.textHScale = 1;
  6220. this.textRise = 0;
  6221. // Default foreground and background colors
  6222. this.fillColor = SVG_DEFAULTS.fillColor;
  6223. this.strokeColor = '#000000';
  6224. this.fillAlpha = 1;
  6225. this.strokeAlpha = 1;
  6226. this.lineWidth = 1;
  6227. this.lineJoin = '';
  6228. this.lineCap = '';
  6229. this.miterLimit = 0;
  6230. this.dashArray = [];
  6231. this.dashPhase = 0;
  6232. this.dependencies = [];
  6233. // Clipping
  6234. this.clipId = '';
  6235. this.pendingClip = false;
  6236. this.maskId = '';
  6237. }
  6238. SVGExtraState.prototype = {
  6239. clone: function SVGExtraState_clone() {
  6240. return Object.create(this);
  6241. },
  6242. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6243. this.x = x;
  6244. this.y = y;
  6245. }
  6246. };
  6247. return SVGExtraState;
  6248. })();
  6249. var SVGGraphics = (function SVGGraphicsClosure() {
  6250. function createScratchSVG(width, height) {
  6251. var NS = 'http://www.w3.org/2000/svg';
  6252. var svg = document.createElementNS(NS, 'svg:svg');
  6253. svg.setAttributeNS(null, 'version', '1.1');
  6254. svg.setAttributeNS(null, 'width', width + 'px');
  6255. svg.setAttributeNS(null, 'height', height + 'px');
  6256. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6257. return svg;
  6258. }
  6259. function opListToTree(opList) {
  6260. var opTree = [];
  6261. var tmp = [];
  6262. var opListLen = opList.length;
  6263. for (var x = 0; x < opListLen; x++) {
  6264. if (opList[x].fn === 'save') {
  6265. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6266. tmp.push(opTree);
  6267. opTree = opTree[opTree.length - 1].items;
  6268. continue;
  6269. }
  6270. if(opList[x].fn === 'restore') {
  6271. opTree = tmp.pop();
  6272. } else {
  6273. opTree.push(opList[x]);
  6274. }
  6275. }
  6276. return opTree;
  6277. }
  6278. /**
  6279. * Formats float number.
  6280. * @param value {number} number to format.
  6281. * @returns {string}
  6282. */
  6283. function pf(value) {
  6284. if (value === (value | 0)) { // integer number
  6285. return value.toString();
  6286. }
  6287. var s = value.toFixed(10);
  6288. var i = s.length - 1;
  6289. if (s[i] !== '0') {
  6290. return s;
  6291. }
  6292. // removing trailing zeros
  6293. do {
  6294. i--;
  6295. } while (s[i] === '0');
  6296. return s.substr(0, s[i] === '.' ? i : i + 1);
  6297. }
  6298. /**
  6299. * Formats transform matrix. The standard rotation, scale and translate
  6300. * matrices are replaced by their shorter forms, and for identity matrix
  6301. * returns empty string to save the memory.
  6302. * @param m {Array} matrix to format.
  6303. * @returns {string}
  6304. */
  6305. function pm(m) {
  6306. if (m[4] === 0 && m[5] === 0) {
  6307. if (m[1] === 0 && m[2] === 0) {
  6308. if (m[0] === 1 && m[3] === 1) {
  6309. return '';
  6310. }
  6311. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6312. }
  6313. if (m[0] === m[3] && m[1] === -m[2]) {
  6314. var a = Math.acos(m[0]) * 180 / Math.PI;
  6315. return 'rotate(' + pf(a) + ')';
  6316. }
  6317. } else {
  6318. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6319. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6320. }
  6321. }
  6322. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6323. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6324. }
  6325. function SVGGraphics(commonObjs, objs) {
  6326. this.current = new SVGExtraState();
  6327. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6328. this.transformStack = [];
  6329. this.extraStack = [];
  6330. this.commonObjs = commonObjs;
  6331. this.objs = objs;
  6332. this.pendingEOFill = false;
  6333. this.embedFonts = false;
  6334. this.embeddedFonts = {};
  6335. this.cssStyle = null;
  6336. }
  6337. var NS = 'http://www.w3.org/2000/svg';
  6338. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6339. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6340. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6341. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6342. var clipCount = 0;
  6343. var maskCount = 0;
  6344. SVGGraphics.prototype = {
  6345. save: function SVGGraphics_save() {
  6346. this.transformStack.push(this.transformMatrix);
  6347. var old = this.current;
  6348. this.extraStack.push(old);
  6349. this.current = old.clone();
  6350. },
  6351. restore: function SVGGraphics_restore() {
  6352. this.transformMatrix = this.transformStack.pop();
  6353. this.current = this.extraStack.pop();
  6354. this.tgrp = document.createElementNS(NS, 'svg:g');
  6355. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6356. this.pgrp.appendChild(this.tgrp);
  6357. },
  6358. group: function SVGGraphics_group(items) {
  6359. this.save();
  6360. this.executeOpTree(items);
  6361. this.restore();
  6362. },
  6363. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6364. var fnArray = operatorList.fnArray;
  6365. var fnArrayLen = fnArray.length;
  6366. var argsArray = operatorList.argsArray;
  6367. var self = this;
  6368. for (var i = 0; i < fnArrayLen; i++) {
  6369. if (OPS.dependency === fnArray[i]) {
  6370. var deps = argsArray[i];
  6371. for (var n = 0, nn = deps.length; n < nn; n++) {
  6372. var obj = deps[n];
  6373. var common = obj.substring(0, 2) === 'g_';
  6374. var promise;
  6375. if (common) {
  6376. promise = new Promise(function(resolve) {
  6377. self.commonObjs.get(obj, resolve);
  6378. });
  6379. } else {
  6380. promise = new Promise(function(resolve) {
  6381. self.objs.get(obj, resolve);
  6382. });
  6383. }
  6384. this.current.dependencies.push(promise);
  6385. }
  6386. }
  6387. }
  6388. return Promise.all(this.current.dependencies);
  6389. },
  6390. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6391. var transformMatrix = [a, b, c, d, e, f];
  6392. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6393. transformMatrix);
  6394. this.tgrp = document.createElementNS(NS, 'svg:g');
  6395. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6396. },
  6397. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6398. this.svg = createScratchSVG(viewport.width, viewport.height);
  6399. this.viewport = viewport;
  6400. return this.loadDependencies(operatorList).then(function () {
  6401. this.transformMatrix = IDENTITY_MATRIX;
  6402. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6403. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6404. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6405. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6406. this.defs = document.createElementNS(NS, 'svg:defs');
  6407. this.pgrp.appendChild(this.defs);
  6408. this.pgrp.appendChild(this.tgrp);
  6409. this.svg.appendChild(this.pgrp);
  6410. var opTree = this.convertOpList(operatorList);
  6411. this.executeOpTree(opTree);
  6412. return this.svg;
  6413. }.bind(this));
  6414. },
  6415. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6416. var argsArray = operatorList.argsArray;
  6417. var fnArray = operatorList.fnArray;
  6418. var fnArrayLen = fnArray.length;
  6419. var REVOPS = [];
  6420. var opList = [];
  6421. for (var op in OPS) {
  6422. REVOPS[OPS[op]] = op;
  6423. }
  6424. for (var x = 0; x < fnArrayLen; x++) {
  6425. var fnId = fnArray[x];
  6426. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6427. }
  6428. return opListToTree(opList);
  6429. },
  6430. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6431. var opTreeLen = opTree.length;
  6432. for(var x = 0; x < opTreeLen; x++) {
  6433. var fn = opTree[x].fn;
  6434. var fnId = opTree[x].fnId;
  6435. var args = opTree[x].args;
  6436. switch (fnId | 0) {
  6437. case OPS.beginText:
  6438. this.beginText();
  6439. break;
  6440. case OPS.setLeading:
  6441. this.setLeading(args);
  6442. break;
  6443. case OPS.setLeadingMoveText:
  6444. this.setLeadingMoveText(args[0], args[1]);
  6445. break;
  6446. case OPS.setFont:
  6447. this.setFont(args);
  6448. break;
  6449. case OPS.showText:
  6450. this.showText(args[0]);
  6451. break;
  6452. case OPS.showSpacedText:
  6453. this.showText(args[0]);
  6454. break;
  6455. case OPS.endText:
  6456. this.endText();
  6457. break;
  6458. case OPS.moveText:
  6459. this.moveText(args[0], args[1]);
  6460. break;
  6461. case OPS.setCharSpacing:
  6462. this.setCharSpacing(args[0]);
  6463. break;
  6464. case OPS.setWordSpacing:
  6465. this.setWordSpacing(args[0]);
  6466. break;
  6467. case OPS.setHScale:
  6468. this.setHScale(args[0]);
  6469. break;
  6470. case OPS.setTextMatrix:
  6471. this.setTextMatrix(args[0], args[1], args[2],
  6472. args[3], args[4], args[5]);
  6473. break;
  6474. case OPS.setLineWidth:
  6475. this.setLineWidth(args[0]);
  6476. break;
  6477. case OPS.setLineJoin:
  6478. this.setLineJoin(args[0]);
  6479. break;
  6480. case OPS.setLineCap:
  6481. this.setLineCap(args[0]);
  6482. break;
  6483. case OPS.setMiterLimit:
  6484. this.setMiterLimit(args[0]);
  6485. break;
  6486. case OPS.setFillRGBColor:
  6487. this.setFillRGBColor(args[0], args[1], args[2]);
  6488. break;
  6489. case OPS.setStrokeRGBColor:
  6490. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6491. break;
  6492. case OPS.setDash:
  6493. this.setDash(args[0], args[1]);
  6494. break;
  6495. case OPS.setGState:
  6496. this.setGState(args[0]);
  6497. break;
  6498. case OPS.fill:
  6499. this.fill();
  6500. break;
  6501. case OPS.eoFill:
  6502. this.eoFill();
  6503. break;
  6504. case OPS.stroke:
  6505. this.stroke();
  6506. break;
  6507. case OPS.fillStroke:
  6508. this.fillStroke();
  6509. break;
  6510. case OPS.eoFillStroke:
  6511. this.eoFillStroke();
  6512. break;
  6513. case OPS.clip:
  6514. this.clip('nonzero');
  6515. break;
  6516. case OPS.eoClip:
  6517. this.clip('evenodd');
  6518. break;
  6519. case OPS.paintSolidColorImageMask:
  6520. this.paintSolidColorImageMask();
  6521. break;
  6522. case OPS.paintJpegXObject:
  6523. this.paintJpegXObject(args[0], args[1], args[2]);
  6524. break;
  6525. case OPS.paintImageXObject:
  6526. this.paintImageXObject(args[0]);
  6527. break;
  6528. case OPS.paintInlineImageXObject:
  6529. this.paintInlineImageXObject(args[0]);
  6530. break;
  6531. case OPS.paintImageMaskXObject:
  6532. this.paintImageMaskXObject(args[0]);
  6533. break;
  6534. case OPS.paintFormXObjectBegin:
  6535. this.paintFormXObjectBegin(args[0], args[1]);
  6536. break;
  6537. case OPS.paintFormXObjectEnd:
  6538. this.paintFormXObjectEnd();
  6539. break;
  6540. case OPS.closePath:
  6541. this.closePath();
  6542. break;
  6543. case OPS.closeStroke:
  6544. this.closeStroke();
  6545. break;
  6546. case OPS.closeFillStroke:
  6547. this.closeFillStroke();
  6548. break;
  6549. case OPS.nextLine:
  6550. this.nextLine();
  6551. break;
  6552. case OPS.transform:
  6553. this.transform(args[0], args[1], args[2], args[3],
  6554. args[4], args[5]);
  6555. break;
  6556. case OPS.constructPath:
  6557. this.constructPath(args[0], args[1]);
  6558. break;
  6559. case OPS.endPath:
  6560. this.endPath();
  6561. break;
  6562. case 92:
  6563. this.group(opTree[x].items);
  6564. break;
  6565. default:
  6566. warn('Unimplemented method '+ fn);
  6567. break;
  6568. }
  6569. }
  6570. },
  6571. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6572. this.current.wordSpacing = wordSpacing;
  6573. },
  6574. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6575. this.current.charSpacing = charSpacing;
  6576. },
  6577. nextLine: function SVGGraphics_nextLine() {
  6578. this.moveText(0, this.current.leading);
  6579. },
  6580. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6581. var current = this.current;
  6582. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6583. this.current.x = this.current.lineX = 0;
  6584. this.current.y = this.current.lineY = 0;
  6585. current.xcoords = [];
  6586. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6587. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6588. current.tspan.setAttributeNS(null, 'font-size',
  6589. pf(current.fontSize) + 'px');
  6590. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6591. current.txtElement = document.createElementNS(NS, 'svg:text');
  6592. current.txtElement.appendChild(current.tspan);
  6593. },
  6594. beginText: function SVGGraphics_beginText() {
  6595. this.current.x = this.current.lineX = 0;
  6596. this.current.y = this.current.lineY = 0;
  6597. this.current.textMatrix = IDENTITY_MATRIX;
  6598. this.current.lineMatrix = IDENTITY_MATRIX;
  6599. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6600. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6601. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6602. this.current.xcoords = [];
  6603. },
  6604. moveText: function SVGGraphics_moveText(x, y) {
  6605. var current = this.current;
  6606. this.current.x = this.current.lineX += x;
  6607. this.current.y = this.current.lineY += y;
  6608. current.xcoords = [];
  6609. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6610. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6611. current.tspan.setAttributeNS(null, 'font-size',
  6612. pf(current.fontSize) + 'px');
  6613. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6614. },
  6615. showText: function SVGGraphics_showText(glyphs) {
  6616. var current = this.current;
  6617. var font = current.font;
  6618. var fontSize = current.fontSize;
  6619. if (fontSize === 0) {
  6620. return;
  6621. }
  6622. var charSpacing = current.charSpacing;
  6623. var wordSpacing = current.wordSpacing;
  6624. var fontDirection = current.fontDirection;
  6625. var textHScale = current.textHScale * fontDirection;
  6626. var glyphsLength = glyphs.length;
  6627. var vertical = font.vertical;
  6628. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6629. var x = 0, i;
  6630. for (i = 0; i < glyphsLength; ++i) {
  6631. var glyph = glyphs[i];
  6632. if (glyph === null) {
  6633. // word break
  6634. x += fontDirection * wordSpacing;
  6635. continue;
  6636. } else if (isNum(glyph)) {
  6637. x += -glyph * fontSize * 0.001;
  6638. continue;
  6639. }
  6640. current.xcoords.push(current.x + x * textHScale);
  6641. var width = glyph.width;
  6642. var character = glyph.fontChar;
  6643. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6644. x += charWidth;
  6645. current.tspan.textContent += character;
  6646. }
  6647. if (vertical) {
  6648. current.y -= x * textHScale;
  6649. } else {
  6650. current.x += x * textHScale;
  6651. }
  6652. current.tspan.setAttributeNS(null, 'x',
  6653. current.xcoords.map(pf).join(' '));
  6654. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6655. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6656. current.tspan.setAttributeNS(null, 'font-size',
  6657. pf(current.fontSize) + 'px');
  6658. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6659. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6660. }
  6661. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6662. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6663. }
  6664. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6665. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6666. }
  6667. current.txtElement.setAttributeNS(null, 'transform',
  6668. pm(current.textMatrix) +
  6669. ' scale(1, -1)' );
  6670. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6671. current.txtElement.appendChild(current.tspan);
  6672. current.txtgrp.appendChild(current.txtElement);
  6673. this.tgrp.appendChild(current.txtElement);
  6674. },
  6675. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6676. this.setLeading(-y);
  6677. this.moveText(x, y);
  6678. },
  6679. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6680. if (!this.cssStyle) {
  6681. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6682. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6683. this.defs.appendChild(this.cssStyle);
  6684. }
  6685. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6686. this.cssStyle.textContent +=
  6687. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6688. ' src: url(' + url + '); }\n';
  6689. },
  6690. setFont: function SVGGraphics_setFont(details) {
  6691. var current = this.current;
  6692. var fontObj = this.commonObjs.get(details[0]);
  6693. var size = details[1];
  6694. this.current.font = fontObj;
  6695. if (this.embedFonts && fontObj.data &&
  6696. !this.embeddedFonts[fontObj.loadedName]) {
  6697. this.addFontStyle(fontObj);
  6698. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6699. }
  6700. current.fontMatrix = (fontObj.fontMatrix ?
  6701. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6702. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6703. (fontObj.bold ? 'bold' : 'normal');
  6704. var italic = fontObj.italic ? 'italic' : 'normal';
  6705. if (size < 0) {
  6706. size = -size;
  6707. current.fontDirection = -1;
  6708. } else {
  6709. current.fontDirection = 1;
  6710. }
  6711. current.fontSize = size;
  6712. current.fontFamily = fontObj.loadedName;
  6713. current.fontWeight = bold;
  6714. current.fontStyle = italic;
  6715. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6716. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6717. current.xcoords = [];
  6718. },
  6719. endText: function SVGGraphics_endText() {
  6720. if (this.current.pendingClip) {
  6721. this.cgrp.appendChild(this.tgrp);
  6722. this.pgrp.appendChild(this.cgrp);
  6723. } else {
  6724. this.pgrp.appendChild(this.tgrp);
  6725. }
  6726. this.tgrp = document.createElementNS(NS, 'svg:g');
  6727. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6728. },
  6729. // Path properties
  6730. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6731. this.current.lineWidth = width;
  6732. },
  6733. setLineCap: function SVGGraphics_setLineCap(style) {
  6734. this.current.lineCap = LINE_CAP_STYLES[style];
  6735. },
  6736. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6737. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6738. },
  6739. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6740. this.current.miterLimit = limit;
  6741. },
  6742. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6743. var color = Util.makeCssRgb(r, g, b);
  6744. this.current.strokeColor = color;
  6745. },
  6746. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6747. var color = Util.makeCssRgb(r, g, b);
  6748. this.current.fillColor = color;
  6749. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6750. this.current.xcoords = [];
  6751. },
  6752. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6753. this.current.dashArray = dashArray;
  6754. this.current.dashPhase = dashPhase;
  6755. },
  6756. constructPath: function SVGGraphics_constructPath(ops, args) {
  6757. var current = this.current;
  6758. var x = current.x, y = current.y;
  6759. current.path = document.createElementNS(NS, 'svg:path');
  6760. var d = [];
  6761. var opLength = ops.length;
  6762. for (var i = 0, j = 0; i < opLength; i++) {
  6763. switch (ops[i] | 0) {
  6764. case OPS.rectangle:
  6765. x = args[j++];
  6766. y = args[j++];
  6767. var width = args[j++];
  6768. var height = args[j++];
  6769. var xw = x + width;
  6770. var yh = y + height;
  6771. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6772. 'L', pf(x), pf(yh), 'Z');
  6773. break;
  6774. case OPS.moveTo:
  6775. x = args[j++];
  6776. y = args[j++];
  6777. d.push('M', pf(x), pf(y));
  6778. break;
  6779. case OPS.lineTo:
  6780. x = args[j++];
  6781. y = args[j++];
  6782. d.push('L', pf(x) , pf(y));
  6783. break;
  6784. case OPS.curveTo:
  6785. x = args[j + 4];
  6786. y = args[j + 5];
  6787. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6788. pf(args[j + 3]), pf(x), pf(y));
  6789. j += 6;
  6790. break;
  6791. case OPS.curveTo2:
  6792. x = args[j + 2];
  6793. y = args[j + 3];
  6794. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6795. pf(args[j + 2]), pf(args[j + 3]));
  6796. j += 4;
  6797. break;
  6798. case OPS.curveTo3:
  6799. x = args[j + 2];
  6800. y = args[j + 3];
  6801. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6802. pf(x), pf(y));
  6803. j += 4;
  6804. break;
  6805. case OPS.closePath:
  6806. d.push('Z');
  6807. break;
  6808. }
  6809. }
  6810. current.path.setAttributeNS(null, 'd', d.join(' '));
  6811. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6812. pf(current.miterLimit));
  6813. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6814. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6815. current.path.setAttributeNS(null, 'stroke-width',
  6816. pf(current.lineWidth) + 'px');
  6817. current.path.setAttributeNS(null, 'stroke-dasharray',
  6818. current.dashArray.map(pf).join(' '));
  6819. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6820. pf(current.dashPhase) + 'px');
  6821. current.path.setAttributeNS(null, 'fill', 'none');
  6822. this.tgrp.appendChild(current.path);
  6823. if (current.pendingClip) {
  6824. this.cgrp.appendChild(this.tgrp);
  6825. this.pgrp.appendChild(this.cgrp);
  6826. } else {
  6827. this.pgrp.appendChild(this.tgrp);
  6828. }
  6829. // Saving a reference in current.element so that it can be addressed
  6830. // in 'fill' and 'stroke'
  6831. current.element = current.path;
  6832. current.setCurrentPoint(x, y);
  6833. },
  6834. endPath: function SVGGraphics_endPath() {
  6835. var current = this.current;
  6836. if (current.pendingClip) {
  6837. this.cgrp.appendChild(this.tgrp);
  6838. this.pgrp.appendChild(this.cgrp);
  6839. } else {
  6840. this.pgrp.appendChild(this.tgrp);
  6841. }
  6842. this.tgrp = document.createElementNS(NS, 'svg:g');
  6843. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6844. },
  6845. clip: function SVGGraphics_clip(type) {
  6846. var current = this.current;
  6847. // Add current path to clipping path
  6848. current.clipId = 'clippath' + clipCount;
  6849. clipCount++;
  6850. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6851. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6852. var clipElement = current.element.cloneNode();
  6853. if (type === 'evenodd') {
  6854. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6855. } else {
  6856. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6857. }
  6858. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6859. this.clippath.appendChild(clipElement);
  6860. this.defs.appendChild(this.clippath);
  6861. // Create a new group with that attribute
  6862. current.pendingClip = true;
  6863. this.cgrp = document.createElementNS(NS, 'svg:g');
  6864. this.cgrp.setAttributeNS(null, 'clip-path',
  6865. 'url(#' + current.clipId + ')');
  6866. this.pgrp.appendChild(this.cgrp);
  6867. },
  6868. closePath: function SVGGraphics_closePath() {
  6869. var current = this.current;
  6870. var d = current.path.getAttributeNS(null, 'd');
  6871. d += 'Z';
  6872. current.path.setAttributeNS(null, 'd', d);
  6873. },
  6874. setLeading: function SVGGraphics_setLeading(leading) {
  6875. this.current.leading = -leading;
  6876. },
  6877. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6878. this.current.textRise = textRise;
  6879. },
  6880. setHScale: function SVGGraphics_setHScale(scale) {
  6881. this.current.textHScale = scale / 100;
  6882. },
  6883. setGState: function SVGGraphics_setGState(states) {
  6884. for (var i = 0, ii = states.length; i < ii; i++) {
  6885. var state = states[i];
  6886. var key = state[0];
  6887. var value = state[1];
  6888. switch (key) {
  6889. case 'LW':
  6890. this.setLineWidth(value);
  6891. break;
  6892. case 'LC':
  6893. this.setLineCap(value);
  6894. break;
  6895. case 'LJ':
  6896. this.setLineJoin(value);
  6897. break;
  6898. case 'ML':
  6899. this.setMiterLimit(value);
  6900. break;
  6901. case 'D':
  6902. this.setDash(value[0], value[1]);
  6903. break;
  6904. case 'RI':
  6905. break;
  6906. case 'FL':
  6907. break;
  6908. case 'Font':
  6909. this.setFont(value);
  6910. break;
  6911. case 'CA':
  6912. break;
  6913. case 'ca':
  6914. break;
  6915. case 'BM':
  6916. break;
  6917. case 'SMask':
  6918. break;
  6919. }
  6920. }
  6921. },
  6922. fill: function SVGGraphics_fill() {
  6923. var current = this.current;
  6924. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6925. },
  6926. stroke: function SVGGraphics_stroke() {
  6927. var current = this.current;
  6928. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6929. current.element.setAttributeNS(null, 'fill', 'none');
  6930. },
  6931. eoFill: function SVGGraphics_eoFill() {
  6932. var current = this.current;
  6933. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6934. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6935. },
  6936. fillStroke: function SVGGraphics_fillStroke() {
  6937. // Order is important since stroke wants fill to be none.
  6938. // First stroke, then if fill needed, it will be overwritten.
  6939. this.stroke();
  6940. this.fill();
  6941. },
  6942. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6943. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6944. this.fillStroke();
  6945. },
  6946. closeStroke: function SVGGraphics_closeStroke() {
  6947. this.closePath();
  6948. this.stroke();
  6949. },
  6950. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6951. this.closePath();
  6952. this.fillStroke();
  6953. },
  6954. paintSolidColorImageMask:
  6955. function SVGGraphics_paintSolidColorImageMask() {
  6956. var current = this.current;
  6957. var rect = document.createElementNS(NS, 'svg:rect');
  6958. rect.setAttributeNS(null, 'x', '0');
  6959. rect.setAttributeNS(null, 'y', '0');
  6960. rect.setAttributeNS(null, 'width', '1px');
  6961. rect.setAttributeNS(null, 'height', '1px');
  6962. rect.setAttributeNS(null, 'fill', current.fillColor);
  6963. this.tgrp.appendChild(rect);
  6964. },
  6965. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6966. var current = this.current;
  6967. var imgObj = this.objs.get(objId);
  6968. var imgEl = document.createElementNS(NS, 'svg:image');
  6969. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6970. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6971. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6972. imgEl.setAttributeNS(null, 'x', '0');
  6973. imgEl.setAttributeNS(null, 'y', pf(-h));
  6974. imgEl.setAttributeNS(null, 'transform',
  6975. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6976. this.tgrp.appendChild(imgEl);
  6977. if (current.pendingClip) {
  6978. this.cgrp.appendChild(this.tgrp);
  6979. this.pgrp.appendChild(this.cgrp);
  6980. } else {
  6981. this.pgrp.appendChild(this.tgrp);
  6982. }
  6983. },
  6984. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6985. var imgData = this.objs.get(objId);
  6986. if (!imgData) {
  6987. warn('Dependent image isn\'t ready yet');
  6988. return;
  6989. }
  6990. this.paintInlineImageXObject(imgData);
  6991. },
  6992. paintInlineImageXObject:
  6993. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6994. var current = this.current;
  6995. var width = imgData.width;
  6996. var height = imgData.height;
  6997. var imgSrc = convertImgDataToPng(imgData);
  6998. var cliprect = document.createElementNS(NS, 'svg:rect');
  6999. cliprect.setAttributeNS(null, 'x', '0');
  7000. cliprect.setAttributeNS(null, 'y', '0');
  7001. cliprect.setAttributeNS(null, 'width', pf(width));
  7002. cliprect.setAttributeNS(null, 'height', pf(height));
  7003. current.element = cliprect;
  7004. this.clip('nonzero');
  7005. var imgEl = document.createElementNS(NS, 'svg:image');
  7006. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7007. imgEl.setAttributeNS(null, 'x', '0');
  7008. imgEl.setAttributeNS(null, 'y', pf(-height));
  7009. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7010. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7011. imgEl.setAttributeNS(null, 'transform',
  7012. 'scale(' + pf(1 / width) + ' ' +
  7013. pf(-1 / height) + ')');
  7014. if (mask) {
  7015. mask.appendChild(imgEl);
  7016. } else {
  7017. this.tgrp.appendChild(imgEl);
  7018. }
  7019. if (current.pendingClip) {
  7020. this.cgrp.appendChild(this.tgrp);
  7021. this.pgrp.appendChild(this.cgrp);
  7022. } else {
  7023. this.pgrp.appendChild(this.tgrp);
  7024. }
  7025. },
  7026. paintImageMaskXObject:
  7027. function SVGGraphics_paintImageMaskXObject(imgData) {
  7028. var current = this.current;
  7029. var width = imgData.width;
  7030. var height = imgData.height;
  7031. var fillColor = current.fillColor;
  7032. current.maskId = 'mask' + maskCount++;
  7033. var mask = document.createElementNS(NS, 'svg:mask');
  7034. mask.setAttributeNS(null, 'id', current.maskId);
  7035. var rect = document.createElementNS(NS, 'svg:rect');
  7036. rect.setAttributeNS(null, 'x', '0');
  7037. rect.setAttributeNS(null, 'y', '0');
  7038. rect.setAttributeNS(null, 'width', pf(width));
  7039. rect.setAttributeNS(null, 'height', pf(height));
  7040. rect.setAttributeNS(null, 'fill', fillColor);
  7041. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7042. this.defs.appendChild(mask);
  7043. this.tgrp.appendChild(rect);
  7044. this.paintInlineImageXObject(imgData, mask);
  7045. },
  7046. paintFormXObjectBegin:
  7047. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7048. this.save();
  7049. if (isArray(matrix) && matrix.length === 6) {
  7050. this.transform(matrix[0], matrix[1], matrix[2],
  7051. matrix[3], matrix[4], matrix[5]);
  7052. }
  7053. if (isArray(bbox) && bbox.length === 4) {
  7054. var width = bbox[2] - bbox[0];
  7055. var height = bbox[3] - bbox[1];
  7056. var cliprect = document.createElementNS(NS, 'svg:rect');
  7057. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7058. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7059. cliprect.setAttributeNS(null, 'width', pf(width));
  7060. cliprect.setAttributeNS(null, 'height', pf(height));
  7061. this.current.element = cliprect;
  7062. this.clip('nonzero');
  7063. this.endPath();
  7064. }
  7065. },
  7066. paintFormXObjectEnd:
  7067. function SVGGraphics_paintFormXObjectEnd() {
  7068. this.restore();
  7069. }
  7070. };
  7071. return SVGGraphics;
  7072. })();
  7073. PDFJS.SVGGraphics = SVGGraphics;
  7074. var NetworkManager = (function NetworkManagerClosure() {
  7075. var OK_RESPONSE = 200;
  7076. var PARTIAL_CONTENT_RESPONSE = 206;
  7077. function NetworkManager(url, args) {
  7078. this.url = url;
  7079. args = args || {};
  7080. this.isHttp = /^https?:/i.test(url);
  7081. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7082. this.withCredentials = args.withCredentials || false;
  7083. this.getXhr = args.getXhr ||
  7084. function NetworkManager_getXhr() {
  7085. return new XMLHttpRequest();
  7086. };
  7087. this.currXhrId = 0;
  7088. this.pendingRequests = {};
  7089. this.loadedRequests = {};
  7090. }
  7091. function getArrayBuffer(xhr) {
  7092. var data = xhr.response;
  7093. if (typeof data !== 'string') {
  7094. return data;
  7095. }
  7096. var length = data.length;
  7097. var array = new Uint8Array(length);
  7098. for (var i = 0; i < length; i++) {
  7099. array[i] = data.charCodeAt(i) & 0xFF;
  7100. }
  7101. return array.buffer;
  7102. }
  7103. NetworkManager.prototype = {
  7104. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7105. var args = {
  7106. begin: begin,
  7107. end: end
  7108. };
  7109. for (var prop in listeners) {
  7110. args[prop] = listeners[prop];
  7111. }
  7112. return this.request(args);
  7113. },
  7114. requestFull: function NetworkManager_requestFull(listeners) {
  7115. return this.request(listeners);
  7116. },
  7117. request: function NetworkManager_request(args) {
  7118. var xhr = this.getXhr();
  7119. var xhrId = this.currXhrId++;
  7120. var pendingRequest = this.pendingRequests[xhrId] = {
  7121. xhr: xhr
  7122. };
  7123. xhr.open('GET', this.url);
  7124. xhr.withCredentials = this.withCredentials;
  7125. for (var property in this.httpHeaders) {
  7126. var value = this.httpHeaders[property];
  7127. if (typeof value === 'undefined') {
  7128. continue;
  7129. }
  7130. xhr.setRequestHeader(property, value);
  7131. }
  7132. if (this.isHttp && 'begin' in args && 'end' in args) {
  7133. var rangeStr = args.begin + '-' + (args.end - 1);
  7134. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7135. pendingRequest.expectedStatus = 206;
  7136. } else {
  7137. pendingRequest.expectedStatus = 200;
  7138. }
  7139. if (args.onProgressiveData) {
  7140. // Some legacy browsers might throw an exception.
  7141. try {
  7142. xhr.responseType = 'moz-chunked-arraybuffer';
  7143. } catch(e) {}
  7144. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7145. pendingRequest.onProgressiveData = args.onProgressiveData;
  7146. pendingRequest.mozChunked = true;
  7147. } else {
  7148. xhr.responseType = 'arraybuffer';
  7149. }
  7150. } else {
  7151. xhr.responseType = 'arraybuffer';
  7152. }
  7153. if (args.onError) {
  7154. xhr.onerror = function(evt) {
  7155. args.onError(xhr.status);
  7156. };
  7157. }
  7158. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7159. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7160. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7161. pendingRequest.onDone = args.onDone;
  7162. pendingRequest.onError = args.onError;
  7163. pendingRequest.onProgress = args.onProgress;
  7164. xhr.send(null);
  7165. return xhrId;
  7166. },
  7167. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7168. var pendingRequest = this.pendingRequests[xhrId];
  7169. if (!pendingRequest) {
  7170. // Maybe abortRequest was called...
  7171. return;
  7172. }
  7173. if (pendingRequest.mozChunked) {
  7174. var chunk = getArrayBuffer(pendingRequest.xhr);
  7175. pendingRequest.onProgressiveData(chunk);
  7176. }
  7177. var onProgress = pendingRequest.onProgress;
  7178. if (onProgress) {
  7179. onProgress(evt);
  7180. }
  7181. },
  7182. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7183. var pendingRequest = this.pendingRequests[xhrId];
  7184. if (!pendingRequest) {
  7185. // Maybe abortRequest was called...
  7186. return;
  7187. }
  7188. var xhr = pendingRequest.xhr;
  7189. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7190. pendingRequest.onHeadersReceived();
  7191. delete pendingRequest.onHeadersReceived;
  7192. }
  7193. if (xhr.readyState !== 4) {
  7194. return;
  7195. }
  7196. if (!(xhrId in this.pendingRequests)) {
  7197. // The XHR request might have been aborted in onHeadersReceived()
  7198. // callback, in which case we should abort request
  7199. return;
  7200. }
  7201. delete this.pendingRequests[xhrId];
  7202. // success status == 0 can be on ftp, file and other protocols
  7203. if (xhr.status === 0 && this.isHttp) {
  7204. if (pendingRequest.onError) {
  7205. pendingRequest.onError(xhr.status);
  7206. }
  7207. return;
  7208. }
  7209. var xhrStatus = xhr.status || OK_RESPONSE;
  7210. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7211. // "A server MAY ignore the Range header". This means it's possible to
  7212. // get a 200 rather than a 206 response from a range request.
  7213. var ok_response_on_range_request =
  7214. xhrStatus === OK_RESPONSE &&
  7215. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7216. if (!ok_response_on_range_request &&
  7217. xhrStatus !== pendingRequest.expectedStatus) {
  7218. if (pendingRequest.onError) {
  7219. pendingRequest.onError(xhr.status);
  7220. }
  7221. return;
  7222. }
  7223. this.loadedRequests[xhrId] = true;
  7224. var chunk = getArrayBuffer(xhr);
  7225. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7226. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7227. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7228. var begin = parseInt(matches[1], 10);
  7229. pendingRequest.onDone({
  7230. begin: begin,
  7231. chunk: chunk
  7232. });
  7233. } else if (pendingRequest.onProgressiveData) {
  7234. pendingRequest.onDone(null);
  7235. } else {
  7236. pendingRequest.onDone({
  7237. begin: 0,
  7238. chunk: chunk
  7239. });
  7240. }
  7241. },
  7242. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7243. for (var xhrId in this.pendingRequests) {
  7244. return true;
  7245. }
  7246. return false;
  7247. },
  7248. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7249. return this.pendingRequests[xhrId].xhr;
  7250. },
  7251. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7252. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7253. },
  7254. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7255. return xhrId in this.pendingRequests;
  7256. },
  7257. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7258. return xhrId in this.loadedRequests;
  7259. },
  7260. abortAllRequests: function NetworkManager_abortAllRequests() {
  7261. for (var xhrId in this.pendingRequests) {
  7262. this.abortRequest(xhrId | 0);
  7263. }
  7264. },
  7265. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7266. var xhr = this.pendingRequests[xhrId].xhr;
  7267. delete this.pendingRequests[xhrId];
  7268. xhr.abort();
  7269. }
  7270. };
  7271. return NetworkManager;
  7272. })();
  7273. var ChunkedStream = (function ChunkedStreamClosure() {
  7274. function ChunkedStream(length, chunkSize, manager) {
  7275. this.bytes = new Uint8Array(length);
  7276. this.start = 0;
  7277. this.pos = 0;
  7278. this.end = length;
  7279. this.chunkSize = chunkSize;
  7280. this.loadedChunks = [];
  7281. this.numChunksLoaded = 0;
  7282. this.numChunks = Math.ceil(length / chunkSize);
  7283. this.manager = manager;
  7284. this.progressiveDataLength = 0;
  7285. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7286. }
  7287. // required methods for a stream. if a particular stream does not
  7288. // implement these, an error should be thrown
  7289. ChunkedStream.prototype = {
  7290. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7291. var chunks = [];
  7292. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7293. if (!this.loadedChunks[chunk]) {
  7294. chunks.push(chunk);
  7295. }
  7296. }
  7297. return chunks;
  7298. },
  7299. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7300. return [this];
  7301. },
  7302. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7303. return this.numChunksLoaded === this.numChunks;
  7304. },
  7305. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7306. var end = begin + chunk.byteLength;
  7307. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7308. // Using this.length is inaccurate here since this.start can be moved
  7309. // See ChunkedStream.moveStart()
  7310. var length = this.bytes.length;
  7311. assert(end % this.chunkSize === 0 || end === length,
  7312. 'Bad end offset: ' + end);
  7313. this.bytes.set(new Uint8Array(chunk), begin);
  7314. var chunkSize = this.chunkSize;
  7315. var beginChunk = Math.floor(begin / chunkSize);
  7316. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7317. var curChunk;
  7318. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7319. if (!this.loadedChunks[curChunk]) {
  7320. this.loadedChunks[curChunk] = true;
  7321. ++this.numChunksLoaded;
  7322. }
  7323. }
  7324. },
  7325. onReceiveProgressiveData:
  7326. function ChunkedStream_onReceiveProgressiveData(data) {
  7327. var position = this.progressiveDataLength;
  7328. var beginChunk = Math.floor(position / this.chunkSize);
  7329. this.bytes.set(new Uint8Array(data), position);
  7330. position += data.byteLength;
  7331. this.progressiveDataLength = position;
  7332. var endChunk = position >= this.end ? this.numChunks :
  7333. Math.floor(position / this.chunkSize);
  7334. var curChunk;
  7335. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7336. if (!this.loadedChunks[curChunk]) {
  7337. this.loadedChunks[curChunk] = true;
  7338. ++this.numChunksLoaded;
  7339. }
  7340. }
  7341. },
  7342. ensureByte: function ChunkedStream_ensureByte(pos) {
  7343. var chunk = Math.floor(pos / this.chunkSize);
  7344. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7345. return;
  7346. }
  7347. if (!this.loadedChunks[chunk]) {
  7348. throw new MissingDataException(pos, pos + 1);
  7349. }
  7350. this.lastSuccessfulEnsureByteChunk = chunk;
  7351. },
  7352. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7353. if (begin >= end) {
  7354. return;
  7355. }
  7356. if (end <= this.progressiveDataLength) {
  7357. return;
  7358. }
  7359. var chunkSize = this.chunkSize;
  7360. var beginChunk = Math.floor(begin / chunkSize);
  7361. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7362. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7363. if (!this.loadedChunks[chunk]) {
  7364. throw new MissingDataException(begin, end);
  7365. }
  7366. }
  7367. },
  7368. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7369. var chunk, n;
  7370. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7371. if (!this.loadedChunks[chunk]) {
  7372. return chunk;
  7373. }
  7374. }
  7375. // Wrap around to beginning
  7376. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7377. if (!this.loadedChunks[chunk]) {
  7378. return chunk;
  7379. }
  7380. }
  7381. return null;
  7382. },
  7383. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7384. return !!this.loadedChunks[chunk];
  7385. },
  7386. get length() {
  7387. return this.end - this.start;
  7388. },
  7389. get isEmpty() {
  7390. return this.length === 0;
  7391. },
  7392. getByte: function ChunkedStream_getByte() {
  7393. var pos = this.pos;
  7394. if (pos >= this.end) {
  7395. return -1;
  7396. }
  7397. this.ensureByte(pos);
  7398. return this.bytes[this.pos++];
  7399. },
  7400. getUint16: function ChunkedStream_getUint16() {
  7401. var b0 = this.getByte();
  7402. var b1 = this.getByte();
  7403. if (b0 === -1 || b1 === -1) {
  7404. return -1;
  7405. }
  7406. return (b0 << 8) + b1;
  7407. },
  7408. getInt32: function ChunkedStream_getInt32() {
  7409. var b0 = this.getByte();
  7410. var b1 = this.getByte();
  7411. var b2 = this.getByte();
  7412. var b3 = this.getByte();
  7413. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7414. },
  7415. // returns subarray of original buffer
  7416. // should only be read
  7417. getBytes: function ChunkedStream_getBytes(length) {
  7418. var bytes = this.bytes;
  7419. var pos = this.pos;
  7420. var strEnd = this.end;
  7421. if (!length) {
  7422. this.ensureRange(pos, strEnd);
  7423. return bytes.subarray(pos, strEnd);
  7424. }
  7425. var end = pos + length;
  7426. if (end > strEnd) {
  7427. end = strEnd;
  7428. }
  7429. this.ensureRange(pos, end);
  7430. this.pos = end;
  7431. return bytes.subarray(pos, end);
  7432. },
  7433. peekByte: function ChunkedStream_peekByte() {
  7434. var peekedByte = this.getByte();
  7435. this.pos--;
  7436. return peekedByte;
  7437. },
  7438. peekBytes: function ChunkedStream_peekBytes(length) {
  7439. var bytes = this.getBytes(length);
  7440. this.pos -= bytes.length;
  7441. return bytes;
  7442. },
  7443. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7444. this.ensureRange(begin, end);
  7445. return this.bytes.subarray(begin, end);
  7446. },
  7447. skip: function ChunkedStream_skip(n) {
  7448. if (!n) {
  7449. n = 1;
  7450. }
  7451. this.pos += n;
  7452. },
  7453. reset: function ChunkedStream_reset() {
  7454. this.pos = this.start;
  7455. },
  7456. moveStart: function ChunkedStream_moveStart() {
  7457. this.start = this.pos;
  7458. },
  7459. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7460. this.ensureRange(start, start + length);
  7461. function ChunkedStreamSubstream() {}
  7462. ChunkedStreamSubstream.prototype = Object.create(this);
  7463. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7464. var chunkSize = this.chunkSize;
  7465. var beginChunk = Math.floor(this.start / chunkSize);
  7466. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7467. var missingChunks = [];
  7468. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7469. if (!this.loadedChunks[chunk]) {
  7470. missingChunks.push(chunk);
  7471. }
  7472. }
  7473. return missingChunks;
  7474. };
  7475. var subStream = new ChunkedStreamSubstream();
  7476. subStream.pos = subStream.start = start;
  7477. subStream.end = start + length || this.end;
  7478. subStream.dict = dict;
  7479. return subStream;
  7480. },
  7481. isStream: true
  7482. };
  7483. return ChunkedStream;
  7484. })();
  7485. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7486. function ChunkedStreamManager(length, chunkSize, url, args) {
  7487. this.stream = new ChunkedStream(length, chunkSize, this);
  7488. this.length = length;
  7489. this.chunkSize = chunkSize;
  7490. this.url = url;
  7491. this.disableAutoFetch = args.disableAutoFetch;
  7492. var msgHandler = this.msgHandler = args.msgHandler;
  7493. if (args.chunkedViewerLoading) {
  7494. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7495. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7496. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7497. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7498. };
  7499. } else {
  7500. var getXhr = function getXhr() {
  7501. return new XMLHttpRequest();
  7502. };
  7503. this.networkManager = new NetworkManager(this.url, {
  7504. getXhr: getXhr,
  7505. httpHeaders: args.httpHeaders,
  7506. withCredentials: args.withCredentials
  7507. });
  7508. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7509. this.networkManager.requestRange(begin, end, {
  7510. onDone: this.onReceiveData.bind(this),
  7511. onProgress: this.onProgress.bind(this)
  7512. });
  7513. };
  7514. }
  7515. this.currRequestId = 0;
  7516. this.chunksNeededByRequest = {};
  7517. this.requestsByChunk = {};
  7518. this.callbacksByRequest = {};
  7519. this.progressiveDataLength = 0;
  7520. this._loadedStreamCapability = createPromiseCapability();
  7521. if (args.initialData) {
  7522. this.onReceiveData({chunk: args.initialData});
  7523. }
  7524. }
  7525. ChunkedStreamManager.prototype = {
  7526. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7527. return this._loadedStreamCapability.promise;
  7528. },
  7529. // Get all the chunks that are not yet loaded and groups them into
  7530. // contiguous ranges to load in as few requests as possible
  7531. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7532. var missingChunks = this.stream.getMissingChunks();
  7533. this.requestChunks(missingChunks);
  7534. return this._loadedStreamCapability.promise;
  7535. },
  7536. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7537. callback) {
  7538. var requestId = this.currRequestId++;
  7539. var chunksNeeded;
  7540. var i, ii;
  7541. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7542. for (i = 0, ii = chunks.length; i < ii; i++) {
  7543. if (!this.stream.hasChunk(chunks[i])) {
  7544. chunksNeeded[chunks[i]] = true;
  7545. }
  7546. }
  7547. if (isEmptyObj(chunksNeeded)) {
  7548. if (callback) {
  7549. callback();
  7550. }
  7551. return;
  7552. }
  7553. this.callbacksByRequest[requestId] = callback;
  7554. var chunksToRequest = [];
  7555. for (var chunk in chunksNeeded) {
  7556. chunk = chunk | 0;
  7557. if (!(chunk in this.requestsByChunk)) {
  7558. this.requestsByChunk[chunk] = [];
  7559. chunksToRequest.push(chunk);
  7560. }
  7561. this.requestsByChunk[chunk].push(requestId);
  7562. }
  7563. if (!chunksToRequest.length) {
  7564. return;
  7565. }
  7566. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7567. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7568. var groupedChunk = groupedChunksToRequest[i];
  7569. var begin = groupedChunk.beginChunk * this.chunkSize;
  7570. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7571. this.sendRequest(begin, end);
  7572. }
  7573. },
  7574. getStream: function ChunkedStreamManager_getStream() {
  7575. return this.stream;
  7576. },
  7577. // Loads any chunks in the requested range that are not yet loaded
  7578. requestRange: function ChunkedStreamManager_requestRange(
  7579. begin, end, callback) {
  7580. end = Math.min(end, this.length);
  7581. var beginChunk = this.getBeginChunk(begin);
  7582. var endChunk = this.getEndChunk(end);
  7583. var chunks = [];
  7584. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7585. chunks.push(chunk);
  7586. }
  7587. this.requestChunks(chunks, callback);
  7588. },
  7589. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7590. callback) {
  7591. ranges = ranges || [];
  7592. var chunksToRequest = [];
  7593. for (var i = 0; i < ranges.length; i++) {
  7594. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7595. var endChunk = this.getEndChunk(ranges[i].end);
  7596. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7597. if (chunksToRequest.indexOf(chunk) < 0) {
  7598. chunksToRequest.push(chunk);
  7599. }
  7600. }
  7601. }
  7602. chunksToRequest.sort(function(a, b) { return a - b; });
  7603. this.requestChunks(chunksToRequest, callback);
  7604. },
  7605. // Groups a sorted array of chunks into as few continguous larger
  7606. // chunks as possible
  7607. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7608. var groupedChunks = [];
  7609. var beginChunk = -1;
  7610. var prevChunk = -1;
  7611. for (var i = 0; i < chunks.length; ++i) {
  7612. var chunk = chunks[i];
  7613. if (beginChunk < 0) {
  7614. beginChunk = chunk;
  7615. }
  7616. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7617. groupedChunks.push({ beginChunk: beginChunk,
  7618. endChunk: prevChunk + 1 });
  7619. beginChunk = chunk;
  7620. }
  7621. if (i + 1 === chunks.length) {
  7622. groupedChunks.push({ beginChunk: beginChunk,
  7623. endChunk: chunk + 1 });
  7624. }
  7625. prevChunk = chunk;
  7626. }
  7627. return groupedChunks;
  7628. },
  7629. onProgress: function ChunkedStreamManager_onProgress(args) {
  7630. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7631. args.loaded);
  7632. this.msgHandler.send('DocProgress', {
  7633. loaded: bytesLoaded,
  7634. total: this.length
  7635. });
  7636. },
  7637. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7638. var chunk = args.chunk;
  7639. var isProgressive = args.begin === undefined;
  7640. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7641. var end = begin + chunk.byteLength;
  7642. var beginChunk = Math.floor(begin / this.chunkSize);
  7643. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7644. Math.ceil(end / this.chunkSize);
  7645. if (isProgressive) {
  7646. this.stream.onReceiveProgressiveData(chunk);
  7647. this.progressiveDataLength = end;
  7648. } else {
  7649. this.stream.onReceiveData(begin, chunk);
  7650. }
  7651. if (this.stream.allChunksLoaded()) {
  7652. this._loadedStreamCapability.resolve(this.stream);
  7653. }
  7654. var loadedRequests = [];
  7655. var i, requestId;
  7656. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7657. // The server might return more chunks than requested
  7658. var requestIds = this.requestsByChunk[chunk] || [];
  7659. delete this.requestsByChunk[chunk];
  7660. for (i = 0; i < requestIds.length; ++i) {
  7661. requestId = requestIds[i];
  7662. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7663. if (chunk in chunksNeeded) {
  7664. delete chunksNeeded[chunk];
  7665. }
  7666. if (!isEmptyObj(chunksNeeded)) {
  7667. continue;
  7668. }
  7669. loadedRequests.push(requestId);
  7670. }
  7671. }
  7672. // If there are no pending requests, automatically fetch the next
  7673. // unfetched chunk of the PDF
  7674. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7675. var nextEmptyChunk;
  7676. if (this.stream.numChunksLoaded === 1) {
  7677. // This is a special optimization so that after fetching the first
  7678. // chunk, rather than fetching the second chunk, we fetch the last
  7679. // chunk.
  7680. var lastChunk = this.stream.numChunks - 1;
  7681. if (!this.stream.hasChunk(lastChunk)) {
  7682. nextEmptyChunk = lastChunk;
  7683. }
  7684. } else {
  7685. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7686. }
  7687. if (isInt(nextEmptyChunk)) {
  7688. this.requestChunks([nextEmptyChunk]);
  7689. }
  7690. }
  7691. for (i = 0; i < loadedRequests.length; ++i) {
  7692. requestId = loadedRequests[i];
  7693. var callback = this.callbacksByRequest[requestId];
  7694. delete this.callbacksByRequest[requestId];
  7695. if (callback) {
  7696. callback();
  7697. }
  7698. }
  7699. this.msgHandler.send('DocProgress', {
  7700. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7701. total: this.length
  7702. });
  7703. },
  7704. onError: function ChunkedStreamManager_onError(err) {
  7705. this._loadedStreamCapability.reject(err);
  7706. },
  7707. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7708. var chunk = Math.floor(begin / this.chunkSize);
  7709. return chunk;
  7710. },
  7711. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7712. if (end % this.chunkSize === 0) {
  7713. return end / this.chunkSize;
  7714. }
  7715. // 0 -> 0
  7716. // 1 -> 1
  7717. // 99 -> 1
  7718. // 100 -> 1
  7719. // 101 -> 2
  7720. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7721. return chunk;
  7722. }
  7723. };
  7724. return ChunkedStreamManager;
  7725. })();
  7726. // The maximum number of bytes fetched per range request
  7727. var RANGE_CHUNK_SIZE = 65536;
  7728. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7729. var BasePdfManager = (function BasePdfManagerClosure() {
  7730. function BasePdfManager() {
  7731. throw new Error('Cannot initialize BaseManagerManager');
  7732. }
  7733. BasePdfManager.prototype = {
  7734. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7735. throw new NotImplementedException();
  7736. },
  7737. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7738. return this.ensure(this.pdfDocument, prop, args);
  7739. },
  7740. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7741. return this.ensure(this.pdfDocument.xref, prop, args);
  7742. },
  7743. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7744. return this.ensure(this.pdfDocument.catalog, prop, args);
  7745. },
  7746. getPage: function BasePdfManager_pagePage(pageIndex) {
  7747. return this.pdfDocument.getPage(pageIndex);
  7748. },
  7749. cleanup: function BasePdfManager_cleanup() {
  7750. return this.pdfDocument.cleanup();
  7751. },
  7752. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7753. return new NotImplementedException();
  7754. },
  7755. requestRange: function BasePdfManager_ensure(begin, end) {
  7756. return new NotImplementedException();
  7757. },
  7758. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7759. return new NotImplementedException();
  7760. },
  7761. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7762. return new NotImplementedException();
  7763. },
  7764. updatePassword: function BasePdfManager_updatePassword(password) {
  7765. this.pdfDocument.xref.password = this.password = password;
  7766. if (this._passwordChangedCapability) {
  7767. this._passwordChangedCapability.resolve();
  7768. }
  7769. },
  7770. passwordChanged: function BasePdfManager_passwordChanged() {
  7771. this._passwordChangedCapability = createPromiseCapability();
  7772. return this._passwordChangedCapability.promise;
  7773. },
  7774. terminate: function BasePdfManager_terminate() {
  7775. return new NotImplementedException();
  7776. }
  7777. };
  7778. return BasePdfManager;
  7779. })();
  7780. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7781. function LocalPdfManager(data, password) {
  7782. var stream = new Stream(data);
  7783. this.pdfDocument = new PDFDocument(this, stream, password);
  7784. this._loadedStreamCapability = createPromiseCapability();
  7785. this._loadedStreamCapability.resolve(stream);
  7786. }
  7787. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7788. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7789. LocalPdfManager.prototype.ensure =
  7790. function LocalPdfManager_ensure(obj, prop, args) {
  7791. return new Promise(function (resolve, reject) {
  7792. try {
  7793. var value = obj[prop];
  7794. var result;
  7795. if (typeof value === 'function') {
  7796. result = value.apply(obj, args);
  7797. } else {
  7798. result = value;
  7799. }
  7800. resolve(result);
  7801. } catch (e) {
  7802. reject(e);
  7803. }
  7804. });
  7805. };
  7806. LocalPdfManager.prototype.requestRange =
  7807. function LocalPdfManager_requestRange(begin, end) {
  7808. return Promise.resolve();
  7809. };
  7810. LocalPdfManager.prototype.requestLoadedStream =
  7811. function LocalPdfManager_requestLoadedStream() {
  7812. };
  7813. LocalPdfManager.prototype.onLoadedStream =
  7814. function LocalPdfManager_getLoadedStream() {
  7815. return this._loadedStreamCapability.promise;
  7816. };
  7817. LocalPdfManager.prototype.terminate =
  7818. function LocalPdfManager_terminate() {
  7819. return;
  7820. };
  7821. return LocalPdfManager;
  7822. })();
  7823. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7824. function NetworkPdfManager(args, msgHandler) {
  7825. this.msgHandler = msgHandler;
  7826. var params = {
  7827. msgHandler: msgHandler,
  7828. httpHeaders: args.httpHeaders,
  7829. withCredentials: args.withCredentials,
  7830. chunkedViewerLoading: args.chunkedViewerLoading,
  7831. disableAutoFetch: args.disableAutoFetch,
  7832. initialData: args.initialData
  7833. };
  7834. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7835. args.url, params);
  7836. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7837. args.password);
  7838. }
  7839. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7840. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7841. NetworkPdfManager.prototype.ensure =
  7842. function NetworkPdfManager_ensure(obj, prop, args) {
  7843. var pdfManager = this;
  7844. return new Promise(function (resolve, reject) {
  7845. function ensureHelper() {
  7846. try {
  7847. var result;
  7848. var value = obj[prop];
  7849. if (typeof value === 'function') {
  7850. result = value.apply(obj, args);
  7851. } else {
  7852. result = value;
  7853. }
  7854. resolve(result);
  7855. } catch(e) {
  7856. if (!(e instanceof MissingDataException)) {
  7857. reject(e);
  7858. return;
  7859. }
  7860. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7861. }
  7862. }
  7863. ensureHelper();
  7864. });
  7865. };
  7866. NetworkPdfManager.prototype.requestRange =
  7867. function NetworkPdfManager_requestRange(begin, end) {
  7868. return new Promise(function (resolve) {
  7869. this.streamManager.requestRange(begin, end, function() {
  7870. resolve();
  7871. });
  7872. }.bind(this));
  7873. };
  7874. NetworkPdfManager.prototype.requestLoadedStream =
  7875. function NetworkPdfManager_requestLoadedStream() {
  7876. this.streamManager.requestAllChunks();
  7877. };
  7878. NetworkPdfManager.prototype.sendProgressiveData =
  7879. function NetworkPdfManager_sendProgressiveData(chunk) {
  7880. this.streamManager.onReceiveData({ chunk: chunk });
  7881. };
  7882. NetworkPdfManager.prototype.onLoadedStream =
  7883. function NetworkPdfManager_getLoadedStream() {
  7884. return this.streamManager.onLoadedStream();
  7885. };
  7886. NetworkPdfManager.prototype.terminate =
  7887. function NetworkPdfManager_terminate() {
  7888. this.streamManager.networkManager.abortAllRequests();
  7889. };
  7890. return NetworkPdfManager;
  7891. })();
  7892. var Page = (function PageClosure() {
  7893. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7894. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7895. this.pdfManager = pdfManager;
  7896. this.pageIndex = pageIndex;
  7897. this.pageDict = pageDict;
  7898. this.xref = xref;
  7899. this.ref = ref;
  7900. this.fontCache = fontCache;
  7901. this.idCounters = {
  7902. obj: 0
  7903. };
  7904. this.resourcesPromise = null;
  7905. }
  7906. Page.prototype = {
  7907. getPageProp: function Page_getPageProp(key) {
  7908. return this.pageDict.get(key);
  7909. },
  7910. getInheritedPageProp: function Page_inheritPageProp(key) {
  7911. var dict = this.pageDict;
  7912. var value = dict.get(key);
  7913. while (value === undefined) {
  7914. dict = dict.get('Parent');
  7915. if (!dict) {
  7916. break;
  7917. }
  7918. value = dict.get(key);
  7919. }
  7920. return value;
  7921. },
  7922. get content() {
  7923. return this.getPageProp('Contents');
  7924. },
  7925. get resources() {
  7926. var value = this.getInheritedPageProp('Resources');
  7927. // For robustness: The spec states that a \Resources entry has to be
  7928. // present, but can be empty. Some document omit it still. In this case
  7929. // return an empty dictionary:
  7930. if (value === undefined) {
  7931. value = Dict.empty;
  7932. }
  7933. return shadow(this, 'resources', value);
  7934. },
  7935. get mediaBox() {
  7936. var obj = this.getInheritedPageProp('MediaBox');
  7937. // Reset invalid media box to letter size.
  7938. if (!isArray(obj) || obj.length !== 4) {
  7939. obj = LETTER_SIZE_MEDIABOX;
  7940. }
  7941. return shadow(this, 'mediaBox', obj);
  7942. },
  7943. get view() {
  7944. var mediaBox = this.mediaBox;
  7945. var cropBox = this.getInheritedPageProp('CropBox');
  7946. if (!isArray(cropBox) || cropBox.length !== 4) {
  7947. return shadow(this, 'view', mediaBox);
  7948. }
  7949. // From the spec, 6th ed., p.963:
  7950. // "The crop, bleed, trim, and art boxes should not ordinarily
  7951. // extend beyond the boundaries of the media box. If they do, they are
  7952. // effectively reduced to their intersection with the media box."
  7953. cropBox = Util.intersect(cropBox, mediaBox);
  7954. if (!cropBox) {
  7955. return shadow(this, 'view', mediaBox);
  7956. }
  7957. return shadow(this, 'view', cropBox);
  7958. },
  7959. get annotationRefs() {
  7960. return shadow(this, 'annotationRefs',
  7961. this.getInheritedPageProp('Annots'));
  7962. },
  7963. get rotate() {
  7964. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7965. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7966. if (rotate % 90 !== 0) {
  7967. rotate = 0;
  7968. } else if (rotate >= 360) {
  7969. rotate = rotate % 360;
  7970. } else if (rotate < 0) {
  7971. // The spec doesn't cover negatives, assume its counterclockwise
  7972. // rotation. The following is the other implementation of modulo.
  7973. rotate = ((rotate % 360) + 360) % 360;
  7974. }
  7975. return shadow(this, 'rotate', rotate);
  7976. },
  7977. getContentStream: function Page_getContentStream() {
  7978. var content = this.content;
  7979. var stream;
  7980. if (isArray(content)) {
  7981. // fetching items
  7982. var xref = this.xref;
  7983. var i, n = content.length;
  7984. var streams = [];
  7985. for (i = 0; i < n; ++i) {
  7986. streams.push(xref.fetchIfRef(content[i]));
  7987. }
  7988. stream = new StreamsSequenceStream(streams);
  7989. } else if (isStream(content)) {
  7990. stream = content;
  7991. } else {
  7992. // replacing non-existent page content with empty one
  7993. stream = new NullStream();
  7994. }
  7995. return stream;
  7996. },
  7997. loadResources: function Page_loadResources(keys) {
  7998. if (!this.resourcesPromise) {
  7999. // TODO: add async getInheritedPageProp and remove this.
  8000. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  8001. }
  8002. return this.resourcesPromise.then(function resourceSuccess() {
  8003. var objectLoader = new ObjectLoader(this.resources.map,
  8004. keys,
  8005. this.xref);
  8006. return objectLoader.load();
  8007. }.bind(this));
  8008. },
  8009. getOperatorList: function Page_getOperatorList(handler, intent) {
  8010. var self = this;
  8011. var pdfManager = this.pdfManager;
  8012. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8013. []);
  8014. var resourcesPromise = this.loadResources([
  8015. 'ExtGState',
  8016. 'ColorSpace',
  8017. 'Pattern',
  8018. 'Shading',
  8019. 'XObject',
  8020. 'Font'
  8021. // ProcSet
  8022. // Properties
  8023. ]);
  8024. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8025. handler, this.pageIndex,
  8026. 'p' + this.pageIndex + '_',
  8027. this.idCounters,
  8028. this.fontCache);
  8029. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8030. var pageListPromise = dataPromises.then(function(data) {
  8031. var contentStream = data[0];
  8032. var opList = new OperatorList(intent, handler, self.pageIndex);
  8033. handler.send('StartRenderPage', {
  8034. transparency: partialEvaluator.hasBlendModes(self.resources),
  8035. pageIndex: self.pageIndex,
  8036. intent: intent
  8037. });
  8038. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8039. opList).then(function () {
  8040. return opList;
  8041. });
  8042. });
  8043. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8044. return Promise.all([pageListPromise, annotationsPromise]).then(
  8045. function(datas) {
  8046. var pageOpList = datas[0];
  8047. var annotations = datas[1];
  8048. if (annotations.length === 0) {
  8049. pageOpList.flush(true);
  8050. return pageOpList;
  8051. }
  8052. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8053. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8054. return annotationsReadyPromise.then(function () {
  8055. pageOpList.flush(true);
  8056. return pageOpList;
  8057. });
  8058. });
  8059. },
  8060. extractTextContent: function Page_extractTextContent() {
  8061. var handler = {
  8062. on: function nullHandlerOn() {},
  8063. send: function nullHandlerSend() {}
  8064. };
  8065. var self = this;
  8066. var pdfManager = this.pdfManager;
  8067. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8068. []);
  8069. var resourcesPromise = this.loadResources([
  8070. 'ExtGState',
  8071. 'XObject',
  8072. 'Font'
  8073. ]);
  8074. var dataPromises = Promise.all([contentStreamPromise,
  8075. resourcesPromise]);
  8076. return dataPromises.then(function(data) {
  8077. var contentStream = data[0];
  8078. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8079. handler, self.pageIndex,
  8080. 'p' + self.pageIndex + '_',
  8081. self.idCounters,
  8082. self.fontCache);
  8083. return partialEvaluator.getTextContent(contentStream,
  8084. self.resources);
  8085. });
  8086. },
  8087. getAnnotationsData: function Page_getAnnotationsData() {
  8088. var annotations = this.annotations;
  8089. var annotationsData = [];
  8090. for (var i = 0, n = annotations.length; i < n; ++i) {
  8091. annotationsData.push(annotations[i].getData());
  8092. }
  8093. return annotationsData;
  8094. },
  8095. get annotations() {
  8096. var annotations = [];
  8097. var annotationRefs = (this.annotationRefs || []);
  8098. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8099. var annotationRef = annotationRefs[i];
  8100. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8101. if (annotation) {
  8102. annotations.push(annotation);
  8103. }
  8104. }
  8105. return shadow(this, 'annotations', annotations);
  8106. }
  8107. };
  8108. return Page;
  8109. })();
  8110. /**
  8111. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8112. * `PDFDoc`, this one doesn't have any job management code.
  8113. * Right now there exists one PDFDocument on the main thread + one object
  8114. * for each worker. If there is no worker support enabled, there are two
  8115. * `PDFDocument` objects on the main thread created.
  8116. */
  8117. var PDFDocument = (function PDFDocumentClosure() {
  8118. var FINGERPRINT_FIRST_BYTES = 1024;
  8119. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8120. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8121. function PDFDocument(pdfManager, arg, password) {
  8122. if (isStream(arg)) {
  8123. init.call(this, pdfManager, arg, password);
  8124. } else if (isArrayBuffer(arg)) {
  8125. init.call(this, pdfManager, new Stream(arg), password);
  8126. } else {
  8127. error('PDFDocument: Unknown argument type');
  8128. }
  8129. }
  8130. function init(pdfManager, stream, password) {
  8131. assert(stream.length > 0, 'stream must have data');
  8132. this.pdfManager = pdfManager;
  8133. this.stream = stream;
  8134. var xref = new XRef(this.stream, password, pdfManager);
  8135. this.xref = xref;
  8136. }
  8137. function find(stream, needle, limit, backwards) {
  8138. var pos = stream.pos;
  8139. var end = stream.end;
  8140. var strBuf = [];
  8141. if (pos + limit > end) {
  8142. limit = end - pos;
  8143. }
  8144. for (var n = 0; n < limit; ++n) {
  8145. strBuf.push(String.fromCharCode(stream.getByte()));
  8146. }
  8147. var str = strBuf.join('');
  8148. stream.pos = pos;
  8149. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8150. if (index === -1) {
  8151. return false; /* not found */
  8152. }
  8153. stream.pos += index;
  8154. return true; /* found */
  8155. }
  8156. var DocumentInfoValidators = {
  8157. get entries() {
  8158. // Lazily build this since all the validation functions below are not
  8159. // defined until after this file loads.
  8160. return shadow(this, 'entries', {
  8161. Title: isString,
  8162. Author: isString,
  8163. Subject: isString,
  8164. Keywords: isString,
  8165. Creator: isString,
  8166. Producer: isString,
  8167. CreationDate: isString,
  8168. ModDate: isString,
  8169. Trapped: isName
  8170. });
  8171. }
  8172. };
  8173. PDFDocument.prototype = {
  8174. parse: function PDFDocument_parse(recoveryMode) {
  8175. this.setup(recoveryMode);
  8176. try {
  8177. // checking if AcroForm is present
  8178. this.acroForm = this.catalog.catDict.get('AcroForm');
  8179. if (this.acroForm) {
  8180. this.xfa = this.acroForm.get('XFA');
  8181. var fields = this.acroForm.get('Fields');
  8182. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8183. !this.xfa) {
  8184. // no fields and no XFA -- not a form (?)
  8185. this.acroForm = null;
  8186. }
  8187. }
  8188. } catch (ex) {
  8189. info('Something wrong with AcroForm entry');
  8190. this.acroForm = null;
  8191. }
  8192. },
  8193. get linearization() {
  8194. var linearization = null;
  8195. if (this.stream.length) {
  8196. try {
  8197. linearization = Linearization.create(this.stream);
  8198. } catch (err) {
  8199. if (err instanceof MissingDataException) {
  8200. throw err;
  8201. }
  8202. info(err);
  8203. }
  8204. }
  8205. // shadow the prototype getter with a data property
  8206. return shadow(this, 'linearization', linearization);
  8207. },
  8208. get startXRef() {
  8209. var stream = this.stream;
  8210. var startXRef = 0;
  8211. var linearization = this.linearization;
  8212. if (linearization) {
  8213. // Find end of first obj.
  8214. stream.reset();
  8215. if (find(stream, 'endobj', 1024)) {
  8216. startXRef = stream.pos + 6;
  8217. }
  8218. } else {
  8219. // Find startxref by jumping backward from the end of the file.
  8220. var step = 1024;
  8221. var found = false, pos = stream.end;
  8222. while (!found && pos > 0) {
  8223. pos -= step - 'startxref'.length;
  8224. if (pos < 0) {
  8225. pos = 0;
  8226. }
  8227. stream.pos = pos;
  8228. found = find(stream, 'startxref', step, true);
  8229. }
  8230. if (found) {
  8231. stream.skip(9);
  8232. var ch;
  8233. do {
  8234. ch = stream.getByte();
  8235. } while (Lexer.isSpace(ch));
  8236. var str = '';
  8237. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8238. str += String.fromCharCode(ch);
  8239. ch = stream.getByte();
  8240. }
  8241. startXRef = parseInt(str, 10);
  8242. if (isNaN(startXRef)) {
  8243. startXRef = 0;
  8244. }
  8245. }
  8246. }
  8247. // shadow the prototype getter with a data property
  8248. return shadow(this, 'startXRef', startXRef);
  8249. },
  8250. get mainXRefEntriesOffset() {
  8251. var mainXRefEntriesOffset = 0;
  8252. var linearization = this.linearization;
  8253. if (linearization) {
  8254. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8255. }
  8256. // shadow the prototype getter with a data property
  8257. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8258. },
  8259. // Find the header, remove leading garbage and setup the stream
  8260. // starting from the header.
  8261. checkHeader: function PDFDocument_checkHeader() {
  8262. var stream = this.stream;
  8263. stream.reset();
  8264. if (find(stream, '%PDF-', 1024)) {
  8265. // Found the header, trim off any garbage before it.
  8266. stream.moveStart();
  8267. // Reading file format version
  8268. var MAX_VERSION_LENGTH = 12;
  8269. var version = '', ch;
  8270. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8271. if (version.length >= MAX_VERSION_LENGTH) {
  8272. break;
  8273. }
  8274. version += String.fromCharCode(ch);
  8275. }
  8276. // removing "%PDF-"-prefix
  8277. this.pdfFormatVersion = version.substring(5);
  8278. return;
  8279. }
  8280. // May not be a PDF file, continue anyway.
  8281. },
  8282. parseStartXRef: function PDFDocument_parseStartXRef() {
  8283. var startXRef = this.startXRef;
  8284. this.xref.setStartXRef(startXRef);
  8285. },
  8286. setup: function PDFDocument_setup(recoveryMode) {
  8287. this.xref.parse(recoveryMode);
  8288. this.catalog = new Catalog(this.pdfManager, this.xref);
  8289. },
  8290. get numPages() {
  8291. var linearization = this.linearization;
  8292. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8293. // shadow the prototype getter
  8294. return shadow(this, 'numPages', num);
  8295. },
  8296. get documentInfo() {
  8297. var docInfo = {
  8298. PDFFormatVersion: this.pdfFormatVersion,
  8299. IsAcroFormPresent: !!this.acroForm,
  8300. IsXFAPresent: !!this.xfa
  8301. };
  8302. var infoDict;
  8303. try {
  8304. infoDict = this.xref.trailer.get('Info');
  8305. } catch (err) {
  8306. info('The document information dictionary is invalid.');
  8307. }
  8308. if (infoDict) {
  8309. var validEntries = DocumentInfoValidators.entries;
  8310. // Only fill the document info with valid entries from the spec.
  8311. for (var key in validEntries) {
  8312. if (infoDict.has(key)) {
  8313. var value = infoDict.get(key);
  8314. // Make sure the value conforms to the spec.
  8315. if (validEntries[key](value)) {
  8316. docInfo[key] = (typeof value !== 'string' ?
  8317. value : stringToPDFString(value));
  8318. } else {
  8319. info('Bad value in document info for "' + key + '"');
  8320. }
  8321. }
  8322. }
  8323. }
  8324. return shadow(this, 'documentInfo', docInfo);
  8325. },
  8326. get fingerprint() {
  8327. var xref = this.xref, idArray, hash, fileID = '';
  8328. if (xref.trailer.has('ID')) {
  8329. idArray = xref.trailer.get('ID');
  8330. }
  8331. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8332. hash = stringToBytes(idArray[0]);
  8333. } else {
  8334. if (this.stream.ensureRange) {
  8335. this.stream.ensureRange(0,
  8336. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8337. }
  8338. hash = calculateMD5(this.stream.bytes.subarray(0,
  8339. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8340. }
  8341. for (var i = 0, n = hash.length; i < n; i++) {
  8342. var hex = hash[i].toString(16);
  8343. fileID += hex.length === 1 ? '0' + hex : hex;
  8344. }
  8345. return shadow(this, 'fingerprint', fileID);
  8346. },
  8347. getPage: function PDFDocument_getPage(pageIndex) {
  8348. return this.catalog.getPage(pageIndex);
  8349. },
  8350. cleanup: function PDFDocument_cleanup() {
  8351. return this.catalog.cleanup();
  8352. }
  8353. };
  8354. return PDFDocument;
  8355. })();
  8356. var Name = (function NameClosure() {
  8357. function Name(name) {
  8358. this.name = name;
  8359. }
  8360. Name.prototype = {};
  8361. var nameCache = {};
  8362. Name.get = function Name_get(name) {
  8363. var nameValue = nameCache[name];
  8364. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8365. };
  8366. return Name;
  8367. })();
  8368. var Cmd = (function CmdClosure() {
  8369. function Cmd(cmd) {
  8370. this.cmd = cmd;
  8371. }
  8372. Cmd.prototype = {};
  8373. var cmdCache = {};
  8374. Cmd.get = function Cmd_get(cmd) {
  8375. var cmdValue = cmdCache[cmd];
  8376. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8377. };
  8378. return Cmd;
  8379. })();
  8380. var Dict = (function DictClosure() {
  8381. var nonSerializable = function nonSerializableClosure() {
  8382. return nonSerializable; // creating closure on some variable
  8383. };
  8384. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8385. 'Background': true,
  8386. 'ExtGState': true,
  8387. 'Halftone': true,
  8388. 'Layout': true,
  8389. 'Mask': true,
  8390. 'Pagination': true,
  8391. 'Printing': true
  8392. };
  8393. function isRecursionAllowedFor(dict) {
  8394. if (!isName(dict.Type)) {
  8395. return true;
  8396. }
  8397. var dictType = dict.Type.name;
  8398. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8399. }
  8400. // xref is optional
  8401. function Dict(xref) {
  8402. // Map should only be used internally, use functions below to access.
  8403. this.map = Object.create(null);
  8404. this.xref = xref;
  8405. this.objId = null;
  8406. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8407. }
  8408. Dict.prototype = {
  8409. assignXref: function Dict_assignXref(newXref) {
  8410. this.xref = newXref;
  8411. },
  8412. // automatically dereferences Ref objects
  8413. get: function Dict_get(key1, key2, key3) {
  8414. var value;
  8415. var xref = this.xref;
  8416. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8417. typeof key2 === 'undefined') {
  8418. return xref ? xref.fetchIfRef(value) : value;
  8419. }
  8420. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8421. typeof key3 === 'undefined') {
  8422. return xref ? xref.fetchIfRef(value) : value;
  8423. }
  8424. value = this.map[key3] || null;
  8425. return xref ? xref.fetchIfRef(value) : value;
  8426. },
  8427. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8428. getAsync: function Dict_getAsync(key1, key2, key3) {
  8429. var value;
  8430. var xref = this.xref;
  8431. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8432. typeof key2 === 'undefined') {
  8433. if (xref) {
  8434. return xref.fetchIfRefAsync(value);
  8435. }
  8436. return Promise.resolve(value);
  8437. }
  8438. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8439. typeof key3 === 'undefined') {
  8440. if (xref) {
  8441. return xref.fetchIfRefAsync(value);
  8442. }
  8443. return Promise.resolve(value);
  8444. }
  8445. value = this.map[key3] || null;
  8446. if (xref) {
  8447. return xref.fetchIfRefAsync(value);
  8448. }
  8449. return Promise.resolve(value);
  8450. },
  8451. // no dereferencing
  8452. getRaw: function Dict_getRaw(key) {
  8453. return this.map[key];
  8454. },
  8455. // creates new map and dereferences all Refs
  8456. getAll: function Dict_getAll() {
  8457. var all = Object.create(null);
  8458. var queue = null;
  8459. var key, obj;
  8460. for (key in this.map) {
  8461. obj = this.get(key);
  8462. if (obj instanceof Dict) {
  8463. if (isRecursionAllowedFor(obj)) {
  8464. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8465. } else {
  8466. all[key] = this.getRaw(key);
  8467. }
  8468. } else {
  8469. all[key] = obj;
  8470. }
  8471. }
  8472. if (!queue) {
  8473. return all;
  8474. }
  8475. // trying to take cyclic references into the account
  8476. var processed = Object.create(null);
  8477. while (queue.length > 0) {
  8478. var item = queue.shift();
  8479. var itemObj = item.obj;
  8480. var objId = itemObj.objId;
  8481. if (objId && objId in processed) {
  8482. item.target[item.key] = processed[objId];
  8483. continue;
  8484. }
  8485. var dereferenced = Object.create(null);
  8486. for (key in itemObj.map) {
  8487. obj = itemObj.get(key);
  8488. if (obj instanceof Dict) {
  8489. if (isRecursionAllowedFor(obj)) {
  8490. queue.push({target: dereferenced, key: key, obj: obj});
  8491. } else {
  8492. dereferenced[key] = itemObj.getRaw(key);
  8493. }
  8494. } else {
  8495. dereferenced[key] = obj;
  8496. }
  8497. }
  8498. if (objId) {
  8499. processed[objId] = dereferenced;
  8500. }
  8501. item.target[item.key] = dereferenced;
  8502. }
  8503. return all;
  8504. },
  8505. set: function Dict_set(key, value) {
  8506. this.map[key] = value;
  8507. },
  8508. has: function Dict_has(key) {
  8509. return key in this.map;
  8510. },
  8511. forEach: function Dict_forEach(callback) {
  8512. for (var key in this.map) {
  8513. callback(key, this.get(key));
  8514. }
  8515. }
  8516. };
  8517. Dict.empty = new Dict(null);
  8518. return Dict;
  8519. })();
  8520. var Ref = (function RefClosure() {
  8521. function Ref(num, gen) {
  8522. this.num = num;
  8523. this.gen = gen;
  8524. }
  8525. Ref.prototype = {
  8526. toString: function Ref_toString() {
  8527. // This function is hot, so we make the string as compact as possible.
  8528. // |this.gen| is almost always zero, so we treat that case specially.
  8529. var str = this.num + 'R';
  8530. if (this.gen !== 0) {
  8531. str += this.gen;
  8532. }
  8533. return str;
  8534. }
  8535. };
  8536. return Ref;
  8537. })();
  8538. // The reference is identified by number and generation.
  8539. // This structure stores only one instance of the reference.
  8540. var RefSet = (function RefSetClosure() {
  8541. function RefSet() {
  8542. this.dict = {};
  8543. }
  8544. RefSet.prototype = {
  8545. has: function RefSet_has(ref) {
  8546. return ref.toString() in this.dict;
  8547. },
  8548. put: function RefSet_put(ref) {
  8549. this.dict[ref.toString()] = true;
  8550. },
  8551. remove: function RefSet_remove(ref) {
  8552. delete this.dict[ref.toString()];
  8553. }
  8554. };
  8555. return RefSet;
  8556. })();
  8557. var RefSetCache = (function RefSetCacheClosure() {
  8558. function RefSetCache() {
  8559. this.dict = Object.create(null);
  8560. }
  8561. RefSetCache.prototype = {
  8562. get: function RefSetCache_get(ref) {
  8563. return this.dict[ref.toString()];
  8564. },
  8565. has: function RefSetCache_has(ref) {
  8566. return ref.toString() in this.dict;
  8567. },
  8568. put: function RefSetCache_put(ref, obj) {
  8569. this.dict[ref.toString()] = obj;
  8570. },
  8571. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8572. this.dict[ref.toString()] = this.get(aliasRef);
  8573. },
  8574. forEach: function RefSetCache_forEach(fn, thisArg) {
  8575. for (var i in this.dict) {
  8576. fn.call(thisArg, this.dict[i]);
  8577. }
  8578. },
  8579. clear: function RefSetCache_clear() {
  8580. this.dict = Object.create(null);
  8581. }
  8582. };
  8583. return RefSetCache;
  8584. })();
  8585. var Catalog = (function CatalogClosure() {
  8586. function Catalog(pdfManager, xref) {
  8587. this.pdfManager = pdfManager;
  8588. this.xref = xref;
  8589. this.catDict = xref.getCatalogObj();
  8590. this.fontCache = new RefSetCache();
  8591. assert(isDict(this.catDict),
  8592. 'catalog object is not a dictionary');
  8593. this.pagePromises = [];
  8594. }
  8595. Catalog.prototype = {
  8596. get metadata() {
  8597. var streamRef = this.catDict.getRaw('Metadata');
  8598. if (!isRef(streamRef)) {
  8599. return shadow(this, 'metadata', null);
  8600. }
  8601. var encryptMetadata = (!this.xref.encrypt ? false :
  8602. this.xref.encrypt.encryptMetadata);
  8603. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8604. var metadata;
  8605. if (stream && isDict(stream.dict)) {
  8606. var type = stream.dict.get('Type');
  8607. var subtype = stream.dict.get('Subtype');
  8608. if (isName(type) && isName(subtype) &&
  8609. type.name === 'Metadata' && subtype.name === 'XML') {
  8610. // XXX: This should examine the charset the XML document defines,
  8611. // however since there are currently no real means to decode
  8612. // arbitrary charsets, let's just hope that the author of the PDF
  8613. // was reasonable enough to stick with the XML default charset,
  8614. // which is UTF-8.
  8615. try {
  8616. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8617. } catch (e) {
  8618. info('Skipping invalid metadata.');
  8619. }
  8620. }
  8621. }
  8622. return shadow(this, 'metadata', metadata);
  8623. },
  8624. get toplevelPagesDict() {
  8625. var pagesObj = this.catDict.get('Pages');
  8626. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8627. // shadow the prototype getter
  8628. return shadow(this, 'toplevelPagesDict', pagesObj);
  8629. },
  8630. get documentOutline() {
  8631. var obj = null;
  8632. try {
  8633. obj = this.readDocumentOutline();
  8634. } catch (ex) {
  8635. if (ex instanceof MissingDataException) {
  8636. throw ex;
  8637. }
  8638. warn('Unable to read document outline');
  8639. }
  8640. return shadow(this, 'documentOutline', obj);
  8641. },
  8642. readDocumentOutline: function Catalog_readDocumentOutline() {
  8643. var xref = this.xref;
  8644. var obj = this.catDict.get('Outlines');
  8645. var root = { items: [] };
  8646. if (isDict(obj)) {
  8647. obj = obj.getRaw('First');
  8648. var processed = new RefSet();
  8649. if (isRef(obj)) {
  8650. var queue = [{obj: obj, parent: root}];
  8651. // to avoid recursion keeping track of the items
  8652. // in the processed dictionary
  8653. processed.put(obj);
  8654. while (queue.length > 0) {
  8655. var i = queue.shift();
  8656. var outlineDict = xref.fetchIfRef(i.obj);
  8657. if (outlineDict === null) {
  8658. continue;
  8659. }
  8660. if (!outlineDict.has('Title')) {
  8661. error('Invalid outline item');
  8662. }
  8663. var dest = outlineDict.get('A');
  8664. if (dest) {
  8665. dest = dest.get('D');
  8666. } else if (outlineDict.has('Dest')) {
  8667. dest = outlineDict.getRaw('Dest');
  8668. if (isName(dest)) {
  8669. dest = dest.name;
  8670. }
  8671. }
  8672. var title = outlineDict.get('Title');
  8673. var outlineItem = {
  8674. dest: dest,
  8675. title: stringToPDFString(title),
  8676. color: outlineDict.get('C') || [0, 0, 0],
  8677. count: outlineDict.get('Count'),
  8678. bold: !!(outlineDict.get('F') & 2),
  8679. italic: !!(outlineDict.get('F') & 1),
  8680. items: []
  8681. };
  8682. i.parent.items.push(outlineItem);
  8683. obj = outlineDict.getRaw('First');
  8684. if (isRef(obj) && !processed.has(obj)) {
  8685. queue.push({obj: obj, parent: outlineItem});
  8686. processed.put(obj);
  8687. }
  8688. obj = outlineDict.getRaw('Next');
  8689. if (isRef(obj) && !processed.has(obj)) {
  8690. queue.push({obj: obj, parent: i.parent});
  8691. processed.put(obj);
  8692. }
  8693. }
  8694. }
  8695. }
  8696. return (root.items.length > 0 ? root.items : null);
  8697. },
  8698. get numPages() {
  8699. var obj = this.toplevelPagesDict.get('Count');
  8700. assert(
  8701. isInt(obj),
  8702. 'page count in top level pages object is not an integer'
  8703. );
  8704. // shadow the prototype getter
  8705. return shadow(this, 'num', obj);
  8706. },
  8707. get destinations() {
  8708. function fetchDestination(dest) {
  8709. return isDict(dest) ? dest.get('D') : dest;
  8710. }
  8711. var xref = this.xref;
  8712. var dests = {}, nameTreeRef, nameDictionaryRef;
  8713. var obj = this.catDict.get('Names');
  8714. if (obj && obj.has('Dests')) {
  8715. nameTreeRef = obj.getRaw('Dests');
  8716. } else if (this.catDict.has('Dests')) {
  8717. nameDictionaryRef = this.catDict.get('Dests');
  8718. }
  8719. if (nameDictionaryRef) {
  8720. // reading simple destination dictionary
  8721. obj = nameDictionaryRef;
  8722. obj.forEach(function catalogForEach(key, value) {
  8723. if (!value) {
  8724. return;
  8725. }
  8726. dests[key] = fetchDestination(value);
  8727. });
  8728. }
  8729. if (nameTreeRef) {
  8730. var nameTree = new NameTree(nameTreeRef, xref);
  8731. var names = nameTree.getAll();
  8732. for (var name in names) {
  8733. if (!names.hasOwnProperty(name)) {
  8734. continue;
  8735. }
  8736. dests[name] = fetchDestination(names[name]);
  8737. }
  8738. }
  8739. return shadow(this, 'destinations', dests);
  8740. },
  8741. getDestination: function Catalog_getDestination(destinationId) {
  8742. function fetchDestination(dest) {
  8743. return isDict(dest) ? dest.get('D') : dest;
  8744. }
  8745. var xref = this.xref;
  8746. var dest, nameTreeRef, nameDictionaryRef;
  8747. var obj = this.catDict.get('Names');
  8748. if (obj && obj.has('Dests')) {
  8749. nameTreeRef = obj.getRaw('Dests');
  8750. } else if (this.catDict.has('Dests')) {
  8751. nameDictionaryRef = this.catDict.get('Dests');
  8752. }
  8753. if (nameDictionaryRef) {
  8754. // reading simple destination dictionary
  8755. obj = nameDictionaryRef;
  8756. obj.forEach(function catalogForEach(key, value) {
  8757. if (!value) {
  8758. return;
  8759. }
  8760. if (key === destinationId) {
  8761. dest = fetchDestination(value);
  8762. }
  8763. });
  8764. }
  8765. if (nameTreeRef) {
  8766. var nameTree = new NameTree(nameTreeRef, xref);
  8767. dest = fetchDestination(nameTree.get(destinationId));
  8768. }
  8769. return dest;
  8770. },
  8771. get attachments() {
  8772. var xref = this.xref;
  8773. var attachments = null, nameTreeRef;
  8774. var obj = this.catDict.get('Names');
  8775. if (obj) {
  8776. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8777. }
  8778. if (nameTreeRef) {
  8779. var nameTree = new NameTree(nameTreeRef, xref);
  8780. var names = nameTree.getAll();
  8781. for (var name in names) {
  8782. if (!names.hasOwnProperty(name)) {
  8783. continue;
  8784. }
  8785. var fs = new FileSpec(names[name], xref);
  8786. if (!attachments) {
  8787. attachments = {};
  8788. }
  8789. attachments[stringToPDFString(name)] = fs.serializable;
  8790. }
  8791. }
  8792. return shadow(this, 'attachments', attachments);
  8793. },
  8794. get javaScript() {
  8795. var xref = this.xref;
  8796. var obj = this.catDict.get('Names');
  8797. var javaScript = [];
  8798. if (obj && obj.has('JavaScript')) {
  8799. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8800. var names = nameTree.getAll();
  8801. for (var name in names) {
  8802. if (!names.hasOwnProperty(name)) {
  8803. continue;
  8804. }
  8805. // We don't really use the JavaScript right now. This code is
  8806. // defensive so we don't cause errors on document load.
  8807. var jsDict = names[name];
  8808. if (!isDict(jsDict)) {
  8809. continue;
  8810. }
  8811. var type = jsDict.get('S');
  8812. if (!isName(type) || type.name !== 'JavaScript') {
  8813. continue;
  8814. }
  8815. var js = jsDict.get('JS');
  8816. if (!isString(js) && !isStream(js)) {
  8817. continue;
  8818. }
  8819. if (isStream(js)) {
  8820. js = bytesToString(js.getBytes());
  8821. }
  8822. javaScript.push(stringToPDFString(js));
  8823. }
  8824. }
  8825. // Append OpenAction actions to javaScript array
  8826. var openactionDict = this.catDict.get('OpenAction');
  8827. if (isDict(openactionDict)) {
  8828. var objType = openactionDict.get('Type');
  8829. var actionType = openactionDict.get('S');
  8830. var action = openactionDict.get('N');
  8831. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8832. isName(actionType) && actionType.name === 'Named' &&
  8833. isName(action) && action.name === 'Print');
  8834. if (isPrintAction) {
  8835. javaScript.push('print(true);');
  8836. }
  8837. }
  8838. return shadow(this, 'javaScript', javaScript);
  8839. },
  8840. cleanup: function Catalog_cleanup() {
  8841. var promises = [];
  8842. this.fontCache.forEach(function (promise) {
  8843. promises.push(promise);
  8844. });
  8845. return Promise.all(promises).then(function (translatedFonts) {
  8846. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8847. var font = translatedFonts[i].dict;
  8848. delete font.translated;
  8849. }
  8850. this.fontCache.clear();
  8851. }.bind(this));
  8852. },
  8853. getPage: function Catalog_getPage(pageIndex) {
  8854. if (!(pageIndex in this.pagePromises)) {
  8855. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8856. function (a) {
  8857. var dict = a[0];
  8858. var ref = a[1];
  8859. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8860. this.fontCache);
  8861. }.bind(this)
  8862. );
  8863. }
  8864. return this.pagePromises[pageIndex];
  8865. },
  8866. getPageDict: function Catalog_getPageDict(pageIndex) {
  8867. var capability = createPromiseCapability();
  8868. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8869. var currentPageIndex = 0;
  8870. var xref = this.xref;
  8871. function next() {
  8872. while (nodesToVisit.length) {
  8873. var currentNode = nodesToVisit.pop();
  8874. if (isRef(currentNode)) {
  8875. xref.fetchAsync(currentNode).then(function (obj) {
  8876. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8877. if (pageIndex === currentPageIndex) {
  8878. capability.resolve([obj, currentNode]);
  8879. } else {
  8880. currentPageIndex++;
  8881. next();
  8882. }
  8883. return;
  8884. }
  8885. nodesToVisit.push(obj);
  8886. next();
  8887. }, capability.reject);
  8888. return;
  8889. }
  8890. // must be a child page dictionary
  8891. assert(
  8892. isDict(currentNode),
  8893. 'page dictionary kid reference points to wrong type of object'
  8894. );
  8895. var count = currentNode.get('Count');
  8896. // Skip nodes where the page can't be.
  8897. if (currentPageIndex + count <= pageIndex) {
  8898. currentPageIndex += count;
  8899. continue;
  8900. }
  8901. var kids = currentNode.get('Kids');
  8902. assert(isArray(kids), 'page dictionary kids object is not an array');
  8903. if (count === kids.length) {
  8904. // Nodes that don't have the page have been skipped and this is the
  8905. // bottom of the tree which means the page requested must be a
  8906. // descendant of this pages node. Ideally we would just resolve the
  8907. // promise with the page ref here, but there is the case where more
  8908. // pages nodes could link to single a page (see issue 3666 pdf). To
  8909. // handle this push it back on the queue so if it is a pages node it
  8910. // will be descended into.
  8911. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8912. currentPageIndex = pageIndex;
  8913. continue;
  8914. } else {
  8915. for (var last = kids.length - 1; last >= 0; last--) {
  8916. nodesToVisit.push(kids[last]);
  8917. }
  8918. }
  8919. }
  8920. capability.reject('Page index ' + pageIndex + ' not found.');
  8921. }
  8922. next();
  8923. return capability.promise;
  8924. },
  8925. getPageIndex: function Catalog_getPageIndex(ref) {
  8926. // The page tree nodes have the count of all the leaves below them. To get
  8927. // how many pages are before we just have to walk up the tree and keep
  8928. // adding the count of siblings to the left of the node.
  8929. var xref = this.xref;
  8930. function pagesBeforeRef(kidRef) {
  8931. var total = 0;
  8932. var parentRef;
  8933. return xref.fetchAsync(kidRef).then(function (node) {
  8934. if (!node) {
  8935. return null;
  8936. }
  8937. parentRef = node.getRaw('Parent');
  8938. return node.getAsync('Parent');
  8939. }).then(function (parent) {
  8940. if (!parent) {
  8941. return null;
  8942. }
  8943. return parent.getAsync('Kids');
  8944. }).then(function (kids) {
  8945. if (!kids) {
  8946. return null;
  8947. }
  8948. var kidPromises = [];
  8949. var found = false;
  8950. for (var i = 0; i < kids.length; i++) {
  8951. var kid = kids[i];
  8952. assert(isRef(kid), 'kids must be a ref');
  8953. if (kid.num === kidRef.num) {
  8954. found = true;
  8955. break;
  8956. }
  8957. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8958. if (kid.has('Count')) {
  8959. var count = kid.get('Count');
  8960. total += count;
  8961. } else { // page leaf node
  8962. total++;
  8963. }
  8964. }));
  8965. }
  8966. if (!found) {
  8967. error('kid ref not found in parents kids');
  8968. }
  8969. return Promise.all(kidPromises).then(function () {
  8970. return [total, parentRef];
  8971. });
  8972. });
  8973. }
  8974. var total = 0;
  8975. function next(ref) {
  8976. return pagesBeforeRef(ref).then(function (args) {
  8977. if (!args) {
  8978. return total;
  8979. }
  8980. var count = args[0];
  8981. var parentRef = args[1];
  8982. total += count;
  8983. return next(parentRef);
  8984. });
  8985. }
  8986. return next(ref);
  8987. }
  8988. };
  8989. return Catalog;
  8990. })();
  8991. var XRef = (function XRefClosure() {
  8992. function XRef(stream, password) {
  8993. this.stream = stream;
  8994. this.entries = [];
  8995. this.xrefstms = {};
  8996. // prepare the XRef cache
  8997. this.cache = [];
  8998. this.password = password;
  8999. this.stats = {
  9000. streamTypes: [],
  9001. fontTypes: []
  9002. };
  9003. }
  9004. XRef.prototype = {
  9005. setStartXRef: function XRef_setStartXRef(startXRef) {
  9006. // Store the starting positions of xref tables as we process them
  9007. // so we can recover from missing data errors
  9008. this.startXRefQueue = [startXRef];
  9009. },
  9010. parse: function XRef_parse(recoveryMode) {
  9011. var trailerDict;
  9012. if (!recoveryMode) {
  9013. trailerDict = this.readXRef();
  9014. } else {
  9015. warn('Indexing all PDF objects');
  9016. trailerDict = this.indexObjects();
  9017. }
  9018. trailerDict.assignXref(this);
  9019. this.trailer = trailerDict;
  9020. var encrypt = trailerDict.get('Encrypt');
  9021. if (encrypt) {
  9022. var ids = trailerDict.get('ID');
  9023. var fileId = (ids && ids.length) ? ids[0] : '';
  9024. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9025. this.password);
  9026. }
  9027. // get the root dictionary (catalog) object
  9028. if (!(this.root = trailerDict.get('Root'))) {
  9029. error('Invalid root reference');
  9030. }
  9031. },
  9032. processXRefTable: function XRef_processXRefTable(parser) {
  9033. if (!('tableState' in this)) {
  9034. // Stores state of the table as we process it so we can resume
  9035. // from middle of table in case of missing data error
  9036. this.tableState = {
  9037. entryNum: 0,
  9038. streamPos: parser.lexer.stream.pos,
  9039. parserBuf1: parser.buf1,
  9040. parserBuf2: parser.buf2
  9041. };
  9042. }
  9043. var obj = this.readXRefTable(parser);
  9044. // Sanity check
  9045. if (!isCmd(obj, 'trailer')) {
  9046. error('Invalid XRef table: could not find trailer dictionary');
  9047. }
  9048. // Read trailer dictionary, e.g.
  9049. // trailer
  9050. // << /Size 22
  9051. // /Root 20R
  9052. // /Info 10R
  9053. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9054. // >>
  9055. // The parser goes through the entire stream << ... >> and provides
  9056. // a getter interface for the key-value table
  9057. var dict = parser.getObj();
  9058. // The pdflib PDF generator can generate a nested trailer dictionary
  9059. if (!isDict(dict) && dict.dict) {
  9060. dict = dict.dict;
  9061. }
  9062. if (!isDict(dict)) {
  9063. error('Invalid XRef table: could not parse trailer dictionary');
  9064. }
  9065. delete this.tableState;
  9066. return dict;
  9067. },
  9068. readXRefTable: function XRef_readXRefTable(parser) {
  9069. // Example of cross-reference table:
  9070. // xref
  9071. // 0 1 <-- subsection header (first obj #, obj count)
  9072. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9073. // 23 2 <-- subsection header ... and so on ...
  9074. // 0000025518 00002 n
  9075. // 0000025635 00000 n
  9076. // trailer
  9077. // ...
  9078. var stream = parser.lexer.stream;
  9079. var tableState = this.tableState;
  9080. stream.pos = tableState.streamPos;
  9081. parser.buf1 = tableState.parserBuf1;
  9082. parser.buf2 = tableState.parserBuf2;
  9083. // Outer loop is over subsection headers
  9084. var obj;
  9085. while (true) {
  9086. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9087. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9088. break;
  9089. }
  9090. tableState.firstEntryNum = obj;
  9091. tableState.entryCount = parser.getObj();
  9092. }
  9093. var first = tableState.firstEntryNum;
  9094. var count = tableState.entryCount;
  9095. if (!isInt(first) || !isInt(count)) {
  9096. error('Invalid XRef table: wrong types in subsection header');
  9097. }
  9098. // Inner loop is over objects themselves
  9099. for (var i = tableState.entryNum; i < count; i++) {
  9100. tableState.streamPos = stream.pos;
  9101. tableState.entryNum = i;
  9102. tableState.parserBuf1 = parser.buf1;
  9103. tableState.parserBuf2 = parser.buf2;
  9104. var entry = {};
  9105. entry.offset = parser.getObj();
  9106. entry.gen = parser.getObj();
  9107. var type = parser.getObj();
  9108. if (isCmd(type, 'f')) {
  9109. entry.free = true;
  9110. } else if (isCmd(type, 'n')) {
  9111. entry.uncompressed = true;
  9112. }
  9113. // Validate entry obj
  9114. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9115. !(entry.free || entry.uncompressed)) {
  9116. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9117. }
  9118. if (!this.entries[i + first]) {
  9119. this.entries[i + first] = entry;
  9120. }
  9121. }
  9122. tableState.entryNum = 0;
  9123. tableState.streamPos = stream.pos;
  9124. tableState.parserBuf1 = parser.buf1;
  9125. tableState.parserBuf2 = parser.buf2;
  9126. delete tableState.firstEntryNum;
  9127. delete tableState.entryCount;
  9128. }
  9129. // Per issue 3248: hp scanners generate bad XRef
  9130. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9131. // shifting the entries
  9132. this.entries.shift();
  9133. }
  9134. // Sanity check: as per spec, first object must be free
  9135. if (this.entries[0] && !this.entries[0].free) {
  9136. error('Invalid XRef table: unexpected first object');
  9137. }
  9138. return obj;
  9139. },
  9140. processXRefStream: function XRef_processXRefStream(stream) {
  9141. if (!('streamState' in this)) {
  9142. // Stores state of the stream as we process it so we can resume
  9143. // from middle of stream in case of missing data error
  9144. var streamParameters = stream.dict;
  9145. var byteWidths = streamParameters.get('W');
  9146. var range = streamParameters.get('Index');
  9147. if (!range) {
  9148. range = [0, streamParameters.get('Size')];
  9149. }
  9150. this.streamState = {
  9151. entryRanges: range,
  9152. byteWidths: byteWidths,
  9153. entryNum: 0,
  9154. streamPos: stream.pos
  9155. };
  9156. }
  9157. this.readXRefStream(stream);
  9158. delete this.streamState;
  9159. return stream.dict;
  9160. },
  9161. readXRefStream: function XRef_readXRefStream(stream) {
  9162. var i, j;
  9163. var streamState = this.streamState;
  9164. stream.pos = streamState.streamPos;
  9165. var byteWidths = streamState.byteWidths;
  9166. var typeFieldWidth = byteWidths[0];
  9167. var offsetFieldWidth = byteWidths[1];
  9168. var generationFieldWidth = byteWidths[2];
  9169. var entryRanges = streamState.entryRanges;
  9170. while (entryRanges.length > 0) {
  9171. var first = entryRanges[0];
  9172. var n = entryRanges[1];
  9173. if (!isInt(first) || !isInt(n)) {
  9174. error('Invalid XRef range fields: ' + first + ', ' + n);
  9175. }
  9176. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9177. !isInt(generationFieldWidth)) {
  9178. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9179. }
  9180. for (i = streamState.entryNum; i < n; ++i) {
  9181. streamState.entryNum = i;
  9182. streamState.streamPos = stream.pos;
  9183. var type = 0, offset = 0, generation = 0;
  9184. for (j = 0; j < typeFieldWidth; ++j) {
  9185. type = (type << 8) | stream.getByte();
  9186. }
  9187. // if type field is absent, its default value is 1
  9188. if (typeFieldWidth === 0) {
  9189. type = 1;
  9190. }
  9191. for (j = 0; j < offsetFieldWidth; ++j) {
  9192. offset = (offset << 8) | stream.getByte();
  9193. }
  9194. for (j = 0; j < generationFieldWidth; ++j) {
  9195. generation = (generation << 8) | stream.getByte();
  9196. }
  9197. var entry = {};
  9198. entry.offset = offset;
  9199. entry.gen = generation;
  9200. switch (type) {
  9201. case 0:
  9202. entry.free = true;
  9203. break;
  9204. case 1:
  9205. entry.uncompressed = true;
  9206. break;
  9207. case 2:
  9208. break;
  9209. default:
  9210. error('Invalid XRef entry type: ' + type);
  9211. }
  9212. if (!this.entries[first + i]) {
  9213. this.entries[first + i] = entry;
  9214. }
  9215. }
  9216. streamState.entryNum = 0;
  9217. streamState.streamPos = stream.pos;
  9218. entryRanges.splice(0, 2);
  9219. }
  9220. },
  9221. indexObjects: function XRef_indexObjects() {
  9222. // Simple scan through the PDF content to find objects,
  9223. // trailers and XRef streams.
  9224. function readToken(data, offset) {
  9225. var token = '', ch = data[offset];
  9226. while (ch !== 13 && ch !== 10) {
  9227. if (++offset >= data.length) {
  9228. break;
  9229. }
  9230. token += String.fromCharCode(ch);
  9231. ch = data[offset];
  9232. }
  9233. return token;
  9234. }
  9235. function skipUntil(data, offset, what) {
  9236. var length = what.length, dataLength = data.length;
  9237. var skipped = 0;
  9238. // finding byte sequence
  9239. while (offset < dataLength) {
  9240. var i = 0;
  9241. while (i < length && data[offset + i] === what[i]) {
  9242. ++i;
  9243. }
  9244. if (i >= length) {
  9245. break; // sequence found
  9246. }
  9247. offset++;
  9248. skipped++;
  9249. }
  9250. return skipped;
  9251. }
  9252. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9253. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9254. 101, 102]);
  9255. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9256. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9257. var stream = this.stream;
  9258. stream.pos = 0;
  9259. var buffer = stream.getBytes();
  9260. var position = stream.start, length = buffer.length;
  9261. var trailers = [], xrefStms = [];
  9262. while (position < length) {
  9263. var ch = buffer[position];
  9264. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9265. ++position;
  9266. continue;
  9267. }
  9268. if (ch === 37) { // %-comment
  9269. do {
  9270. ++position;
  9271. if (position >= length) {
  9272. break;
  9273. }
  9274. ch = buffer[position];
  9275. } while (ch !== 13 && ch !== 10);
  9276. continue;
  9277. }
  9278. var token = readToken(buffer, position);
  9279. var m;
  9280. if (token === 'xref') {
  9281. position += skipUntil(buffer, position, trailerBytes);
  9282. trailers.push(position);
  9283. position += skipUntil(buffer, position, startxrefBytes);
  9284. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9285. this.entries[m[1]] = {
  9286. offset: position,
  9287. gen: m[2] | 0,
  9288. uncompressed: true
  9289. };
  9290. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9291. var content = buffer.subarray(position, position + contentLength);
  9292. // checking XRef stream suspect
  9293. // (it shall have '/XRef' and next char is not a letter)
  9294. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9295. if (xrefTagOffset < contentLength &&
  9296. content[xrefTagOffset + 5] < 64) {
  9297. xrefStms.push(position);
  9298. this.xrefstms[position] = 1; // don't read it recursively
  9299. }
  9300. position += contentLength;
  9301. } else {
  9302. position += token.length + 1;
  9303. }
  9304. }
  9305. // reading XRef streams
  9306. var i, ii;
  9307. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9308. this.startXRefQueue.push(xrefStms[i]);
  9309. this.readXRef(/* recoveryMode */ true);
  9310. }
  9311. // finding main trailer
  9312. var dict;
  9313. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9314. stream.pos = trailers[i];
  9315. var parser = new Parser(new Lexer(stream), true, this);
  9316. var obj = parser.getObj();
  9317. if (!isCmd(obj, 'trailer')) {
  9318. continue;
  9319. }
  9320. // read the trailer dictionary
  9321. if (!isDict(dict = parser.getObj())) {
  9322. continue;
  9323. }
  9324. // taking the first one with 'ID'
  9325. if (dict.has('ID')) {
  9326. return dict;
  9327. }
  9328. }
  9329. // no tailer with 'ID', taking last one (if exists)
  9330. if (dict) {
  9331. return dict;
  9332. }
  9333. // nothing helps
  9334. // calling error() would reject worker with an UnknownErrorException.
  9335. throw new InvalidPDFException('Invalid PDF structure');
  9336. },
  9337. readXRef: function XRef_readXRef(recoveryMode) {
  9338. var stream = this.stream;
  9339. try {
  9340. while (this.startXRefQueue.length) {
  9341. var startXRef = this.startXRefQueue[0];
  9342. stream.pos = startXRef + stream.start;
  9343. var parser = new Parser(new Lexer(stream), true, this);
  9344. var obj = parser.getObj();
  9345. var dict;
  9346. // Get dictionary
  9347. if (isCmd(obj, 'xref')) {
  9348. // Parse end-of-file XRef
  9349. dict = this.processXRefTable(parser);
  9350. if (!this.topDict) {
  9351. this.topDict = dict;
  9352. }
  9353. // Recursively get other XRefs 'XRefStm', if any
  9354. obj = dict.get('XRefStm');
  9355. if (isInt(obj)) {
  9356. var pos = obj;
  9357. // ignore previously loaded xref streams
  9358. // (possible infinite recursion)
  9359. if (!(pos in this.xrefstms)) {
  9360. this.xrefstms[pos] = 1;
  9361. this.startXRefQueue.push(pos);
  9362. }
  9363. }
  9364. } else if (isInt(obj)) {
  9365. // Parse in-stream XRef
  9366. if (!isInt(parser.getObj()) ||
  9367. !isCmd(parser.getObj(), 'obj') ||
  9368. !isStream(obj = parser.getObj())) {
  9369. error('Invalid XRef stream');
  9370. }
  9371. dict = this.processXRefStream(obj);
  9372. if (!this.topDict) {
  9373. this.topDict = dict;
  9374. }
  9375. if (!dict) {
  9376. error('Failed to read XRef stream');
  9377. }
  9378. } else {
  9379. error('Invalid XRef stream header');
  9380. }
  9381. // Recursively get previous dictionary, if any
  9382. obj = dict.get('Prev');
  9383. if (isInt(obj)) {
  9384. this.startXRefQueue.push(obj);
  9385. } else if (isRef(obj)) {
  9386. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9387. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9388. this.startXRefQueue.push(obj.num);
  9389. }
  9390. this.startXRefQueue.shift();
  9391. }
  9392. return this.topDict;
  9393. } catch (e) {
  9394. if (e instanceof MissingDataException) {
  9395. throw e;
  9396. }
  9397. info('(while reading XRef): ' + e);
  9398. }
  9399. if (recoveryMode) {
  9400. return;
  9401. }
  9402. throw new XRefParseException();
  9403. },
  9404. getEntry: function XRef_getEntry(i) {
  9405. var xrefEntry = this.entries[i];
  9406. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9407. return xrefEntry;
  9408. }
  9409. return null;
  9410. },
  9411. fetchIfRef: function XRef_fetchIfRef(obj) {
  9412. if (!isRef(obj)) {
  9413. return obj;
  9414. }
  9415. return this.fetch(obj);
  9416. },
  9417. fetch: function XRef_fetch(ref, suppressEncryption) {
  9418. assert(isRef(ref), 'ref object is not a reference');
  9419. var num = ref.num;
  9420. if (num in this.cache) {
  9421. var cacheEntry = this.cache[num];
  9422. return cacheEntry;
  9423. }
  9424. var xrefEntry = this.getEntry(num);
  9425. // the referenced entry can be free
  9426. if (xrefEntry === null) {
  9427. return (this.cache[num] = null);
  9428. }
  9429. if (xrefEntry.uncompressed) {
  9430. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9431. } else {
  9432. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9433. }
  9434. if (isDict(xrefEntry)){
  9435. xrefEntry.objId = ref.toString();
  9436. } else if (isStream(xrefEntry)) {
  9437. xrefEntry.dict.objId = ref.toString();
  9438. }
  9439. return xrefEntry;
  9440. },
  9441. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9442. suppressEncryption) {
  9443. var gen = ref.gen;
  9444. var num = ref.num;
  9445. if (xrefEntry.gen !== gen) {
  9446. error('inconsistent generation in XRef');
  9447. }
  9448. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9449. this.stream.start);
  9450. var parser = new Parser(new Lexer(stream), true, this);
  9451. var obj1 = parser.getObj();
  9452. var obj2 = parser.getObj();
  9453. var obj3 = parser.getObj();
  9454. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9455. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9456. !isCmd(obj3)) {
  9457. error('bad XRef entry');
  9458. }
  9459. if (!isCmd(obj3, 'obj')) {
  9460. // some bad PDFs use "obj1234" and really mean 1234
  9461. if (obj3.cmd.indexOf('obj') === 0) {
  9462. num = parseInt(obj3.cmd.substring(3), 10);
  9463. if (!isNaN(num)) {
  9464. return num;
  9465. }
  9466. }
  9467. error('bad XRef entry');
  9468. }
  9469. if (this.encrypt && !suppressEncryption) {
  9470. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9471. } else {
  9472. xrefEntry = parser.getObj();
  9473. }
  9474. if (!isStream(xrefEntry)) {
  9475. this.cache[num] = xrefEntry;
  9476. }
  9477. return xrefEntry;
  9478. },
  9479. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9480. suppressEncryption) {
  9481. var tableOffset = xrefEntry.offset;
  9482. var stream = this.fetch(new Ref(tableOffset, 0));
  9483. if (!isStream(stream)) {
  9484. error('bad ObjStm stream');
  9485. }
  9486. var first = stream.dict.get('First');
  9487. var n = stream.dict.get('N');
  9488. if (!isInt(first) || !isInt(n)) {
  9489. error('invalid first and n parameters for ObjStm stream');
  9490. }
  9491. var parser = new Parser(new Lexer(stream), false, this);
  9492. parser.allowStreams = true;
  9493. var i, entries = [], num, nums = [];
  9494. // read the object numbers to populate cache
  9495. for (i = 0; i < n; ++i) {
  9496. num = parser.getObj();
  9497. if (!isInt(num)) {
  9498. error('invalid object number in the ObjStm stream: ' + num);
  9499. }
  9500. nums.push(num);
  9501. var offset = parser.getObj();
  9502. if (!isInt(offset)) {
  9503. error('invalid object offset in the ObjStm stream: ' + offset);
  9504. }
  9505. }
  9506. // read stream objects for cache
  9507. for (i = 0; i < n; ++i) {
  9508. entries.push(parser.getObj());
  9509. num = nums[i];
  9510. var entry = this.entries[num];
  9511. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9512. this.cache[num] = entries[i];
  9513. }
  9514. }
  9515. xrefEntry = entries[xrefEntry.gen];
  9516. if (xrefEntry === undefined) {
  9517. error('bad XRef entry for compressed object');
  9518. }
  9519. return xrefEntry;
  9520. },
  9521. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9522. if (!isRef(obj)) {
  9523. return Promise.resolve(obj);
  9524. }
  9525. return this.fetchAsync(obj);
  9526. },
  9527. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9528. var streamManager = this.stream.manager;
  9529. var xref = this;
  9530. return new Promise(function tryFetch(resolve, reject) {
  9531. try {
  9532. resolve(xref.fetch(ref, suppressEncryption));
  9533. } catch (e) {
  9534. if (e instanceof MissingDataException) {
  9535. streamManager.requestRange(e.begin, e.end, function () {
  9536. tryFetch(resolve, reject);
  9537. });
  9538. return;
  9539. }
  9540. reject(e);
  9541. }
  9542. });
  9543. },
  9544. getCatalogObj: function XRef_getCatalogObj() {
  9545. return this.root;
  9546. }
  9547. };
  9548. return XRef;
  9549. })();
  9550. /**
  9551. * A NameTree is like a Dict but has some advantageous properties, see the
  9552. * spec (7.9.6) for more details.
  9553. * TODO: implement all the Dict functions and make this more efficent.
  9554. */
  9555. var NameTree = (function NameTreeClosure() {
  9556. function NameTree(root, xref) {
  9557. this.root = root;
  9558. this.xref = xref;
  9559. }
  9560. NameTree.prototype = {
  9561. getAll: function NameTree_getAll() {
  9562. var dict = {};
  9563. if (!this.root) {
  9564. return dict;
  9565. }
  9566. var xref = this.xref;
  9567. // reading name tree
  9568. var processed = new RefSet();
  9569. processed.put(this.root);
  9570. var queue = [this.root];
  9571. while (queue.length > 0) {
  9572. var i, n;
  9573. var obj = xref.fetchIfRef(queue.shift());
  9574. if (!isDict(obj)) {
  9575. continue;
  9576. }
  9577. if (obj.has('Kids')) {
  9578. var kids = obj.get('Kids');
  9579. for (i = 0, n = kids.length; i < n; i++) {
  9580. var kid = kids[i];
  9581. if (processed.has(kid)) {
  9582. error('invalid destinations');
  9583. }
  9584. queue.push(kid);
  9585. processed.put(kid);
  9586. }
  9587. continue;
  9588. }
  9589. var names = obj.get('Names');
  9590. if (names) {
  9591. for (i = 0, n = names.length; i < n; i += 2) {
  9592. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9593. }
  9594. }
  9595. }
  9596. return dict;
  9597. },
  9598. get: function NameTree_get(destinationId) {
  9599. if (!this.root) {
  9600. return null;
  9601. }
  9602. var xref = this.xref;
  9603. var kidsOrNames = xref.fetchIfRef(this.root);
  9604. var loopCount = 0;
  9605. var MAX_NAMES_LEVELS = 10;
  9606. var l, r, m;
  9607. // Perform a binary search to quickly find the entry that
  9608. // contains the named destination we are looking for.
  9609. while (kidsOrNames.has('Kids')) {
  9610. loopCount++;
  9611. if (loopCount > MAX_NAMES_LEVELS) {
  9612. warn('Search depth limit for named destionations has been reached.');
  9613. return null;
  9614. }
  9615. var kids = kidsOrNames.get('Kids');
  9616. if (!isArray(kids)) {
  9617. return null;
  9618. }
  9619. l = 0;
  9620. r = kids.length - 1;
  9621. while (l <= r) {
  9622. m = (l + r) >> 1;
  9623. var kid = xref.fetchIfRef(kids[m]);
  9624. var limits = kid.get('Limits');
  9625. if (destinationId < limits[0]) {
  9626. r = m - 1;
  9627. } else if (destinationId > limits[1]) {
  9628. l = m + 1;
  9629. } else {
  9630. kidsOrNames = xref.fetchIfRef(kids[m]);
  9631. break;
  9632. }
  9633. }
  9634. if (l > r) {
  9635. return null;
  9636. }
  9637. }
  9638. // If we get here, then we have found the right entry. Now
  9639. // go through the named destinations in the Named dictionary
  9640. // until we find the exact destination we're looking for.
  9641. var names = kidsOrNames.get('Names');
  9642. if (isArray(names)) {
  9643. // Perform a binary search to reduce the lookup time.
  9644. l = 0;
  9645. r = names.length - 2;
  9646. while (l <= r) {
  9647. // Check only even indices (0, 2, 4, ...) because the
  9648. // odd indices contain the actual D array.
  9649. m = (l + r) & ~1;
  9650. if (destinationId < names[m]) {
  9651. r = m - 2;
  9652. } else if (destinationId > names[m]) {
  9653. l = m + 2;
  9654. } else {
  9655. return xref.fetchIfRef(names[m + 1]);
  9656. }
  9657. }
  9658. }
  9659. return null;
  9660. }
  9661. };
  9662. return NameTree;
  9663. })();
  9664. /**
  9665. * "A PDF file can refer to the contents of another file by using a File
  9666. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9667. * NOTE: Only embedded files are supported (as part of the attachments support)
  9668. * TODO: support the 'URL' file system (with caching if !/V), portable
  9669. * collections attributes and related files (/RF)
  9670. */
  9671. var FileSpec = (function FileSpecClosure() {
  9672. function FileSpec(root, xref) {
  9673. if (!root || !isDict(root)) {
  9674. return;
  9675. }
  9676. this.xref = xref;
  9677. this.root = root;
  9678. if (root.has('FS')) {
  9679. this.fs = root.get('FS');
  9680. }
  9681. this.description = root.has('Desc') ?
  9682. stringToPDFString(root.get('Desc')) :
  9683. '';
  9684. if (root.has('RF')) {
  9685. warn('Related file specifications are not supported');
  9686. }
  9687. this.contentAvailable = true;
  9688. if (!root.has('EF')) {
  9689. this.contentAvailable = false;
  9690. warn('Non-embedded file specifications are not supported');
  9691. }
  9692. }
  9693. function pickPlatformItem(dict) {
  9694. // Look for the filename in this order:
  9695. // UF, F, Unix, Mac, DOS
  9696. if (dict.has('UF')) {
  9697. return dict.get('UF');
  9698. } else if (dict.has('F')) {
  9699. return dict.get('F');
  9700. } else if (dict.has('Unix')) {
  9701. return dict.get('Unix');
  9702. } else if (dict.has('Mac')) {
  9703. return dict.get('Mac');
  9704. } else if (dict.has('DOS')) {
  9705. return dict.get('DOS');
  9706. } else {
  9707. return null;
  9708. }
  9709. }
  9710. FileSpec.prototype = {
  9711. get filename() {
  9712. if (!this._filename && this.root) {
  9713. var filename = pickPlatformItem(this.root) || 'unnamed';
  9714. this._filename = stringToPDFString(filename).
  9715. replace(/\\\\/g, '\\').
  9716. replace(/\\\//g, '/').
  9717. replace(/\\/g, '/');
  9718. }
  9719. return this._filename;
  9720. },
  9721. get content() {
  9722. if (!this.contentAvailable) {
  9723. return null;
  9724. }
  9725. if (!this.contentRef && this.root) {
  9726. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9727. }
  9728. var content = null;
  9729. if (this.contentRef) {
  9730. var xref = this.xref;
  9731. var fileObj = xref.fetchIfRef(this.contentRef);
  9732. if (fileObj && isStream(fileObj)) {
  9733. content = fileObj.getBytes();
  9734. } else {
  9735. warn('Embedded file specification points to non-existing/invalid ' +
  9736. 'content');
  9737. }
  9738. } else {
  9739. warn('Embedded file specification does not have a content');
  9740. }
  9741. return content;
  9742. },
  9743. get serializable() {
  9744. return {
  9745. filename: this.filename,
  9746. content: this.content
  9747. };
  9748. }
  9749. };
  9750. return FileSpec;
  9751. })();
  9752. /**
  9753. * A helper for loading missing data in object graphs. It traverses the graph
  9754. * depth first and queues up any objects that have missing data. Once it has
  9755. * has traversed as many objects that are available it attempts to bundle the
  9756. * missing data requests and then resume from the nodes that weren't ready.
  9757. *
  9758. * NOTE: It provides protection from circular references by keeping track of
  9759. * of loaded references. However, you must be careful not to load any graphs
  9760. * that have references to the catalog or other pages since that will cause the
  9761. * entire PDF document object graph to be traversed.
  9762. */
  9763. var ObjectLoader = (function() {
  9764. function mayHaveChildren(value) {
  9765. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9766. }
  9767. function addChildren(node, nodesToVisit) {
  9768. var value;
  9769. if (isDict(node) || isStream(node)) {
  9770. var map;
  9771. if (isDict(node)) {
  9772. map = node.map;
  9773. } else {
  9774. map = node.dict.map;
  9775. }
  9776. for (var key in map) {
  9777. value = map[key];
  9778. if (mayHaveChildren(value)) {
  9779. nodesToVisit.push(value);
  9780. }
  9781. }
  9782. } else if (isArray(node)) {
  9783. for (var i = 0, ii = node.length; i < ii; i++) {
  9784. value = node[i];
  9785. if (mayHaveChildren(value)) {
  9786. nodesToVisit.push(value);
  9787. }
  9788. }
  9789. }
  9790. }
  9791. function ObjectLoader(obj, keys, xref) {
  9792. this.obj = obj;
  9793. this.keys = keys;
  9794. this.xref = xref;
  9795. this.refSet = null;
  9796. }
  9797. ObjectLoader.prototype = {
  9798. load: function ObjectLoader_load() {
  9799. var keys = this.keys;
  9800. this.capability = createPromiseCapability();
  9801. // Don't walk the graph if all the data is already loaded.
  9802. if (!(this.xref.stream instanceof ChunkedStream) ||
  9803. this.xref.stream.getMissingChunks().length === 0) {
  9804. this.capability.resolve();
  9805. return this.capability.promise;
  9806. }
  9807. this.refSet = new RefSet();
  9808. // Setup the initial nodes to visit.
  9809. var nodesToVisit = [];
  9810. for (var i = 0; i < keys.length; i++) {
  9811. nodesToVisit.push(this.obj[keys[i]]);
  9812. }
  9813. this.walk(nodesToVisit);
  9814. return this.capability.promise;
  9815. },
  9816. walk: function ObjectLoader_walk(nodesToVisit) {
  9817. var nodesToRevisit = [];
  9818. var pendingRequests = [];
  9819. // DFS walk of the object graph.
  9820. while (nodesToVisit.length) {
  9821. var currentNode = nodesToVisit.pop();
  9822. // Only references or chunked streams can cause missing data exceptions.
  9823. if (isRef(currentNode)) {
  9824. // Skip nodes that have already been visited.
  9825. if (this.refSet.has(currentNode)) {
  9826. continue;
  9827. }
  9828. try {
  9829. var ref = currentNode;
  9830. this.refSet.put(ref);
  9831. currentNode = this.xref.fetch(currentNode);
  9832. } catch (e) {
  9833. if (!(e instanceof MissingDataException)) {
  9834. throw e;
  9835. }
  9836. nodesToRevisit.push(currentNode);
  9837. pendingRequests.push({ begin: e.begin, end: e.end });
  9838. }
  9839. }
  9840. if (currentNode && currentNode.getBaseStreams) {
  9841. var baseStreams = currentNode.getBaseStreams();
  9842. var foundMissingData = false;
  9843. for (var i = 0; i < baseStreams.length; i++) {
  9844. var stream = baseStreams[i];
  9845. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9846. foundMissingData = true;
  9847. pendingRequests.push({
  9848. begin: stream.start,
  9849. end: stream.end
  9850. });
  9851. }
  9852. }
  9853. if (foundMissingData) {
  9854. nodesToRevisit.push(currentNode);
  9855. }
  9856. }
  9857. addChildren(currentNode, nodesToVisit);
  9858. }
  9859. if (pendingRequests.length) {
  9860. this.xref.stream.manager.requestRanges(pendingRequests,
  9861. function pendingRequestCallback() {
  9862. nodesToVisit = nodesToRevisit;
  9863. for (var i = 0; i < nodesToRevisit.length; i++) {
  9864. var node = nodesToRevisit[i];
  9865. // Remove any reference nodes from the currrent refset so they
  9866. // aren't skipped when we revist them.
  9867. if (isRef(node)) {
  9868. this.refSet.remove(node);
  9869. }
  9870. }
  9871. this.walk(nodesToVisit);
  9872. }.bind(this));
  9873. return;
  9874. }
  9875. // Everything is loaded.
  9876. this.refSet = null;
  9877. this.capability.resolve();
  9878. }
  9879. };
  9880. return ObjectLoader;
  9881. })();
  9882. var ISOAdobeCharset = [
  9883. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9884. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9885. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9886. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9887. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9888. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9889. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9890. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9891. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9892. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9893. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9894. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9895. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9896. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9897. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9898. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9899. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9900. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9901. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9902. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9903. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9904. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9905. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9906. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9907. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9908. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9909. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9910. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9911. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9912. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9913. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9914. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9915. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9916. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9917. ];
  9918. var ExpertCharset = [
  9919. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9920. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9921. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9922. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9923. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9924. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9925. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9926. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9927. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9928. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9929. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9930. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9931. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9932. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9933. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9934. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9935. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9936. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9937. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9938. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9939. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9940. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9941. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9942. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9943. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9944. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9945. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9946. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9947. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9948. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9949. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9950. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9951. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9952. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9953. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9954. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9955. 'Ydieresissmall'
  9956. ];
  9957. var ExpertSubsetCharset = [
  9958. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9959. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9960. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9961. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9962. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9963. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9964. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9965. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9966. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9967. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9968. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9969. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9970. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9971. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9972. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9973. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9974. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9975. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9976. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9977. 'periodinferior', 'commainferior'
  9978. ];
  9979. var DEFAULT_ICON_SIZE = 22; // px
  9980. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9981. var Annotation = (function AnnotationClosure() {
  9982. // 12.5.5: Algorithm: Appearance streams
  9983. function getTransformMatrix(rect, bbox, matrix) {
  9984. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9985. var minX = bounds[0];
  9986. var minY = bounds[1];
  9987. var maxX = bounds[2];
  9988. var maxY = bounds[3];
  9989. if (minX === maxX || minY === maxY) {
  9990. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9991. // just apply the transform for rect
  9992. return [1, 0, 0, 1, rect[0], rect[1]];
  9993. }
  9994. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9995. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9996. return [
  9997. xRatio,
  9998. 0,
  9999. 0,
  10000. yRatio,
  10001. rect[0] - minX * xRatio,
  10002. rect[1] - minY * yRatio
  10003. ];
  10004. }
  10005. function getDefaultAppearance(dict) {
  10006. var appearanceState = dict.get('AP');
  10007. if (!isDict(appearanceState)) {
  10008. return;
  10009. }
  10010. var appearance;
  10011. var appearances = appearanceState.get('N');
  10012. if (isDict(appearances)) {
  10013. var as = dict.get('AS');
  10014. if (as && appearances.has(as.name)) {
  10015. appearance = appearances.get(as.name);
  10016. }
  10017. } else {
  10018. appearance = appearances;
  10019. }
  10020. return appearance;
  10021. }
  10022. function Annotation(params) {
  10023. var dict = params.dict;
  10024. var data = this.data = {};
  10025. data.subtype = dict.get('Subtype').name;
  10026. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10027. data.rect = Util.normalizeRect(rect);
  10028. data.annotationFlags = dict.get('F');
  10029. var color = dict.get('C');
  10030. if (!color) {
  10031. // The PDF spec does not mention how a missing color array is interpreted.
  10032. // Adobe Reader seems to default to black in this case.
  10033. data.color = [0, 0, 0];
  10034. } else if (isArray(color)) {
  10035. switch (color.length) {
  10036. case 0:
  10037. // Empty array denotes transparent border.
  10038. data.color = null;
  10039. break;
  10040. case 1:
  10041. // TODO: implement DeviceGray
  10042. break;
  10043. case 3:
  10044. data.color = color;
  10045. break;
  10046. case 4:
  10047. // TODO: implement DeviceCMYK
  10048. break;
  10049. }
  10050. }
  10051. // Some types of annotations have border style dict which has more
  10052. // info than the border array
  10053. if (dict.has('BS')) {
  10054. var borderStyle = dict.get('BS');
  10055. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10056. } else {
  10057. var borderArray = dict.get('Border') || [0, 0, 1];
  10058. data.borderWidth = borderArray[2] || 0;
  10059. // TODO: implement proper support for annotations with line dash patterns.
  10060. var dashArray = borderArray[3];
  10061. if (data.borderWidth > 0 && dashArray) {
  10062. if (!isArray(dashArray)) {
  10063. // Ignore the border if dashArray is not actually an array,
  10064. // this is consistent with the behaviour in Adobe Reader.
  10065. data.borderWidth = 0;
  10066. } else {
  10067. var dashArrayLength = dashArray.length;
  10068. if (dashArrayLength > 0) {
  10069. // According to the PDF specification: the elements in a dashArray
  10070. // shall be numbers that are nonnegative and not all equal to zero.
  10071. var isInvalid = false;
  10072. var numPositive = 0;
  10073. for (var i = 0; i < dashArrayLength; i++) {
  10074. var validNumber = (+dashArray[i] >= 0);
  10075. if (!validNumber) {
  10076. isInvalid = true;
  10077. break;
  10078. } else if (dashArray[i] > 0) {
  10079. numPositive++;
  10080. }
  10081. }
  10082. if (isInvalid || numPositive === 0) {
  10083. data.borderWidth = 0;
  10084. }
  10085. }
  10086. }
  10087. }
  10088. }
  10089. this.appearance = getDefaultAppearance(dict);
  10090. data.hasAppearance = !!this.appearance;
  10091. data.id = params.ref.num;
  10092. }
  10093. Annotation.prototype = {
  10094. getData: function Annotation_getData() {
  10095. return this.data;
  10096. },
  10097. isInvisible: function Annotation_isInvisible() {
  10098. var data = this.data;
  10099. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10100. return false;
  10101. } else {
  10102. return !!(data &&
  10103. data.annotationFlags && // Default: not invisible
  10104. data.annotationFlags & 0x1); // Invisible
  10105. }
  10106. },
  10107. isViewable: function Annotation_isViewable() {
  10108. var data = this.data;
  10109. return !!(!this.isInvisible() &&
  10110. data &&
  10111. (!data.annotationFlags ||
  10112. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10113. data.rect); // rectangle is necessary
  10114. },
  10115. isPrintable: function Annotation_isPrintable() {
  10116. var data = this.data;
  10117. return !!(!this.isInvisible() &&
  10118. data &&
  10119. data.annotationFlags && // Default: not printable
  10120. data.annotationFlags & 0x4 && // Print
  10121. !(data.annotationFlags & 0x2) && // Hidden
  10122. data.rect); // rectangle is necessary
  10123. },
  10124. loadResources: function Annotation_loadResources(keys) {
  10125. return new Promise(function (resolve, reject) {
  10126. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10127. if (!resources) {
  10128. resolve();
  10129. return;
  10130. }
  10131. var objectLoader = new ObjectLoader(resources.map,
  10132. keys,
  10133. resources.xref);
  10134. objectLoader.load().then(function() {
  10135. resolve(resources);
  10136. }, reject);
  10137. }, reject);
  10138. }.bind(this));
  10139. },
  10140. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10141. if (!this.appearance) {
  10142. return Promise.resolve(new OperatorList());
  10143. }
  10144. var data = this.data;
  10145. var appearanceDict = this.appearance.dict;
  10146. var resourcesPromise = this.loadResources([
  10147. 'ExtGState',
  10148. 'ColorSpace',
  10149. 'Pattern',
  10150. 'Shading',
  10151. 'XObject',
  10152. 'Font'
  10153. // ProcSet
  10154. // Properties
  10155. ]);
  10156. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10157. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10158. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10159. var self = this;
  10160. return resourcesPromise.then(function(resources) {
  10161. var opList = new OperatorList();
  10162. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10163. return evaluator.getOperatorList(self.appearance, resources, opList).
  10164. then(function () {
  10165. opList.addOp(OPS.endAnnotation, []);
  10166. self.appearance.reset();
  10167. return opList;
  10168. });
  10169. });
  10170. }
  10171. };
  10172. Annotation.getConstructor =
  10173. function Annotation_getConstructor(subtype, fieldType) {
  10174. if (!subtype) {
  10175. return;
  10176. }
  10177. // TODO(mack): Implement FreeText annotations
  10178. if (subtype === 'Link') {
  10179. return LinkAnnotation;
  10180. } else if (subtype === 'Text') {
  10181. return TextAnnotation;
  10182. } else if (subtype === 'Widget') {
  10183. if (!fieldType) {
  10184. return;
  10185. }
  10186. if (fieldType === 'Tx') {
  10187. return TextWidgetAnnotation;
  10188. } else {
  10189. return WidgetAnnotation;
  10190. }
  10191. } else {
  10192. return Annotation;
  10193. }
  10194. };
  10195. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10196. var dict = xref.fetchIfRef(ref);
  10197. if (!isDict(dict)) {
  10198. return;
  10199. }
  10200. var subtype = dict.get('Subtype');
  10201. subtype = isName(subtype) ? subtype.name : '';
  10202. if (!subtype) {
  10203. return;
  10204. }
  10205. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10206. fieldType = isName(fieldType) ? fieldType.name : '';
  10207. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10208. if (!Constructor) {
  10209. return;
  10210. }
  10211. var params = {
  10212. dict: dict,
  10213. ref: ref,
  10214. };
  10215. var annotation = new Constructor(params);
  10216. if (annotation.isViewable() || annotation.isPrintable()) {
  10217. return annotation;
  10218. } else {
  10219. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10220. warn('unimplemented annotation type: ' + subtype);
  10221. }
  10222. }
  10223. };
  10224. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10225. annotations, opList, pdfManager, partialEvaluator, intent) {
  10226. function reject(e) {
  10227. annotationsReadyCapability.reject(e);
  10228. }
  10229. var annotationsReadyCapability = createPromiseCapability();
  10230. var annotationPromises = [];
  10231. for (var i = 0, n = annotations.length; i < n; ++i) {
  10232. if (intent === 'display' && annotations[i].isViewable() ||
  10233. intent === 'print' && annotations[i].isPrintable()) {
  10234. annotationPromises.push(
  10235. annotations[i].getOperatorList(partialEvaluator));
  10236. }
  10237. }
  10238. Promise.all(annotationPromises).then(function(datas) {
  10239. opList.addOp(OPS.beginAnnotations, []);
  10240. for (var i = 0, n = datas.length; i < n; ++i) {
  10241. var annotOpList = datas[i];
  10242. opList.addOpList(annotOpList);
  10243. }
  10244. opList.addOp(OPS.endAnnotations, []);
  10245. annotationsReadyCapability.resolve();
  10246. }, reject);
  10247. return annotationsReadyCapability.promise;
  10248. };
  10249. return Annotation;
  10250. })();
  10251. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10252. function WidgetAnnotation(params) {
  10253. Annotation.call(this, params);
  10254. var dict = params.dict;
  10255. var data = this.data;
  10256. data.fieldValue = stringToPDFString(
  10257. Util.getInheritableProperty(dict, 'V') || '');
  10258. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10259. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10260. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10261. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10262. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10263. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10264. // Building the full field name by collecting the field and
  10265. // its ancestors 'T' data and joining them using '.'.
  10266. var fieldName = [];
  10267. var namedItem = dict;
  10268. var ref = params.ref;
  10269. while (namedItem) {
  10270. var parent = namedItem.get('Parent');
  10271. var parentRef = namedItem.getRaw('Parent');
  10272. var name = namedItem.get('T');
  10273. if (name) {
  10274. fieldName.unshift(stringToPDFString(name));
  10275. } else if (parent && ref) {
  10276. // The field name is absent, that means more than one field
  10277. // with the same name may exist. Replacing the empty name
  10278. // with the '`' plus index in the parent's 'Kids' array.
  10279. // This is not in the PDF spec but necessary to id the
  10280. // the input controls.
  10281. var kids = parent.get('Kids');
  10282. var j, jj;
  10283. for (j = 0, jj = kids.length; j < jj; j++) {
  10284. var kidRef = kids[j];
  10285. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10286. break;
  10287. }
  10288. }
  10289. fieldName.unshift('`' + j);
  10290. }
  10291. namedItem = parent;
  10292. ref = parentRef;
  10293. }
  10294. data.fullName = fieldName.join('.');
  10295. }
  10296. var parent = Annotation.prototype;
  10297. Util.inherit(WidgetAnnotation, Annotation, {
  10298. isViewable: function WidgetAnnotation_isViewable() {
  10299. if (this.data.fieldType === 'Sig') {
  10300. warn('unimplemented annotation type: Widget signature');
  10301. return false;
  10302. }
  10303. return parent.isViewable.call(this);
  10304. }
  10305. });
  10306. return WidgetAnnotation;
  10307. })();
  10308. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10309. function TextWidgetAnnotation(params) {
  10310. WidgetAnnotation.call(this, params);
  10311. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10312. this.data.annotationType = AnnotationType.WIDGET;
  10313. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10314. }
  10315. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10316. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10317. if (this.appearance) {
  10318. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10319. }
  10320. var opList = new OperatorList();
  10321. var data = this.data;
  10322. // Even if there is an appearance stream, ignore it. This is the
  10323. // behaviour used by Adobe Reader.
  10324. if (!data.defaultAppearance) {
  10325. return Promise.resolve(opList);
  10326. }
  10327. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10328. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10329. then(function () {
  10330. return opList;
  10331. });
  10332. }
  10333. });
  10334. return TextWidgetAnnotation;
  10335. })();
  10336. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10337. function InteractiveAnnotation(params) {
  10338. Annotation.call(this, params);
  10339. this.data.hasHtml = true;
  10340. }
  10341. Util.inherit(InteractiveAnnotation, Annotation, { });
  10342. return InteractiveAnnotation;
  10343. })();
  10344. var TextAnnotation = (function TextAnnotationClosure() {
  10345. function TextAnnotation(params) {
  10346. InteractiveAnnotation.call(this, params);
  10347. var dict = params.dict;
  10348. var data = this.data;
  10349. var content = dict.get('Contents');
  10350. var title = dict.get('T');
  10351. data.annotationType = AnnotationType.TEXT;
  10352. data.content = stringToPDFString(content || '');
  10353. data.title = stringToPDFString(title || '');
  10354. if (data.hasAppearance) {
  10355. data.name = 'NoIcon';
  10356. } else {
  10357. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10358. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10359. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10360. }
  10361. if (dict.has('C')) {
  10362. data.hasBgColor = true;
  10363. }
  10364. }
  10365. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10366. return TextAnnotation;
  10367. })();
  10368. var LinkAnnotation = (function LinkAnnotationClosure() {
  10369. function LinkAnnotation(params) {
  10370. InteractiveAnnotation.call(this, params);
  10371. var dict = params.dict;
  10372. var data = this.data;
  10373. data.annotationType = AnnotationType.LINK;
  10374. var action = dict.get('A');
  10375. if (action && isDict(action)) {
  10376. var linkType = action.get('S').name;
  10377. if (linkType === 'URI') {
  10378. var url = action.get('URI');
  10379. if (isName(url)) {
  10380. // Some bad PDFs do not put parentheses around relative URLs.
  10381. url = '/' + url.name;
  10382. } else if (url) {
  10383. url = addDefaultProtocolToUrl(url);
  10384. }
  10385. // TODO: pdf spec mentions urls can be relative to a Base
  10386. // entry in the dictionary.
  10387. if (!isValidUrl(url, false)) {
  10388. url = '';
  10389. }
  10390. data.url = url;
  10391. } else if (linkType === 'GoTo') {
  10392. data.dest = action.get('D');
  10393. } else if (linkType === 'GoToR') {
  10394. var urlDict = action.get('F');
  10395. if (isDict(urlDict)) {
  10396. // We assume that the 'url' is a Filspec dictionary
  10397. // and fetch the url without checking any further
  10398. url = urlDict.get('F') || '';
  10399. }
  10400. // TODO: pdf reference says that GoToR
  10401. // can also have 'NewWindow' attribute
  10402. if (!isValidUrl(url, false)) {
  10403. url = '';
  10404. }
  10405. data.url = url;
  10406. data.dest = action.get('D');
  10407. } else if (linkType === 'Named') {
  10408. data.action = action.get('N').name;
  10409. } else {
  10410. warn('unrecognized link type: ' + linkType);
  10411. }
  10412. } else if (dict.has('Dest')) {
  10413. // simple destination link
  10414. var dest = dict.get('Dest');
  10415. data.dest = isName(dest) ? dest.name : dest;
  10416. }
  10417. }
  10418. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10419. function addDefaultProtocolToUrl(url) {
  10420. if (url && url.indexOf('www.') === 0) {
  10421. return ('http://' + url);
  10422. }
  10423. return url;
  10424. }
  10425. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10426. return LinkAnnotation;
  10427. })();
  10428. var PDFFunction = (function PDFFunctionClosure() {
  10429. var CONSTRUCT_SAMPLED = 0;
  10430. var CONSTRUCT_INTERPOLATED = 2;
  10431. var CONSTRUCT_STICHED = 3;
  10432. var CONSTRUCT_POSTSCRIPT = 4;
  10433. return {
  10434. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10435. str) {
  10436. var i, ii;
  10437. var length = 1;
  10438. for (i = 0, ii = size.length; i < ii; i++) {
  10439. length *= size[i];
  10440. }
  10441. length *= outputSize;
  10442. var array = new Array(length);
  10443. var codeSize = 0;
  10444. var codeBuf = 0;
  10445. // 32 is a valid bps so shifting won't work
  10446. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10447. var strBytes = str.getBytes((length * bps + 7) / 8);
  10448. var strIdx = 0;
  10449. for (i = 0; i < length; i++) {
  10450. while (codeSize < bps) {
  10451. codeBuf <<= 8;
  10452. codeBuf |= strBytes[strIdx++];
  10453. codeSize += 8;
  10454. }
  10455. codeSize -= bps;
  10456. array[i] = (codeBuf >> codeSize) * sampleMul;
  10457. codeBuf &= (1 << codeSize) - 1;
  10458. }
  10459. return array;
  10460. },
  10461. getIR: function PDFFunction_getIR(xref, fn) {
  10462. var dict = fn.dict;
  10463. if (!dict) {
  10464. dict = fn;
  10465. }
  10466. var types = [this.constructSampled,
  10467. null,
  10468. this.constructInterpolated,
  10469. this.constructStiched,
  10470. this.constructPostScript];
  10471. var typeNum = dict.get('FunctionType');
  10472. var typeFn = types[typeNum];
  10473. if (!typeFn) {
  10474. error('Unknown type of function');
  10475. }
  10476. return typeFn.call(this, fn, dict, xref);
  10477. },
  10478. fromIR: function PDFFunction_fromIR(IR) {
  10479. var type = IR[0];
  10480. switch (type) {
  10481. case CONSTRUCT_SAMPLED:
  10482. return this.constructSampledFromIR(IR);
  10483. case CONSTRUCT_INTERPOLATED:
  10484. return this.constructInterpolatedFromIR(IR);
  10485. case CONSTRUCT_STICHED:
  10486. return this.constructStichedFromIR(IR);
  10487. //case CONSTRUCT_POSTSCRIPT:
  10488. default:
  10489. return this.constructPostScriptFromIR(IR);
  10490. }
  10491. },
  10492. parse: function PDFFunction_parse(xref, fn) {
  10493. var IR = this.getIR(xref, fn);
  10494. return this.fromIR(IR);
  10495. },
  10496. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10497. if (!isArray(fnObj)) {
  10498. // not an array -- parsing as regular function
  10499. return this.parse(xref, fnObj);
  10500. }
  10501. var fnArray = [];
  10502. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10503. var obj = xref.fetchIfRef(fnObj[j]);
  10504. fnArray.push(PDFFunction.parse(xref, obj));
  10505. }
  10506. return function (src, srcOffset, dest, destOffset) {
  10507. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10508. fnArray[i](src, srcOffset, dest, destOffset + i);
  10509. }
  10510. };
  10511. },
  10512. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10513. function toMultiArray(arr) {
  10514. var inputLength = arr.length;
  10515. var out = [];
  10516. var index = 0;
  10517. for (var i = 0; i < inputLength; i += 2) {
  10518. out[index] = [arr[i], arr[i + 1]];
  10519. ++index;
  10520. }
  10521. return out;
  10522. }
  10523. var domain = dict.get('Domain');
  10524. var range = dict.get('Range');
  10525. if (!domain || !range) {
  10526. error('No domain or range');
  10527. }
  10528. var inputSize = domain.length / 2;
  10529. var outputSize = range.length / 2;
  10530. domain = toMultiArray(domain);
  10531. range = toMultiArray(range);
  10532. var size = dict.get('Size');
  10533. var bps = dict.get('BitsPerSample');
  10534. var order = dict.get('Order') || 1;
  10535. if (order !== 1) {
  10536. // No description how cubic spline interpolation works in PDF32000:2008
  10537. // As in poppler, ignoring order, linear interpolation may work as good
  10538. info('No support for cubic spline interpolation: ' + order);
  10539. }
  10540. var encode = dict.get('Encode');
  10541. if (!encode) {
  10542. encode = [];
  10543. for (var i = 0; i < inputSize; ++i) {
  10544. encode.push(0);
  10545. encode.push(size[i] - 1);
  10546. }
  10547. }
  10548. encode = toMultiArray(encode);
  10549. var decode = dict.get('Decode');
  10550. if (!decode) {
  10551. decode = range;
  10552. } else {
  10553. decode = toMultiArray(decode);
  10554. }
  10555. var samples = this.getSampleArray(size, outputSize, bps, str);
  10556. return [
  10557. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10558. outputSize, Math.pow(2, bps) - 1, range
  10559. ];
  10560. },
  10561. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10562. // See chapter 3, page 109 of the PDF reference
  10563. function interpolate(x, xmin, xmax, ymin, ymax) {
  10564. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10565. }
  10566. return function constructSampledFromIRResult(src, srcOffset,
  10567. dest, destOffset) {
  10568. // See chapter 3, page 110 of the PDF reference.
  10569. var m = IR[1];
  10570. var domain = IR[2];
  10571. var encode = IR[3];
  10572. var decode = IR[4];
  10573. var samples = IR[5];
  10574. var size = IR[6];
  10575. var n = IR[7];
  10576. //var mask = IR[8];
  10577. var range = IR[9];
  10578. // Building the cube vertices: its part and sample index
  10579. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10580. var cubeVertices = 1 << m;
  10581. var cubeN = new Float64Array(cubeVertices);
  10582. var cubeVertex = new Uint32Array(cubeVertices);
  10583. var i, j;
  10584. for (j = 0; j < cubeVertices; j++) {
  10585. cubeN[j] = 1;
  10586. }
  10587. var k = n, pos = 1;
  10588. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10589. for (i = 0; i < m; ++i) {
  10590. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10591. var domain_2i = domain[i][0];
  10592. var domain_2i_1 = domain[i][1];
  10593. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10594. domain_2i_1);
  10595. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10596. // Encode_2i, Encode_2i+1)
  10597. var e = interpolate(xi, domain_2i, domain_2i_1,
  10598. encode[i][0], encode[i][1]);
  10599. // e_i' = min(max(e_i, 0), Size_i - 1)
  10600. var size_i = size[i];
  10601. e = Math.min(Math.max(e, 0), size_i - 1);
  10602. // Adjusting the cube: N and vertex sample index
  10603. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10604. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10605. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10606. var offset0 = e0 * k;
  10607. var offset1 = offset0 + k; // e1 * k
  10608. for (j = 0; j < cubeVertices; j++) {
  10609. if (j & pos) {
  10610. cubeN[j] *= n1;
  10611. cubeVertex[j] += offset1;
  10612. } else {
  10613. cubeN[j] *= n0;
  10614. cubeVertex[j] += offset0;
  10615. }
  10616. }
  10617. k *= size_i;
  10618. pos <<= 1;
  10619. }
  10620. for (j = 0; j < n; ++j) {
  10621. // Sum all cube vertices' samples portions
  10622. var rj = 0;
  10623. for (i = 0; i < cubeVertices; i++) {
  10624. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10625. }
  10626. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10627. // Decode_2j, Decode_2j+1)
  10628. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10629. // y_j = min(max(r_j, range_2j), range_2j+1)
  10630. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10631. range[j][1]);
  10632. }
  10633. };
  10634. },
  10635. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10636. dict) {
  10637. var c0 = dict.get('C0') || [0];
  10638. var c1 = dict.get('C1') || [1];
  10639. var n = dict.get('N');
  10640. if (!isArray(c0) || !isArray(c1)) {
  10641. error('Illegal dictionary for interpolated function');
  10642. }
  10643. var length = c0.length;
  10644. var diff = [];
  10645. for (var i = 0; i < length; ++i) {
  10646. diff.push(c1[i] - c0[i]);
  10647. }
  10648. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10649. },
  10650. constructInterpolatedFromIR:
  10651. function PDFFunction_constructInterpolatedFromIR(IR) {
  10652. var c0 = IR[1];
  10653. var diff = IR[2];
  10654. var n = IR[3];
  10655. var length = diff.length;
  10656. return function constructInterpolatedFromIRResult(src, srcOffset,
  10657. dest, destOffset) {
  10658. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10659. for (var j = 0; j < length; ++j) {
  10660. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10661. }
  10662. };
  10663. },
  10664. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10665. var domain = dict.get('Domain');
  10666. if (!domain) {
  10667. error('No domain');
  10668. }
  10669. var inputSize = domain.length / 2;
  10670. if (inputSize !== 1) {
  10671. error('Bad domain for stiched function');
  10672. }
  10673. var fnRefs = dict.get('Functions');
  10674. var fns = [];
  10675. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10676. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10677. }
  10678. var bounds = dict.get('Bounds');
  10679. var encode = dict.get('Encode');
  10680. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10681. },
  10682. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10683. var domain = IR[1];
  10684. var bounds = IR[2];
  10685. var encode = IR[3];
  10686. var fnsIR = IR[4];
  10687. var fns = [];
  10688. var tmpBuf = new Float32Array(1);
  10689. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10690. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10691. }
  10692. return function constructStichedFromIRResult(src, srcOffset,
  10693. dest, destOffset) {
  10694. var clip = function constructStichedFromIRClip(v, min, max) {
  10695. if (v > max) {
  10696. v = max;
  10697. } else if (v < min) {
  10698. v = min;
  10699. }
  10700. return v;
  10701. };
  10702. // clip to domain
  10703. var v = clip(src[srcOffset], domain[0], domain[1]);
  10704. // calulate which bound the value is in
  10705. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10706. if (v < bounds[i]) {
  10707. break;
  10708. }
  10709. }
  10710. // encode value into domain of function
  10711. var dmin = domain[0];
  10712. if (i > 0) {
  10713. dmin = bounds[i - 1];
  10714. }
  10715. var dmax = domain[1];
  10716. if (i < bounds.length) {
  10717. dmax = bounds[i];
  10718. }
  10719. var rmin = encode[2 * i];
  10720. var rmax = encode[2 * i + 1];
  10721. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10722. // call the appropriate function
  10723. fns[i](tmpBuf, 0, dest, destOffset);
  10724. };
  10725. },
  10726. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10727. xref) {
  10728. var domain = dict.get('Domain');
  10729. var range = dict.get('Range');
  10730. if (!domain) {
  10731. error('No domain.');
  10732. }
  10733. if (!range) {
  10734. error('No range.');
  10735. }
  10736. var lexer = new PostScriptLexer(fn);
  10737. var parser = new PostScriptParser(lexer);
  10738. var code = parser.parse();
  10739. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10740. },
  10741. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10742. IR) {
  10743. var domain = IR[1];
  10744. var range = IR[2];
  10745. var code = IR[3];
  10746. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10747. if (compiled) {
  10748. // Compiled function consists of simple expressions such as addition,
  10749. // subtraction, Math.max, and also contains 'var' and 'return'
  10750. // statements. See the generation in the PostScriptCompiler below.
  10751. /*jshint -W054 */
  10752. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10753. }
  10754. info('Unable to compile PS function');
  10755. var numOutputs = range.length >> 1;
  10756. var numInputs = domain.length >> 1;
  10757. var evaluator = new PostScriptEvaluator(code);
  10758. // Cache the values for a big speed up, the cache size is limited though
  10759. // since the number of possible values can be huge from a PS function.
  10760. var cache = {};
  10761. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10762. // seen in our tests.
  10763. var MAX_CACHE_SIZE = 2048 * 4;
  10764. var cache_available = MAX_CACHE_SIZE;
  10765. var tmpBuf = new Float32Array(numInputs);
  10766. return function constructPostScriptFromIRResult(src, srcOffset,
  10767. dest, destOffset) {
  10768. var i, value;
  10769. var key = '';
  10770. var input = tmpBuf;
  10771. for (i = 0; i < numInputs; i++) {
  10772. value = src[srcOffset + i];
  10773. input[i] = value;
  10774. key += value + '_';
  10775. }
  10776. var cachedValue = cache[key];
  10777. if (cachedValue !== undefined) {
  10778. dest.set(cachedValue, destOffset);
  10779. return;
  10780. }
  10781. var output = new Float32Array(numOutputs);
  10782. var stack = evaluator.execute(input);
  10783. var stackIndex = stack.length - numOutputs;
  10784. for (i = 0; i < numOutputs; i++) {
  10785. value = stack[stackIndex + i];
  10786. var bound = range[i * 2];
  10787. if (value < bound) {
  10788. value = bound;
  10789. } else {
  10790. bound = range[i * 2 +1];
  10791. if (value > bound) {
  10792. value = bound;
  10793. }
  10794. }
  10795. output[i] = value;
  10796. }
  10797. if (cache_available > 0) {
  10798. cache_available--;
  10799. cache[key] = output;
  10800. }
  10801. dest.set(output, destOffset);
  10802. };
  10803. }
  10804. };
  10805. })();
  10806. function isPDFFunction(v) {
  10807. var fnDict;
  10808. if (typeof v !== 'object') {
  10809. return false;
  10810. } else if (isDict(v)) {
  10811. fnDict = v;
  10812. } else if (isStream(v)) {
  10813. fnDict = v.dict;
  10814. } else {
  10815. return false;
  10816. }
  10817. return fnDict.has('FunctionType');
  10818. }
  10819. var PostScriptStack = (function PostScriptStackClosure() {
  10820. var MAX_STACK_SIZE = 100;
  10821. function PostScriptStack(initialStack) {
  10822. this.stack = !initialStack ? [] :
  10823. Array.prototype.slice.call(initialStack, 0);
  10824. }
  10825. PostScriptStack.prototype = {
  10826. push: function PostScriptStack_push(value) {
  10827. if (this.stack.length >= MAX_STACK_SIZE) {
  10828. error('PostScript function stack overflow.');
  10829. }
  10830. this.stack.push(value);
  10831. },
  10832. pop: function PostScriptStack_pop() {
  10833. if (this.stack.length <= 0) {
  10834. error('PostScript function stack underflow.');
  10835. }
  10836. return this.stack.pop();
  10837. },
  10838. copy: function PostScriptStack_copy(n) {
  10839. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10840. error('PostScript function stack overflow.');
  10841. }
  10842. var stack = this.stack;
  10843. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10844. stack.push(stack[i]);
  10845. }
  10846. },
  10847. index: function PostScriptStack_index(n) {
  10848. this.push(this.stack[this.stack.length - n - 1]);
  10849. },
  10850. // rotate the last n stack elements p times
  10851. roll: function PostScriptStack_roll(n, p) {
  10852. var stack = this.stack;
  10853. var l = stack.length - n;
  10854. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10855. for (i = l, j = r; i < j; i++, j--) {
  10856. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10857. }
  10858. for (i = l, j = c - 1; i < j; i++, j--) {
  10859. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10860. }
  10861. for (i = c, j = r; i < j; i++, j--) {
  10862. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10863. }
  10864. }
  10865. };
  10866. return PostScriptStack;
  10867. })();
  10868. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10869. function PostScriptEvaluator(operators) {
  10870. this.operators = operators;
  10871. }
  10872. PostScriptEvaluator.prototype = {
  10873. execute: function PostScriptEvaluator_execute(initialStack) {
  10874. var stack = new PostScriptStack(initialStack);
  10875. var counter = 0;
  10876. var operators = this.operators;
  10877. var length = operators.length;
  10878. var operator, a, b;
  10879. while (counter < length) {
  10880. operator = operators[counter++];
  10881. if (typeof operator === 'number') {
  10882. // Operator is really an operand and should be pushed to the stack.
  10883. stack.push(operator);
  10884. continue;
  10885. }
  10886. switch (operator) {
  10887. // non standard ps operators
  10888. case 'jz': // jump if false
  10889. b = stack.pop();
  10890. a = stack.pop();
  10891. if (!a) {
  10892. counter = b;
  10893. }
  10894. break;
  10895. case 'j': // jump
  10896. a = stack.pop();
  10897. counter = a;
  10898. break;
  10899. // all ps operators in alphabetical order (excluding if/ifelse)
  10900. case 'abs':
  10901. a = stack.pop();
  10902. stack.push(Math.abs(a));
  10903. break;
  10904. case 'add':
  10905. b = stack.pop();
  10906. a = stack.pop();
  10907. stack.push(a + b);
  10908. break;
  10909. case 'and':
  10910. b = stack.pop();
  10911. a = stack.pop();
  10912. if (isBool(a) && isBool(b)) {
  10913. stack.push(a && b);
  10914. } else {
  10915. stack.push(a & b);
  10916. }
  10917. break;
  10918. case 'atan':
  10919. a = stack.pop();
  10920. stack.push(Math.atan(a));
  10921. break;
  10922. case 'bitshift':
  10923. b = stack.pop();
  10924. a = stack.pop();
  10925. if (a > 0) {
  10926. stack.push(a << b);
  10927. } else {
  10928. stack.push(a >> b);
  10929. }
  10930. break;
  10931. case 'ceiling':
  10932. a = stack.pop();
  10933. stack.push(Math.ceil(a));
  10934. break;
  10935. case 'copy':
  10936. a = stack.pop();
  10937. stack.copy(a);
  10938. break;
  10939. case 'cos':
  10940. a = stack.pop();
  10941. stack.push(Math.cos(a));
  10942. break;
  10943. case 'cvi':
  10944. a = stack.pop() | 0;
  10945. stack.push(a);
  10946. break;
  10947. case 'cvr':
  10948. // noop
  10949. break;
  10950. case 'div':
  10951. b = stack.pop();
  10952. a = stack.pop();
  10953. stack.push(a / b);
  10954. break;
  10955. case 'dup':
  10956. stack.copy(1);
  10957. break;
  10958. case 'eq':
  10959. b = stack.pop();
  10960. a = stack.pop();
  10961. stack.push(a === b);
  10962. break;
  10963. case 'exch':
  10964. stack.roll(2, 1);
  10965. break;
  10966. case 'exp':
  10967. b = stack.pop();
  10968. a = stack.pop();
  10969. stack.push(Math.pow(a, b));
  10970. break;
  10971. case 'false':
  10972. stack.push(false);
  10973. break;
  10974. case 'floor':
  10975. a = stack.pop();
  10976. stack.push(Math.floor(a));
  10977. break;
  10978. case 'ge':
  10979. b = stack.pop();
  10980. a = stack.pop();
  10981. stack.push(a >= b);
  10982. break;
  10983. case 'gt':
  10984. b = stack.pop();
  10985. a = stack.pop();
  10986. stack.push(a > b);
  10987. break;
  10988. case 'idiv':
  10989. b = stack.pop();
  10990. a = stack.pop();
  10991. stack.push((a / b) | 0);
  10992. break;
  10993. case 'index':
  10994. a = stack.pop();
  10995. stack.index(a);
  10996. break;
  10997. case 'le':
  10998. b = stack.pop();
  10999. a = stack.pop();
  11000. stack.push(a <= b);
  11001. break;
  11002. case 'ln':
  11003. a = stack.pop();
  11004. stack.push(Math.log(a));
  11005. break;
  11006. case 'log':
  11007. a = stack.pop();
  11008. stack.push(Math.log(a) / Math.LN10);
  11009. break;
  11010. case 'lt':
  11011. b = stack.pop();
  11012. a = stack.pop();
  11013. stack.push(a < b);
  11014. break;
  11015. case 'mod':
  11016. b = stack.pop();
  11017. a = stack.pop();
  11018. stack.push(a % b);
  11019. break;
  11020. case 'mul':
  11021. b = stack.pop();
  11022. a = stack.pop();
  11023. stack.push(a * b);
  11024. break;
  11025. case 'ne':
  11026. b = stack.pop();
  11027. a = stack.pop();
  11028. stack.push(a !== b);
  11029. break;
  11030. case 'neg':
  11031. a = stack.pop();
  11032. stack.push(-a);
  11033. break;
  11034. case 'not':
  11035. a = stack.pop();
  11036. if (isBool(a)) {
  11037. stack.push(!a);
  11038. } else {
  11039. stack.push(~a);
  11040. }
  11041. break;
  11042. case 'or':
  11043. b = stack.pop();
  11044. a = stack.pop();
  11045. if (isBool(a) && isBool(b)) {
  11046. stack.push(a || b);
  11047. } else {
  11048. stack.push(a | b);
  11049. }
  11050. break;
  11051. case 'pop':
  11052. stack.pop();
  11053. break;
  11054. case 'roll':
  11055. b = stack.pop();
  11056. a = stack.pop();
  11057. stack.roll(a, b);
  11058. break;
  11059. case 'round':
  11060. a = stack.pop();
  11061. stack.push(Math.round(a));
  11062. break;
  11063. case 'sin':
  11064. a = stack.pop();
  11065. stack.push(Math.sin(a));
  11066. break;
  11067. case 'sqrt':
  11068. a = stack.pop();
  11069. stack.push(Math.sqrt(a));
  11070. break;
  11071. case 'sub':
  11072. b = stack.pop();
  11073. a = stack.pop();
  11074. stack.push(a - b);
  11075. break;
  11076. case 'true':
  11077. stack.push(true);
  11078. break;
  11079. case 'truncate':
  11080. a = stack.pop();
  11081. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11082. stack.push(a);
  11083. break;
  11084. case 'xor':
  11085. b = stack.pop();
  11086. a = stack.pop();
  11087. if (isBool(a) && isBool(b)) {
  11088. stack.push(a !== b);
  11089. } else {
  11090. stack.push(a ^ b);
  11091. }
  11092. break;
  11093. default:
  11094. error('Unknown operator ' + operator);
  11095. break;
  11096. }
  11097. }
  11098. return stack.stack;
  11099. }
  11100. };
  11101. return PostScriptEvaluator;
  11102. })();
  11103. // Most of the PDFs functions consist of simple operations such as:
  11104. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11105. //
  11106. // We can compile most of such programs, and at the same moment, we can
  11107. // optimize some expressions using basic math properties. Keeping track of
  11108. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11109. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11110. function AstNode(type) {
  11111. this.type = type;
  11112. }
  11113. AstNode.prototype.visit = function (visitor) {
  11114. throw new Error('abstract method');
  11115. };
  11116. function AstArgument(index, min, max) {
  11117. AstNode.call(this, 'args');
  11118. this.index = index;
  11119. this.min = min;
  11120. this.max = max;
  11121. }
  11122. AstArgument.prototype = Object.create(AstNode.prototype);
  11123. AstArgument.prototype.visit = function (visitor) {
  11124. visitor.visitArgument(this);
  11125. };
  11126. function AstLiteral(number) {
  11127. AstNode.call(this, 'literal');
  11128. this.number = number;
  11129. this.min = number;
  11130. this.max = number;
  11131. }
  11132. AstLiteral.prototype = Object.create(AstNode.prototype);
  11133. AstLiteral.prototype.visit = function (visitor) {
  11134. visitor.visitLiteral(this);
  11135. };
  11136. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11137. AstNode.call(this, 'binary');
  11138. this.op = op;
  11139. this.arg1 = arg1;
  11140. this.arg2 = arg2;
  11141. this.min = min;
  11142. this.max = max;
  11143. }
  11144. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11145. AstBinaryOperation.prototype.visit = function (visitor) {
  11146. visitor.visitBinaryOperation(this);
  11147. };
  11148. function AstMin(arg, max) {
  11149. AstNode.call(this, 'max');
  11150. this.arg = arg;
  11151. this.min = arg.min;
  11152. this.max = max;
  11153. }
  11154. AstMin.prototype = Object.create(AstNode.prototype);
  11155. AstMin.prototype.visit = function (visitor) {
  11156. visitor.visitMin(this);
  11157. };
  11158. function AstVariable(index, min, max) {
  11159. AstNode.call(this, 'var');
  11160. this.index = index;
  11161. this.min = min;
  11162. this.max = max;
  11163. }
  11164. AstVariable.prototype = Object.create(AstNode.prototype);
  11165. AstVariable.prototype.visit = function (visitor) {
  11166. visitor.visitVariable(this);
  11167. };
  11168. function AstVariableDefinition(variable, arg) {
  11169. AstNode.call(this, 'definition');
  11170. this.variable = variable;
  11171. this.arg = arg;
  11172. }
  11173. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11174. AstVariableDefinition.prototype.visit = function (visitor) {
  11175. visitor.visitVariableDefinition(this);
  11176. };
  11177. function ExpressionBuilderVisitor() {
  11178. this.parts = [];
  11179. }
  11180. ExpressionBuilderVisitor.prototype = {
  11181. visitArgument: function (arg) {
  11182. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11183. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11184. },
  11185. visitVariable: function (variable) {
  11186. this.parts.push('v', variable.index);
  11187. },
  11188. visitLiteral: function (literal) {
  11189. this.parts.push(literal.number);
  11190. },
  11191. visitBinaryOperation: function (operation) {
  11192. this.parts.push('(');
  11193. operation.arg1.visit(this);
  11194. this.parts.push(' ', operation.op, ' ');
  11195. operation.arg2.visit(this);
  11196. this.parts.push(')');
  11197. },
  11198. visitVariableDefinition: function (definition) {
  11199. this.parts.push('var ');
  11200. definition.variable.visit(this);
  11201. this.parts.push(' = ');
  11202. definition.arg.visit(this);
  11203. this.parts.push(';');
  11204. },
  11205. visitMin: function (max) {
  11206. this.parts.push('Math.min(');
  11207. max.arg.visit(this);
  11208. this.parts.push(', ', max.max, ')');
  11209. },
  11210. toString: function () {
  11211. return this.parts.join('');
  11212. }
  11213. };
  11214. function buildAddOperation(num1, num2) {
  11215. if (num2.type === 'literal' && num2.number === 0) {
  11216. // optimization: second operand is 0
  11217. return num1;
  11218. }
  11219. if (num1.type === 'literal' && num1.number === 0) {
  11220. // optimization: first operand is 0
  11221. return num2;
  11222. }
  11223. if (num2.type === 'literal' && num1.type === 'literal') {
  11224. // optimization: operands operand are literals
  11225. return new AstLiteral(num1.number + num2.number);
  11226. }
  11227. return new AstBinaryOperation('+', num1, num2,
  11228. num1.min + num2.min, num1.max + num2.max);
  11229. }
  11230. function buildMulOperation(num1, num2) {
  11231. if (num2.type === 'literal') {
  11232. // optimization: second operands is a literal...
  11233. if (num2.number === 0) {
  11234. return new AstLiteral(0); // and it's 0
  11235. } else if (num2.number === 1) {
  11236. return num1; // and it's 1
  11237. } else if (num1.type === 'literal') {
  11238. // ... and first operands is a literal too
  11239. return new AstLiteral(num1.number * num2.number);
  11240. }
  11241. }
  11242. if (num1.type === 'literal') {
  11243. // optimization: first operands is a literal...
  11244. if (num1.number === 0) {
  11245. return new AstLiteral(0); // and it's 0
  11246. } else if (num1.number === 1) {
  11247. return num2; // and it's 1
  11248. }
  11249. }
  11250. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11251. num1.max * num2.min, num1.max * num2.max);
  11252. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11253. num1.max * num2.min, num1.max * num2.max);
  11254. return new AstBinaryOperation('*', num1, num2, min, max);
  11255. }
  11256. function buildSubOperation(num1, num2) {
  11257. if (num2.type === 'literal') {
  11258. // optimization: second operands is a literal...
  11259. if (num2.number === 0) {
  11260. return num1; // ... and it's 0
  11261. } else if (num1.type === 'literal') {
  11262. // ... and first operands is a literal too
  11263. return new AstLiteral(num1.number - num2.number);
  11264. }
  11265. }
  11266. if (num2.type === 'binary' && num2.op === '-' &&
  11267. num1.type === 'literal' && num1.number === 1 &&
  11268. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11269. // optimization for case: 1 - (1 - x)
  11270. return num2.arg2;
  11271. }
  11272. return new AstBinaryOperation('-', num1, num2,
  11273. num1.min - num2.max, num1.max - num2.min);
  11274. }
  11275. function buildMinOperation(num1, max) {
  11276. if (num1.min >= max) {
  11277. // optimization: num1 min value is not less than required max
  11278. return new AstLiteral(max); // just returning max
  11279. } else if (num1.max <= max) {
  11280. // optimization: num1 max value is not greater than required max
  11281. return num1; // just returning an argument
  11282. }
  11283. return new AstMin(num1, max);
  11284. }
  11285. function PostScriptCompiler() {}
  11286. PostScriptCompiler.prototype = {
  11287. compile: function PostScriptCompiler_compile(code, domain, range) {
  11288. var stack = [];
  11289. var i, ii;
  11290. var instructions = [];
  11291. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11292. var lastRegister = 0;
  11293. var n, j, min, max;
  11294. var num1, num2, ast1, ast2, tmpVar, item;
  11295. for (i = 0; i < inputSize; i++) {
  11296. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11297. }
  11298. for (i = 0, ii = code.length; i < ii; i++) {
  11299. item = code[i];
  11300. if (typeof item === 'number') {
  11301. stack.push(new AstLiteral(item));
  11302. continue;
  11303. }
  11304. switch (item) {
  11305. case 'add':
  11306. if (stack.length < 2) {
  11307. return null;
  11308. }
  11309. num2 = stack.pop();
  11310. num1 = stack.pop();
  11311. stack.push(buildAddOperation(num1, num2));
  11312. break;
  11313. case 'cvr':
  11314. if (stack.length < 1) {
  11315. return null;
  11316. }
  11317. break;
  11318. case 'mul':
  11319. if (stack.length < 2) {
  11320. return null;
  11321. }
  11322. num2 = stack.pop();
  11323. num1 = stack.pop();
  11324. stack.push(buildMulOperation(num1, num2));
  11325. break;
  11326. case 'sub':
  11327. if (stack.length < 2) {
  11328. return null;
  11329. }
  11330. num2 = stack.pop();
  11331. num1 = stack.pop();
  11332. stack.push(buildSubOperation(num1, num2));
  11333. break;
  11334. case 'exch':
  11335. if (stack.length < 2) {
  11336. return null;
  11337. }
  11338. ast1 = stack.pop(); ast2 = stack.pop();
  11339. stack.push(ast1, ast2);
  11340. break;
  11341. case 'pop':
  11342. if (stack.length < 1) {
  11343. return null;
  11344. }
  11345. stack.pop();
  11346. break;
  11347. case 'index':
  11348. if (stack.length < 1) {
  11349. return null;
  11350. }
  11351. num1 = stack.pop();
  11352. if (num1.type !== 'literal') {
  11353. return null;
  11354. }
  11355. n = num1.number;
  11356. if (n < 0 || (n|0) !== n || stack.length < n) {
  11357. return null;
  11358. }
  11359. ast1 = stack[stack.length - n - 1];
  11360. if (ast1.type === 'literal' || ast1.type === 'var') {
  11361. stack.push(ast1);
  11362. break;
  11363. }
  11364. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11365. stack[stack.length - n - 1] = tmpVar;
  11366. stack.push(tmpVar);
  11367. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11368. break;
  11369. case 'dup':
  11370. if (stack.length < 1) {
  11371. return null;
  11372. }
  11373. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11374. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11375. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11376. // special case of the commands sequence for the min operation
  11377. num1 = stack.pop();
  11378. stack.push(buildMinOperation(num1, code[i + 1]));
  11379. i += 6;
  11380. break;
  11381. }
  11382. ast1 = stack[stack.length - 1];
  11383. if (ast1.type === 'literal' || ast1.type === 'var') {
  11384. // we don't have to save into intermediate variable a literal or
  11385. // variable.
  11386. stack.push(ast1);
  11387. break;
  11388. }
  11389. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11390. stack[stack.length - 1] = tmpVar;
  11391. stack.push(tmpVar);
  11392. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11393. break;
  11394. case 'roll':
  11395. if (stack.length < 2) {
  11396. return null;
  11397. }
  11398. num2 = stack.pop();
  11399. num1 = stack.pop();
  11400. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11401. // both roll operands must be numbers
  11402. return null;
  11403. }
  11404. j = num2.number;
  11405. n = num1.number;
  11406. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11407. // ... and integers
  11408. return null;
  11409. }
  11410. j = ((j % n) + n) % n;
  11411. if (j === 0) {
  11412. break; // just skipping -- there are nothing to rotate
  11413. }
  11414. Array.prototype.push.apply(stack,
  11415. stack.splice(stack.length - n, n - j));
  11416. break;
  11417. default:
  11418. return null; // unsupported operator
  11419. }
  11420. }
  11421. if (stack.length !== outputSize) {
  11422. return null;
  11423. }
  11424. var result = [];
  11425. instructions.forEach(function (instruction) {
  11426. var statementBuilder = new ExpressionBuilderVisitor();
  11427. instruction.visit(statementBuilder);
  11428. result.push(statementBuilder.toString());
  11429. });
  11430. stack.forEach(function (expr, i) {
  11431. var statementBuilder = new ExpressionBuilderVisitor();
  11432. expr.visit(statementBuilder);
  11433. var min = range[i * 2], max = range[i * 2 + 1];
  11434. var out = [statementBuilder.toString()];
  11435. if (min > expr.min) {
  11436. out.unshift('Math.max(', min, ', ');
  11437. out.push(')');
  11438. }
  11439. if (max < expr.max) {
  11440. out.unshift('Math.min(', max, ', ');
  11441. out.push(')');
  11442. }
  11443. out.unshift('dest[destOffset + ', i, '] = ');
  11444. out.push(';');
  11445. result.push(out.join(''));
  11446. });
  11447. return result.join('\n');
  11448. }
  11449. };
  11450. return PostScriptCompiler;
  11451. })();
  11452. var ColorSpace = (function ColorSpaceClosure() {
  11453. // Constructor should define this.numComps, this.defaultColor, this.name
  11454. function ColorSpace() {
  11455. error('should not call ColorSpace constructor');
  11456. }
  11457. ColorSpace.prototype = {
  11458. /**
  11459. * Converts the color value to the RGB color. The color components are
  11460. * located in the src array starting from the srcOffset. Returns the array
  11461. * of the rgb components, each value ranging from [0,255].
  11462. */
  11463. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11464. var rgb = new Uint8Array(3);
  11465. this.getRgbItem(src, srcOffset, rgb, 0);
  11466. return rgb;
  11467. },
  11468. /**
  11469. * Converts the color value to the RGB color, similar to the getRgb method.
  11470. * The result placed into the dest array starting from the destOffset.
  11471. */
  11472. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11473. dest, destOffset) {
  11474. error('Should not call ColorSpace.getRgbItem');
  11475. },
  11476. /**
  11477. * Converts the specified number of the color values to the RGB colors.
  11478. * The colors are located in the src array starting from the srcOffset.
  11479. * The result is placed into the dest array starting from the destOffset.
  11480. * The src array items shall be in [0,2^bits) range, the dest array items
  11481. * will be in [0,255] range. alpha01 indicates how many alpha components
  11482. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11483. * array).
  11484. */
  11485. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11486. dest, destOffset, bits,
  11487. alpha01) {
  11488. error('Should not call ColorSpace.getRgbBuffer');
  11489. },
  11490. /**
  11491. * Determines the number of bytes required to store the result of the
  11492. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11493. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11494. */
  11495. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11496. alpha01) {
  11497. error('Should not call ColorSpace.getOutputLength');
  11498. },
  11499. /**
  11500. * Returns true if source data will be equal the result/output data.
  11501. */
  11502. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11503. return false;
  11504. },
  11505. /**
  11506. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11507. * how many alpha components there are in the dest array; it will be either
  11508. * 0 (RGB array) or 1 (RGBA array).
  11509. */
  11510. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11511. originalHeight, width, height,
  11512. actualHeight, bpc, comps, alpha01) {
  11513. var count = originalWidth * originalHeight;
  11514. var rgbBuf = null;
  11515. var numComponentColors = 1 << bpc;
  11516. var needsResizing = originalHeight !== height || originalWidth !== width;
  11517. var i, ii;
  11518. if (this.isPassthrough(bpc)) {
  11519. rgbBuf = comps;
  11520. } else if (this.numComps === 1 && count > numComponentColors &&
  11521. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11522. // Optimization: create a color map when there is just one component and
  11523. // we are converting more colors than the size of the color map. We
  11524. // don't build the map if the colorspace is gray or rgb since those
  11525. // methods are faster than building a map. This mainly offers big speed
  11526. // ups for indexed and alternate colorspaces.
  11527. //
  11528. // TODO it may be worth while to cache the color map. While running
  11529. // testing I never hit a cache so I will leave that out for now (perhaps
  11530. // we are reparsing colorspaces too much?).
  11531. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11532. new Uint16Array(numComponentColors);
  11533. var key;
  11534. for (i = 0; i < numComponentColors; i++) {
  11535. allColors[i] = i;
  11536. }
  11537. var colorMap = new Uint8Array(numComponentColors * 3);
  11538. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11539. /* alpha01 = */ 0);
  11540. var destPos, rgbPos;
  11541. if (!needsResizing) {
  11542. // Fill in the RGB values directly into |dest|.
  11543. destPos = 0;
  11544. for (i = 0; i < count; ++i) {
  11545. key = comps[i] * 3;
  11546. dest[destPos++] = colorMap[key];
  11547. dest[destPos++] = colorMap[key + 1];
  11548. dest[destPos++] = colorMap[key + 2];
  11549. destPos += alpha01;
  11550. }
  11551. } else {
  11552. rgbBuf = new Uint8Array(count * 3);
  11553. rgbPos = 0;
  11554. for (i = 0; i < count; ++i) {
  11555. key = comps[i] * 3;
  11556. rgbBuf[rgbPos++] = colorMap[key];
  11557. rgbBuf[rgbPos++] = colorMap[key + 1];
  11558. rgbBuf[rgbPos++] = colorMap[key + 2];
  11559. }
  11560. }
  11561. } else {
  11562. if (!needsResizing) {
  11563. // Fill in the RGB values directly into |dest|.
  11564. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11565. alpha01);
  11566. } else {
  11567. rgbBuf = new Uint8Array(count * 3);
  11568. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11569. /* alpha01 = */ 0);
  11570. }
  11571. }
  11572. if (rgbBuf) {
  11573. if (needsResizing) {
  11574. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11575. height, dest, alpha01);
  11576. } else {
  11577. rgbPos = 0;
  11578. destPos = 0;
  11579. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11580. dest[destPos++] = rgbBuf[rgbPos++];
  11581. dest[destPos++] = rgbBuf[rgbPos++];
  11582. dest[destPos++] = rgbBuf[rgbPos++];
  11583. destPos += alpha01;
  11584. }
  11585. }
  11586. }
  11587. },
  11588. /**
  11589. * True if the colorspace has components in the default range of [0, 1].
  11590. * This should be true for all colorspaces except for lab color spaces
  11591. * which are [0,100], [-128, 127], [-128, 127].
  11592. */
  11593. usesZeroToOneRange: true
  11594. };
  11595. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11596. var IR = ColorSpace.parseToIR(cs, xref, res);
  11597. if (IR instanceof AlternateCS) {
  11598. return IR;
  11599. }
  11600. return ColorSpace.fromIR(IR);
  11601. };
  11602. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11603. var name = isArray(IR) ? IR[0] : IR;
  11604. var whitePoint, blackPoint, gamma;
  11605. switch (name) {
  11606. case 'DeviceGrayCS':
  11607. return this.singletons.gray;
  11608. case 'DeviceRgbCS':
  11609. return this.singletons.rgb;
  11610. case 'DeviceCmykCS':
  11611. return this.singletons.cmyk;
  11612. case 'CalGrayCS':
  11613. whitePoint = IR[1].WhitePoint;
  11614. blackPoint = IR[1].BlackPoint;
  11615. gamma = IR[1].Gamma;
  11616. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11617. case 'CalRGBCS':
  11618. whitePoint = IR[1].WhitePoint;
  11619. blackPoint = IR[1].BlackPoint;
  11620. gamma = IR[1].Gamma;
  11621. var matrix = IR[1].Matrix;
  11622. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11623. case 'PatternCS':
  11624. var basePatternCS = IR[1];
  11625. if (basePatternCS) {
  11626. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11627. }
  11628. return new PatternCS(basePatternCS);
  11629. case 'IndexedCS':
  11630. var baseIndexedCS = IR[1];
  11631. var hiVal = IR[2];
  11632. var lookup = IR[3];
  11633. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11634. case 'AlternateCS':
  11635. var numComps = IR[1];
  11636. var alt = IR[2];
  11637. var tintFnIR = IR[3];
  11638. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11639. PDFFunction.fromIR(tintFnIR));
  11640. case 'LabCS':
  11641. whitePoint = IR[1].WhitePoint;
  11642. blackPoint = IR[1].BlackPoint;
  11643. var range = IR[1].Range;
  11644. return new LabCS(whitePoint, blackPoint, range);
  11645. default:
  11646. error('Unknown name ' + name);
  11647. }
  11648. return null;
  11649. };
  11650. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11651. if (isName(cs)) {
  11652. var colorSpaces = res.get('ColorSpace');
  11653. if (isDict(colorSpaces)) {
  11654. var refcs = colorSpaces.get(cs.name);
  11655. if (refcs) {
  11656. cs = refcs;
  11657. }
  11658. }
  11659. }
  11660. cs = xref.fetchIfRef(cs);
  11661. var mode;
  11662. if (isName(cs)) {
  11663. mode = cs.name;
  11664. this.mode = mode;
  11665. switch (mode) {
  11666. case 'DeviceGray':
  11667. case 'G':
  11668. return 'DeviceGrayCS';
  11669. case 'DeviceRGB':
  11670. case 'RGB':
  11671. return 'DeviceRgbCS';
  11672. case 'DeviceCMYK':
  11673. case 'CMYK':
  11674. return 'DeviceCmykCS';
  11675. case 'Pattern':
  11676. return ['PatternCS', null];
  11677. default:
  11678. error('unrecognized colorspace ' + mode);
  11679. }
  11680. } else if (isArray(cs)) {
  11681. mode = cs[0].name;
  11682. this.mode = mode;
  11683. var numComps, params;
  11684. switch (mode) {
  11685. case 'DeviceGray':
  11686. case 'G':
  11687. return 'DeviceGrayCS';
  11688. case 'DeviceRGB':
  11689. case 'RGB':
  11690. return 'DeviceRgbCS';
  11691. case 'DeviceCMYK':
  11692. case 'CMYK':
  11693. return 'DeviceCmykCS';
  11694. case 'CalGray':
  11695. params = xref.fetchIfRef(cs[1]).getAll();
  11696. return ['CalGrayCS', params];
  11697. case 'CalRGB':
  11698. params = xref.fetchIfRef(cs[1]).getAll();
  11699. return ['CalRGBCS', params];
  11700. case 'ICCBased':
  11701. var stream = xref.fetchIfRef(cs[1]);
  11702. var dict = stream.dict;
  11703. numComps = dict.get('N');
  11704. if (numComps === 1) {
  11705. return 'DeviceGrayCS';
  11706. } else if (numComps === 3) {
  11707. return 'DeviceRgbCS';
  11708. } else if (numComps === 4) {
  11709. return 'DeviceCmykCS';
  11710. }
  11711. break;
  11712. case 'Pattern':
  11713. var basePatternCS = cs[1];
  11714. if (basePatternCS) {
  11715. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11716. }
  11717. return ['PatternCS', basePatternCS];
  11718. case 'Indexed':
  11719. case 'I':
  11720. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11721. var hiVal = cs[2] + 1;
  11722. var lookup = xref.fetchIfRef(cs[3]);
  11723. if (isStream(lookup)) {
  11724. lookup = lookup.getBytes();
  11725. }
  11726. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11727. case 'Separation':
  11728. case 'DeviceN':
  11729. var name = cs[1];
  11730. numComps = 1;
  11731. if (isName(name)) {
  11732. numComps = 1;
  11733. } else if (isArray(name)) {
  11734. numComps = name.length;
  11735. }
  11736. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11737. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11738. return ['AlternateCS', numComps, alt, tintFnIR];
  11739. case 'Lab':
  11740. params = cs[1].getAll();
  11741. return ['LabCS', params];
  11742. default:
  11743. error('unimplemented color space object "' + mode + '"');
  11744. }
  11745. } else {
  11746. error('unrecognized color space object: "' + cs + '"');
  11747. }
  11748. return null;
  11749. };
  11750. /**
  11751. * Checks if a decode map matches the default decode map for a color space.
  11752. * This handles the general decode maps where there are two values per
  11753. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11754. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11755. * slightly different.
  11756. * @param {Array} decode Decode map (usually from an image).
  11757. * @param {Number} n Number of components the color space has.
  11758. */
  11759. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11760. if (!decode) {
  11761. return true;
  11762. }
  11763. if (n * 2 !== decode.length) {
  11764. warn('The decode map is not the correct length');
  11765. return true;
  11766. }
  11767. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11768. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11769. return false;
  11770. }
  11771. }
  11772. return true;
  11773. };
  11774. ColorSpace.singletons = {
  11775. get gray() {
  11776. return shadow(this, 'gray', new DeviceGrayCS());
  11777. },
  11778. get rgb() {
  11779. return shadow(this, 'rgb', new DeviceRgbCS());
  11780. },
  11781. get cmyk() {
  11782. return shadow(this, 'cmyk', new DeviceCmykCS());
  11783. }
  11784. };
  11785. return ColorSpace;
  11786. })();
  11787. /**
  11788. * Alternate color space handles both Separation and DeviceN color spaces. A
  11789. * Separation color space is actually just a DeviceN with one color component.
  11790. * Both color spaces use a tinting function to convert colors to a base color
  11791. * space.
  11792. */
  11793. var AlternateCS = (function AlternateCSClosure() {
  11794. function AlternateCS(numComps, base, tintFn) {
  11795. this.name = 'Alternate';
  11796. this.numComps = numComps;
  11797. this.defaultColor = new Float32Array(numComps);
  11798. for (var i = 0; i < numComps; ++i) {
  11799. this.defaultColor[i] = 1;
  11800. }
  11801. this.base = base;
  11802. this.tintFn = tintFn;
  11803. this.tmpBuf = new Float32Array(base.numComps);
  11804. }
  11805. AlternateCS.prototype = {
  11806. getRgb: ColorSpace.prototype.getRgb,
  11807. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11808. dest, destOffset) {
  11809. var tmpBuf = this.tmpBuf;
  11810. this.tintFn(src, srcOffset, tmpBuf, 0);
  11811. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11812. },
  11813. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11814. dest, destOffset, bits,
  11815. alpha01) {
  11816. var tintFn = this.tintFn;
  11817. var base = this.base;
  11818. var scale = 1 / ((1 << bits) - 1);
  11819. var baseNumComps = base.numComps;
  11820. var usesZeroToOneRange = base.usesZeroToOneRange;
  11821. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11822. alpha01 === 0;
  11823. var pos = isPassthrough ? destOffset : 0;
  11824. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11825. var numComps = this.numComps;
  11826. var scaled = new Float32Array(numComps);
  11827. var tinted = new Float32Array(baseNumComps);
  11828. var i, j;
  11829. if (usesZeroToOneRange) {
  11830. for (i = 0; i < count; i++) {
  11831. for (j = 0; j < numComps; j++) {
  11832. scaled[j] = src[srcOffset++] * scale;
  11833. }
  11834. tintFn(scaled, 0, tinted, 0);
  11835. for (j = 0; j < baseNumComps; j++) {
  11836. baseBuf[pos++] = tinted[j] * 255;
  11837. }
  11838. }
  11839. } else {
  11840. for (i = 0; i < count; i++) {
  11841. for (j = 0; j < numComps; j++) {
  11842. scaled[j] = src[srcOffset++] * scale;
  11843. }
  11844. tintFn(scaled, 0, tinted, 0);
  11845. base.getRgbItem(tinted, 0, baseBuf, pos);
  11846. pos += baseNumComps;
  11847. }
  11848. }
  11849. if (!isPassthrough) {
  11850. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11851. }
  11852. },
  11853. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11854. alpha01) {
  11855. return this.base.getOutputLength(inputLength *
  11856. this.base.numComps / this.numComps,
  11857. alpha01);
  11858. },
  11859. isPassthrough: ColorSpace.prototype.isPassthrough,
  11860. fillRgb: ColorSpace.prototype.fillRgb,
  11861. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11862. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11863. },
  11864. usesZeroToOneRange: true
  11865. };
  11866. return AlternateCS;
  11867. })();
  11868. var PatternCS = (function PatternCSClosure() {
  11869. function PatternCS(baseCS) {
  11870. this.name = 'Pattern';
  11871. this.base = baseCS;
  11872. }
  11873. PatternCS.prototype = {};
  11874. return PatternCS;
  11875. })();
  11876. var IndexedCS = (function IndexedCSClosure() {
  11877. function IndexedCS(base, highVal, lookup) {
  11878. this.name = 'Indexed';
  11879. this.numComps = 1;
  11880. this.defaultColor = new Uint8Array([0]);
  11881. this.base = base;
  11882. this.highVal = highVal;
  11883. var baseNumComps = base.numComps;
  11884. var length = baseNumComps * highVal;
  11885. var lookupArray;
  11886. if (isStream(lookup)) {
  11887. lookupArray = new Uint8Array(length);
  11888. var bytes = lookup.getBytes(length);
  11889. lookupArray.set(bytes);
  11890. } else if (isString(lookup)) {
  11891. lookupArray = new Uint8Array(length);
  11892. for (var i = 0; i < length; ++i) {
  11893. lookupArray[i] = lookup.charCodeAt(i);
  11894. }
  11895. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11896. lookupArray = lookup;
  11897. } else {
  11898. error('Unrecognized lookup table: ' + lookup);
  11899. }
  11900. this.lookup = lookupArray;
  11901. }
  11902. IndexedCS.prototype = {
  11903. getRgb: ColorSpace.prototype.getRgb,
  11904. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11905. dest, destOffset) {
  11906. var numComps = this.base.numComps;
  11907. var start = src[srcOffset] * numComps;
  11908. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11909. },
  11910. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11911. dest, destOffset, bits,
  11912. alpha01) {
  11913. var base = this.base;
  11914. var numComps = base.numComps;
  11915. var outputDelta = base.getOutputLength(numComps, alpha01);
  11916. var lookup = this.lookup;
  11917. for (var i = 0; i < count; ++i) {
  11918. var lookupPos = src[srcOffset++] * numComps;
  11919. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11920. destOffset += outputDelta;
  11921. }
  11922. },
  11923. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11924. return this.base.getOutputLength(inputLength * this.base.numComps,
  11925. alpha01);
  11926. },
  11927. isPassthrough: ColorSpace.prototype.isPassthrough,
  11928. fillRgb: ColorSpace.prototype.fillRgb,
  11929. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11930. // indexed color maps shouldn't be changed
  11931. return true;
  11932. },
  11933. usesZeroToOneRange: true
  11934. };
  11935. return IndexedCS;
  11936. })();
  11937. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11938. function DeviceGrayCS() {
  11939. this.name = 'DeviceGray';
  11940. this.numComps = 1;
  11941. this.defaultColor = new Float32Array([0]);
  11942. }
  11943. DeviceGrayCS.prototype = {
  11944. getRgb: ColorSpace.prototype.getRgb,
  11945. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11946. dest, destOffset) {
  11947. var c = (src[srcOffset] * 255) | 0;
  11948. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11949. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11950. },
  11951. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11952. dest, destOffset, bits,
  11953. alpha01) {
  11954. var scale = 255 / ((1 << bits) - 1);
  11955. var j = srcOffset, q = destOffset;
  11956. for (var i = 0; i < count; ++i) {
  11957. var c = (scale * src[j++]) | 0;
  11958. dest[q++] = c;
  11959. dest[q++] = c;
  11960. dest[q++] = c;
  11961. q += alpha01;
  11962. }
  11963. },
  11964. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11965. alpha01) {
  11966. return inputLength * (3 + alpha01);
  11967. },
  11968. isPassthrough: ColorSpace.prototype.isPassthrough,
  11969. fillRgb: ColorSpace.prototype.fillRgb,
  11970. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11971. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11972. },
  11973. usesZeroToOneRange: true
  11974. };
  11975. return DeviceGrayCS;
  11976. })();
  11977. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11978. function DeviceRgbCS() {
  11979. this.name = 'DeviceRGB';
  11980. this.numComps = 3;
  11981. this.defaultColor = new Float32Array([0, 0, 0]);
  11982. }
  11983. DeviceRgbCS.prototype = {
  11984. getRgb: ColorSpace.prototype.getRgb,
  11985. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11986. dest, destOffset) {
  11987. var r = (src[srcOffset] * 255) | 0;
  11988. var g = (src[srcOffset + 1] * 255) | 0;
  11989. var b = (src[srcOffset + 2] * 255) | 0;
  11990. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11991. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11992. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11993. },
  11994. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11995. dest, destOffset, bits,
  11996. alpha01) {
  11997. if (bits === 8 && alpha01 === 0) {
  11998. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11999. return;
  12000. }
  12001. var scale = 255 / ((1 << bits) - 1);
  12002. var j = srcOffset, q = destOffset;
  12003. for (var i = 0; i < count; ++i) {
  12004. dest[q++] = (scale * src[j++]) | 0;
  12005. dest[q++] = (scale * src[j++]) | 0;
  12006. dest[q++] = (scale * src[j++]) | 0;
  12007. q += alpha01;
  12008. }
  12009. },
  12010. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12011. alpha01) {
  12012. return (inputLength * (3 + alpha01) / 3) | 0;
  12013. },
  12014. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12015. return bits === 8;
  12016. },
  12017. fillRgb: ColorSpace.prototype.fillRgb,
  12018. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12019. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12020. },
  12021. usesZeroToOneRange: true
  12022. };
  12023. return DeviceRgbCS;
  12024. })();
  12025. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12026. // The coefficients below was found using numerical analysis: the method of
  12027. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12028. // where color_value is the tabular value from the table of sampled RGB colors
  12029. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12030. // CMYK color conversion using the estimation below:
  12031. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12032. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12033. var c = src[srcOffset + 0] * srcScale;
  12034. var m = src[srcOffset + 1] * srcScale;
  12035. var y = src[srcOffset + 2] * srcScale;
  12036. var k = src[srcOffset + 3] * srcScale;
  12037. var r =
  12038. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12039. 18.82290502165302 * y + 212.25662451639585 * k +
  12040. -285.2331026137004) +
  12041. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12042. -17.873870861415444 * k - 5.497006427196366) +
  12043. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12044. 17.5119270841813) +
  12045. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12046. var g =
  12047. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12048. 6.871425592049007 * y + 31.159100130055922 * k +
  12049. -79.2970844816548) +
  12050. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12051. 131.35250912493976 * k - 190.9453302588951) +
  12052. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12053. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12054. var b =
  12055. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12056. 30.89978309703729 * y - 0.23883238689178934 * k +
  12057. -14.183576799673286) +
  12058. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12059. 50.606957656360734 * k - 112.23884253719248) +
  12060. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12061. -193.58209356861505) +
  12062. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12063. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12064. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12065. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12066. }
  12067. function DeviceCmykCS() {
  12068. this.name = 'DeviceCMYK';
  12069. this.numComps = 4;
  12070. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12071. }
  12072. DeviceCmykCS.prototype = {
  12073. getRgb: ColorSpace.prototype.getRgb,
  12074. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12075. dest, destOffset) {
  12076. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12077. },
  12078. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12079. dest, destOffset, bits,
  12080. alpha01) {
  12081. var scale = 1 / ((1 << bits) - 1);
  12082. for (var i = 0; i < count; i++) {
  12083. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12084. srcOffset += 4;
  12085. destOffset += 3 + alpha01;
  12086. }
  12087. },
  12088. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12089. alpha01) {
  12090. return (inputLength / 4 * (3 + alpha01)) | 0;
  12091. },
  12092. isPassthrough: ColorSpace.prototype.isPassthrough,
  12093. fillRgb: ColorSpace.prototype.fillRgb,
  12094. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12095. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12096. },
  12097. usesZeroToOneRange: true
  12098. };
  12099. return DeviceCmykCS;
  12100. })();
  12101. //
  12102. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12103. //
  12104. var CalGrayCS = (function CalGrayCSClosure() {
  12105. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12106. this.name = 'CalGray';
  12107. this.numComps = 1;
  12108. this.defaultColor = new Float32Array([0]);
  12109. if (!whitePoint) {
  12110. error('WhitePoint missing - required for color space CalGray');
  12111. }
  12112. blackPoint = blackPoint || [0, 0, 0];
  12113. gamma = gamma || 1;
  12114. // Translate arguments to spec variables.
  12115. this.XW = whitePoint[0];
  12116. this.YW = whitePoint[1];
  12117. this.ZW = whitePoint[2];
  12118. this.XB = blackPoint[0];
  12119. this.YB = blackPoint[1];
  12120. this.ZB = blackPoint[2];
  12121. this.G = gamma;
  12122. // Validate variables as per spec.
  12123. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12124. error('Invalid WhitePoint components for ' + this.name +
  12125. ', no fallback available');
  12126. }
  12127. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12128. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12129. this.XB = this.YB = this.ZB = 0;
  12130. }
  12131. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12132. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12133. ', ZB: ' + this.ZB + ', only default values are supported.');
  12134. }
  12135. if (this.G < 1) {
  12136. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12137. ', falling back to default');
  12138. this.G = 1;
  12139. }
  12140. }
  12141. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12142. // A represents a gray component of a calibrated gray space.
  12143. // A <---> AG in the spec
  12144. var A = src[srcOffset] * scale;
  12145. var AG = Math.pow(A, cs.G);
  12146. // Computes L as per spec. ( = cs.YW * AG )
  12147. // Except if other than default BlackPoint values are used.
  12148. var L = cs.YW * AG;
  12149. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12150. // Convert values to rgb range [0, 255].
  12151. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12152. dest[destOffset] = val;
  12153. dest[destOffset + 1] = val;
  12154. dest[destOffset + 2] = val;
  12155. }
  12156. CalGrayCS.prototype = {
  12157. getRgb: ColorSpace.prototype.getRgb,
  12158. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12159. dest, destOffset) {
  12160. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12161. },
  12162. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12163. dest, destOffset, bits,
  12164. alpha01) {
  12165. var scale = 1 / ((1 << bits) - 1);
  12166. for (var i = 0; i < count; ++i) {
  12167. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12168. srcOffset += 1;
  12169. destOffset += 3 + alpha01;
  12170. }
  12171. },
  12172. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12173. return inputLength * (3 + alpha01);
  12174. },
  12175. isPassthrough: ColorSpace.prototype.isPassthrough,
  12176. fillRgb: ColorSpace.prototype.fillRgb,
  12177. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12178. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12179. },
  12180. usesZeroToOneRange: true
  12181. };
  12182. return CalGrayCS;
  12183. })();
  12184. //
  12185. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12186. //
  12187. var CalRGBCS = (function CalRGBCSClosure() {
  12188. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12189. // matrices.
  12190. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12191. 0.8951, 0.2664, -0.1614,
  12192. -0.7502, 1.7135, 0.0367,
  12193. 0.0389, -0.0685, 1.0296]);
  12194. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12195. 0.9869929, -0.1470543, 0.1599627,
  12196. 0.4323053, 0.5183603, 0.0492912,
  12197. -0.0085287, 0.0400428, 0.9684867]);
  12198. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12199. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12200. 3.2404542, -1.5371385, -0.4985314,
  12201. -0.9692660, 1.8760108, 0.0415560,
  12202. 0.0556434, -0.2040259, 1.0572252]);
  12203. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12204. var tempNormalizeMatrix = new Float32Array(3);
  12205. var tempConvertMatrix1 = new Float32Array(3);
  12206. var tempConvertMatrix2 = new Float32Array(3);
  12207. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12208. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12209. this.name = 'CalRGB';
  12210. this.numComps = 3;
  12211. this.defaultColor = new Float32Array(3);
  12212. if (!whitePoint) {
  12213. error('WhitePoint missing - required for color space CalRGB');
  12214. }
  12215. blackPoint = blackPoint || new Float32Array(3);
  12216. gamma = gamma || new Float32Array([1, 1, 1]);
  12217. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12218. // Translate arguments to spec variables.
  12219. var XW = whitePoint[0];
  12220. var YW = whitePoint[1];
  12221. var ZW = whitePoint[2];
  12222. this.whitePoint = whitePoint;
  12223. var XB = blackPoint[0];
  12224. var YB = blackPoint[1];
  12225. var ZB = blackPoint[2];
  12226. this.blackPoint = blackPoint;
  12227. this.GR = gamma[0];
  12228. this.GG = gamma[1];
  12229. this.GB = gamma[2];
  12230. this.MXA = matrix[0];
  12231. this.MYA = matrix[1];
  12232. this.MZA = matrix[2];
  12233. this.MXB = matrix[3];
  12234. this.MYB = matrix[4];
  12235. this.MZB = matrix[5];
  12236. this.MXC = matrix[6];
  12237. this.MYC = matrix[7];
  12238. this.MZC = matrix[8];
  12239. // Validate variables as per spec.
  12240. if (XW < 0 || ZW < 0 || YW !== 1) {
  12241. error('Invalid WhitePoint components for ' + this.name +
  12242. ', no fallback available');
  12243. }
  12244. if (XB < 0 || YB < 0 || ZB < 0) {
  12245. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12246. ', ' + ZB + '], falling back to default');
  12247. this.blackPoint = new Float32Array(3);
  12248. }
  12249. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12250. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12251. '] for ' + this.name + ', falling back to default');
  12252. this.GR = this.GG = this.GB = 1;
  12253. }
  12254. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12255. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12256. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12257. info('Invalid Matrix for ' + this.name + ' [' +
  12258. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12259. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12260. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12261. '], falling back to default');
  12262. this.MXA = this.MYB = this.MZC = 1;
  12263. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12264. }
  12265. }
  12266. function matrixProduct(a, b, result) {
  12267. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12268. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12269. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12270. }
  12271. function convertToFlat(sourceWhitePoint, LMS, result) {
  12272. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12273. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12274. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12275. }
  12276. function convertToD65(sourceWhitePoint, LMS, result) {
  12277. var D65X = 0.95047;
  12278. var D65Y = 1;
  12279. var D65Z = 1.08883;
  12280. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12281. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12282. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12283. }
  12284. function sRGBTransferFunction(color) {
  12285. // See http://en.wikipedia.org/wiki/SRGB.
  12286. if (color <= 0.0031308){
  12287. return adjustToRange(0, 1, 12.92 * color);
  12288. }
  12289. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12290. }
  12291. function adjustToRange(min, max, value) {
  12292. return Math.max(min, Math.min(max, value));
  12293. }
  12294. function decodeL(L) {
  12295. if (L < 0) {
  12296. return -decodeL(-L);
  12297. }
  12298. if (L > 8.0) {
  12299. return Math.pow(((L + 16) / 116), 3);
  12300. }
  12301. return L * DECODE_L_CONSTANT;
  12302. }
  12303. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12304. // In case the blackPoint is already the default blackPoint then there is
  12305. // no need to do compensation.
  12306. if (sourceBlackPoint[0] === 0 &&
  12307. sourceBlackPoint[1] === 0 &&
  12308. sourceBlackPoint[2] === 0) {
  12309. result[0] = XYZ_Flat[0];
  12310. result[1] = XYZ_Flat[1];
  12311. result[2] = XYZ_Flat[2];
  12312. return;
  12313. }
  12314. // For the blackPoint calculation details, please see
  12315. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12316. // AdobeBPC.pdf.
  12317. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12318. var zeroDecodeL = decodeL(0);
  12319. var X_DST = zeroDecodeL;
  12320. var X_SRC = decodeL(sourceBlackPoint[0]);
  12321. var Y_DST = zeroDecodeL;
  12322. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12323. var Z_DST = zeroDecodeL;
  12324. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12325. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12326. var X_Offset = 1 - X_Scale;
  12327. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12328. var Y_Offset = 1 - Y_Scale;
  12329. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12330. var Z_Offset = 1 - Z_Scale;
  12331. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12332. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12333. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12334. }
  12335. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12336. // In case the whitePoint is already flat then there is no need to do
  12337. // normalization.
  12338. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12339. result[0] = XYZ_In[0];
  12340. result[1] = XYZ_In[1];
  12341. result[2] = XYZ_In[2];
  12342. return;
  12343. }
  12344. var LMS = result;
  12345. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12346. var LMS_Flat = tempNormalizeMatrix;
  12347. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12348. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12349. }
  12350. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12351. var LMS = result;
  12352. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12353. var LMS_D65 = tempNormalizeMatrix;
  12354. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12355. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12356. }
  12357. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12358. // A, B and C represent a red, green and blue components of a calibrated
  12359. // rgb space.
  12360. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12361. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12362. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12363. // A <---> AGR in the spec
  12364. // B <---> BGG in the spec
  12365. // C <---> CGB in the spec
  12366. var AGR = Math.pow(A, cs.GR);
  12367. var BGG = Math.pow(B, cs.GG);
  12368. var CGB = Math.pow(C, cs.GB);
  12369. // Computes intermediate variables L, M, N as per spec.
  12370. // To decode X, Y, Z values map L, M, N directly to them.
  12371. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12372. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12373. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12374. // The following calculations are based on this document:
  12375. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12376. // AdobeBPC.pdf.
  12377. var XYZ = tempConvertMatrix1;
  12378. XYZ[0] = X;
  12379. XYZ[1] = Y;
  12380. XYZ[2] = Z;
  12381. var XYZ_Flat = tempConvertMatrix2;
  12382. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12383. var XYZ_Black = tempConvertMatrix1;
  12384. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12385. var XYZ_D65 = tempConvertMatrix2;
  12386. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12387. var SRGB = tempConvertMatrix1;
  12388. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12389. var sR = sRGBTransferFunction(SRGB[0]);
  12390. var sG = sRGBTransferFunction(SRGB[1]);
  12391. var sB = sRGBTransferFunction(SRGB[2]);
  12392. // Convert the values to rgb range [0, 255].
  12393. dest[destOffset] = Math.round(sR * 255);
  12394. dest[destOffset + 1] = Math.round(sG * 255);
  12395. dest[destOffset + 2] = Math.round(sB * 255);
  12396. }
  12397. CalRGBCS.prototype = {
  12398. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12399. var rgb = new Uint8Array(3);
  12400. this.getRgbItem(src, srcOffset, rgb, 0);
  12401. return rgb;
  12402. },
  12403. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12404. dest, destOffset) {
  12405. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12406. },
  12407. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12408. dest, destOffset, bits,
  12409. alpha01) {
  12410. var scale = 1 / ((1 << bits) - 1);
  12411. for (var i = 0; i < count; ++i) {
  12412. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12413. srcOffset += 3;
  12414. destOffset += 3 + alpha01;
  12415. }
  12416. },
  12417. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12418. return (inputLength * (3 + alpha01) / 3) | 0;
  12419. },
  12420. isPassthrough: ColorSpace.prototype.isPassthrough,
  12421. fillRgb: ColorSpace.prototype.fillRgb,
  12422. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12423. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12424. },
  12425. usesZeroToOneRange: true
  12426. };
  12427. return CalRGBCS;
  12428. })();
  12429. //
  12430. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12431. //
  12432. var LabCS = (function LabCSClosure() {
  12433. function LabCS(whitePoint, blackPoint, range) {
  12434. this.name = 'Lab';
  12435. this.numComps = 3;
  12436. this.defaultColor = new Float32Array([0, 0, 0]);
  12437. if (!whitePoint) {
  12438. error('WhitePoint missing - required for color space Lab');
  12439. }
  12440. blackPoint = blackPoint || [0, 0, 0];
  12441. range = range || [-100, 100, -100, 100];
  12442. // Translate args to spec variables
  12443. this.XW = whitePoint[0];
  12444. this.YW = whitePoint[1];
  12445. this.ZW = whitePoint[2];
  12446. this.amin = range[0];
  12447. this.amax = range[1];
  12448. this.bmin = range[2];
  12449. this.bmax = range[3];
  12450. // These are here just for completeness - the spec doesn't offer any
  12451. // formulas that use BlackPoint in Lab
  12452. this.XB = blackPoint[0];
  12453. this.YB = blackPoint[1];
  12454. this.ZB = blackPoint[2];
  12455. // Validate vars as per spec
  12456. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12457. error('Invalid WhitePoint components, no fallback available');
  12458. }
  12459. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12460. info('Invalid BlackPoint, falling back to default');
  12461. this.XB = this.YB = this.ZB = 0;
  12462. }
  12463. if (this.amin > this.amax || this.bmin > this.bmax) {
  12464. info('Invalid Range, falling back to defaults');
  12465. this.amin = -100;
  12466. this.amax = 100;
  12467. this.bmin = -100;
  12468. this.bmax = 100;
  12469. }
  12470. }
  12471. // Function g(x) from spec
  12472. function fn_g(x) {
  12473. if (x >= 6 / 29) {
  12474. return x * x * x;
  12475. } else {
  12476. return (108 / 841) * (x - 4 / 29);
  12477. }
  12478. }
  12479. function decode(value, high1, low2, high2) {
  12480. return low2 + (value) * (high2 - low2) / (high1);
  12481. }
  12482. // If decoding is needed maxVal should be 2^bits per component - 1.
  12483. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12484. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12485. // not the usual [0, 1]. If a command like setFillColor is used the src
  12486. // values will already be within the correct range. However, if we are
  12487. // converting an image we have to map the values to the correct range given
  12488. // above.
  12489. // Ls,as,bs <---> L*,a*,b* in the spec
  12490. var Ls = src[srcOffset];
  12491. var as = src[srcOffset + 1];
  12492. var bs = src[srcOffset + 2];
  12493. if (maxVal !== false) {
  12494. Ls = decode(Ls, maxVal, 0, 100);
  12495. as = decode(as, maxVal, cs.amin, cs.amax);
  12496. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12497. }
  12498. // Adjust limits of 'as' and 'bs'
  12499. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12500. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12501. // Computes intermediate variables X,Y,Z as per spec
  12502. var M = (Ls + 16) / 116;
  12503. var L = M + (as / 500);
  12504. var N = M - (bs / 200);
  12505. var X = cs.XW * fn_g(L);
  12506. var Y = cs.YW * fn_g(M);
  12507. var Z = cs.ZW * fn_g(N);
  12508. var r, g, b;
  12509. // Using different conversions for D50 and D65 white points,
  12510. // per http://www.color.org/srgb.pdf
  12511. if (cs.ZW < 1) {
  12512. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12513. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12514. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12515. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12516. } else {
  12517. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12518. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12519. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12520. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12521. }
  12522. // clamp color values to [0,1] range then convert to [0,255] range.
  12523. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12524. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12525. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12526. }
  12527. LabCS.prototype = {
  12528. getRgb: ColorSpace.prototype.getRgb,
  12529. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12530. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12531. },
  12532. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12533. dest, destOffset, bits,
  12534. alpha01) {
  12535. var maxVal = (1 << bits) - 1;
  12536. for (var i = 0; i < count; i++) {
  12537. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12538. srcOffset += 3;
  12539. destOffset += 3 + alpha01;
  12540. }
  12541. },
  12542. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12543. return (inputLength * (3 + alpha01) / 3) | 0;
  12544. },
  12545. isPassthrough: ColorSpace.prototype.isPassthrough,
  12546. fillRgb: ColorSpace.prototype.fillRgb,
  12547. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12548. // XXX: Decoding is handled with the lab conversion because of the strange
  12549. // ranges that are used.
  12550. return true;
  12551. },
  12552. usesZeroToOneRange: false
  12553. };
  12554. return LabCS;
  12555. })();
  12556. var ARCFourCipher = (function ARCFourCipherClosure() {
  12557. function ARCFourCipher(key) {
  12558. this.a = 0;
  12559. this.b = 0;
  12560. var s = new Uint8Array(256);
  12561. var i, j = 0, tmp, keyLength = key.length;
  12562. for (i = 0; i < 256; ++i) {
  12563. s[i] = i;
  12564. }
  12565. for (i = 0; i < 256; ++i) {
  12566. tmp = s[i];
  12567. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12568. s[i] = s[j];
  12569. s[j] = tmp;
  12570. }
  12571. this.s = s;
  12572. }
  12573. ARCFourCipher.prototype = {
  12574. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12575. var i, n = data.length, tmp, tmp2;
  12576. var a = this.a, b = this.b, s = this.s;
  12577. var output = new Uint8Array(n);
  12578. for (i = 0; i < n; ++i) {
  12579. a = (a + 1) & 0xFF;
  12580. tmp = s[a];
  12581. b = (b + tmp) & 0xFF;
  12582. tmp2 = s[b];
  12583. s[a] = tmp2;
  12584. s[b] = tmp;
  12585. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12586. }
  12587. this.a = a;
  12588. this.b = b;
  12589. return output;
  12590. }
  12591. };
  12592. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12593. return ARCFourCipher;
  12594. })();
  12595. var calculateMD5 = (function calculateMD5Closure() {
  12596. var r = new Uint8Array([
  12597. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12598. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12599. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12600. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12601. var k = new Int32Array([
  12602. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12603. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12604. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12605. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12606. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12607. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12608. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12609. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12610. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12611. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12612. -145523070, -1120210379, 718787259, -343485551]);
  12613. function hash(data, offset, length) {
  12614. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12615. // pre-processing
  12616. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12617. var padded = new Uint8Array(paddedLength);
  12618. var i, j, n;
  12619. for (i = 0; i < length; ++i) {
  12620. padded[i] = data[offset++];
  12621. }
  12622. padded[i++] = 0x80;
  12623. n = paddedLength - 8;
  12624. while (i < n) {
  12625. padded[i++] = 0;
  12626. }
  12627. padded[i++] = (length << 3) & 0xFF;
  12628. padded[i++] = (length >> 5) & 0xFF;
  12629. padded[i++] = (length >> 13) & 0xFF;
  12630. padded[i++] = (length >> 21) & 0xFF;
  12631. padded[i++] = (length >>> 29) & 0xFF;
  12632. padded[i++] = 0;
  12633. padded[i++] = 0;
  12634. padded[i++] = 0;
  12635. var w = new Int32Array(16);
  12636. for (i = 0; i < paddedLength;) {
  12637. for (j = 0; j < 16; ++j, i += 4) {
  12638. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12639. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12640. }
  12641. var a = h0, b = h1, c = h2, d = h3, f, g;
  12642. for (j = 0; j < 64; ++j) {
  12643. if (j < 16) {
  12644. f = (b & c) | ((~b) & d);
  12645. g = j;
  12646. } else if (j < 32) {
  12647. f = (d & b) | ((~d) & c);
  12648. g = (5 * j + 1) & 15;
  12649. } else if (j < 48) {
  12650. f = b ^ c ^ d;
  12651. g = (3 * j + 5) & 15;
  12652. } else {
  12653. f = c ^ (b | (~d));
  12654. g = (7 * j) & 15;
  12655. }
  12656. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12657. d = c;
  12658. c = b;
  12659. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12660. a = tmp;
  12661. }
  12662. h0 = (h0 + a) | 0;
  12663. h1 = (h1 + b) | 0;
  12664. h2 = (h2 + c) | 0;
  12665. h3 = (h3 + d) | 0;
  12666. }
  12667. return new Uint8Array([
  12668. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12669. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12670. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12671. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12672. ]);
  12673. }
  12674. return hash;
  12675. })();
  12676. var Word64 = (function Word64Closure() {
  12677. function Word64(highInteger, lowInteger) {
  12678. this.high = highInteger | 0;
  12679. this.low = lowInteger | 0;
  12680. }
  12681. Word64.prototype = {
  12682. and: function Word64_and(word) {
  12683. this.high &= word.high;
  12684. this.low &= word.low;
  12685. },
  12686. xor: function Word64_xor(word) {
  12687. this.high ^= word.high;
  12688. this.low ^= word.low;
  12689. },
  12690. or: function Word64_or(word) {
  12691. this.high |= word.high;
  12692. this.low |= word.low;
  12693. },
  12694. shiftRight: function Word64_shiftRight(places) {
  12695. if (places >= 32) {
  12696. this.low = (this.high >>> (places - 32)) | 0;
  12697. this.high = 0;
  12698. } else {
  12699. this.low = (this.low >>> places) | (this.high << (32 - places));
  12700. this.high = (this.high >>> places) | 0;
  12701. }
  12702. },
  12703. shiftLeft: function Word64_shiftLeft(places) {
  12704. if (places >= 32) {
  12705. this.high = this.low << (places - 32);
  12706. this.low = 0;
  12707. } else {
  12708. this.high = (this.high << places) | (this.low >>> (32 - places));
  12709. this.low = this.low << places;
  12710. }
  12711. },
  12712. rotateRight: function Word64_rotateRight(places) {
  12713. var low, high;
  12714. if (places & 32) {
  12715. high = this.low;
  12716. low = this.high;
  12717. } else {
  12718. low = this.low;
  12719. high = this.high;
  12720. }
  12721. places &= 31;
  12722. this.low = (low >>> places) | (high << (32 - places));
  12723. this.high = (high >>> places) | (low << (32 - places));
  12724. },
  12725. not: function Word64_not() {
  12726. this.high = ~this.high;
  12727. this.low = ~this.low;
  12728. },
  12729. add: function Word64_add(word) {
  12730. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12731. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12732. if (lowAdd > 0xFFFFFFFF) {
  12733. highAdd += 1;
  12734. }
  12735. this.low = lowAdd | 0;
  12736. this.high = highAdd | 0;
  12737. },
  12738. copyTo: function Word64_copyTo(bytes, offset) {
  12739. bytes[offset] = (this.high >>> 24) & 0xFF;
  12740. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12741. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12742. bytes[offset + 3] = this.high & 0xFF;
  12743. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12744. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12745. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12746. bytes[offset + 7] = this.low & 0xFF;
  12747. },
  12748. assign: function Word64_assign(word) {
  12749. this.high = word.high;
  12750. this.low = word.low;
  12751. }
  12752. };
  12753. return Word64;
  12754. })();
  12755. var calculateSHA256 = (function calculateSHA256Closure() {
  12756. function rotr(x, n) {
  12757. return (x >>> n) | (x << 32 - n);
  12758. }
  12759. function ch(x, y, z) {
  12760. return (x & y) ^ (~x & z);
  12761. }
  12762. function maj(x, y, z) {
  12763. return (x & y) ^ (x & z) ^ (y & z);
  12764. }
  12765. function sigma(x) {
  12766. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12767. }
  12768. function sigmaPrime(x) {
  12769. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12770. }
  12771. function littleSigma(x) {
  12772. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12773. }
  12774. function littleSigmaPrime(x) {
  12775. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12776. }
  12777. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12778. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12779. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12780. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12781. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12782. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12783. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12784. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12785. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12786. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12787. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12788. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12789. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12790. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12791. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12792. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12793. function hash(data, offset, length) {
  12794. // initial hash values
  12795. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12796. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12797. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12798. // pre-processing
  12799. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12800. var padded = new Uint8Array(paddedLength);
  12801. var i, j, n;
  12802. for (i = 0; i < length; ++i) {
  12803. padded[i] = data[offset++];
  12804. }
  12805. padded[i++] = 0x80;
  12806. n = paddedLength - 8;
  12807. while (i < n) {
  12808. padded[i++] = 0;
  12809. }
  12810. padded[i++] = 0;
  12811. padded[i++] = 0;
  12812. padded[i++] = 0;
  12813. padded[i++] = (length >>> 29) & 0xFF;
  12814. padded[i++] = (length >> 21) & 0xFF;
  12815. padded[i++] = (length >> 13) & 0xFF;
  12816. padded[i++] = (length >> 5) & 0xFF;
  12817. padded[i++] = (length << 3) & 0xFF;
  12818. var w = new Uint32Array(64);
  12819. // for each 512 bit block
  12820. for (i = 0; i < paddedLength;) {
  12821. for (j = 0; j < 16; ++j) {
  12822. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12823. (padded[i + 2] << 8) | (padded[i + 3]));
  12824. i += 4;
  12825. }
  12826. for (j = 16; j < 64; ++j) {
  12827. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12828. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12829. }
  12830. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12831. f = h5, g = h6, h = h7, t1, t2;
  12832. for (j = 0; j < 64; ++j) {
  12833. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12834. t2 = sigma(a) + maj(a, b, c);
  12835. h = g;
  12836. g = f;
  12837. f = e;
  12838. e = (d + t1) | 0;
  12839. d = c;
  12840. c = b;
  12841. b = a;
  12842. a = (t1 + t2) | 0;
  12843. }
  12844. h0 = (h0 + a) | 0;
  12845. h1 = (h1 + b) | 0;
  12846. h2 = (h2 + c) | 0;
  12847. h3 = (h3 + d) | 0;
  12848. h4 = (h4 + e) | 0;
  12849. h5 = (h5 + f) | 0;
  12850. h6 = (h6 + g) | 0;
  12851. h7 = (h7 + h) | 0;
  12852. }
  12853. return new Uint8Array([
  12854. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12855. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12856. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12857. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12858. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12859. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12860. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12861. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12862. ]);
  12863. }
  12864. return hash;
  12865. })();
  12866. var calculateSHA512 = (function calculateSHA512Closure() {
  12867. function ch(result, x, y, z, tmp) {
  12868. result.assign(x);
  12869. result.and(y);
  12870. tmp.assign(x);
  12871. tmp.not();
  12872. tmp.and(z);
  12873. result.xor(tmp);
  12874. }
  12875. function maj(result, x, y, z, tmp) {
  12876. result.assign(x);
  12877. result.and(y);
  12878. tmp.assign(x);
  12879. tmp.and(z);
  12880. result.xor(tmp);
  12881. tmp.assign(y);
  12882. tmp.and(z);
  12883. result.xor(tmp);
  12884. }
  12885. function sigma(result, x, tmp) {
  12886. result.assign(x);
  12887. result.rotateRight(28);
  12888. tmp.assign(x);
  12889. tmp.rotateRight(34);
  12890. result.xor(tmp);
  12891. tmp.assign(x);
  12892. tmp.rotateRight(39);
  12893. result.xor(tmp);
  12894. }
  12895. function sigmaPrime(result, x, tmp) {
  12896. result.assign(x);
  12897. result.rotateRight(14);
  12898. tmp.assign(x);
  12899. tmp.rotateRight(18);
  12900. result.xor(tmp);
  12901. tmp.assign(x);
  12902. tmp.rotateRight(41);
  12903. result.xor(tmp);
  12904. }
  12905. function littleSigma(result, x, tmp) {
  12906. result.assign(x);
  12907. result.rotateRight(1);
  12908. tmp.assign(x);
  12909. tmp.rotateRight(8);
  12910. result.xor(tmp);
  12911. tmp.assign(x);
  12912. tmp.shiftRight(7);
  12913. result.xor(tmp);
  12914. }
  12915. function littleSigmaPrime(result, x, tmp) {
  12916. result.assign(x);
  12917. result.rotateRight(19);
  12918. tmp.assign(x);
  12919. tmp.rotateRight(61);
  12920. result.xor(tmp);
  12921. tmp.assign(x);
  12922. tmp.shiftRight(6);
  12923. result.xor(tmp);
  12924. }
  12925. var k = [
  12926. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12927. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12928. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12929. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12930. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12931. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12932. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12933. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12934. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12935. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12936. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12937. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12938. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12939. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12940. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12941. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12942. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12943. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12944. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12945. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12946. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12947. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12948. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12949. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12950. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12951. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12952. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12953. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12954. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12955. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12956. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12957. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12958. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12959. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12960. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12961. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12962. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12963. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12964. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12965. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12966. function hash(data, offset, length, mode384) {
  12967. mode384 = !!mode384;
  12968. // initial hash values
  12969. var h0, h1, h2, h3, h4, h5, h6, h7;
  12970. if (!mode384) {
  12971. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12972. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12973. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12974. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12975. h4 = new Word64(0x510e527f, 0xade682d1);
  12976. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12977. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12978. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12979. }
  12980. else {
  12981. // SHA384 is exactly the same
  12982. // except with different starting values and a trimmed result
  12983. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12984. h1 = new Word64(0x629a292a, 0x367cd507);
  12985. h2 = new Word64(0x9159015a, 0x3070dd17);
  12986. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12987. h4 = new Word64(0x67332667, 0xffc00b31);
  12988. h5 = new Word64(0x8eb44a87, 0x68581511);
  12989. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12990. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12991. }
  12992. // pre-processing
  12993. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12994. var padded = new Uint8Array(paddedLength);
  12995. var i, j, n;
  12996. for (i = 0; i < length; ++i) {
  12997. padded[i] = data[offset++];
  12998. }
  12999. padded[i++] = 0x80;
  13000. n = paddedLength - 16;
  13001. while (i < n) {
  13002. padded[i++] = 0;
  13003. }
  13004. padded[i++] = 0;
  13005. padded[i++] = 0;
  13006. padded[i++] = 0;
  13007. padded[i++] = 0;
  13008. padded[i++] = 0;
  13009. padded[i++] = 0;
  13010. padded[i++] = 0;
  13011. padded[i++] = 0;
  13012. padded[i++] = 0;
  13013. padded[i++] = 0;
  13014. padded[i++] = 0;
  13015. padded[i++] = (length >>> 29) & 0xFF;
  13016. padded[i++] = (length >> 21) & 0xFF;
  13017. padded[i++] = (length >> 13) & 0xFF;
  13018. padded[i++] = (length >> 5) & 0xFF;
  13019. padded[i++] = (length << 3) & 0xFF;
  13020. var w = new Array(80);
  13021. for (i = 0; i < 80; i++) {
  13022. w[i] = new Word64(0, 0);
  13023. }
  13024. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13025. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13026. var g = new Word64(0, 0), h = new Word64(0, 0);
  13027. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13028. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13029. // for each 1024 bit block
  13030. for (i = 0; i < paddedLength;) {
  13031. for (j = 0; j < 16; ++j) {
  13032. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13033. (padded[i + 2] << 8) | (padded[i + 3]);
  13034. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13035. (padded[i + 6]) << 8 | (padded[i + 7]);
  13036. i += 8;
  13037. }
  13038. for (j = 16; j < 80; ++j) {
  13039. tmp3 = w[j];
  13040. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13041. tmp3.add(w[j - 7]);
  13042. littleSigma(tmp1, w[j - 15], tmp2);
  13043. tmp3.add(tmp1);
  13044. tmp3.add(w[j - 16]);
  13045. }
  13046. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13047. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13048. for (j = 0; j < 80; ++j) {
  13049. t1.assign(h);
  13050. sigmaPrime(tmp1, e, tmp2);
  13051. t1.add(tmp1);
  13052. ch(tmp1, e, f, g, tmp2);
  13053. t1.add(tmp1);
  13054. t1.add(k[j]);
  13055. t1.add(w[j]);
  13056. sigma(t2, a, tmp2);
  13057. maj(tmp1, a, b, c, tmp2);
  13058. t2.add(tmp1);
  13059. tmp3 = h;
  13060. h = g;
  13061. g = f;
  13062. f = e;
  13063. d.add(t1);
  13064. e = d;
  13065. d = c;
  13066. c = b;
  13067. b = a;
  13068. tmp3.assign(t1);
  13069. tmp3.add(t2);
  13070. a = tmp3;
  13071. }
  13072. h0.add(a);
  13073. h1.add(b);
  13074. h2.add(c);
  13075. h3.add(d);
  13076. h4.add(e);
  13077. h5.add(f);
  13078. h6.add(g);
  13079. h7.add(h);
  13080. }
  13081. var result;
  13082. if (!mode384) {
  13083. result = new Uint8Array(64);
  13084. h0.copyTo(result,0);
  13085. h1.copyTo(result,8);
  13086. h2.copyTo(result,16);
  13087. h3.copyTo(result,24);
  13088. h4.copyTo(result,32);
  13089. h5.copyTo(result,40);
  13090. h6.copyTo(result,48);
  13091. h7.copyTo(result,56);
  13092. }
  13093. else {
  13094. result = new Uint8Array(48);
  13095. h0.copyTo(result,0);
  13096. h1.copyTo(result,8);
  13097. h2.copyTo(result,16);
  13098. h3.copyTo(result,24);
  13099. h4.copyTo(result,32);
  13100. h5.copyTo(result,40);
  13101. }
  13102. return result;
  13103. }
  13104. return hash;
  13105. })();
  13106. var calculateSHA384 = (function calculateSHA384Closure() {
  13107. function hash(data, offset, length) {
  13108. return calculateSHA512(data, offset, length, true);
  13109. }
  13110. return hash;
  13111. })();
  13112. var NullCipher = (function NullCipherClosure() {
  13113. function NullCipher() {
  13114. }
  13115. NullCipher.prototype = {
  13116. decryptBlock: function NullCipher_decryptBlock(data) {
  13117. return data;
  13118. }
  13119. };
  13120. return NullCipher;
  13121. })();
  13122. var AES128Cipher = (function AES128CipherClosure() {
  13123. var rcon = new Uint8Array([
  13124. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13125. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13126. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13127. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13128. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13129. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13130. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13131. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13132. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13133. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13134. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13135. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13136. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13137. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13138. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13139. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13140. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13141. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13142. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13143. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13144. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13145. 0x74, 0xe8, 0xcb, 0x8d]);
  13146. var s = new Uint8Array([
  13147. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13148. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13149. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13150. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13151. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13152. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13153. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13154. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13155. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13156. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13157. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13158. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13159. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13160. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13161. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13162. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13163. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13164. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13165. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13166. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13167. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13168. 0xb0, 0x54, 0xbb, 0x16]);
  13169. var inv_s = new Uint8Array([
  13170. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13171. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13172. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13173. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13174. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13175. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13176. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13177. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13178. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13179. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13180. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13181. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13182. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13183. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13184. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13185. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13186. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13187. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13188. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13189. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13190. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13191. 0x55, 0x21, 0x0c, 0x7d]);
  13192. var mixCol = new Uint8Array(256);
  13193. for (var i = 0; i < 256; i++) {
  13194. if (i < 128) {
  13195. mixCol[i] = i << 1;
  13196. } else {
  13197. mixCol[i] = (i << 1) ^ 0x1b;
  13198. }
  13199. }
  13200. var mix = new Uint32Array([
  13201. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13202. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13203. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13204. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13205. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13206. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13207. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13208. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13209. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13210. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13211. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13212. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13213. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13214. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13215. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13216. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13217. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13218. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13219. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13220. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13221. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13222. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13223. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13224. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13225. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13226. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13227. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13228. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13229. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13230. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13231. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13232. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13233. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13234. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13235. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13236. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13237. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13238. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13239. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13240. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13241. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13242. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13243. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13244. function expandKey128(cipherKey) {
  13245. var b = 176, result = new Uint8Array(b);
  13246. result.set(cipherKey);
  13247. for (var j = 16, i = 1; j < b; ++i) {
  13248. // RotWord
  13249. var t1 = result[j - 3], t2 = result[j - 2],
  13250. t3 = result[j - 1], t4 = result[j - 4];
  13251. // SubWord
  13252. t1 = s[t1];
  13253. t2 = s[t2];
  13254. t3 = s[t3];
  13255. t4 = s[t4];
  13256. // Rcon
  13257. t1 = t1 ^ rcon[i];
  13258. for (var n = 0; n < 4; ++n) {
  13259. result[j] = (t1 ^= result[j - 16]);
  13260. j++;
  13261. result[j] = (t2 ^= result[j - 16]);
  13262. j++;
  13263. result[j] = (t3 ^= result[j - 16]);
  13264. j++;
  13265. result[j] = (t4 ^= result[j - 16]);
  13266. j++;
  13267. }
  13268. }
  13269. return result;
  13270. }
  13271. function decrypt128(input, key) {
  13272. var state = new Uint8Array(16);
  13273. state.set(input);
  13274. var i, j, k;
  13275. var t, u, v;
  13276. // AddRoundKey
  13277. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13278. state[j] ^= key[k];
  13279. }
  13280. for (i = 9; i >= 1; --i) {
  13281. // InvShiftRows
  13282. t = state[13];
  13283. state[13] = state[9];
  13284. state[9] = state[5];
  13285. state[5] = state[1];
  13286. state[1] = t;
  13287. t = state[14];
  13288. u = state[10];
  13289. state[14] = state[6];
  13290. state[10] = state[2];
  13291. state[6] = t;
  13292. state[2] = u;
  13293. t = state[15];
  13294. u = state[11];
  13295. v = state[7];
  13296. state[15] = state[3];
  13297. state[11] = t;
  13298. state[7] = u;
  13299. state[3] = v;
  13300. // InvSubBytes
  13301. for (j = 0; j < 16; ++j) {
  13302. state[j] = inv_s[state[j]];
  13303. }
  13304. // AddRoundKey
  13305. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13306. state[j] ^= key[k];
  13307. }
  13308. // InvMixColumns
  13309. for (j = 0; j < 16; j += 4) {
  13310. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13311. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13312. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13313. (s3 >>> 24) ^ (s3 << 8));
  13314. state[j] = (t >>> 24) & 0xFF;
  13315. state[j + 1] = (t >> 16) & 0xFF;
  13316. state[j + 2] = (t >> 8) & 0xFF;
  13317. state[j + 3] = t & 0xFF;
  13318. }
  13319. }
  13320. // InvShiftRows
  13321. t = state[13];
  13322. state[13] = state[9];
  13323. state[9] = state[5];
  13324. state[5] = state[1];
  13325. state[1] = t;
  13326. t = state[14];
  13327. u = state[10];
  13328. state[14] = state[6];
  13329. state[10] = state[2];
  13330. state[6] = t;
  13331. state[2] = u;
  13332. t = state[15];
  13333. u = state[11];
  13334. v = state[7];
  13335. state[15] = state[3];
  13336. state[11] = t;
  13337. state[7] = u;
  13338. state[3] = v;
  13339. for (j = 0; j < 16; ++j) {
  13340. // InvSubBytes
  13341. state[j] = inv_s[state[j]];
  13342. // AddRoundKey
  13343. state[j] ^= key[j];
  13344. }
  13345. return state;
  13346. }
  13347. function encrypt128(input, key) {
  13348. var t, u, v, k;
  13349. var state = new Uint8Array(16);
  13350. state.set(input);
  13351. for (j = 0; j < 16; ++j) {
  13352. // AddRoundKey
  13353. state[j] ^= key[j];
  13354. }
  13355. for (i = 1; i < 10; i++) {
  13356. //SubBytes
  13357. for (j = 0; j < 16; ++j) {
  13358. state[j] = s[state[j]];
  13359. }
  13360. //ShiftRows
  13361. v = state[1];
  13362. state[1] = state[5];
  13363. state[5] = state[9];
  13364. state[9] = state[13];
  13365. state[13] = v;
  13366. v = state[2];
  13367. u = state[6];
  13368. state[2] = state[10];
  13369. state[6] = state[14];
  13370. state[10] = v;
  13371. state[14] = u;
  13372. v = state[3];
  13373. u = state[7];
  13374. t = state[11];
  13375. state[3] = state[15];
  13376. state[7] = v;
  13377. state[11] = u;
  13378. state[15] = t;
  13379. //MixColumns
  13380. for (var j = 0; j < 16; j += 4) {
  13381. var s0 = state[j + 0], s1 = state[j + 1];
  13382. var s2 = state[j + 2], s3 = state[j + 3];
  13383. t = s0 ^ s1 ^ s2 ^ s3;
  13384. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13385. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13386. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13387. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13388. }
  13389. //AddRoundKey
  13390. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13391. state[j] ^= key[k];
  13392. }
  13393. }
  13394. //SubBytes
  13395. for (j = 0; j < 16; ++j) {
  13396. state[j] = s[state[j]];
  13397. }
  13398. //ShiftRows
  13399. v = state[1];
  13400. state[1] = state[5];
  13401. state[5] = state[9];
  13402. state[9] = state[13];
  13403. state[13] = v;
  13404. v = state[2];
  13405. u = state[6];
  13406. state[2] = state[10];
  13407. state[6] = state[14];
  13408. state[10] = v;
  13409. state[14] = u;
  13410. v = state[3];
  13411. u = state[7];
  13412. t = state[11];
  13413. state[3] = state[15];
  13414. state[7] = v;
  13415. state[11] = u;
  13416. state[15] = t;
  13417. //AddRoundKey
  13418. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13419. state[j] ^= key[k];
  13420. }
  13421. return state;
  13422. }
  13423. function AES128Cipher(key) {
  13424. this.key = expandKey128(key);
  13425. this.buffer = new Uint8Array(16);
  13426. this.bufferPosition = 0;
  13427. }
  13428. function decryptBlock2(data, finalize) {
  13429. var i, j, ii, sourceLength = data.length,
  13430. buffer = this.buffer, bufferLength = this.bufferPosition,
  13431. result = [], iv = this.iv;
  13432. for (i = 0; i < sourceLength; ++i) {
  13433. buffer[bufferLength] = data[i];
  13434. ++bufferLength;
  13435. if (bufferLength < 16) {
  13436. continue;
  13437. }
  13438. // buffer is full, decrypting
  13439. var plain = decrypt128(buffer, this.key);
  13440. // xor-ing the IV vector to get plain text
  13441. for (j = 0; j < 16; ++j) {
  13442. plain[j] ^= iv[j];
  13443. }
  13444. iv = buffer;
  13445. result.push(plain);
  13446. buffer = new Uint8Array(16);
  13447. bufferLength = 0;
  13448. }
  13449. // saving incomplete buffer
  13450. this.buffer = buffer;
  13451. this.bufferLength = bufferLength;
  13452. this.iv = iv;
  13453. if (result.length === 0) {
  13454. return new Uint8Array([]);
  13455. }
  13456. // combining plain text blocks into one
  13457. var outputLength = 16 * result.length;
  13458. if (finalize) {
  13459. // undo a padding that is described in RFC 2898
  13460. var lastBlock = result[result.length - 1];
  13461. var psLen = lastBlock[15];
  13462. if (psLen <= 16) {
  13463. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13464. if (lastBlock[i] !== psLen) {
  13465. // Invalid padding, assume that the block has no padding.
  13466. psLen = 0;
  13467. break;
  13468. }
  13469. }
  13470. outputLength -= psLen;
  13471. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13472. }
  13473. }
  13474. var output = new Uint8Array(outputLength);
  13475. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13476. output.set(result[i], j);
  13477. }
  13478. return output;
  13479. }
  13480. AES128Cipher.prototype = {
  13481. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13482. var i, sourceLength = data.length;
  13483. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13484. // waiting for IV values -- they are at the start of the stream
  13485. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13486. buffer[bufferLength] = data[i];
  13487. }
  13488. if (bufferLength < 16) {
  13489. // need more data
  13490. this.bufferLength = bufferLength;
  13491. return new Uint8Array([]);
  13492. }
  13493. this.iv = buffer;
  13494. this.buffer = new Uint8Array(16);
  13495. this.bufferLength = 0;
  13496. // starting decryption
  13497. this.decryptBlock = decryptBlock2;
  13498. return this.decryptBlock(data.subarray(16), finalize);
  13499. },
  13500. encrypt: function AES128Cipher_encrypt(data, iv) {
  13501. var i, j, ii, sourceLength = data.length,
  13502. buffer = this.buffer, bufferLength = this.bufferPosition,
  13503. result = [];
  13504. if (!iv) {
  13505. iv = new Uint8Array(16);
  13506. }
  13507. for (i = 0; i < sourceLength; ++i) {
  13508. buffer[bufferLength] = data[i];
  13509. ++bufferLength;
  13510. if (bufferLength < 16) {
  13511. continue;
  13512. }
  13513. for (j = 0; j < 16; ++j) {
  13514. buffer[j] ^= iv[j];
  13515. }
  13516. // buffer is full, encrypting
  13517. var cipher = encrypt128(buffer, this.key);
  13518. iv = cipher;
  13519. result.push(cipher);
  13520. buffer = new Uint8Array(16);
  13521. bufferLength = 0;
  13522. }
  13523. // saving incomplete buffer
  13524. this.buffer = buffer;
  13525. this.bufferLength = bufferLength;
  13526. this.iv = iv;
  13527. if (result.length === 0) {
  13528. return new Uint8Array([]);
  13529. }
  13530. // combining plain text blocks into one
  13531. var outputLength = 16 * result.length;
  13532. var output = new Uint8Array(outputLength);
  13533. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13534. output.set(result[i], j);
  13535. }
  13536. return output;
  13537. }
  13538. };
  13539. return AES128Cipher;
  13540. })();
  13541. var AES256Cipher = (function AES256CipherClosure() {
  13542. var rcon = new Uint8Array([
  13543. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13544. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13545. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13546. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13547. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13548. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13549. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13550. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13551. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13552. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13553. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13554. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13555. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13556. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13557. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13558. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13559. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13560. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13561. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13562. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13563. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13564. 0x74, 0xe8, 0xcb, 0x8d]);
  13565. var s = new Uint8Array([
  13566. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13567. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13568. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13569. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13570. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13571. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13572. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13573. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13574. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13575. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13576. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13577. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13578. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13579. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13580. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13581. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13582. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13583. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13584. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13585. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13586. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13587. 0xb0, 0x54, 0xbb, 0x16]);
  13588. var inv_s = new Uint8Array([
  13589. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13590. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13591. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13592. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13593. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13594. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13595. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13596. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13597. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13598. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13599. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13600. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13601. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13602. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13603. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13604. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13605. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13606. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13607. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13608. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13609. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13610. 0x55, 0x21, 0x0c, 0x7d]);
  13611. var mixCol = new Uint8Array(256);
  13612. for (var i = 0; i < 256; i++) {
  13613. if (i < 128) {
  13614. mixCol[i] = i << 1;
  13615. } else {
  13616. mixCol[i] = (i << 1) ^ 0x1b;
  13617. }
  13618. }
  13619. var mix = new Uint32Array([
  13620. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13621. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13622. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13623. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13624. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13625. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13626. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13627. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13628. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13629. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13630. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13631. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13632. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13633. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13634. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13635. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13636. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13637. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13638. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13639. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13640. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13641. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13642. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13643. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13644. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13645. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13646. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13647. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13648. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13649. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13650. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13651. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13652. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13653. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13654. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13655. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13656. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13657. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13658. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13659. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13660. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13661. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13662. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13663. function expandKey256(cipherKey) {
  13664. var b = 240, result = new Uint8Array(b);
  13665. var r = 1;
  13666. result.set(cipherKey);
  13667. for (var j = 32, i = 1; j < b; ++i) {
  13668. if (j % 32 === 16) {
  13669. t1 = s[t1];
  13670. t2 = s[t2];
  13671. t3 = s[t3];
  13672. t4 = s[t4];
  13673. } else if (j % 32 === 0) {
  13674. // RotWord
  13675. var t1 = result[j - 3], t2 = result[j - 2],
  13676. t3 = result[j - 1], t4 = result[j - 4];
  13677. // SubWord
  13678. t1 = s[t1];
  13679. t2 = s[t2];
  13680. t3 = s[t3];
  13681. t4 = s[t4];
  13682. // Rcon
  13683. t1 = t1 ^ r;
  13684. if ((r <<= 1) >= 256) {
  13685. r = (r ^ 0x1b) & 0xFF;
  13686. }
  13687. }
  13688. for (var n = 0; n < 4; ++n) {
  13689. result[j] = (t1 ^= result[j - 32]);
  13690. j++;
  13691. result[j] = (t2 ^= result[j - 32]);
  13692. j++;
  13693. result[j] = (t3 ^= result[j - 32]);
  13694. j++;
  13695. result[j] = (t4 ^= result[j - 32]);
  13696. j++;
  13697. }
  13698. }
  13699. return result;
  13700. }
  13701. function decrypt256(input, key) {
  13702. var state = new Uint8Array(16);
  13703. state.set(input);
  13704. var i, j, k;
  13705. var t, u, v;
  13706. // AddRoundKey
  13707. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13708. state[j] ^= key[k];
  13709. }
  13710. for (i = 13; i >= 1; --i) {
  13711. // InvShiftRows
  13712. t = state[13];
  13713. state[13] = state[9];
  13714. state[9] = state[5];
  13715. state[5] = state[1];
  13716. state[1] = t;
  13717. t = state[14];
  13718. u = state[10];
  13719. state[14] = state[6];
  13720. state[10] = state[2];
  13721. state[6] = t;
  13722. state[2] = u;
  13723. t = state[15];
  13724. u = state[11];
  13725. v = state[7];
  13726. state[15] = state[3];
  13727. state[11] = t;
  13728. state[7] = u;
  13729. state[3] = v;
  13730. // InvSubBytes
  13731. for (j = 0; j < 16; ++j) {
  13732. state[j] = inv_s[state[j]];
  13733. }
  13734. // AddRoundKey
  13735. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13736. state[j] ^= key[k];
  13737. }
  13738. // InvMixColumns
  13739. for (j = 0; j < 16; j += 4) {
  13740. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13741. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13742. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13743. (s3 >>> 24) ^ (s3 << 8));
  13744. state[j] = (t >>> 24) & 0xFF;
  13745. state[j + 1] = (t >> 16) & 0xFF;
  13746. state[j + 2] = (t >> 8) & 0xFF;
  13747. state[j + 3] = t & 0xFF;
  13748. }
  13749. }
  13750. // InvShiftRows
  13751. t = state[13];
  13752. state[13] = state[9];
  13753. state[9] = state[5];
  13754. state[5] = state[1];
  13755. state[1] = t;
  13756. t = state[14];
  13757. u = state[10];
  13758. state[14] = state[6];
  13759. state[10] = state[2];
  13760. state[6] = t;
  13761. state[2] = u;
  13762. t = state[15];
  13763. u = state[11];
  13764. v = state[7];
  13765. state[15] = state[3];
  13766. state[11] = t;
  13767. state[7] = u;
  13768. state[3] = v;
  13769. for (j = 0; j < 16; ++j) {
  13770. // InvSubBytes
  13771. state[j] = inv_s[state[j]];
  13772. // AddRoundKey
  13773. state[j] ^= key[j];
  13774. }
  13775. return state;
  13776. }
  13777. function encrypt256(input, key) {
  13778. var t, u, v, k;
  13779. var state = new Uint8Array(16);
  13780. state.set(input);
  13781. for (j = 0; j < 16; ++j) {
  13782. // AddRoundKey
  13783. state[j] ^= key[j];
  13784. }
  13785. for (i = 1; i < 14; i++) {
  13786. //SubBytes
  13787. for (j = 0; j < 16; ++j) {
  13788. state[j] = s[state[j]];
  13789. }
  13790. //ShiftRows
  13791. v = state[1];
  13792. state[1] = state[5];
  13793. state[5] = state[9];
  13794. state[9] = state[13];
  13795. state[13] = v;
  13796. v = state[2];
  13797. u = state[6];
  13798. state[2] = state[10];
  13799. state[6] = state[14];
  13800. state[10] = v;
  13801. state[14] = u;
  13802. v = state[3];
  13803. u = state[7];
  13804. t = state[11];
  13805. state[3] = state[15];
  13806. state[7] = v;
  13807. state[11] = u;
  13808. state[15] = t;
  13809. //MixColumns
  13810. for (var j = 0; j < 16; j += 4) {
  13811. var s0 = state[j + 0], s1 = state[j + 1];
  13812. var s2 = state[j + 2], s3 = state[j + 3];
  13813. t = s0 ^ s1 ^ s2 ^ s3;
  13814. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13815. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13816. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13817. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13818. }
  13819. //AddRoundKey
  13820. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13821. state[j] ^= key[k];
  13822. }
  13823. }
  13824. //SubBytes
  13825. for (j = 0; j < 16; ++j) {
  13826. state[j] = s[state[j]];
  13827. }
  13828. //ShiftRows
  13829. v = state[1];
  13830. state[1] = state[5];
  13831. state[5] = state[9];
  13832. state[9] = state[13];
  13833. state[13] = v;
  13834. v = state[2];
  13835. u = state[6];
  13836. state[2] = state[10];
  13837. state[6] = state[14];
  13838. state[10] = v;
  13839. state[14] = u;
  13840. v = state[3];
  13841. u = state[7];
  13842. t = state[11];
  13843. state[3] = state[15];
  13844. state[7] = v;
  13845. state[11] = u;
  13846. state[15] = t;
  13847. //AddRoundKey
  13848. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13849. state[j] ^= key[k];
  13850. }
  13851. return state;
  13852. }
  13853. function AES256Cipher(key) {
  13854. this.key = expandKey256(key);
  13855. this.buffer = new Uint8Array(16);
  13856. this.bufferPosition = 0;
  13857. }
  13858. function decryptBlock2(data, finalize) {
  13859. var i, j, ii, sourceLength = data.length,
  13860. buffer = this.buffer, bufferLength = this.bufferPosition,
  13861. result = [], iv = this.iv;
  13862. for (i = 0; i < sourceLength; ++i) {
  13863. buffer[bufferLength] = data[i];
  13864. ++bufferLength;
  13865. if (bufferLength < 16) {
  13866. continue;
  13867. }
  13868. // buffer is full, decrypting
  13869. var plain = decrypt256(buffer, this.key);
  13870. // xor-ing the IV vector to get plain text
  13871. for (j = 0; j < 16; ++j) {
  13872. plain[j] ^= iv[j];
  13873. }
  13874. iv = buffer;
  13875. result.push(plain);
  13876. buffer = new Uint8Array(16);
  13877. bufferLength = 0;
  13878. }
  13879. // saving incomplete buffer
  13880. this.buffer = buffer;
  13881. this.bufferLength = bufferLength;
  13882. this.iv = iv;
  13883. if (result.length === 0) {
  13884. return new Uint8Array([]);
  13885. }
  13886. // combining plain text blocks into one
  13887. var outputLength = 16 * result.length;
  13888. if (finalize) {
  13889. // undo a padding that is described in RFC 2898
  13890. var lastBlock = result[result.length - 1];
  13891. var psLen = lastBlock[15];
  13892. if (psLen <= 16) {
  13893. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13894. if (lastBlock[i] !== psLen) {
  13895. // Invalid padding, assume that the block has no padding.
  13896. psLen = 0;
  13897. break;
  13898. }
  13899. }
  13900. outputLength -= psLen;
  13901. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13902. }
  13903. }
  13904. var output = new Uint8Array(outputLength);
  13905. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13906. output.set(result[i], j);
  13907. }
  13908. return output;
  13909. }
  13910. AES256Cipher.prototype = {
  13911. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13912. var i, sourceLength = data.length;
  13913. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13914. // if not supplied an IV wait for IV values
  13915. // they are at the start of the stream
  13916. if (iv) {
  13917. this.iv = iv;
  13918. } else {
  13919. for (i = 0; bufferLength < 16 &&
  13920. i < sourceLength; ++i, ++bufferLength) {
  13921. buffer[bufferLength] = data[i];
  13922. }
  13923. if (bufferLength < 16) {
  13924. //need more data
  13925. this.bufferLength = bufferLength;
  13926. return new Uint8Array([]);
  13927. }
  13928. this.iv = buffer;
  13929. data = data.subarray(16);
  13930. }
  13931. this.buffer = new Uint8Array(16);
  13932. this.bufferLength = 0;
  13933. // starting decryption
  13934. this.decryptBlock = decryptBlock2;
  13935. return this.decryptBlock(data, finalize);
  13936. },
  13937. encrypt: function AES256Cipher_encrypt(data, iv) {
  13938. var i, j, ii, sourceLength = data.length,
  13939. buffer = this.buffer, bufferLength = this.bufferPosition,
  13940. result = [];
  13941. if (!iv) {
  13942. iv = new Uint8Array(16);
  13943. }
  13944. for (i = 0; i < sourceLength; ++i) {
  13945. buffer[bufferLength] = data[i];
  13946. ++bufferLength;
  13947. if (bufferLength < 16) {
  13948. continue;
  13949. }
  13950. for (j = 0; j < 16; ++j) {
  13951. buffer[j] ^= iv[j];
  13952. }
  13953. // buffer is full, encrypting
  13954. var cipher = encrypt256(buffer, this.key);
  13955. this.iv = cipher;
  13956. result.push(cipher);
  13957. buffer = new Uint8Array(16);
  13958. bufferLength = 0;
  13959. }
  13960. // saving incomplete buffer
  13961. this.buffer = buffer;
  13962. this.bufferLength = bufferLength;
  13963. this.iv = iv;
  13964. if (result.length === 0) {
  13965. return new Uint8Array([]);
  13966. }
  13967. // combining plain text blocks into one
  13968. var outputLength = 16 * result.length;
  13969. var output = new Uint8Array(outputLength);
  13970. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13971. output.set(result[i], j);
  13972. }
  13973. return output;
  13974. }
  13975. };
  13976. return AES256Cipher;
  13977. })();
  13978. var PDF17 = (function PDF17Closure() {
  13979. function compareByteArrays(array1, array2) {
  13980. if (array1.length !== array2.length) {
  13981. return false;
  13982. }
  13983. for (var i = 0; i < array1.length; i++) {
  13984. if (array1[i] !== array2[i]) {
  13985. return false;
  13986. }
  13987. }
  13988. return true;
  13989. }
  13990. function PDF17() {
  13991. }
  13992. PDF17.prototype = {
  13993. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13994. ownerValidationSalt,
  13995. userBytes,
  13996. ownerPassword) {
  13997. var hashData = new Uint8Array(password.length + 56);
  13998. hashData.set(password, 0);
  13999. hashData.set(ownerValidationSalt, password.length);
  14000. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14001. var result = calculateSHA256(hashData, 0, hashData.length);
  14002. return compareByteArrays(result, ownerPassword);
  14003. },
  14004. checkUserPassword: function PDF17_checkUserPassword(password,
  14005. userValidationSalt,
  14006. userPassword) {
  14007. var hashData = new Uint8Array(password.length + 8);
  14008. hashData.set(password, 0);
  14009. hashData.set(userValidationSalt, password.length);
  14010. var result = calculateSHA256(hashData, 0, hashData.length);
  14011. return compareByteArrays(result, userPassword);
  14012. },
  14013. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14014. ownerEncryption) {
  14015. var hashData = new Uint8Array(password.length + 56);
  14016. hashData.set(password, 0);
  14017. hashData.set(ownerKeySalt, password.length);
  14018. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14019. var key = calculateSHA256(hashData, 0, hashData.length);
  14020. var cipher = new AES256Cipher(key);
  14021. return cipher.decryptBlock(ownerEncryption,
  14022. false,
  14023. new Uint8Array(16));
  14024. },
  14025. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14026. userEncryption) {
  14027. var hashData = new Uint8Array(password.length + 8);
  14028. hashData.set(password, 0);
  14029. hashData.set(userKeySalt, password.length);
  14030. //key is the decryption key for the UE string
  14031. var key = calculateSHA256(hashData, 0, hashData.length);
  14032. var cipher = new AES256Cipher(key);
  14033. return cipher.decryptBlock(userEncryption,
  14034. false,
  14035. new Uint8Array(16));
  14036. }
  14037. };
  14038. return PDF17;
  14039. })();
  14040. var PDF20 = (function PDF20Closure() {
  14041. function concatArrays(array1, array2) {
  14042. var t = new Uint8Array(array1.length + array2.length);
  14043. t.set(array1, 0);
  14044. t.set(array2, array1.length);
  14045. return t;
  14046. }
  14047. function calculatePDF20Hash(password, input, userBytes) {
  14048. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14049. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14050. var e = [0];
  14051. var i = 0;
  14052. while (i < 64 || e[e.length - 1] > i - 32) {
  14053. var arrayLength = password.length + k.length + userBytes.length;
  14054. var k1 = new Uint8Array(arrayLength * 64);
  14055. var array = concatArrays(password, k);
  14056. array = concatArrays(array, userBytes);
  14057. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14058. k1.set(array, pos);
  14059. }
  14060. //AES128 CBC NO PADDING with
  14061. //first 16 bytes of k as the key and the second 16 as the iv.
  14062. var cipher = new AES128Cipher(k.subarray(0, 16));
  14063. e = cipher.encrypt(k1, k.subarray(16, 32));
  14064. //Now we have to take the first 16 bytes of an unsigned
  14065. //big endian integer... and compute the remainder
  14066. //modulo 3.... That is a fairly large number and
  14067. //JavaScript isn't going to handle that well...
  14068. //So we're using a trick that allows us to perform
  14069. //modulo math byte by byte
  14070. var remainder = 0;
  14071. for (var z = 0; z < 16; z++) {
  14072. remainder *= (256 % 3);
  14073. remainder %= 3;
  14074. remainder += ((e[z] >>> 0) % 3);
  14075. remainder %= 3;
  14076. }
  14077. if (remainder === 0) {
  14078. k = calculateSHA256(e, 0, e.length);
  14079. }
  14080. else if (remainder === 1) {
  14081. k = calculateSHA384(e, 0, e.length);
  14082. }
  14083. else if (remainder === 2) {
  14084. k = calculateSHA512(e, 0, e.length);
  14085. }
  14086. i++;
  14087. }
  14088. return k.subarray(0, 32);
  14089. }
  14090. function PDF20() {
  14091. }
  14092. function compareByteArrays(array1, array2) {
  14093. if (array1.length !== array2.length) {
  14094. return false;
  14095. }
  14096. for (var i = 0; i < array1.length; i++) {
  14097. if (array1[i] !== array2[i]) {
  14098. return false;
  14099. }
  14100. }
  14101. return true;
  14102. }
  14103. PDF20.prototype = {
  14104. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14105. return calculatePDF20Hash(password, concatBytes, userBytes);
  14106. },
  14107. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14108. ownerValidationSalt,
  14109. userBytes,
  14110. ownerPassword) {
  14111. var hashData = new Uint8Array(password.length + 56);
  14112. hashData.set(password, 0);
  14113. hashData.set(ownerValidationSalt, password.length);
  14114. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14115. var result = calculatePDF20Hash(password, hashData, userBytes);
  14116. return compareByteArrays(result, ownerPassword);
  14117. },
  14118. checkUserPassword: function PDF20_checkUserPassword(password,
  14119. userValidationSalt,
  14120. userPassword) {
  14121. var hashData = new Uint8Array(password.length + 8);
  14122. hashData.set(password, 0);
  14123. hashData.set(userValidationSalt, password.length);
  14124. var result = calculatePDF20Hash(password, hashData, []);
  14125. return compareByteArrays(result, userPassword);
  14126. },
  14127. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14128. ownerEncryption) {
  14129. var hashData = new Uint8Array(password.length + 56);
  14130. hashData.set(password, 0);
  14131. hashData.set(ownerKeySalt, password.length);
  14132. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14133. var key = calculatePDF20Hash(password, hashData, userBytes);
  14134. var cipher = new AES256Cipher(key);
  14135. return cipher.decryptBlock(ownerEncryption,
  14136. false,
  14137. new Uint8Array(16));
  14138. },
  14139. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14140. userEncryption) {
  14141. var hashData = new Uint8Array(password.length + 8);
  14142. hashData.set(password, 0);
  14143. hashData.set(userKeySalt, password.length);
  14144. //key is the decryption key for the UE string
  14145. var key = calculatePDF20Hash(password, hashData, []);
  14146. var cipher = new AES256Cipher(key);
  14147. return cipher.decryptBlock(userEncryption,
  14148. false,
  14149. new Uint8Array(16));
  14150. }
  14151. };
  14152. return PDF20;
  14153. })();
  14154. var CipherTransform = (function CipherTransformClosure() {
  14155. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14156. this.stringCipherConstructor = stringCipherConstructor;
  14157. this.streamCipherConstructor = streamCipherConstructor;
  14158. }
  14159. CipherTransform.prototype = {
  14160. createStream: function CipherTransform_createStream(stream, length) {
  14161. var cipher = new this.streamCipherConstructor();
  14162. return new DecryptStream(stream, length,
  14163. function cipherTransformDecryptStream(data, finalize) {
  14164. return cipher.decryptBlock(data, finalize);
  14165. }
  14166. );
  14167. },
  14168. decryptString: function CipherTransform_decryptString(s) {
  14169. var cipher = new this.stringCipherConstructor();
  14170. var data = stringToBytes(s);
  14171. data = cipher.decryptBlock(data, true);
  14172. return bytesToString(data);
  14173. }
  14174. };
  14175. return CipherTransform;
  14176. })();
  14177. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14178. var defaultPasswordBytes = new Uint8Array([
  14179. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14180. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14181. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14182. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14183. function createEncryptionKey20(revision, password, ownerPassword,
  14184. ownerValidationSalt, ownerKeySalt, uBytes,
  14185. userPassword, userValidationSalt, userKeySalt,
  14186. ownerEncryption, userEncryption, perms) {
  14187. if (password) {
  14188. var passwordLength = Math.min(127, password.length);
  14189. password = password.subarray(0, passwordLength);
  14190. } else {
  14191. password = [];
  14192. }
  14193. var pdfAlgorithm;
  14194. if (revision === 6) {
  14195. pdfAlgorithm = new PDF20();
  14196. } else {
  14197. pdfAlgorithm = new PDF17();
  14198. }
  14199. if (pdfAlgorithm) {
  14200. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14201. userPassword)) {
  14202. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14203. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14204. uBytes,
  14205. ownerPassword)) {
  14206. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14207. ownerEncryption);
  14208. }
  14209. }
  14210. return null;
  14211. }
  14212. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14213. flags, revision, keyLength, encryptMetadata) {
  14214. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14215. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14216. if (password) {
  14217. n = Math.min(32, password.length);
  14218. for (; i < n; ++i) {
  14219. hashData[i] = password[i];
  14220. }
  14221. }
  14222. j = 0;
  14223. while (i < 32) {
  14224. hashData[i++] = defaultPasswordBytes[j++];
  14225. }
  14226. // as now the padded password in the hashData[0..i]
  14227. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14228. hashData[i++] = ownerPassword[j];
  14229. }
  14230. hashData[i++] = flags & 0xFF;
  14231. hashData[i++] = (flags >> 8) & 0xFF;
  14232. hashData[i++] = (flags >> 16) & 0xFF;
  14233. hashData[i++] = (flags >>> 24) & 0xFF;
  14234. for (j = 0, n = fileId.length; j < n; ++j) {
  14235. hashData[i++] = fileId[j];
  14236. }
  14237. if (revision >= 4 && !encryptMetadata) {
  14238. hashData[i++] = 0xFF;
  14239. hashData[i++] = 0xFF;
  14240. hashData[i++] = 0xFF;
  14241. hashData[i++] = 0xFF;
  14242. }
  14243. var hash = calculateMD5(hashData, 0, i);
  14244. var keyLengthInBytes = keyLength >> 3;
  14245. if (revision >= 3) {
  14246. for (j = 0; j < 50; ++j) {
  14247. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14248. }
  14249. }
  14250. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14251. var cipher, checkData;
  14252. if (revision >= 3) {
  14253. for (i = 0; i < 32; ++i) {
  14254. hashData[i] = defaultPasswordBytes[i];
  14255. }
  14256. for (j = 0, n = fileId.length; j < n; ++j) {
  14257. hashData[i++] = fileId[j];
  14258. }
  14259. cipher = new ARCFourCipher(encryptionKey);
  14260. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14261. n = encryptionKey.length;
  14262. var derivedKey = new Uint8Array(n), k;
  14263. for (j = 1; j <= 19; ++j) {
  14264. for (k = 0; k < n; ++k) {
  14265. derivedKey[k] = encryptionKey[k] ^ j;
  14266. }
  14267. cipher = new ARCFourCipher(derivedKey);
  14268. checkData = cipher.encryptBlock(checkData);
  14269. }
  14270. for (j = 0, n = checkData.length; j < n; ++j) {
  14271. if (userPassword[j] !== checkData[j]) {
  14272. return null;
  14273. }
  14274. }
  14275. } else {
  14276. cipher = new ARCFourCipher(encryptionKey);
  14277. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14278. for (j = 0, n = checkData.length; j < n; ++j) {
  14279. if (userPassword[j] !== checkData[j]) {
  14280. return null;
  14281. }
  14282. }
  14283. }
  14284. return encryptionKey;
  14285. }
  14286. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14287. var hashData = new Uint8Array(32), i = 0, j, n;
  14288. n = Math.min(32, password.length);
  14289. for (; i < n; ++i) {
  14290. hashData[i] = password[i];
  14291. }
  14292. j = 0;
  14293. while (i < 32) {
  14294. hashData[i++] = defaultPasswordBytes[j++];
  14295. }
  14296. var hash = calculateMD5(hashData, 0, i);
  14297. var keyLengthInBytes = keyLength >> 3;
  14298. if (revision >= 3) {
  14299. for (j = 0; j < 50; ++j) {
  14300. hash = calculateMD5(hash, 0, hash.length);
  14301. }
  14302. }
  14303. var cipher, userPassword;
  14304. if (revision >= 3) {
  14305. userPassword = ownerPassword;
  14306. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14307. for (j = 19; j >= 0; j--) {
  14308. for (k = 0; k < keyLengthInBytes; ++k) {
  14309. derivedKey[k] = hash[k] ^ j;
  14310. }
  14311. cipher = new ARCFourCipher(derivedKey);
  14312. userPassword = cipher.encryptBlock(userPassword);
  14313. }
  14314. } else {
  14315. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14316. userPassword = cipher.encryptBlock(ownerPassword);
  14317. }
  14318. return userPassword;
  14319. }
  14320. var identityName = Name.get('Identity');
  14321. function CipherTransformFactory(dict, fileId, password) {
  14322. var filter = dict.get('Filter');
  14323. if (!isName(filter) || filter.name !== 'Standard') {
  14324. error('unknown encryption method');
  14325. }
  14326. this.dict = dict;
  14327. var algorithm = dict.get('V');
  14328. if (!isInt(algorithm) ||
  14329. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14330. algorithm !== 5)) {
  14331. error('unsupported encryption algorithm');
  14332. }
  14333. this.algorithm = algorithm;
  14334. var keyLength = dict.get('Length') || 40;
  14335. if (!isInt(keyLength) ||
  14336. keyLength < 40 || (keyLength % 8) !== 0) {
  14337. error('invalid key length');
  14338. }
  14339. // prepare keys
  14340. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14341. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14342. var flags = dict.get('P');
  14343. var revision = dict.get('R');
  14344. // meaningful when V is 4 or 5
  14345. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14346. dict.get('EncryptMetadata') !== false);
  14347. this.encryptMetadata = encryptMetadata;
  14348. var fileIdBytes = stringToBytes(fileId);
  14349. var passwordBytes;
  14350. if (password) {
  14351. passwordBytes = stringToBytes(password);
  14352. }
  14353. var encryptionKey;
  14354. if (algorithm !== 5) {
  14355. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14356. ownerPassword, userPassword, flags,
  14357. revision, keyLength, encryptMetadata);
  14358. }
  14359. else {
  14360. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14361. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14362. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14363. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14364. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14365. var ownerEncryption = stringToBytes(dict.get('OE'));
  14366. var userEncryption = stringToBytes(dict.get('UE'));
  14367. var perms = stringToBytes(dict.get('Perms'));
  14368. encryptionKey =
  14369. createEncryptionKey20(revision, passwordBytes,
  14370. ownerPassword, ownerValidationSalt,
  14371. ownerKeySalt, uBytes,
  14372. userPassword, userValidationSalt,
  14373. userKeySalt, ownerEncryption,
  14374. userEncryption, perms);
  14375. }
  14376. if (!encryptionKey && !password) {
  14377. throw new PasswordException('No password given',
  14378. PasswordResponses.NEED_PASSWORD);
  14379. } else if (!encryptionKey && password) {
  14380. // Attempting use the password as an owner password
  14381. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14382. revision, keyLength);
  14383. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14384. ownerPassword, userPassword, flags,
  14385. revision, keyLength, encryptMetadata);
  14386. }
  14387. if (!encryptionKey) {
  14388. throw new PasswordException('Incorrect Password',
  14389. PasswordResponses.INCORRECT_PASSWORD);
  14390. }
  14391. this.encryptionKey = encryptionKey;
  14392. if (algorithm >= 4) {
  14393. this.cf = dict.get('CF');
  14394. this.stmf = dict.get('StmF') || identityName;
  14395. this.strf = dict.get('StrF') || identityName;
  14396. this.eff = dict.get('EFF') || this.strf;
  14397. }
  14398. }
  14399. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14400. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14401. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14402. key[i] = encryptionKey[i];
  14403. }
  14404. key[i++] = num & 0xFF;
  14405. key[i++] = (num >> 8) & 0xFF;
  14406. key[i++] = (num >> 16) & 0xFF;
  14407. key[i++] = gen & 0xFF;
  14408. key[i++] = (gen >> 8) & 0xFF;
  14409. if (isAes) {
  14410. key[i++] = 0x73;
  14411. key[i++] = 0x41;
  14412. key[i++] = 0x6C;
  14413. key[i++] = 0x54;
  14414. }
  14415. var hash = calculateMD5(key, 0, i);
  14416. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14417. }
  14418. function buildCipherConstructor(cf, name, num, gen, key) {
  14419. var cryptFilter = cf.get(name.name);
  14420. var cfm;
  14421. if (cryptFilter !== null && cryptFilter !== undefined) {
  14422. cfm = cryptFilter.get('CFM');
  14423. }
  14424. if (!cfm || cfm.name === 'None') {
  14425. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14426. return new NullCipher();
  14427. };
  14428. }
  14429. if ('V2' === cfm.name) {
  14430. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14431. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14432. };
  14433. }
  14434. if ('AESV2' === cfm.name) {
  14435. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14436. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14437. };
  14438. }
  14439. if ('AESV3' === cfm.name) {
  14440. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14441. return new AES256Cipher(key);
  14442. };
  14443. }
  14444. error('Unknown crypto method');
  14445. }
  14446. CipherTransformFactory.prototype = {
  14447. createCipherTransform:
  14448. function CipherTransformFactory_createCipherTransform(num, gen) {
  14449. if (this.algorithm === 4 || this.algorithm === 5) {
  14450. return new CipherTransform(
  14451. buildCipherConstructor(this.cf, this.stmf,
  14452. num, gen, this.encryptionKey),
  14453. buildCipherConstructor(this.cf, this.strf,
  14454. num, gen, this.encryptionKey));
  14455. }
  14456. // algorithms 1 and 2
  14457. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14458. var cipherConstructor = function buildCipherCipherConstructor() {
  14459. return new ARCFourCipher(key);
  14460. };
  14461. return new CipherTransform(cipherConstructor, cipherConstructor);
  14462. }
  14463. };
  14464. return CipherTransformFactory;
  14465. })();
  14466. var PatternType = {
  14467. FUNCTION_BASED: 1,
  14468. AXIAL: 2,
  14469. RADIAL: 3,
  14470. FREE_FORM_MESH: 4,
  14471. LATTICE_FORM_MESH: 5,
  14472. COONS_PATCH_MESH: 6,
  14473. TENSOR_PATCH_MESH: 7
  14474. };
  14475. var Pattern = (function PatternClosure() {
  14476. // Constructor should define this.getPattern
  14477. function Pattern() {
  14478. error('should not call Pattern constructor');
  14479. }
  14480. Pattern.prototype = {
  14481. // Input: current Canvas context
  14482. // Output: the appropriate fillStyle or strokeStyle
  14483. getPattern: function Pattern_getPattern(ctx) {
  14484. error('Should not call Pattern.getStyle: ' + ctx);
  14485. }
  14486. };
  14487. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14488. res) {
  14489. var dict = isStream(shading) ? shading.dict : shading;
  14490. var type = dict.get('ShadingType');
  14491. try {
  14492. switch (type) {
  14493. case PatternType.AXIAL:
  14494. case PatternType.RADIAL:
  14495. // Both radial and axial shadings are handled by RadialAxial shading.
  14496. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14497. case PatternType.FREE_FORM_MESH:
  14498. case PatternType.LATTICE_FORM_MESH:
  14499. case PatternType.COONS_PATCH_MESH:
  14500. case PatternType.TENSOR_PATCH_MESH:
  14501. return new Shadings.Mesh(shading, matrix, xref, res);
  14502. default:
  14503. throw new Error('Unknown PatternType: ' + type);
  14504. }
  14505. } catch (ex) {
  14506. if (ex instanceof MissingDataException) {
  14507. throw ex;
  14508. }
  14509. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14510. warn(ex);
  14511. return new Shadings.Dummy();
  14512. }
  14513. };
  14514. return Pattern;
  14515. })();
  14516. var Shadings = {};
  14517. // A small number to offset the first/last color stops so we can insert ones to
  14518. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14519. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14520. // internally so we have to go bigger.
  14521. Shadings.SMALL_NUMBER = 1e-2;
  14522. // Radial and axial shading have very similar implementations
  14523. // If needed, the implementations can be broken into two classes
  14524. Shadings.RadialAxial = (function RadialAxialClosure() {
  14525. function RadialAxial(dict, matrix, xref, res) {
  14526. this.matrix = matrix;
  14527. this.coordsArr = dict.get('Coords');
  14528. this.shadingType = dict.get('ShadingType');
  14529. this.type = 'Pattern';
  14530. var cs = dict.get('ColorSpace', 'CS');
  14531. cs = ColorSpace.parse(cs, xref, res);
  14532. this.cs = cs;
  14533. var t0 = 0.0, t1 = 1.0;
  14534. if (dict.has('Domain')) {
  14535. var domainArr = dict.get('Domain');
  14536. t0 = domainArr[0];
  14537. t1 = domainArr[1];
  14538. }
  14539. var extendStart = false, extendEnd = false;
  14540. if (dict.has('Extend')) {
  14541. var extendArr = dict.get('Extend');
  14542. extendStart = extendArr[0];
  14543. extendEnd = extendArr[1];
  14544. }
  14545. if (this.shadingType === PatternType.RADIAL &&
  14546. (!extendStart || !extendEnd)) {
  14547. // Radial gradient only currently works if either circle is fully within
  14548. // the other circle.
  14549. var x1 = this.coordsArr[0];
  14550. var y1 = this.coordsArr[1];
  14551. var r1 = this.coordsArr[2];
  14552. var x2 = this.coordsArr[3];
  14553. var y2 = this.coordsArr[4];
  14554. var r2 = this.coordsArr[5];
  14555. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14556. if (r1 <= r2 + distance &&
  14557. r2 <= r1 + distance) {
  14558. warn('Unsupported radial gradient.');
  14559. }
  14560. }
  14561. this.extendStart = extendStart;
  14562. this.extendEnd = extendEnd;
  14563. var fnObj = dict.get('Function');
  14564. var fn = PDFFunction.parseArray(xref, fnObj);
  14565. // 10 samples seems good enough for now, but probably won't work
  14566. // if there are sharp color changes. Ideally, we would implement
  14567. // the spec faithfully and add lossless optimizations.
  14568. var diff = t1 - t0;
  14569. var step = diff / 10;
  14570. var colorStops = this.colorStops = [];
  14571. // Protect against bad domains so we don't end up in an infinte loop below.
  14572. if (t0 >= t1 || step <= 0) {
  14573. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14574. // now.
  14575. info('Bad shading domain.');
  14576. return;
  14577. }
  14578. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14579. var rgbColor;
  14580. for (var i = t0; i <= t1; i += step) {
  14581. ratio[0] = i;
  14582. fn(ratio, 0, color, 0);
  14583. rgbColor = cs.getRgb(color, 0);
  14584. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14585. colorStops.push([(i - t0) / diff, cssColor]);
  14586. }
  14587. var background = 'transparent';
  14588. if (dict.has('Background')) {
  14589. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14590. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14591. }
  14592. if (!extendStart) {
  14593. // Insert a color stop at the front and offset the first real color stop
  14594. // so it doesn't conflict with the one we insert.
  14595. colorStops.unshift([0, background]);
  14596. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14597. }
  14598. if (!extendEnd) {
  14599. // Same idea as above in extendStart but for the end.
  14600. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14601. colorStops.push([1, background]);
  14602. }
  14603. this.colorStops = colorStops;
  14604. }
  14605. RadialAxial.prototype = {
  14606. getIR: function RadialAxial_getIR() {
  14607. var coordsArr = this.coordsArr;
  14608. var shadingType = this.shadingType;
  14609. var type, p0, p1, r0, r1;
  14610. if (shadingType === PatternType.AXIAL) {
  14611. p0 = [coordsArr[0], coordsArr[1]];
  14612. p1 = [coordsArr[2], coordsArr[3]];
  14613. r0 = null;
  14614. r1 = null;
  14615. type = 'axial';
  14616. } else if (shadingType === PatternType.RADIAL) {
  14617. p0 = [coordsArr[0], coordsArr[1]];
  14618. p1 = [coordsArr[3], coordsArr[4]];
  14619. r0 = coordsArr[2];
  14620. r1 = coordsArr[5];
  14621. type = 'radial';
  14622. } else {
  14623. error('getPattern type unknown: ' + shadingType);
  14624. }
  14625. var matrix = this.matrix;
  14626. if (matrix) {
  14627. p0 = Util.applyTransform(p0, matrix);
  14628. p1 = Util.applyTransform(p1, matrix);
  14629. }
  14630. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14631. }
  14632. };
  14633. return RadialAxial;
  14634. })();
  14635. // All mesh shading. For now, they will be presented as set of the triangles
  14636. // to be drawn on the canvas and rgb color for each vertex.
  14637. Shadings.Mesh = (function MeshClosure() {
  14638. function MeshStreamReader(stream, context) {
  14639. this.stream = stream;
  14640. this.context = context;
  14641. this.buffer = 0;
  14642. this.bufferLength = 0;
  14643. var numComps = context.numComps;
  14644. this.tmpCompsBuf = new Float32Array(numComps);
  14645. var csNumComps = context.colorSpace;
  14646. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14647. this.tmpCompsBuf;
  14648. }
  14649. MeshStreamReader.prototype = {
  14650. get hasData() {
  14651. if (this.stream.end) {
  14652. return this.stream.pos < this.stream.end;
  14653. }
  14654. if (this.bufferLength > 0) {
  14655. return true;
  14656. }
  14657. var nextByte = this.stream.getByte();
  14658. if (nextByte < 0) {
  14659. return false;
  14660. }
  14661. this.buffer = nextByte;
  14662. this.bufferLength = 8;
  14663. return true;
  14664. },
  14665. readBits: function MeshStreamReader_readBits(n) {
  14666. var buffer = this.buffer;
  14667. var bufferLength = this.bufferLength;
  14668. if (n === 32) {
  14669. if (bufferLength === 0) {
  14670. return ((this.stream.getByte() << 24) |
  14671. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14672. this.stream.getByte()) >>> 0;
  14673. }
  14674. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14675. (this.stream.getByte() << 8) | this.stream.getByte();
  14676. var nextByte = this.stream.getByte();
  14677. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14678. return ((buffer << (8 - bufferLength)) |
  14679. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14680. }
  14681. if (n === 8 && bufferLength === 0) {
  14682. return this.stream.getByte();
  14683. }
  14684. while (bufferLength < n) {
  14685. buffer = (buffer << 8) | this.stream.getByte();
  14686. bufferLength += 8;
  14687. }
  14688. bufferLength -= n;
  14689. this.bufferLength = bufferLength;
  14690. this.buffer = buffer & ((1 << bufferLength) - 1);
  14691. return buffer >> bufferLength;
  14692. },
  14693. align: function MeshStreamReader_align() {
  14694. this.buffer = 0;
  14695. this.bufferLength = 0;
  14696. },
  14697. readFlag: function MeshStreamReader_readFlag() {
  14698. return this.readBits(this.context.bitsPerFlag);
  14699. },
  14700. readCoordinate: function MeshStreamReader_readCoordinate() {
  14701. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14702. var xi = this.readBits(bitsPerCoordinate);
  14703. var yi = this.readBits(bitsPerCoordinate);
  14704. var decode = this.context.decode;
  14705. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14706. 2.3283064365386963e-10; // 2 ^ -32
  14707. return [
  14708. xi * scale * (decode[1] - decode[0]) + decode[0],
  14709. yi * scale * (decode[3] - decode[2]) + decode[2]
  14710. ];
  14711. },
  14712. readComponents: function MeshStreamReader_readComponents() {
  14713. var numComps = this.context.numComps;
  14714. var bitsPerComponent = this.context.bitsPerComponent;
  14715. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14716. 2.3283064365386963e-10; // 2 ^ -32
  14717. var decode = this.context.decode;
  14718. var components = this.tmpCompsBuf;
  14719. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14720. var ci = this.readBits(bitsPerComponent);
  14721. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14722. }
  14723. var color = this.tmpCsCompsBuf;
  14724. if (this.context.colorFn) {
  14725. this.context.colorFn(components, 0, color, 0);
  14726. }
  14727. return this.context.colorSpace.getRgb(color, 0);
  14728. }
  14729. };
  14730. function decodeType4Shading(mesh, reader) {
  14731. var coords = mesh.coords;
  14732. var colors = mesh.colors;
  14733. var operators = [];
  14734. var ps = []; // not maintaining cs since that will match ps
  14735. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14736. while (reader.hasData) {
  14737. var f = reader.readFlag();
  14738. var coord = reader.readCoordinate();
  14739. var color = reader.readComponents();
  14740. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14741. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14742. switch (f) {
  14743. case 0:
  14744. verticesLeft = 3;
  14745. break;
  14746. case 1:
  14747. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14748. verticesLeft = 1;
  14749. break;
  14750. case 2:
  14751. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14752. verticesLeft = 1;
  14753. break;
  14754. }
  14755. operators.push(f);
  14756. }
  14757. ps.push(coords.length);
  14758. coords.push(coord);
  14759. colors.push(color);
  14760. verticesLeft--;
  14761. reader.align();
  14762. }
  14763. var psPacked = new Int32Array(ps);
  14764. mesh.figures.push({
  14765. type: 'triangles',
  14766. coords: psPacked,
  14767. colors: psPacked
  14768. });
  14769. }
  14770. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14771. var coords = mesh.coords;
  14772. var colors = mesh.colors;
  14773. var ps = []; // not maintaining cs since that will match ps
  14774. while (reader.hasData) {
  14775. var coord = reader.readCoordinate();
  14776. var color = reader.readComponents();
  14777. ps.push(coords.length);
  14778. coords.push(coord);
  14779. colors.push(color);
  14780. }
  14781. var psPacked = new Int32Array(ps);
  14782. mesh.figures.push({
  14783. type: 'lattice',
  14784. coords: psPacked,
  14785. colors: psPacked,
  14786. verticesPerRow: verticesPerRow
  14787. });
  14788. }
  14789. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14790. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14791. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14792. var getB = (function getBClosure() {
  14793. function buildB(count) {
  14794. var lut = [];
  14795. for (var i = 0; i <= count; i++) {
  14796. var t = i / count, t_ = 1 - t;
  14797. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14798. 3 * t * t * t_, t * t * t]));
  14799. }
  14800. return lut;
  14801. }
  14802. var cache = [];
  14803. return function getB(count) {
  14804. if (!cache[count]) {
  14805. cache[count] = buildB(count);
  14806. }
  14807. return cache[count];
  14808. };
  14809. })();
  14810. function buildFigureFromPatch(mesh, index) {
  14811. var figure = mesh.figures[index];
  14812. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14813. var coords = mesh.coords, colors = mesh.colors;
  14814. var pi = figure.coords;
  14815. var ci = figure.colors;
  14816. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14817. coords[pi[12]][0], coords[pi[15]][0]);
  14818. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14819. coords[pi[12]][1], coords[pi[15]][1]);
  14820. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14821. coords[pi[12]][0], coords[pi[15]][0]);
  14822. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14823. coords[pi[12]][1], coords[pi[15]][1]);
  14824. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14825. (mesh.bounds[2] - mesh.bounds[0]));
  14826. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14827. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14828. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14829. (mesh.bounds[3] - mesh.bounds[1]));
  14830. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14831. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14832. var verticesPerRow = splitXBy + 1;
  14833. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14834. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14835. var k = 0;
  14836. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14837. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14838. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14839. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14840. for (var row = 0; row <= splitYBy; row++) {
  14841. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14842. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14843. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14844. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14845. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14846. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14847. for (var col = 0; col <= splitXBy; col++, k++) {
  14848. if ((row === 0 || row === splitYBy) &&
  14849. (col === 0 || col === splitXBy)) {
  14850. continue;
  14851. }
  14852. var x = 0, y = 0;
  14853. var q = 0;
  14854. for (var i = 0; i <= 3; i++) {
  14855. for (var j = 0; j <= 3; j++, q++) {
  14856. var m = bRow[row][i] * bCol[col][j];
  14857. x += coords[pi[q]][0] * m;
  14858. y += coords[pi[q]][1] * m;
  14859. }
  14860. }
  14861. figureCoords[k] = coords.length;
  14862. coords.push([x, y]);
  14863. figureColors[k] = colors.length;
  14864. var newColor = new Uint8Array(3);
  14865. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14866. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14867. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14868. colors.push(newColor);
  14869. }
  14870. }
  14871. figureCoords[0] = pi[0];
  14872. figureColors[0] = ci[0];
  14873. figureCoords[splitXBy] = pi[3];
  14874. figureColors[splitXBy] = ci[1];
  14875. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14876. figureColors[verticesPerRow * splitYBy] = ci[2];
  14877. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14878. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14879. mesh.figures[index] = {
  14880. type: 'lattice',
  14881. coords: figureCoords,
  14882. colors: figureColors,
  14883. verticesPerRow: verticesPerRow
  14884. };
  14885. }
  14886. function decodeType6Shading(mesh, reader) {
  14887. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14888. var coords = mesh.coords;
  14889. var colors = mesh.colors;
  14890. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14891. var cs = new Int32Array(4); // c00, c30, c03, c33
  14892. while (reader.hasData) {
  14893. var f = reader.readFlag();
  14894. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14895. var i, ii;
  14896. var pi = coords.length;
  14897. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14898. coords.push(reader.readCoordinate());
  14899. }
  14900. var ci = colors.length;
  14901. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14902. colors.push(reader.readComponents());
  14903. }
  14904. var tmp1, tmp2, tmp3, tmp4;
  14905. switch (f) {
  14906. case 0:
  14907. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14908. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14909. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14910. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14911. cs[2] = ci + 1; cs[3] = ci + 2;
  14912. cs[0] = ci; cs[1] = ci + 3;
  14913. break;
  14914. case 1:
  14915. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14916. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14917. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14918. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14919. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14920. tmp1 = cs[2]; tmp2 = cs[3];
  14921. cs[2] = ci + 1; cs[3] = ci;
  14922. cs[0] = tmp1; cs[1] = tmp2;
  14923. break;
  14924. case 2:
  14925. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14926. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14927. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14928. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14929. cs[2] = cs[3]; cs[3] = ci + 1;
  14930. cs[0] = cs[1]; cs[1] = ci;
  14931. break;
  14932. case 3:
  14933. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14934. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14935. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14936. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14937. cs[2] = cs[0]; cs[3] = cs[1];
  14938. cs[0] = ci; cs[1] = ci + 1;
  14939. break;
  14940. }
  14941. // set p11, p12, p21, p22
  14942. ps[5] = coords.length;
  14943. coords.push([
  14944. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14945. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14946. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14947. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14948. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14949. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14950. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14951. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14952. ]);
  14953. ps[6] = coords.length;
  14954. coords.push([
  14955. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14956. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14957. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14958. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14959. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14960. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14961. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14962. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14963. ]);
  14964. ps[9] = coords.length;
  14965. coords.push([
  14966. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14967. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14968. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14969. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14970. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14971. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14972. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14973. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14974. ]);
  14975. ps[10] = coords.length;
  14976. coords.push([
  14977. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14978. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14979. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14980. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14981. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14982. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14983. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14984. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14985. ]);
  14986. mesh.figures.push({
  14987. type: 'patch',
  14988. coords: new Int32Array(ps), // making copies of ps and cs
  14989. colors: new Int32Array(cs)
  14990. });
  14991. }
  14992. }
  14993. function decodeType7Shading(mesh, reader) {
  14994. var coords = mesh.coords;
  14995. var colors = mesh.colors;
  14996. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14997. var cs = new Int32Array(4); // c00, c30, c03, c33
  14998. while (reader.hasData) {
  14999. var f = reader.readFlag();
  15000. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15001. var i, ii;
  15002. var pi = coords.length;
  15003. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15004. coords.push(reader.readCoordinate());
  15005. }
  15006. var ci = colors.length;
  15007. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15008. colors.push(reader.readComponents());
  15009. }
  15010. var tmp1, tmp2, tmp3, tmp4;
  15011. switch (f) {
  15012. case 0:
  15013. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15014. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15015. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15016. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15017. cs[2] = ci + 1; cs[3] = ci + 2;
  15018. cs[0] = ci; cs[1] = ci + 3;
  15019. break;
  15020. case 1:
  15021. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15022. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15023. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15024. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15025. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15026. tmp1 = cs[2]; tmp2 = cs[3];
  15027. cs[2] = ci + 1; cs[3] = ci;
  15028. cs[0] = tmp1; cs[1] = tmp2;
  15029. break;
  15030. case 2:
  15031. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15032. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15033. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15034. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15035. cs[2] = cs[3]; cs[3] = ci + 1;
  15036. cs[0] = cs[1]; cs[1] = ci;
  15037. break;
  15038. case 3:
  15039. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15040. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15041. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15042. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15043. cs[2] = cs[0]; cs[3] = cs[1];
  15044. cs[0] = ci; cs[1] = ci + 1;
  15045. break;
  15046. }
  15047. mesh.figures.push({
  15048. type: 'patch',
  15049. coords: new Int32Array(ps), // making copies of ps and cs
  15050. colors: new Int32Array(cs)
  15051. });
  15052. }
  15053. }
  15054. function updateBounds(mesh) {
  15055. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15056. maxX = minX, maxY = minY;
  15057. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15058. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15059. minX = minX > x ? x : minX;
  15060. minY = minY > y ? y : minY;
  15061. maxX = maxX < x ? x : maxX;
  15062. maxY = maxY < y ? y : maxY;
  15063. }
  15064. mesh.bounds = [minX, minY, maxX, maxY];
  15065. }
  15066. function packData(mesh) {
  15067. var i, ii, j, jj;
  15068. var coords = mesh.coords;
  15069. var coordsPacked = new Float32Array(coords.length * 2);
  15070. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15071. var xy = coords[i];
  15072. coordsPacked[j++] = xy[0];
  15073. coordsPacked[j++] = xy[1];
  15074. }
  15075. mesh.coords = coordsPacked;
  15076. var colors = mesh.colors;
  15077. var colorsPacked = new Uint8Array(colors.length * 3);
  15078. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15079. var c = colors[i];
  15080. colorsPacked[j++] = c[0];
  15081. colorsPacked[j++] = c[1];
  15082. colorsPacked[j++] = c[2];
  15083. }
  15084. mesh.colors = colorsPacked;
  15085. var figures = mesh.figures;
  15086. for (i = 0, ii = figures.length; i < ii; i++) {
  15087. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15088. for (j = 0, jj = ps.length; j < jj; j++) {
  15089. ps[j] *= 2;
  15090. cs[j] *= 3;
  15091. }
  15092. }
  15093. }
  15094. function Mesh(stream, matrix, xref, res) {
  15095. assert(isStream(stream), 'Mesh data is not a stream');
  15096. var dict = stream.dict;
  15097. this.matrix = matrix;
  15098. this.shadingType = dict.get('ShadingType');
  15099. this.type = 'Pattern';
  15100. this.bbox = dict.get('BBox');
  15101. var cs = dict.get('ColorSpace', 'CS');
  15102. cs = ColorSpace.parse(cs, xref, res);
  15103. this.cs = cs;
  15104. this.background = dict.has('Background') ?
  15105. cs.getRgb(dict.get('Background'), 0) : null;
  15106. var fnObj = dict.get('Function');
  15107. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15108. this.coords = [];
  15109. this.colors = [];
  15110. this.figures = [];
  15111. var decodeContext = {
  15112. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15113. bitsPerComponent: dict.get('BitsPerComponent'),
  15114. bitsPerFlag: dict.get('BitsPerFlag'),
  15115. decode: dict.get('Decode'),
  15116. colorFn: fn,
  15117. colorSpace: cs,
  15118. numComps: fn ? 1 : cs.numComps
  15119. };
  15120. var reader = new MeshStreamReader(stream, decodeContext);
  15121. var patchMesh = false;
  15122. switch (this.shadingType) {
  15123. case PatternType.FREE_FORM_MESH:
  15124. decodeType4Shading(this, reader);
  15125. break;
  15126. case PatternType.LATTICE_FORM_MESH:
  15127. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15128. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15129. decodeType5Shading(this, reader, verticesPerRow);
  15130. break;
  15131. case PatternType.COONS_PATCH_MESH:
  15132. decodeType6Shading(this, reader);
  15133. patchMesh = true;
  15134. break;
  15135. case PatternType.TENSOR_PATCH_MESH:
  15136. decodeType7Shading(this, reader);
  15137. patchMesh = true;
  15138. break;
  15139. default:
  15140. error('Unsupported mesh type.');
  15141. break;
  15142. }
  15143. if (patchMesh) {
  15144. // dirty bounds calculation for determining, how dense shall be triangles
  15145. updateBounds(this);
  15146. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15147. buildFigureFromPatch(this, i);
  15148. }
  15149. }
  15150. // calculate bounds
  15151. updateBounds(this);
  15152. packData(this);
  15153. }
  15154. Mesh.prototype = {
  15155. getIR: function Mesh_getIR() {
  15156. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15157. this.bounds, this.matrix, this.bbox, this.background];
  15158. }
  15159. };
  15160. return Mesh;
  15161. })();
  15162. Shadings.Dummy = (function DummyClosure() {
  15163. function Dummy() {
  15164. this.type = 'Pattern';
  15165. }
  15166. Dummy.prototype = {
  15167. getIR: function Dummy_getIR() {
  15168. return ['Dummy'];
  15169. }
  15170. };
  15171. return Dummy;
  15172. })();
  15173. function getTilingPatternIR(operatorList, dict, args) {
  15174. var matrix = dict.get('Matrix');
  15175. var bbox = dict.get('BBox');
  15176. var xstep = dict.get('XStep');
  15177. var ystep = dict.get('YStep');
  15178. var paintType = dict.get('PaintType');
  15179. var tilingType = dict.get('TilingType');
  15180. return [
  15181. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15182. paintType, tilingType
  15183. ];
  15184. }
  15185. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15186. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15187. uniquePrefix, idCounters, fontCache) {
  15188. this.pdfManager = pdfManager;
  15189. this.xref = xref;
  15190. this.handler = handler;
  15191. this.pageIndex = pageIndex;
  15192. this.uniquePrefix = uniquePrefix;
  15193. this.idCounters = idCounters;
  15194. this.fontCache = fontCache;
  15195. }
  15196. // Trying to minimize Date.now() usage and check every 100 time
  15197. var TIME_SLOT_DURATION_MS = 20;
  15198. var CHECK_TIME_EVERY = 100;
  15199. function TimeSlotManager() {
  15200. this.reset();
  15201. }
  15202. TimeSlotManager.prototype = {
  15203. check: function TimeSlotManager_check() {
  15204. if (++this.checked < CHECK_TIME_EVERY) {
  15205. return false;
  15206. }
  15207. this.checked = 0;
  15208. return this.endTime <= Date.now();
  15209. },
  15210. reset: function TimeSlotManager_reset() {
  15211. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15212. this.checked = 0;
  15213. }
  15214. };
  15215. var deferred = Promise.resolve();
  15216. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15217. PartialEvaluator.prototype = {
  15218. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15219. if (!isDict(resources)) {
  15220. return false;
  15221. }
  15222. var processed = Object.create(null);
  15223. if (resources.objId) {
  15224. processed[resources.objId] = true;
  15225. }
  15226. var nodes = [resources];
  15227. while (nodes.length) {
  15228. var key;
  15229. var node = nodes.shift();
  15230. // First check the current resources for blend modes.
  15231. var graphicStates = node.get('ExtGState');
  15232. if (isDict(graphicStates)) {
  15233. graphicStates = graphicStates.getAll();
  15234. for (key in graphicStates) {
  15235. var graphicState = graphicStates[key];
  15236. var bm = graphicState['BM'];
  15237. if (isName(bm) && bm.name !== 'Normal') {
  15238. return true;
  15239. }
  15240. }
  15241. }
  15242. // Descend into the XObjects to look for more resources and blend modes.
  15243. var xObjects = node.get('XObject');
  15244. if (!isDict(xObjects)) {
  15245. continue;
  15246. }
  15247. xObjects = xObjects.getAll();
  15248. for (key in xObjects) {
  15249. var xObject = xObjects[key];
  15250. if (!isStream(xObject)) {
  15251. continue;
  15252. }
  15253. if (xObject.dict.objId) {
  15254. if (processed[xObject.dict.objId]) {
  15255. // stream has objId and is processed already
  15256. continue;
  15257. }
  15258. processed[xObject.dict.objId] = true;
  15259. }
  15260. var xResources = xObject.dict.get('Resources');
  15261. // Checking objId to detect an infinite loop.
  15262. if (isDict(xResources) &&
  15263. (!xResources.objId || !processed[xResources.objId])) {
  15264. nodes.push(xResources);
  15265. if (xResources.objId) {
  15266. processed[xResources.objId] = true;
  15267. }
  15268. }
  15269. }
  15270. }
  15271. return false;
  15272. },
  15273. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15274. xobj, smask,
  15275. operatorList,
  15276. initialState) {
  15277. var matrix = xobj.dict.get('Matrix');
  15278. var bbox = xobj.dict.get('BBox');
  15279. var group = xobj.dict.get('Group');
  15280. if (group) {
  15281. var groupOptions = {
  15282. matrix: matrix,
  15283. bbox: bbox,
  15284. smask: smask,
  15285. isolated: false,
  15286. knockout: false
  15287. };
  15288. var groupSubtype = group.get('S');
  15289. var colorSpace;
  15290. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15291. groupOptions.isolated = (group.get('I') || false);
  15292. groupOptions.knockout = (group.get('K') || false);
  15293. colorSpace = (group.has('CS') ?
  15294. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15295. }
  15296. if (smask && smask.backdrop) {
  15297. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15298. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15299. }
  15300. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15301. }
  15302. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15303. return this.getOperatorList(xobj,
  15304. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15305. then(function () {
  15306. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15307. if (group) {
  15308. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15309. }
  15310. });
  15311. },
  15312. buildPaintImageXObject:
  15313. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15314. inline, operatorList,
  15315. cacheKey, imageCache) {
  15316. var self = this;
  15317. var dict = image.dict;
  15318. var w = dict.get('Width', 'W');
  15319. var h = dict.get('Height', 'H');
  15320. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15321. warn('Image dimensions are missing, or not numbers.');
  15322. return;
  15323. }
  15324. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15325. warn('Image exceeded maximum allowed size and was removed.');
  15326. return;
  15327. }
  15328. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15329. var imgData, args;
  15330. if (imageMask) {
  15331. // This depends on a tmpCanvas being filled with the
  15332. // current fillStyle, such that processing the pixel
  15333. // data can't be done here. Instead of creating a
  15334. // complete PDFImage, only read the information needed
  15335. // for later.
  15336. var width = dict.get('Width', 'W');
  15337. var height = dict.get('Height', 'H');
  15338. var bitStrideLength = (width + 7) >> 3;
  15339. var imgArray = image.getBytes(bitStrideLength * height);
  15340. var decode = dict.get('Decode', 'D');
  15341. var inverseDecode = (!!decode && decode[0] > 0);
  15342. imgData = PDFImage.createMask(imgArray, width, height,
  15343. image instanceof DecodeStream,
  15344. inverseDecode);
  15345. imgData.cached = true;
  15346. args = [imgData];
  15347. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15348. if (cacheKey) {
  15349. imageCache[cacheKey] = {
  15350. fn: OPS.paintImageMaskXObject,
  15351. args: args
  15352. };
  15353. }
  15354. return;
  15355. }
  15356. var softMask = (dict.get('SMask', 'SM') || false);
  15357. var mask = (dict.get('Mask') || false);
  15358. var SMALL_IMAGE_DIMENSIONS = 200;
  15359. // Inlining small images into the queue as RGB data
  15360. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15361. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15362. var imageObj = new PDFImage(this.xref, resources, image,
  15363. inline, null, null);
  15364. // We force the use of RGBA_32BPP images here, because we can't handle
  15365. // any other kind.
  15366. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15367. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15368. return;
  15369. }
  15370. // If there is no imageMask, create the PDFImage and a lot
  15371. // of image processing can be done here.
  15372. var uniquePrefix = (this.uniquePrefix || '');
  15373. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15374. operatorList.addDependency(objId);
  15375. args = [objId, w, h];
  15376. if (!softMask && !mask && image instanceof JpegStream &&
  15377. image.isNativelySupported(this.xref, resources)) {
  15378. // These JPEGs don't need any more processing so we can just send it.
  15379. operatorList.addOp(OPS.paintJpegXObject, args);
  15380. this.handler.send('obj',
  15381. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15382. return;
  15383. }
  15384. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15385. then(function(imageObj) {
  15386. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15387. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15388. [imgData.data.buffer]);
  15389. }).then(undefined, function (reason) {
  15390. warn('Unable to decode image: ' + reason);
  15391. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15392. });
  15393. operatorList.addOp(OPS.paintImageXObject, args);
  15394. if (cacheKey) {
  15395. imageCache[cacheKey] = {
  15396. fn: OPS.paintImageXObject,
  15397. args: args
  15398. };
  15399. }
  15400. },
  15401. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15402. operatorList,
  15403. stateManager) {
  15404. var smaskContent = smask.get('G');
  15405. var smaskOptions = {
  15406. subtype: smask.get('S').name,
  15407. backdrop: smask.get('BC')
  15408. };
  15409. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15410. operatorList, stateManager.state.clone());
  15411. },
  15412. handleTilingType:
  15413. function PartialEvaluator_handleTilingType(fn, args, resources,
  15414. pattern, patternDict,
  15415. operatorList) {
  15416. // Create an IR of the pattern code.
  15417. var tilingOpList = new OperatorList();
  15418. return this.getOperatorList(pattern,
  15419. (patternDict.get('Resources') || resources), tilingOpList).
  15420. then(function () {
  15421. // Add the dependencies to the parent operator list so they are
  15422. // resolved before sub operator list is executed synchronously.
  15423. operatorList.addDependencies(tilingOpList.dependencies);
  15424. operatorList.addOp(fn, getTilingPatternIR({
  15425. fnArray: tilingOpList.fnArray,
  15426. argsArray: tilingOpList.argsArray
  15427. }, patternDict, args));
  15428. });
  15429. },
  15430. handleSetFont:
  15431. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15432. operatorList, state) {
  15433. // TODO(mack): Not needed?
  15434. var fontName;
  15435. if (fontArgs) {
  15436. fontArgs = fontArgs.slice();
  15437. fontName = fontArgs[0].name;
  15438. }
  15439. var self = this;
  15440. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15441. function (translated) {
  15442. if (!translated.font.isType3Font) {
  15443. return translated;
  15444. }
  15445. return translated.loadType3Data(self, resources, operatorList).then(
  15446. function () {
  15447. return translated;
  15448. });
  15449. }).then(function (translated) {
  15450. state.font = translated.font;
  15451. translated.send(self.handler);
  15452. return translated.loadedName;
  15453. });
  15454. },
  15455. handleText: function PartialEvaluator_handleText(chars, state) {
  15456. var font = state.font;
  15457. var glyphs = font.charsToGlyphs(chars);
  15458. var isAddToPathSet = !!(state.textRenderingMode &
  15459. TextRenderingMode.ADD_TO_PATH_FLAG);
  15460. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15461. var buildPath = function (fontChar) {
  15462. if (!font.renderer.hasBuiltPath(fontChar)) {
  15463. var path = font.renderer.getPathJs(fontChar);
  15464. this.handler.send('commonobj', [
  15465. font.loadedName + '_path_' + fontChar,
  15466. 'FontPath',
  15467. path
  15468. ]);
  15469. }
  15470. }.bind(this);
  15471. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15472. var glyph = glyphs[i];
  15473. if (glyph === null) {
  15474. continue;
  15475. }
  15476. buildPath(glyph.fontChar);
  15477. // If the glyph has an accent we need to build a path for its
  15478. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15479. var accent = glyph.accent;
  15480. if (accent && accent.fontChar) {
  15481. buildPath(accent.fontChar);
  15482. }
  15483. }
  15484. }
  15485. return glyphs;
  15486. },
  15487. setGState: function PartialEvaluator_setGState(resources, gState,
  15488. operatorList, xref,
  15489. stateManager) {
  15490. // This array holds the converted/processed state data.
  15491. var gStateObj = [];
  15492. var gStateMap = gState.map;
  15493. var self = this;
  15494. var promise = Promise.resolve();
  15495. for (var key in gStateMap) {
  15496. var value = gStateMap[key];
  15497. switch (key) {
  15498. case 'Type':
  15499. break;
  15500. case 'LW':
  15501. case 'LC':
  15502. case 'LJ':
  15503. case 'ML':
  15504. case 'D':
  15505. case 'RI':
  15506. case 'FL':
  15507. case 'CA':
  15508. case 'ca':
  15509. gStateObj.push([key, value]);
  15510. break;
  15511. case 'Font':
  15512. promise = promise.then(function () {
  15513. return self.handleSetFont(resources, null, value[0],
  15514. operatorList, stateManager.state).
  15515. then(function (loadedName) {
  15516. operatorList.addDependency(loadedName);
  15517. gStateObj.push([key, [loadedName, value[1]]]);
  15518. });
  15519. });
  15520. break;
  15521. case 'BM':
  15522. gStateObj.push([key, value]);
  15523. break;
  15524. case 'SMask':
  15525. if (isName(value) && value.name === 'None') {
  15526. gStateObj.push([key, false]);
  15527. break;
  15528. }
  15529. var dict = xref.fetchIfRef(value);
  15530. if (isDict(dict)) {
  15531. promise = promise.then(function () {
  15532. return self.handleSMask(dict, resources, operatorList,
  15533. stateManager);
  15534. });
  15535. gStateObj.push([key, true]);
  15536. } else {
  15537. warn('Unsupported SMask type');
  15538. }
  15539. break;
  15540. // Only generate info log messages for the following since
  15541. // they are unlikely to have a big impact on the rendering.
  15542. case 'OP':
  15543. case 'op':
  15544. case 'OPM':
  15545. case 'BG':
  15546. case 'BG2':
  15547. case 'UCR':
  15548. case 'UCR2':
  15549. case 'TR':
  15550. case 'TR2':
  15551. case 'HT':
  15552. case 'SM':
  15553. case 'SA':
  15554. case 'AIS':
  15555. case 'TK':
  15556. // TODO implement these operators.
  15557. info('graphic state operator ' + key);
  15558. break;
  15559. default:
  15560. info('Unknown graphic state operator ' + key);
  15561. break;
  15562. }
  15563. }
  15564. return promise.then(function () {
  15565. if (gStateObj.length >= 0) {
  15566. operatorList.addOp(OPS.setGState, [gStateObj]);
  15567. }
  15568. });
  15569. },
  15570. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15571. resources) {
  15572. function errorFont() {
  15573. return Promise.resolve(new TranslatedFont('g_font_error',
  15574. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15575. }
  15576. var fontRef;
  15577. if (font) { // Loading by ref.
  15578. assert(isRef(font));
  15579. fontRef = font;
  15580. } else { // Loading by name.
  15581. var fontRes = resources.get('Font');
  15582. if (fontRes) {
  15583. fontRef = fontRes.getRaw(fontName);
  15584. } else {
  15585. warn('fontRes not available');
  15586. return errorFont();
  15587. }
  15588. }
  15589. if (!fontRef) {
  15590. warn('fontRef not available');
  15591. return errorFont();
  15592. }
  15593. if (this.fontCache.has(fontRef)) {
  15594. return this.fontCache.get(fontRef);
  15595. }
  15596. font = xref.fetchIfRef(fontRef);
  15597. if (!isDict(font)) {
  15598. return errorFont();
  15599. }
  15600. // We are holding font.translated references just for fontRef that are not
  15601. // dictionaries (Dict). See explanation below.
  15602. if (font.translated) {
  15603. return font.translated;
  15604. }
  15605. var fontCapability = createPromiseCapability();
  15606. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15607. var descriptor = preEvaluatedFont.descriptor;
  15608. var fontID = fontRef.num + '_' + fontRef.gen;
  15609. if (isDict(descriptor)) {
  15610. if (!descriptor.fontAliases) {
  15611. descriptor.fontAliases = Object.create(null);
  15612. }
  15613. var fontAliases = descriptor.fontAliases;
  15614. var hash = preEvaluatedFont.hash;
  15615. if (fontAliases[hash]) {
  15616. var aliasFontRef = fontAliases[hash].aliasRef;
  15617. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15618. this.fontCache.putAlias(fontRef, aliasFontRef);
  15619. return this.fontCache.get(fontRef);
  15620. }
  15621. }
  15622. if (!fontAliases[hash]) {
  15623. fontAliases[hash] = {
  15624. fontID: Font.getFontID()
  15625. };
  15626. }
  15627. fontAliases[hash].aliasRef = fontRef;
  15628. fontID = fontAliases[hash].fontID;
  15629. }
  15630. // Workaround for bad PDF generators that don't reference fonts
  15631. // properly, i.e. by not using an object identifier.
  15632. // Check if the fontRef is a Dict (as opposed to a standard object),
  15633. // in which case we don't cache the font and instead reference it by
  15634. // fontName in font.loadedName below.
  15635. var fontRefIsDict = isDict(fontRef);
  15636. if (!fontRefIsDict) {
  15637. this.fontCache.put(fontRef, fontCapability.promise);
  15638. }
  15639. // Keep track of each font we translated so the caller can
  15640. // load them asynchronously before calling display on a page.
  15641. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15642. fontName.replace(/\W/g, '') : fontID);
  15643. font.translated = fontCapability.promise;
  15644. // TODO move promises into translate font
  15645. var translatedPromise;
  15646. try {
  15647. translatedPromise = Promise.resolve(
  15648. this.translateFont(preEvaluatedFont, xref));
  15649. } catch (e) {
  15650. translatedPromise = Promise.reject(e);
  15651. }
  15652. translatedPromise.then(function (translatedFont) {
  15653. if (translatedFont.fontType !== undefined) {
  15654. var xrefFontStats = xref.stats.fontTypes;
  15655. xrefFontStats[translatedFont.fontType] = true;
  15656. }
  15657. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15658. translatedFont, font));
  15659. }, function (reason) {
  15660. // TODO fontCapability.reject?
  15661. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15662. try {
  15663. // error, but it's still nice to have font type reported
  15664. var descriptor = preEvaluatedFont.descriptor;
  15665. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15666. var subtype = fontFile3 && fontFile3.get('Subtype');
  15667. var fontType = getFontType(preEvaluatedFont.type,
  15668. subtype && subtype.name);
  15669. var xrefFontStats = xref.stats.fontTypes;
  15670. xrefFontStats[fontType] = true;
  15671. } catch (ex) { }
  15672. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15673. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15674. font));
  15675. });
  15676. return fontCapability.promise;
  15677. },
  15678. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15679. var lastIndex = operatorList.length - 1;
  15680. if (!args) {
  15681. args = [];
  15682. }
  15683. if (lastIndex < 0 ||
  15684. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15685. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15686. } else {
  15687. var opArgs = operatorList.argsArray[lastIndex];
  15688. opArgs[0].push(fn);
  15689. Array.prototype.push.apply(opArgs[1], args);
  15690. }
  15691. },
  15692. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15693. cs, patterns, resources, xref) {
  15694. // compile tiling patterns
  15695. var patternName = args[args.length - 1];
  15696. // SCN/scn applies patterns along with normal colors
  15697. var pattern;
  15698. if (isName(patternName) &&
  15699. (pattern = patterns.get(patternName.name))) {
  15700. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15701. var typeNum = dict.get('PatternType');
  15702. if (typeNum === TILING_PATTERN) {
  15703. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15704. return this.handleTilingType(fn, color, resources, pattern,
  15705. dict, operatorList);
  15706. } else if (typeNum === SHADING_PATTERN) {
  15707. var shading = dict.get('Shading');
  15708. var matrix = dict.get('Matrix');
  15709. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15710. operatorList.addOp(fn, pattern.getIR());
  15711. return Promise.resolve();
  15712. } else {
  15713. return Promise.reject('Unknown PatternType: ' + typeNum);
  15714. }
  15715. }
  15716. // TODO shall we fail here?
  15717. operatorList.addOp(fn, args);
  15718. return Promise.resolve();
  15719. },
  15720. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15721. resources,
  15722. operatorList,
  15723. initialState) {
  15724. var self = this;
  15725. var xref = this.xref;
  15726. var imageCache = {};
  15727. assert(operatorList);
  15728. resources = (resources || Dict.empty);
  15729. var xobjs = (resources.get('XObject') || Dict.empty);
  15730. var patterns = (resources.get('Pattern') || Dict.empty);
  15731. var stateManager = new StateManager(initialState || new EvalState());
  15732. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15733. var timeSlotManager = new TimeSlotManager();
  15734. return new Promise(function next(resolve, reject) {
  15735. timeSlotManager.reset();
  15736. var stop, operation = {}, i, ii, cs;
  15737. while (!(stop = timeSlotManager.check())) {
  15738. // The arguments parsed by read() are used beyond this loop, so we
  15739. // cannot reuse the same array on each iteration. Therefore we pass
  15740. // in |null| as the initial value (see the comment on
  15741. // EvaluatorPreprocessor_read() for why).
  15742. operation.args = null;
  15743. if (!(preprocessor.read(operation))) {
  15744. break;
  15745. }
  15746. var args = operation.args;
  15747. var fn = operation.fn;
  15748. switch (fn | 0) {
  15749. case OPS.paintXObject:
  15750. if (args[0].code) {
  15751. break;
  15752. }
  15753. // eagerly compile XForm objects
  15754. var name = args[0].name;
  15755. if (imageCache[name] !== undefined) {
  15756. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15757. args = null;
  15758. continue;
  15759. }
  15760. var xobj = xobjs.get(name);
  15761. if (xobj) {
  15762. assert(isStream(xobj), 'XObject should be a stream');
  15763. var type = xobj.dict.get('Subtype');
  15764. assert(isName(type),
  15765. 'XObject should have a Name subtype');
  15766. if (type.name === 'Form') {
  15767. stateManager.save();
  15768. return self.buildFormXObject(resources, xobj, null,
  15769. operatorList,
  15770. stateManager.state.clone()).
  15771. then(function () {
  15772. stateManager.restore();
  15773. next(resolve, reject);
  15774. }, reject);
  15775. } else if (type.name === 'Image') {
  15776. self.buildPaintImageXObject(resources, xobj, false,
  15777. operatorList, name, imageCache);
  15778. args = null;
  15779. continue;
  15780. } else if (type.name === 'PS') {
  15781. // PostScript XObjects are unused when viewing documents.
  15782. // See section 4.7.1 of Adobe's PDF reference.
  15783. info('Ignored XObject subtype PS');
  15784. continue;
  15785. } else {
  15786. error('Unhandled XObject subtype ' + type.name);
  15787. }
  15788. }
  15789. break;
  15790. case OPS.setFont:
  15791. var fontSize = args[1];
  15792. // eagerly collect all fonts
  15793. return self.handleSetFont(resources, args, null,
  15794. operatorList, stateManager.state).
  15795. then(function (loadedName) {
  15796. operatorList.addDependency(loadedName);
  15797. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15798. next(resolve, reject);
  15799. }, reject);
  15800. case OPS.endInlineImage:
  15801. var cacheKey = args[0].cacheKey;
  15802. if (cacheKey) {
  15803. var cacheEntry = imageCache[cacheKey];
  15804. if (cacheEntry !== undefined) {
  15805. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15806. args = null;
  15807. continue;
  15808. }
  15809. }
  15810. self.buildPaintImageXObject(resources, args[0], true,
  15811. operatorList, cacheKey, imageCache);
  15812. args = null;
  15813. continue;
  15814. case OPS.showText:
  15815. args[0] = self.handleText(args[0], stateManager.state);
  15816. break;
  15817. case OPS.showSpacedText:
  15818. var arr = args[0];
  15819. var combinedGlyphs = [];
  15820. var arrLength = arr.length;
  15821. for (i = 0; i < arrLength; ++i) {
  15822. var arrItem = arr[i];
  15823. if (isString(arrItem)) {
  15824. Array.prototype.push.apply(combinedGlyphs,
  15825. self.handleText(arrItem, stateManager.state));
  15826. } else if (isNum(arrItem)) {
  15827. combinedGlyphs.push(arrItem);
  15828. }
  15829. }
  15830. args[0] = combinedGlyphs;
  15831. fn = OPS.showText;
  15832. break;
  15833. case OPS.nextLineShowText:
  15834. operatorList.addOp(OPS.nextLine);
  15835. args[0] = self.handleText(args[0], stateManager.state);
  15836. fn = OPS.showText;
  15837. break;
  15838. case OPS.nextLineSetSpacingShowText:
  15839. operatorList.addOp(OPS.nextLine);
  15840. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15841. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15842. args[0] = self.handleText(args[0], stateManager.state);
  15843. fn = OPS.showText;
  15844. break;
  15845. case OPS.setTextRenderingMode:
  15846. stateManager.state.textRenderingMode = args[0];
  15847. break;
  15848. case OPS.setFillColorSpace:
  15849. stateManager.state.fillColorSpace =
  15850. ColorSpace.parse(args[0], xref, resources);
  15851. continue;
  15852. case OPS.setStrokeColorSpace:
  15853. stateManager.state.strokeColorSpace =
  15854. ColorSpace.parse(args[0], xref, resources);
  15855. continue;
  15856. case OPS.setFillColor:
  15857. cs = stateManager.state.fillColorSpace;
  15858. args = cs.getRgb(args, 0);
  15859. fn = OPS.setFillRGBColor;
  15860. break;
  15861. case OPS.setStrokeColor:
  15862. cs = stateManager.state.strokeColorSpace;
  15863. args = cs.getRgb(args, 0);
  15864. fn = OPS.setStrokeRGBColor;
  15865. break;
  15866. case OPS.setFillGray:
  15867. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15868. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15869. fn = OPS.setFillRGBColor;
  15870. break;
  15871. case OPS.setStrokeGray:
  15872. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15873. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15874. fn = OPS.setStrokeRGBColor;
  15875. break;
  15876. case OPS.setFillCMYKColor:
  15877. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15878. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15879. fn = OPS.setFillRGBColor;
  15880. break;
  15881. case OPS.setStrokeCMYKColor:
  15882. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15883. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15884. fn = OPS.setStrokeRGBColor;
  15885. break;
  15886. case OPS.setFillRGBColor:
  15887. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15888. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15889. break;
  15890. case OPS.setStrokeRGBColor:
  15891. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15892. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15893. break;
  15894. case OPS.setFillColorN:
  15895. cs = stateManager.state.fillColorSpace;
  15896. if (cs.name === 'Pattern') {
  15897. return self.handleColorN(operatorList, OPS.setFillColorN,
  15898. args, cs, patterns, resources, xref).then(function() {
  15899. next(resolve, reject);
  15900. }, reject);
  15901. }
  15902. args = cs.getRgb(args, 0);
  15903. fn = OPS.setFillRGBColor;
  15904. break;
  15905. case OPS.setStrokeColorN:
  15906. cs = stateManager.state.strokeColorSpace;
  15907. if (cs.name === 'Pattern') {
  15908. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15909. args, cs, patterns, resources, xref).then(function() {
  15910. next(resolve, reject);
  15911. }, reject);
  15912. }
  15913. args = cs.getRgb(args, 0);
  15914. fn = OPS.setStrokeRGBColor;
  15915. break;
  15916. case OPS.shadingFill:
  15917. var shadingRes = resources.get('Shading');
  15918. if (!shadingRes) {
  15919. error('No shading resource found');
  15920. }
  15921. var shading = shadingRes.get(args[0].name);
  15922. if (!shading) {
  15923. error('No shading object found');
  15924. }
  15925. var shadingFill = Pattern.parseShading(shading, null, xref,
  15926. resources);
  15927. var patternIR = shadingFill.getIR();
  15928. args = [patternIR];
  15929. fn = OPS.shadingFill;
  15930. break;
  15931. case OPS.setGState:
  15932. var dictName = args[0];
  15933. var extGState = resources.get('ExtGState');
  15934. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15935. break;
  15936. }
  15937. var gState = extGState.get(dictName.name);
  15938. return self.setGState(resources, gState, operatorList, xref,
  15939. stateManager).then(function() {
  15940. next(resolve, reject);
  15941. }, reject);
  15942. case OPS.moveTo:
  15943. case OPS.lineTo:
  15944. case OPS.curveTo:
  15945. case OPS.curveTo2:
  15946. case OPS.curveTo3:
  15947. case OPS.closePath:
  15948. self.buildPath(operatorList, fn, args);
  15949. continue;
  15950. case OPS.rectangle:
  15951. self.buildPath(operatorList, fn, args);
  15952. continue;
  15953. }
  15954. operatorList.addOp(fn, args);
  15955. }
  15956. if (stop) {
  15957. deferred.then(function () {
  15958. next(resolve, reject);
  15959. });
  15960. return;
  15961. }
  15962. // Some PDFs don't close all restores inside object/form.
  15963. // Closing those for them.
  15964. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15965. operatorList.addOp(OPS.restore, []);
  15966. }
  15967. resolve();
  15968. });
  15969. },
  15970. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15971. stateManager) {
  15972. stateManager = (stateManager || new StateManager(new TextState()));
  15973. var textContent = {
  15974. items: [],
  15975. styles: Object.create(null)
  15976. };
  15977. var bidiTexts = textContent.items;
  15978. var SPACE_FACTOR = 0.3;
  15979. var MULTI_SPACE_FACTOR = 1.5;
  15980. var self = this;
  15981. var xref = this.xref;
  15982. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15983. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15984. var xobjs = null;
  15985. var xobjsCache = {};
  15986. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15987. var textState;
  15988. function newTextChunk() {
  15989. var font = textState.font;
  15990. if (!(font.loadedName in textContent.styles)) {
  15991. textContent.styles[font.loadedName] = {
  15992. fontFamily: font.fallbackName,
  15993. ascent: font.ascent,
  15994. descent: font.descent,
  15995. vertical: font.vertical
  15996. };
  15997. }
  15998. return {
  15999. // |str| is initially an array which we push individual chars to, and
  16000. // then runBidi() overwrites it with the final string.
  16001. str: [],
  16002. dir: null,
  16003. width: 0,
  16004. height: 0,
  16005. transform: null,
  16006. fontName: font.loadedName
  16007. };
  16008. }
  16009. function runBidi(textChunk) {
  16010. var str = textChunk.str.join('');
  16011. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  16012. textChunk.str = bidiResult.str;
  16013. textChunk.dir = bidiResult.dir;
  16014. return textChunk;
  16015. }
  16016. function handleSetFont(fontName, fontRef) {
  16017. return self.loadFont(fontName, fontRef, xref, resources).
  16018. then(function (translated) {
  16019. textState.font = translated.font;
  16020. textState.fontMatrix = translated.font.fontMatrix ||
  16021. FONT_IDENTITY_MATRIX;
  16022. });
  16023. }
  16024. function buildTextGeometry(chars, textChunk) {
  16025. var font = textState.font;
  16026. textChunk = textChunk || newTextChunk();
  16027. if (!textChunk.transform) {
  16028. // 9.4.4 Text Space Details
  16029. var tsm = [textState.fontSize * textState.textHScale, 0,
  16030. 0, textState.fontSize,
  16031. 0, textState.textRise];
  16032. var trm = textChunk.transform = Util.transform(textState.ctm,
  16033. Util.transform(textState.textMatrix, tsm));
  16034. if (!font.vertical) {
  16035. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16036. } else {
  16037. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16038. }
  16039. }
  16040. var width = 0;
  16041. var height = 0;
  16042. var glyphs = font.charsToGlyphs(chars);
  16043. var defaultVMetrics = font.defaultVMetrics;
  16044. for (var i = 0; i < glyphs.length; i++) {
  16045. var glyph = glyphs[i];
  16046. if (!glyph) { // Previous glyph was a space.
  16047. width += textState.wordSpacing * textState.textHScale;
  16048. continue;
  16049. }
  16050. var vMetricX = null;
  16051. var vMetricY = null;
  16052. var glyphWidth = null;
  16053. if (font.vertical) {
  16054. if (glyph.vmetric) {
  16055. glyphWidth = glyph.vmetric[0];
  16056. vMetricX = glyph.vmetric[1];
  16057. vMetricY = glyph.vmetric[2];
  16058. } else {
  16059. glyphWidth = glyph.width;
  16060. vMetricX = glyph.width * 0.5;
  16061. vMetricY = defaultVMetrics[2];
  16062. }
  16063. } else {
  16064. glyphWidth = glyph.width;
  16065. }
  16066. var glyphUnicode = glyph.unicode;
  16067. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16068. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16069. }
  16070. glyphUnicode = reverseIfRtl(glyphUnicode);
  16071. // The following will calculate the x and y of the individual glyphs.
  16072. // if (font.vertical) {
  16073. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16074. // textState.fontMatrix[0];
  16075. // tsm[5] -= vMetricY * textState.fontSize *
  16076. // textState.fontMatrix[0];
  16077. // }
  16078. // var trm = Util.transform(textState.textMatrix, tsm);
  16079. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16080. // var x = pt[0];
  16081. // var y = pt[1];
  16082. var tx = 0;
  16083. var ty = 0;
  16084. if (!font.vertical) {
  16085. var w0 = glyphWidth * textState.fontMatrix[0];
  16086. tx = (w0 * textState.fontSize + textState.charSpacing) *
  16087. textState.textHScale;
  16088. width += tx;
  16089. } else {
  16090. var w1 = glyphWidth * textState.fontMatrix[0];
  16091. ty = w1 * textState.fontSize + textState.charSpacing;
  16092. height += ty;
  16093. }
  16094. textState.translateTextMatrix(tx, ty);
  16095. textChunk.str.push(glyphUnicode);
  16096. }
  16097. var a = textState.textLineMatrix[0];
  16098. var b = textState.textLineMatrix[1];
  16099. var scaleLineX = Math.sqrt(a * a + b * b);
  16100. a = textState.ctm[0];
  16101. b = textState.ctm[1];
  16102. var scaleCtmX = Math.sqrt(a * a + b * b);
  16103. if (!font.vertical) {
  16104. textChunk.width += width * scaleCtmX * scaleLineX;
  16105. } else {
  16106. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16107. }
  16108. return textChunk;
  16109. }
  16110. var timeSlotManager = new TimeSlotManager();
  16111. return new Promise(function next(resolve, reject) {
  16112. timeSlotManager.reset();
  16113. var stop, operation = {}, args = [];
  16114. while (!(stop = timeSlotManager.check())) {
  16115. // The arguments parsed by read() are not used beyond this loop, so
  16116. // we can reuse the same array on every iteration, thus avoiding
  16117. // unnecessary allocations.
  16118. args.length = 0;
  16119. operation.args = args;
  16120. if (!(preprocessor.read(operation))) {
  16121. break;
  16122. }
  16123. textState = stateManager.state;
  16124. var fn = operation.fn;
  16125. args = operation.args;
  16126. switch (fn | 0) {
  16127. case OPS.setFont:
  16128. textState.fontSize = args[1];
  16129. return handleSetFont(args[0].name).then(function() {
  16130. next(resolve, reject);
  16131. }, reject);
  16132. case OPS.setTextRise:
  16133. textState.textRise = args[0];
  16134. break;
  16135. case OPS.setHScale:
  16136. textState.textHScale = args[0] / 100;
  16137. break;
  16138. case OPS.setLeading:
  16139. textState.leading = args[0];
  16140. break;
  16141. case OPS.moveText:
  16142. textState.translateTextLineMatrix(args[0], args[1]);
  16143. textState.textMatrix = textState.textLineMatrix.slice();
  16144. break;
  16145. case OPS.setLeadingMoveText:
  16146. textState.leading = -args[1];
  16147. textState.translateTextLineMatrix(args[0], args[1]);
  16148. textState.textMatrix = textState.textLineMatrix.slice();
  16149. break;
  16150. case OPS.nextLine:
  16151. textState.carriageReturn();
  16152. break;
  16153. case OPS.setTextMatrix:
  16154. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16155. args[4], args[5]);
  16156. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16157. args[4], args[5]);
  16158. break;
  16159. case OPS.setCharSpacing:
  16160. textState.charSpacing = args[0];
  16161. break;
  16162. case OPS.setWordSpacing:
  16163. textState.wordSpacing = args[0];
  16164. break;
  16165. case OPS.beginText:
  16166. textState.textMatrix = IDENTITY_MATRIX.slice();
  16167. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16168. break;
  16169. case OPS.showSpacedText:
  16170. var items = args[0];
  16171. var textChunk = newTextChunk();
  16172. var offset;
  16173. for (var j = 0, jj = items.length; j < jj; j++) {
  16174. if (typeof items[j] === 'string') {
  16175. buildTextGeometry(items[j], textChunk);
  16176. } else {
  16177. var val = items[j] / 1000;
  16178. if (!textState.font.vertical) {
  16179. offset = -val * textState.fontSize * textState.textHScale *
  16180. textState.textMatrix[0];
  16181. textState.translateTextMatrix(offset, 0);
  16182. textChunk.width += offset;
  16183. } else {
  16184. offset = -val * textState.fontSize *
  16185. textState.textMatrix[3];
  16186. textState.translateTextMatrix(0, offset);
  16187. textChunk.height += offset;
  16188. }
  16189. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16190. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16191. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16192. fakeSpaces = Math.round(fakeSpaces);
  16193. while (fakeSpaces--) {
  16194. textChunk.str.push(' ');
  16195. }
  16196. } else if (fakeSpaces > SPACE_FACTOR) {
  16197. textChunk.str.push(' ');
  16198. }
  16199. }
  16200. }
  16201. }
  16202. bidiTexts.push(runBidi(textChunk));
  16203. break;
  16204. case OPS.showText:
  16205. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16206. break;
  16207. case OPS.nextLineShowText:
  16208. textState.carriageReturn();
  16209. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16210. break;
  16211. case OPS.nextLineSetSpacingShowText:
  16212. textState.wordSpacing = args[0];
  16213. textState.charSpacing = args[1];
  16214. textState.carriageReturn();
  16215. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16216. break;
  16217. case OPS.paintXObject:
  16218. if (args[0].code) {
  16219. break;
  16220. }
  16221. if (!xobjs) {
  16222. xobjs = (resources.get('XObject') || Dict.empty);
  16223. }
  16224. var name = args[0].name;
  16225. if (xobjsCache.key === name) {
  16226. if (xobjsCache.texts) {
  16227. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16228. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16229. }
  16230. break;
  16231. }
  16232. var xobj = xobjs.get(name);
  16233. if (!xobj) {
  16234. break;
  16235. }
  16236. assert(isStream(xobj), 'XObject should be a stream');
  16237. var type = xobj.dict.get('Subtype');
  16238. assert(isName(type),
  16239. 'XObject should have a Name subtype');
  16240. if ('Form' !== type.name) {
  16241. xobjsCache.key = name;
  16242. xobjsCache.texts = null;
  16243. break;
  16244. }
  16245. stateManager.save();
  16246. var matrix = xobj.dict.get('Matrix');
  16247. if (isArray(matrix) && matrix.length === 6) {
  16248. stateManager.transform(matrix);
  16249. }
  16250. return self.getTextContent(xobj,
  16251. xobj.dict.get('Resources') || resources, stateManager).
  16252. then(function (formTextContent) {
  16253. Util.appendToArray(bidiTexts, formTextContent.items);
  16254. Util.extendObj(textContent.styles, formTextContent.styles);
  16255. stateManager.restore();
  16256. xobjsCache.key = name;
  16257. xobjsCache.texts = formTextContent;
  16258. next(resolve, reject);
  16259. }, reject);
  16260. case OPS.setGState:
  16261. var dictName = args[0];
  16262. var extGState = resources.get('ExtGState');
  16263. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16264. break;
  16265. }
  16266. var gsStateMap = extGState.get(dictName.name);
  16267. var gsStateFont = null;
  16268. for (var key in gsStateMap) {
  16269. if (key === 'Font') {
  16270. assert(!gsStateFont);
  16271. gsStateFont = gsStateMap[key];
  16272. }
  16273. }
  16274. if (gsStateFont) {
  16275. textState.fontSize = gsStateFont[1];
  16276. return handleSetFont(gsStateFont[0]).then(function() {
  16277. next(resolve, reject);
  16278. }, reject);
  16279. }
  16280. break;
  16281. } // switch
  16282. } // while
  16283. if (stop) {
  16284. deferred.then(function () {
  16285. next(resolve, reject);
  16286. });
  16287. return;
  16288. }
  16289. resolve(textContent);
  16290. });
  16291. },
  16292. extractDataStructures: function
  16293. partialEvaluatorExtractDataStructures(dict, baseDict,
  16294. xref, properties) {
  16295. // 9.10.2
  16296. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16297. if (toUnicode) {
  16298. properties.toUnicode = this.readToUnicode(toUnicode);
  16299. }
  16300. if (properties.composite) {
  16301. // CIDSystemInfo helps to match CID to glyphs
  16302. var cidSystemInfo = dict.get('CIDSystemInfo');
  16303. if (isDict(cidSystemInfo)) {
  16304. properties.cidSystemInfo = {
  16305. registry: cidSystemInfo.get('Registry'),
  16306. ordering: cidSystemInfo.get('Ordering'),
  16307. supplement: cidSystemInfo.get('Supplement')
  16308. };
  16309. }
  16310. var cidToGidMap = dict.get('CIDToGIDMap');
  16311. if (isStream(cidToGidMap)) {
  16312. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16313. }
  16314. }
  16315. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16316. // and depends on the font type. The base encoding and differences are
  16317. // read here, but the encoding that is actually used is chosen during
  16318. // glyph mapping in the font.
  16319. // TODO: Loading the built in encoding in the font would allow the
  16320. // differences to be merged in here not require us to hold on to it.
  16321. var differences = [];
  16322. var baseEncodingName = null;
  16323. var encoding;
  16324. if (dict.has('Encoding')) {
  16325. encoding = dict.get('Encoding');
  16326. if (isDict(encoding)) {
  16327. baseEncodingName = encoding.get('BaseEncoding');
  16328. baseEncodingName = (isName(baseEncodingName) ?
  16329. baseEncodingName.name : null);
  16330. // Load the differences between the base and original
  16331. if (encoding.has('Differences')) {
  16332. var diffEncoding = encoding.get('Differences');
  16333. var index = 0;
  16334. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16335. var data = diffEncoding[j];
  16336. if (isNum(data)) {
  16337. index = data;
  16338. } else {
  16339. differences[index++] = data.name;
  16340. }
  16341. }
  16342. }
  16343. } else if (isName(encoding)) {
  16344. baseEncodingName = encoding.name;
  16345. } else {
  16346. error('Encoding is not a Name nor a Dict');
  16347. }
  16348. // According to table 114 if the encoding is a named encoding it must be
  16349. // one of these predefined encodings.
  16350. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16351. baseEncodingName !== 'MacExpertEncoding' &&
  16352. baseEncodingName !== 'WinAnsiEncoding')) {
  16353. baseEncodingName = null;
  16354. }
  16355. }
  16356. if (baseEncodingName) {
  16357. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16358. } else {
  16359. encoding = (properties.type === 'TrueType' ?
  16360. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16361. // The Symbolic attribute can be misused for regular fonts
  16362. // Heuristic: we have to check if the font is a standard one also
  16363. if (!!(properties.flags & FontFlags.Symbolic)) {
  16364. encoding = Encodings.MacRomanEncoding;
  16365. if (!properties.file) {
  16366. if (/Symbol/i.test(properties.name)) {
  16367. encoding = Encodings.SymbolSetEncoding;
  16368. } else if (/Dingbats/i.test(properties.name)) {
  16369. encoding = Encodings.ZapfDingbatsEncoding;
  16370. }
  16371. }
  16372. }
  16373. properties.defaultEncoding = encoding;
  16374. }
  16375. properties.differences = differences;
  16376. properties.baseEncodingName = baseEncodingName;
  16377. properties.dict = dict;
  16378. },
  16379. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16380. var cmap, cmapObj = toUnicode;
  16381. if (isName(cmapObj)) {
  16382. cmap = CMapFactory.create(cmapObj,
  16383. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16384. return new ToUnicodeMap(cmap);
  16385. } else if (isStream(cmapObj)) {
  16386. cmap = CMapFactory.create(cmapObj,
  16387. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16388. // Convert UTF-16BE
  16389. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16390. // to iterate over all keys.
  16391. cmap.forEach(function(token, i) {
  16392. var str = [];
  16393. for (var k = 0; k < token.length; k += 2) {
  16394. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16395. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16396. str.push(w1);
  16397. continue;
  16398. }
  16399. k += 2;
  16400. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16401. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16402. }
  16403. cmap[i] = String.fromCharCode.apply(String, str);
  16404. });
  16405. return new ToUnicodeMap(cmap);
  16406. }
  16407. return null;
  16408. },
  16409. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16410. // Extract the encoding from the CIDToGIDMap
  16411. var glyphsData = cidToGidStream.getBytes();
  16412. // Set encoding 0 to later verify the font has an encoding
  16413. var result = [];
  16414. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16415. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16416. if (glyphID === 0) {
  16417. continue;
  16418. }
  16419. var code = j >> 1;
  16420. result[code] = glyphID;
  16421. }
  16422. return result;
  16423. },
  16424. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16425. descriptor,
  16426. properties) {
  16427. var glyphsWidths = [];
  16428. var defaultWidth = 0;
  16429. var glyphsVMetrics = [];
  16430. var defaultVMetrics;
  16431. var i, ii, j, jj, start, code, widths;
  16432. if (properties.composite) {
  16433. defaultWidth = dict.get('DW') || 1000;
  16434. widths = dict.get('W');
  16435. if (widths) {
  16436. for (i = 0, ii = widths.length; i < ii; i++) {
  16437. start = widths[i++];
  16438. code = xref.fetchIfRef(widths[i]);
  16439. if (isArray(code)) {
  16440. for (j = 0, jj = code.length; j < jj; j++) {
  16441. glyphsWidths[start++] = code[j];
  16442. }
  16443. } else {
  16444. var width = widths[++i];
  16445. for (j = start; j <= code; j++) {
  16446. glyphsWidths[j] = width;
  16447. }
  16448. }
  16449. }
  16450. }
  16451. if (properties.vertical) {
  16452. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16453. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16454. vmetrics = dict.get('W2');
  16455. if (vmetrics) {
  16456. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16457. start = vmetrics[i++];
  16458. code = xref.fetchIfRef(vmetrics[i]);
  16459. if (isArray(code)) {
  16460. for (j = 0, jj = code.length; j < jj; j++) {
  16461. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16462. }
  16463. } else {
  16464. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16465. for (j = start; j <= code; j++) {
  16466. glyphsVMetrics[j] = vmetric;
  16467. }
  16468. }
  16469. }
  16470. }
  16471. }
  16472. } else {
  16473. var firstChar = properties.firstChar;
  16474. widths = dict.get('Widths');
  16475. if (widths) {
  16476. j = firstChar;
  16477. for (i = 0, ii = widths.length; i < ii; i++) {
  16478. glyphsWidths[j++] = widths[i];
  16479. }
  16480. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16481. } else {
  16482. // Trying get the BaseFont metrics (see comment above).
  16483. var baseFontName = dict.get('BaseFont');
  16484. if (isName(baseFontName)) {
  16485. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16486. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16487. properties);
  16488. defaultWidth = metrics.defaultWidth;
  16489. }
  16490. }
  16491. }
  16492. // Heuristic: detection of monospace font by checking all non-zero widths
  16493. var isMonospace = true;
  16494. var firstWidth = defaultWidth;
  16495. for (var glyph in glyphsWidths) {
  16496. var glyphWidth = glyphsWidths[glyph];
  16497. if (!glyphWidth) {
  16498. continue;
  16499. }
  16500. if (!firstWidth) {
  16501. firstWidth = glyphWidth;
  16502. continue;
  16503. }
  16504. if (firstWidth !== glyphWidth) {
  16505. isMonospace = false;
  16506. break;
  16507. }
  16508. }
  16509. if (isMonospace) {
  16510. properties.flags |= FontFlags.FixedPitch;
  16511. }
  16512. properties.defaultWidth = defaultWidth;
  16513. properties.widths = glyphsWidths;
  16514. properties.defaultVMetrics = defaultVMetrics;
  16515. properties.vmetrics = glyphsVMetrics;
  16516. },
  16517. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16518. // Simulating descriptor flags attribute
  16519. var fontNameWoStyle = baseFontName.split('-')[0];
  16520. return (fontNameWoStyle in serifFonts) ||
  16521. (fontNameWoStyle.search(/serif/gi) !== -1);
  16522. },
  16523. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16524. var defaultWidth = 0;
  16525. var widths = [];
  16526. var monospace = false;
  16527. var lookupName = (stdFontMap[name] || name);
  16528. if (!(lookupName in Metrics)) {
  16529. // Use default fonts for looking up font metrics if the passed
  16530. // font is not a base font
  16531. if (this.isSerifFont(name)) {
  16532. lookupName = 'Times-Roman';
  16533. } else {
  16534. lookupName = 'Helvetica';
  16535. }
  16536. }
  16537. var glyphWidths = Metrics[lookupName];
  16538. if (isNum(glyphWidths)) {
  16539. defaultWidth = glyphWidths;
  16540. monospace = true;
  16541. } else {
  16542. widths = glyphWidths;
  16543. }
  16544. return {
  16545. defaultWidth: defaultWidth,
  16546. monospace: monospace,
  16547. widths: widths
  16548. };
  16549. },
  16550. buildCharCodeToWidth:
  16551. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16552. properties) {
  16553. var widths = Object.create(null);
  16554. var differences = properties.differences;
  16555. var encoding = properties.defaultEncoding;
  16556. for (var charCode = 0; charCode < 256; charCode++) {
  16557. if (charCode in differences &&
  16558. widthsByGlyphName[differences[charCode]]) {
  16559. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16560. continue;
  16561. }
  16562. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16563. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16564. continue;
  16565. }
  16566. }
  16567. return widths;
  16568. },
  16569. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16570. var baseDict = dict;
  16571. var type = dict.get('Subtype');
  16572. assert(isName(type), 'invalid font Subtype');
  16573. var composite = false;
  16574. var uint8array;
  16575. if (type.name === 'Type0') {
  16576. // If font is a composite
  16577. // - get the descendant font
  16578. // - set the type according to the descendant font
  16579. // - get the FontDescriptor from the descendant font
  16580. var df = dict.get('DescendantFonts');
  16581. if (!df) {
  16582. error('Descendant fonts are not specified');
  16583. }
  16584. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16585. type = dict.get('Subtype');
  16586. assert(isName(type), 'invalid font Subtype');
  16587. composite = true;
  16588. }
  16589. var descriptor = dict.get('FontDescriptor');
  16590. if (descriptor) {
  16591. var hash = new MurmurHash3_64();
  16592. var encoding = baseDict.getRaw('Encoding');
  16593. if (isName(encoding)) {
  16594. hash.update(encoding.name);
  16595. } else if (isRef(encoding)) {
  16596. hash.update(encoding.num + '_' + encoding.gen);
  16597. }
  16598. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16599. if (isStream(toUnicode)) {
  16600. var stream = toUnicode.str || toUnicode;
  16601. uint8array = stream.buffer ?
  16602. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16603. new Uint8Array(stream.bytes.buffer,
  16604. stream.start, stream.end - stream.start);
  16605. hash.update(uint8array);
  16606. } else if (isName(toUnicode)) {
  16607. hash.update(toUnicode.name);
  16608. }
  16609. var widths = dict.get('Widths') || baseDict.get('Widths');
  16610. if (widths) {
  16611. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16612. hash.update(uint8array);
  16613. }
  16614. }
  16615. return {
  16616. descriptor: descriptor,
  16617. dict: dict,
  16618. baseDict: baseDict,
  16619. composite: composite,
  16620. type: type.name,
  16621. hash: hash ? hash.hexdigest() : ''
  16622. };
  16623. },
  16624. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16625. xref) {
  16626. var baseDict = preEvaluatedFont.baseDict;
  16627. var dict = preEvaluatedFont.dict;
  16628. var composite = preEvaluatedFont.composite;
  16629. var descriptor = preEvaluatedFont.descriptor;
  16630. var type = preEvaluatedFont.type;
  16631. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16632. var properties;
  16633. if (!descriptor) {
  16634. if (type === 'Type3') {
  16635. // FontDescriptor is only required for Type3 fonts when the document
  16636. // is a tagged pdf. Create a barbebones one to get by.
  16637. descriptor = new Dict(null);
  16638. descriptor.set('FontName', Name.get(type));
  16639. } else {
  16640. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16641. // FontDescriptor was not required.
  16642. // This case is here for compatibility.
  16643. var baseFontName = dict.get('BaseFont');
  16644. if (!isName(baseFontName)) {
  16645. error('Base font is not specified');
  16646. }
  16647. // Using base font name as a font name.
  16648. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16649. var metrics = this.getBaseFontMetrics(baseFontName);
  16650. // Simulating descriptor flags attribute
  16651. var fontNameWoStyle = baseFontName.split('-')[0];
  16652. var flags =
  16653. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16654. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16655. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16656. FontFlags.Nonsymbolic);
  16657. properties = {
  16658. type: type,
  16659. name: baseFontName,
  16660. widths: metrics.widths,
  16661. defaultWidth: metrics.defaultWidth,
  16662. flags: flags,
  16663. firstChar: 0,
  16664. lastChar: maxCharIndex
  16665. };
  16666. this.extractDataStructures(dict, dict, xref, properties);
  16667. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16668. properties);
  16669. return new Font(baseFontName, null, properties);
  16670. }
  16671. }
  16672. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16673. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16674. // to ignore this rule when a variant of a standart font is used.
  16675. // TODO Fill the width array depending on which of the base font this is
  16676. // a variant.
  16677. var firstChar = (dict.get('FirstChar') || 0);
  16678. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16679. var fontName = descriptor.get('FontName');
  16680. var baseFont = dict.get('BaseFont');
  16681. // Some bad PDFs have a string as the font name.
  16682. if (isString(fontName)) {
  16683. fontName = Name.get(fontName);
  16684. }
  16685. if (isString(baseFont)) {
  16686. baseFont = Name.get(baseFont);
  16687. }
  16688. if (type !== 'Type3') {
  16689. var fontNameStr = fontName && fontName.name;
  16690. var baseFontStr = baseFont && baseFont.name;
  16691. if (fontNameStr !== baseFontStr) {
  16692. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16693. '" but should be the same as the Font\'s BaseFont "' +
  16694. baseFontStr + '"');
  16695. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16696. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16697. if (fontNameStr && baseFontStr &&
  16698. baseFontStr.indexOf(fontNameStr) === 0) {
  16699. fontName = baseFont;
  16700. }
  16701. }
  16702. }
  16703. fontName = (fontName || baseFont);
  16704. assert(isName(fontName), 'invalid font name');
  16705. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16706. if (fontFile) {
  16707. if (fontFile.dict) {
  16708. var subtype = fontFile.dict.get('Subtype');
  16709. if (subtype) {
  16710. subtype = subtype.name;
  16711. }
  16712. var length1 = fontFile.dict.get('Length1');
  16713. var length2 = fontFile.dict.get('Length2');
  16714. }
  16715. }
  16716. properties = {
  16717. type: type,
  16718. name: fontName.name,
  16719. subtype: subtype,
  16720. file: fontFile,
  16721. length1: length1,
  16722. length2: length2,
  16723. loadedName: baseDict.loadedName,
  16724. composite: composite,
  16725. wideChars: composite,
  16726. fixedPitch: false,
  16727. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16728. firstChar: firstChar || 0,
  16729. lastChar: (lastChar || maxCharIndex),
  16730. bbox: descriptor.get('FontBBox'),
  16731. ascent: descriptor.get('Ascent'),
  16732. descent: descriptor.get('Descent'),
  16733. xHeight: descriptor.get('XHeight'),
  16734. capHeight: descriptor.get('CapHeight'),
  16735. flags: descriptor.get('Flags'),
  16736. italicAngle: descriptor.get('ItalicAngle'),
  16737. coded: false
  16738. };
  16739. if (composite) {
  16740. var cidEncoding = baseDict.get('Encoding');
  16741. if (isName(cidEncoding)) {
  16742. properties.cidEncoding = cidEncoding.name;
  16743. }
  16744. properties.cMap = CMapFactory.create(cidEncoding,
  16745. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16746. properties.vertical = properties.cMap.vertical;
  16747. }
  16748. this.extractDataStructures(dict, baseDict, xref, properties);
  16749. this.extractWidths(dict, xref, descriptor, properties);
  16750. if (type === 'Type3') {
  16751. properties.isType3Font = true;
  16752. }
  16753. return new Font(fontName.name, fontFile, properties);
  16754. }
  16755. };
  16756. return PartialEvaluator;
  16757. })();
  16758. var TranslatedFont = (function TranslatedFontClosure() {
  16759. function TranslatedFont(loadedName, font, dict) {
  16760. this.loadedName = loadedName;
  16761. this.font = font;
  16762. this.dict = dict;
  16763. this.type3Loaded = null;
  16764. this.sent = false;
  16765. }
  16766. TranslatedFont.prototype = {
  16767. send: function (handler) {
  16768. if (this.sent) {
  16769. return;
  16770. }
  16771. var fontData = this.font.exportData();
  16772. handler.send('commonobj', [
  16773. this.loadedName,
  16774. 'Font',
  16775. fontData
  16776. ]);
  16777. this.sent = true;
  16778. },
  16779. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16780. assert(this.font.isType3Font);
  16781. if (this.type3Loaded) {
  16782. return this.type3Loaded;
  16783. }
  16784. var translatedFont = this.font;
  16785. var loadCharProcsPromise = Promise.resolve();
  16786. var charProcs = this.dict.get('CharProcs').getAll();
  16787. var fontResources = this.dict.get('Resources') || resources;
  16788. var charProcKeys = Object.keys(charProcs);
  16789. var charProcOperatorList = {};
  16790. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16791. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16792. var glyphStream = charProcs[key];
  16793. var operatorList = new OperatorList();
  16794. return evaluator.getOperatorList(glyphStream, fontResources,
  16795. operatorList).then(function () {
  16796. charProcOperatorList[key] = operatorList.getIR();
  16797. // Add the dependencies to the parent operator list so they are
  16798. // resolved before sub operator list is executed synchronously.
  16799. parentOperatorList.addDependencies(operatorList.dependencies);
  16800. }, function (reason) {
  16801. warn('Type3 font resource \"' + key + '\" is not available');
  16802. var operatorList = new OperatorList();
  16803. charProcOperatorList[key] = operatorList.getIR();
  16804. });
  16805. }.bind(this, charProcKeys[i]));
  16806. }
  16807. this.type3Loaded = loadCharProcsPromise.then(function () {
  16808. translatedFont.charProcOperatorList = charProcOperatorList;
  16809. });
  16810. return this.type3Loaded;
  16811. }
  16812. };
  16813. return TranslatedFont;
  16814. })();
  16815. var OperatorList = (function OperatorListClosure() {
  16816. var CHUNK_SIZE = 1000;
  16817. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16818. function getTransfers(queue) {
  16819. var transfers = [];
  16820. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16821. for (var i = 0, ii = queue.length; i < ii; i++) {
  16822. switch (fnArray[i]) {
  16823. case OPS.paintInlineImageXObject:
  16824. case OPS.paintInlineImageXObjectGroup:
  16825. case OPS.paintImageMaskXObject:
  16826. var arg = argsArray[i][0]; // first param in imgData
  16827. if (!arg.cached) {
  16828. transfers.push(arg.data.buffer);
  16829. }
  16830. break;
  16831. }
  16832. }
  16833. return transfers;
  16834. }
  16835. function OperatorList(intent, messageHandler, pageIndex) {
  16836. this.messageHandler = messageHandler;
  16837. this.fnArray = [];
  16838. this.argsArray = [];
  16839. this.dependencies = {};
  16840. this.pageIndex = pageIndex;
  16841. this.intent = intent;
  16842. }
  16843. OperatorList.prototype = {
  16844. get length() {
  16845. return this.argsArray.length;
  16846. },
  16847. addOp: function(fn, args) {
  16848. this.fnArray.push(fn);
  16849. this.argsArray.push(args);
  16850. if (this.messageHandler) {
  16851. if (this.fnArray.length >= CHUNK_SIZE) {
  16852. this.flush();
  16853. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16854. (fn === OPS.restore || fn === OPS.endText)) {
  16855. // heuristic to flush on boundary of restore or endText
  16856. this.flush();
  16857. }
  16858. }
  16859. },
  16860. addDependency: function(dependency) {
  16861. if (dependency in this.dependencies) {
  16862. return;
  16863. }
  16864. this.dependencies[dependency] = true;
  16865. this.addOp(OPS.dependency, [dependency]);
  16866. },
  16867. addDependencies: function(dependencies) {
  16868. for (var key in dependencies) {
  16869. this.addDependency(key);
  16870. }
  16871. },
  16872. addOpList: function(opList) {
  16873. Util.extendObj(this.dependencies, opList.dependencies);
  16874. for (var i = 0, ii = opList.length; i < ii; i++) {
  16875. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16876. }
  16877. },
  16878. getIR: function() {
  16879. return {
  16880. fnArray: this.fnArray,
  16881. argsArray: this.argsArray,
  16882. length: this.length
  16883. };
  16884. },
  16885. flush: function(lastChunk) {
  16886. if (this.intent !== 'oplist') {
  16887. new QueueOptimizer().optimize(this);
  16888. }
  16889. var transfers = getTransfers(this);
  16890. this.messageHandler.send('RenderPageChunk', {
  16891. operatorList: {
  16892. fnArray: this.fnArray,
  16893. argsArray: this.argsArray,
  16894. lastChunk: lastChunk,
  16895. length: this.length
  16896. },
  16897. pageIndex: this.pageIndex,
  16898. intent: this.intent
  16899. }, transfers);
  16900. this.dependencies = {};
  16901. this.fnArray.length = 0;
  16902. this.argsArray.length = 0;
  16903. }
  16904. };
  16905. return OperatorList;
  16906. })();
  16907. var StateManager = (function StateManagerClosure() {
  16908. function StateManager(initialState) {
  16909. this.state = initialState;
  16910. this.stateStack = [];
  16911. }
  16912. StateManager.prototype = {
  16913. save: function () {
  16914. var old = this.state;
  16915. this.stateStack.push(this.state);
  16916. this.state = old.clone();
  16917. },
  16918. restore: function () {
  16919. var prev = this.stateStack.pop();
  16920. if (prev) {
  16921. this.state = prev;
  16922. }
  16923. },
  16924. transform: function (args) {
  16925. this.state.ctm = Util.transform(this.state.ctm, args);
  16926. }
  16927. };
  16928. return StateManager;
  16929. })();
  16930. var TextState = (function TextStateClosure() {
  16931. function TextState() {
  16932. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16933. this.fontSize = 0;
  16934. this.font = null;
  16935. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16936. this.textMatrix = IDENTITY_MATRIX.slice();
  16937. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16938. this.charSpacing = 0;
  16939. this.wordSpacing = 0;
  16940. this.leading = 0;
  16941. this.textHScale = 1;
  16942. this.textRise = 0;
  16943. }
  16944. TextState.prototype = {
  16945. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16946. var m = this.textMatrix;
  16947. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16948. },
  16949. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16950. var m = this.textLineMatrix;
  16951. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16952. },
  16953. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16954. var m = this.textMatrix;
  16955. m[4] = m[0] * x + m[2] * y + m[4];
  16956. m[5] = m[1] * x + m[3] * y + m[5];
  16957. },
  16958. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16959. var m = this.textLineMatrix;
  16960. m[4] = m[0] * x + m[2] * y + m[4];
  16961. m[5] = m[1] * x + m[3] * y + m[5];
  16962. },
  16963. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16964. // 9.4.4 Text Space Details
  16965. var tsm = [this.fontSize * this.textHScale, 0,
  16966. 0, this.fontSize,
  16967. 0, this.textRise];
  16968. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16969. },
  16970. carriageReturn: function TextState_carriageReturn() {
  16971. this.translateTextLineMatrix(0, -this.leading);
  16972. this.textMatrix = this.textLineMatrix.slice();
  16973. },
  16974. clone: function TextState_clone() {
  16975. var clone = Object.create(this);
  16976. clone.textMatrix = this.textMatrix.slice();
  16977. clone.textLineMatrix = this.textLineMatrix.slice();
  16978. clone.fontMatrix = this.fontMatrix.slice();
  16979. return clone;
  16980. }
  16981. };
  16982. return TextState;
  16983. })();
  16984. var EvalState = (function EvalStateClosure() {
  16985. function EvalState() {
  16986. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16987. this.font = null;
  16988. this.textRenderingMode = TextRenderingMode.FILL;
  16989. this.fillColorSpace = ColorSpace.singletons.gray;
  16990. this.strokeColorSpace = ColorSpace.singletons.gray;
  16991. }
  16992. EvalState.prototype = {
  16993. clone: function CanvasExtraState_clone() {
  16994. return Object.create(this);
  16995. },
  16996. };
  16997. return EvalState;
  16998. })();
  16999. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17000. // Specifies properties for each command
  17001. //
  17002. // If variableArgs === true: [0, `numArgs`] expected
  17003. // If variableArgs === false: exactly `numArgs` expected
  17004. var OP_MAP = {
  17005. // Graphic state
  17006. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17007. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17008. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17009. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17010. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17011. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17012. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17013. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17014. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17015. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17016. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17017. // Path
  17018. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17019. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17020. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17021. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17022. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17023. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17024. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17025. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17026. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17027. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17028. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17029. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17030. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17031. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17032. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17033. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17034. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17035. // Clipping
  17036. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17037. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17038. // Text
  17039. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17040. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17041. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17042. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17043. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17044. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17045. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17046. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17047. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17048. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17049. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17050. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17051. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17052. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17053. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17054. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17055. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17056. variableArgs: false },
  17057. // Type3 fonts
  17058. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17059. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17060. // Color
  17061. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17062. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17063. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17064. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17065. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17066. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17067. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17068. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17069. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17070. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17071. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17072. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17073. // Shading
  17074. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17075. // Images
  17076. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17077. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17078. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17079. // XObjects
  17080. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17081. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17082. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17083. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17084. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17085. variableArgs: false },
  17086. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17087. // Compatibility
  17088. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17089. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17090. // (reserved partial commands for the lexer)
  17091. BM: null,
  17092. BD: null,
  17093. 'true': null,
  17094. fa: null,
  17095. fal: null,
  17096. fals: null,
  17097. 'false': null,
  17098. nu: null,
  17099. nul: null,
  17100. 'null': null
  17101. };
  17102. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17103. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17104. // dictionary
  17105. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17106. this.stateManager = stateManager;
  17107. this.nonProcessedArgs = [];
  17108. }
  17109. EvaluatorPreprocessor.prototype = {
  17110. get savedStatesDepth() {
  17111. return this.stateManager.stateStack.length;
  17112. },
  17113. // |operation| is an object with two fields:
  17114. //
  17115. // - |fn| is an out param.
  17116. //
  17117. // - |args| is an inout param. On entry, it should have one of two values.
  17118. //
  17119. // - An empty array. This indicates that the caller is providing the
  17120. // array in which the args will be stored in. The caller should use
  17121. // this value if it can reuse a single array for each call to read().
  17122. //
  17123. // - |null|. This indicates that the caller needs this function to create
  17124. // the array in which any args are stored in. If there are zero args,
  17125. // this function will leave |operation.args| as |null| (thus avoiding
  17126. // allocations that would occur if we used an empty array to represent
  17127. // zero arguments). Otherwise, it will replace |null| with a new array
  17128. // containing the arguments. The caller should use this value if it
  17129. // cannot reuse an array for each call to read().
  17130. //
  17131. // These two modes are present because this function is very hot and so
  17132. // avoiding allocations where possible is worthwhile.
  17133. //
  17134. read: function EvaluatorPreprocessor_read(operation) {
  17135. var args = operation.args;
  17136. while (true) {
  17137. var obj = this.parser.getObj();
  17138. if (isCmd(obj)) {
  17139. var cmd = obj.cmd;
  17140. // Check that the command is valid
  17141. var opSpec = OP_MAP[cmd];
  17142. if (!opSpec) {
  17143. warn('Unknown command "' + cmd + '"');
  17144. continue;
  17145. }
  17146. var fn = opSpec.id;
  17147. var numArgs = opSpec.numArgs;
  17148. var argsLength = args !== null ? args.length : 0;
  17149. if (!opSpec.variableArgs) {
  17150. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17151. if (argsLength !== numArgs) {
  17152. var nonProcessedArgs = this.nonProcessedArgs;
  17153. while (argsLength > numArgs) {
  17154. nonProcessedArgs.push(args.shift());
  17155. argsLength--;
  17156. }
  17157. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17158. if (!args) {
  17159. args = [];
  17160. }
  17161. args.unshift(nonProcessedArgs.pop());
  17162. argsLength++;
  17163. }
  17164. }
  17165. if (argsLength < numArgs) {
  17166. // If we receive too few args, it's not possible to possible
  17167. // to execute the command, so skip the command
  17168. info('Command ' + fn + ': because expected ' +
  17169. numArgs + ' args, but received ' + argsLength +
  17170. ' args; skipping');
  17171. args = null;
  17172. continue;
  17173. }
  17174. } else if (argsLength > numArgs) {
  17175. info('Command ' + fn + ': expected [0,' + numArgs +
  17176. '] args, but received ' + argsLength + ' args');
  17177. }
  17178. // TODO figure out how to type-check vararg functions
  17179. this.preprocessCommand(fn, args);
  17180. operation.fn = fn;
  17181. operation.args = args;
  17182. return true;
  17183. } else {
  17184. if (isEOF(obj)) {
  17185. return false; // no more commands
  17186. }
  17187. // argument
  17188. if (obj !== null) {
  17189. if (!args) {
  17190. args = [];
  17191. }
  17192. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17193. assert(args.length <= 33, 'Too many arguments');
  17194. }
  17195. }
  17196. }
  17197. },
  17198. preprocessCommand:
  17199. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17200. switch (fn | 0) {
  17201. case OPS.save:
  17202. this.stateManager.save();
  17203. break;
  17204. case OPS.restore:
  17205. this.stateManager.restore();
  17206. break;
  17207. case OPS.transform:
  17208. this.stateManager.transform(args);
  17209. break;
  17210. }
  17211. }
  17212. };
  17213. return EvaluatorPreprocessor;
  17214. })();
  17215. var QueueOptimizer = (function QueueOptimizerClosure() {
  17216. function addState(parentState, pattern, fn) {
  17217. var state = parentState;
  17218. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17219. var item = pattern[i];
  17220. state = (state[item] || (state[item] = []));
  17221. }
  17222. state[pattern[pattern.length - 1]] = fn;
  17223. }
  17224. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17225. argsArray) {
  17226. // Handles special case of mainly LaTeX documents which use image masks to
  17227. // draw lines with the current fill style.
  17228. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17229. // have been found at iFirstSave.
  17230. var iFirstPIMXO = iFirstSave + 2;
  17231. for (var i = 0; i < count; i++) {
  17232. var arg = argsArray[iFirstPIMXO + 4 * i];
  17233. var imageMask = arg.length === 1 && arg[0];
  17234. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17235. (!imageMask.data.length ||
  17236. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17237. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17238. continue;
  17239. }
  17240. break;
  17241. }
  17242. return count - i;
  17243. }
  17244. var InitialState = [];
  17245. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17246. // sequences with one |paintInlineImageXObjectGroup| operation.
  17247. addState(InitialState,
  17248. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17249. function foundInlineImageGroup(context) {
  17250. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17251. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17252. var MAX_WIDTH = 1000;
  17253. var IMAGE_PADDING = 1;
  17254. var fnArray = context.fnArray, argsArray = context.argsArray;
  17255. var curr = context.iCurr;
  17256. var iFirstSave = curr - 3;
  17257. var iFirstTransform = curr - 2;
  17258. var iFirstPIIXO = curr - 1;
  17259. // Look for the quartets.
  17260. var i = iFirstSave + 4;
  17261. var ii = fnArray.length;
  17262. while (i + 3 < ii) {
  17263. if (fnArray[i] !== OPS.save ||
  17264. fnArray[i + 1] !== OPS.transform ||
  17265. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17266. fnArray[i + 3] !== OPS.restore) {
  17267. break; // ops don't match
  17268. }
  17269. i += 4;
  17270. }
  17271. // At this point, i is the index of the first op past the last valid
  17272. // quartet.
  17273. var count = Math.min((i - iFirstSave) / 4,
  17274. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17275. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17276. return i;
  17277. }
  17278. // assuming that heights of those image is too small (~1 pixel)
  17279. // packing as much as possible by lines
  17280. var maxX = 0;
  17281. var map = [], maxLineHeight = 0;
  17282. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17283. var q;
  17284. for (q = 0; q < count; q++) {
  17285. var transform = argsArray[iFirstTransform + (q << 2)];
  17286. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17287. if (currentX + img.width > MAX_WIDTH) {
  17288. // starting new line
  17289. maxX = Math.max(maxX, currentX);
  17290. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17291. currentX = 0;
  17292. maxLineHeight = 0;
  17293. }
  17294. map.push({
  17295. transform: transform,
  17296. x: currentX, y: currentY,
  17297. w: img.width, h: img.height
  17298. });
  17299. currentX += img.width + 2 * IMAGE_PADDING;
  17300. maxLineHeight = Math.max(maxLineHeight, img.height);
  17301. }
  17302. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17303. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17304. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17305. var imgRowSize = imgWidth << 2;
  17306. for (q = 0; q < count; q++) {
  17307. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17308. // Copy image by lines and extends pixels into padding.
  17309. var rowSize = map[q].w << 2;
  17310. var dataOffset = 0;
  17311. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17312. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17313. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17314. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17315. dataOffset += rowSize;
  17316. offset += imgRowSize;
  17317. }
  17318. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17319. while (offset >= 0) {
  17320. data[offset - 4] = data[offset];
  17321. data[offset - 3] = data[offset + 1];
  17322. data[offset - 2] = data[offset + 2];
  17323. data[offset - 1] = data[offset + 3];
  17324. data[offset + rowSize] = data[offset + rowSize - 4];
  17325. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17326. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17327. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17328. offset -= imgRowSize;
  17329. }
  17330. }
  17331. // Replace queue items.
  17332. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17333. argsArray.splice(iFirstSave, count * 4,
  17334. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17335. data: imgData }, map]);
  17336. return iFirstSave + 1;
  17337. });
  17338. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17339. // sequences with one |paintImageMaskXObjectGroup| or one
  17340. // |paintImageMaskXObjectRepeat| operation.
  17341. addState(InitialState,
  17342. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17343. function foundImageMaskGroup(context) {
  17344. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17345. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17346. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17347. var fnArray = context.fnArray, argsArray = context.argsArray;
  17348. var curr = context.iCurr;
  17349. var iFirstSave = curr - 3;
  17350. var iFirstTransform = curr - 2;
  17351. var iFirstPIMXO = curr - 1;
  17352. // Look for the quartets.
  17353. var i = iFirstSave + 4;
  17354. var ii = fnArray.length;
  17355. while (i + 3 < ii) {
  17356. if (fnArray[i] !== OPS.save ||
  17357. fnArray[i + 1] !== OPS.transform ||
  17358. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17359. fnArray[i + 3] !== OPS.restore) {
  17360. break; // ops don't match
  17361. }
  17362. i += 4;
  17363. }
  17364. // At this point, i is the index of the first op past the last valid
  17365. // quartet.
  17366. var count = (i - iFirstSave) / 4;
  17367. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17368. argsArray);
  17369. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17370. return i;
  17371. }
  17372. var q;
  17373. var isSameImage = false;
  17374. var iTransform, transformArgs;
  17375. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17376. if (argsArray[iFirstTransform][1] === 0 &&
  17377. argsArray[iFirstTransform][2] === 0) {
  17378. isSameImage = true;
  17379. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17380. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17381. iTransform = iFirstTransform + 4;
  17382. var iPIMXO = iFirstPIMXO + 4;
  17383. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17384. transformArgs = argsArray[iTransform];
  17385. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17386. transformArgs[0] !== firstTransformArg0 ||
  17387. transformArgs[1] !== 0 ||
  17388. transformArgs[2] !== 0 ||
  17389. transformArgs[3] !== firstTransformArg3) {
  17390. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17391. isSameImage = false;
  17392. } else {
  17393. count = q;
  17394. }
  17395. break; // different image or transform
  17396. }
  17397. }
  17398. }
  17399. if (isSameImage) {
  17400. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17401. var positions = new Float32Array(count * 2);
  17402. iTransform = iFirstTransform;
  17403. for (q = 0; q < count; q++, iTransform += 4) {
  17404. transformArgs = argsArray[iTransform];
  17405. positions[(q << 1)] = transformArgs[4];
  17406. positions[(q << 1) + 1] = transformArgs[5];
  17407. }
  17408. // Replace queue items.
  17409. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17410. argsArray.splice(iFirstSave, count * 4,
  17411. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17412. } else {
  17413. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17414. var images = [];
  17415. for (q = 0; q < count; q++) {
  17416. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17417. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17418. images.push({ data: maskParams.data, width: maskParams.width,
  17419. height: maskParams.height,
  17420. transform: transformArgs });
  17421. }
  17422. // Replace queue items.
  17423. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17424. argsArray.splice(iFirstSave, count * 4, [images]);
  17425. }
  17426. return iFirstSave + 1;
  17427. });
  17428. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17429. // with one paintImageXObjectRepeat operation, if the |transform| and
  17430. // |paintImageXObjectRepeat| ops are appropriate.
  17431. addState(InitialState,
  17432. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17433. function (context) {
  17434. var MIN_IMAGES_IN_BLOCK = 3;
  17435. var MAX_IMAGES_IN_BLOCK = 1000;
  17436. var fnArray = context.fnArray, argsArray = context.argsArray;
  17437. var curr = context.iCurr;
  17438. var iFirstSave = curr - 3;
  17439. var iFirstTransform = curr - 2;
  17440. var iFirstPIXO = curr - 1;
  17441. var iFirstRestore = curr;
  17442. if (argsArray[iFirstTransform][1] !== 0 ||
  17443. argsArray[iFirstTransform][2] !== 0) {
  17444. return iFirstRestore + 1; // transform has the wrong form
  17445. }
  17446. // Look for the quartets.
  17447. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17448. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17449. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17450. var i = iFirstSave + 4;
  17451. var ii = fnArray.length;
  17452. while (i + 3 < ii) {
  17453. if (fnArray[i] !== OPS.save ||
  17454. fnArray[i + 1] !== OPS.transform ||
  17455. fnArray[i + 2] !== OPS.paintImageXObject ||
  17456. fnArray[i + 3] !== OPS.restore) {
  17457. break; // ops don't match
  17458. }
  17459. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17460. argsArray[i + 1][1] !== 0 ||
  17461. argsArray[i + 1][2] !== 0 ||
  17462. argsArray[i + 1][3] !== firstTransformArg3) {
  17463. break; // transforms don't match
  17464. }
  17465. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17466. break; // images don't match
  17467. }
  17468. i += 4;
  17469. }
  17470. // At this point, i is the index of the first op past the last valid
  17471. // quartet.
  17472. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17473. if (count < MIN_IMAGES_IN_BLOCK) {
  17474. return i;
  17475. }
  17476. // Extract the (x,y) positions from all of the matching transforms.
  17477. var positions = new Float32Array(count * 2);
  17478. var iTransform = iFirstTransform;
  17479. for (var q = 0; q < count; q++, iTransform += 4) {
  17480. var transformArgs = argsArray[iTransform];
  17481. positions[(q << 1)] = transformArgs[4];
  17482. positions[(q << 1) + 1] = transformArgs[5];
  17483. }
  17484. // Replace queue items.
  17485. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17486. positions];
  17487. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17488. argsArray.splice(iFirstSave, count * 4, args);
  17489. return iFirstSave + 1;
  17490. });
  17491. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17492. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17493. // sequences, if the font for each one is the same.
  17494. addState(InitialState,
  17495. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17496. function (context) {
  17497. var MIN_CHARS_IN_BLOCK = 3;
  17498. var MAX_CHARS_IN_BLOCK = 1000;
  17499. var fnArray = context.fnArray, argsArray = context.argsArray;
  17500. var curr = context.iCurr;
  17501. var iFirstBeginText = curr - 4;
  17502. var iFirstSetFont = curr - 3;
  17503. var iFirstSetTextMatrix = curr - 2;
  17504. var iFirstShowText = curr - 1;
  17505. var iFirstEndText = curr;
  17506. // Look for the quintets.
  17507. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17508. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17509. var i = iFirstBeginText + 5;
  17510. var ii = fnArray.length;
  17511. while (i + 4 < ii) {
  17512. if (fnArray[i] !== OPS.beginText ||
  17513. fnArray[i + 1] !== OPS.setFont ||
  17514. fnArray[i + 2] !== OPS.setTextMatrix ||
  17515. fnArray[i + 3] !== OPS.showText ||
  17516. fnArray[i + 4] !== OPS.endText) {
  17517. break; // ops don't match
  17518. }
  17519. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17520. argsArray[i + 1][1] !== firstSetFontArg1) {
  17521. break; // fonts don't match
  17522. }
  17523. i += 5;
  17524. }
  17525. // At this point, i is the index of the first op past the last valid
  17526. // quintet.
  17527. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17528. if (count < MIN_CHARS_IN_BLOCK) {
  17529. return i;
  17530. }
  17531. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17532. // showText, endText), include that as well. (E.g. <something> might be
  17533. // |dependency|.)
  17534. var iFirst = iFirstBeginText;
  17535. if (iFirstBeginText >= 4 &&
  17536. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17537. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17538. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17539. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17540. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17541. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17542. count++;
  17543. iFirst -= 5;
  17544. }
  17545. // Remove (endText, beginText, setFont) trios.
  17546. var iEndText = iFirst + 4;
  17547. for (var q = 1; q < count; q++) {
  17548. fnArray.splice(iEndText, 3);
  17549. argsArray.splice(iEndText, 3);
  17550. iEndText += 2;
  17551. }
  17552. return iEndText + 1;
  17553. });
  17554. function QueueOptimizer() {}
  17555. QueueOptimizer.prototype = {
  17556. optimize: function QueueOptimizer_optimize(queue) {
  17557. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17558. var context = {
  17559. iCurr: 0,
  17560. fnArray: fnArray,
  17561. argsArray: argsArray
  17562. };
  17563. var state;
  17564. var i = 0, ii = fnArray.length;
  17565. while (i < ii) {
  17566. state = (state || InitialState)[fnArray[i]];
  17567. if (typeof state === 'function') { // we found some handler
  17568. context.iCurr = i;
  17569. // state() returns the index of the first non-matching op (if we
  17570. // didn't match) or the first op past the modified ops (if we did
  17571. // match and replace).
  17572. i = state(context);
  17573. state = undefined; // reset the state machine
  17574. ii = context.fnArray.length;
  17575. } else {
  17576. i++;
  17577. }
  17578. }
  17579. }
  17580. };
  17581. return QueueOptimizer;
  17582. })();
  17583. var BUILT_IN_CMAPS = [
  17584. // << Start unicode maps.
  17585. 'Adobe-GB1-UCS2',
  17586. 'Adobe-CNS1-UCS2',
  17587. 'Adobe-Japan1-UCS2',
  17588. 'Adobe-Korea1-UCS2',
  17589. // >> End unicode maps.
  17590. '78-EUC-H',
  17591. '78-EUC-V',
  17592. '78-H',
  17593. '78-RKSJ-H',
  17594. '78-RKSJ-V',
  17595. '78-V',
  17596. '78ms-RKSJ-H',
  17597. '78ms-RKSJ-V',
  17598. '83pv-RKSJ-H',
  17599. '90ms-RKSJ-H',
  17600. '90ms-RKSJ-V',
  17601. '90msp-RKSJ-H',
  17602. '90msp-RKSJ-V',
  17603. '90pv-RKSJ-H',
  17604. '90pv-RKSJ-V',
  17605. 'Add-H',
  17606. 'Add-RKSJ-H',
  17607. 'Add-RKSJ-V',
  17608. 'Add-V',
  17609. 'Adobe-CNS1-0',
  17610. 'Adobe-CNS1-1',
  17611. 'Adobe-CNS1-2',
  17612. 'Adobe-CNS1-3',
  17613. 'Adobe-CNS1-4',
  17614. 'Adobe-CNS1-5',
  17615. 'Adobe-CNS1-6',
  17616. 'Adobe-GB1-0',
  17617. 'Adobe-GB1-1',
  17618. 'Adobe-GB1-2',
  17619. 'Adobe-GB1-3',
  17620. 'Adobe-GB1-4',
  17621. 'Adobe-GB1-5',
  17622. 'Adobe-Japan1-0',
  17623. 'Adobe-Japan1-1',
  17624. 'Adobe-Japan1-2',
  17625. 'Adobe-Japan1-3',
  17626. 'Adobe-Japan1-4',
  17627. 'Adobe-Japan1-5',
  17628. 'Adobe-Japan1-6',
  17629. 'Adobe-Korea1-0',
  17630. 'Adobe-Korea1-1',
  17631. 'Adobe-Korea1-2',
  17632. 'B5-H',
  17633. 'B5-V',
  17634. 'B5pc-H',
  17635. 'B5pc-V',
  17636. 'CNS-EUC-H',
  17637. 'CNS-EUC-V',
  17638. 'CNS1-H',
  17639. 'CNS1-V',
  17640. 'CNS2-H',
  17641. 'CNS2-V',
  17642. 'ETHK-B5-H',
  17643. 'ETHK-B5-V',
  17644. 'ETen-B5-H',
  17645. 'ETen-B5-V',
  17646. 'ETenms-B5-H',
  17647. 'ETenms-B5-V',
  17648. 'EUC-H',
  17649. 'EUC-V',
  17650. 'Ext-H',
  17651. 'Ext-RKSJ-H',
  17652. 'Ext-RKSJ-V',
  17653. 'Ext-V',
  17654. 'GB-EUC-H',
  17655. 'GB-EUC-V',
  17656. 'GB-H',
  17657. 'GB-V',
  17658. 'GBK-EUC-H',
  17659. 'GBK-EUC-V',
  17660. 'GBK2K-H',
  17661. 'GBK2K-V',
  17662. 'GBKp-EUC-H',
  17663. 'GBKp-EUC-V',
  17664. 'GBT-EUC-H',
  17665. 'GBT-EUC-V',
  17666. 'GBT-H',
  17667. 'GBT-V',
  17668. 'GBTpc-EUC-H',
  17669. 'GBTpc-EUC-V',
  17670. 'GBpc-EUC-H',
  17671. 'GBpc-EUC-V',
  17672. 'H',
  17673. 'HKdla-B5-H',
  17674. 'HKdla-B5-V',
  17675. 'HKdlb-B5-H',
  17676. 'HKdlb-B5-V',
  17677. 'HKgccs-B5-H',
  17678. 'HKgccs-B5-V',
  17679. 'HKm314-B5-H',
  17680. 'HKm314-B5-V',
  17681. 'HKm471-B5-H',
  17682. 'HKm471-B5-V',
  17683. 'HKscs-B5-H',
  17684. 'HKscs-B5-V',
  17685. 'Hankaku',
  17686. 'Hiragana',
  17687. 'KSC-EUC-H',
  17688. 'KSC-EUC-V',
  17689. 'KSC-H',
  17690. 'KSC-Johab-H',
  17691. 'KSC-Johab-V',
  17692. 'KSC-V',
  17693. 'KSCms-UHC-H',
  17694. 'KSCms-UHC-HW-H',
  17695. 'KSCms-UHC-HW-V',
  17696. 'KSCms-UHC-V',
  17697. 'KSCpc-EUC-H',
  17698. 'KSCpc-EUC-V',
  17699. 'Katakana',
  17700. 'NWP-H',
  17701. 'NWP-V',
  17702. 'RKSJ-H',
  17703. 'RKSJ-V',
  17704. 'Roman',
  17705. 'UniCNS-UCS2-H',
  17706. 'UniCNS-UCS2-V',
  17707. 'UniCNS-UTF16-H',
  17708. 'UniCNS-UTF16-V',
  17709. 'UniCNS-UTF32-H',
  17710. 'UniCNS-UTF32-V',
  17711. 'UniCNS-UTF8-H',
  17712. 'UniCNS-UTF8-V',
  17713. 'UniGB-UCS2-H',
  17714. 'UniGB-UCS2-V',
  17715. 'UniGB-UTF16-H',
  17716. 'UniGB-UTF16-V',
  17717. 'UniGB-UTF32-H',
  17718. 'UniGB-UTF32-V',
  17719. 'UniGB-UTF8-H',
  17720. 'UniGB-UTF8-V',
  17721. 'UniJIS-UCS2-H',
  17722. 'UniJIS-UCS2-HW-H',
  17723. 'UniJIS-UCS2-HW-V',
  17724. 'UniJIS-UCS2-V',
  17725. 'UniJIS-UTF16-H',
  17726. 'UniJIS-UTF16-V',
  17727. 'UniJIS-UTF32-H',
  17728. 'UniJIS-UTF32-V',
  17729. 'UniJIS-UTF8-H',
  17730. 'UniJIS-UTF8-V',
  17731. 'UniJIS2004-UTF16-H',
  17732. 'UniJIS2004-UTF16-V',
  17733. 'UniJIS2004-UTF32-H',
  17734. 'UniJIS2004-UTF32-V',
  17735. 'UniJIS2004-UTF8-H',
  17736. 'UniJIS2004-UTF8-V',
  17737. 'UniJISPro-UCS2-HW-V',
  17738. 'UniJISPro-UCS2-V',
  17739. 'UniJISPro-UTF8-V',
  17740. 'UniJISX0213-UTF32-H',
  17741. 'UniJISX0213-UTF32-V',
  17742. 'UniJISX02132004-UTF32-H',
  17743. 'UniJISX02132004-UTF32-V',
  17744. 'UniKS-UCS2-H',
  17745. 'UniKS-UCS2-V',
  17746. 'UniKS-UTF16-H',
  17747. 'UniKS-UTF16-V',
  17748. 'UniKS-UTF32-H',
  17749. 'UniKS-UTF32-V',
  17750. 'UniKS-UTF8-H',
  17751. 'UniKS-UTF8-V',
  17752. 'V',
  17753. 'WP-Symbol'];
  17754. // CMap, not to be confused with TrueType's cmap.
  17755. var CMap = (function CMapClosure() {
  17756. function CMap(builtInCMap) {
  17757. // Codespace ranges are stored as follows:
  17758. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17759. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17760. this.codespaceRanges = [[], [], [], []];
  17761. this.numCodespaceRanges = 0;
  17762. // Map entries have one of two forms.
  17763. // - cid chars are 16-bit unsigned integers, stored as integers.
  17764. // - bf chars are variable-length byte sequences, stored as strings, with
  17765. // one byte per character.
  17766. this._map = [];
  17767. this.vertical = false;
  17768. this.useCMap = null;
  17769. this.builtInCMap = builtInCMap;
  17770. }
  17771. CMap.prototype = {
  17772. addCodespaceRange: function(n, low, high) {
  17773. this.codespaceRanges[n - 1].push(low, high);
  17774. this.numCodespaceRanges++;
  17775. },
  17776. mapCidRange: function(low, high, dstLow) {
  17777. while (low <= high) {
  17778. this._map[low++] = dstLow++;
  17779. }
  17780. },
  17781. mapBfRange: function(low, high, dstLow) {
  17782. var lastByte = dstLow.length - 1;
  17783. while (low <= high) {
  17784. this._map[low++] = dstLow;
  17785. // Only the last byte has to be incremented.
  17786. dstLow = dstLow.substr(0, lastByte) +
  17787. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17788. }
  17789. },
  17790. mapBfRangeToArray: function(low, high, array) {
  17791. var i = 0, ii = array.length;
  17792. while (low <= high && i < ii) {
  17793. this._map[low] = array[i++];
  17794. ++low;
  17795. }
  17796. },
  17797. // This is used for both bf and cid chars.
  17798. mapOne: function(src, dst) {
  17799. this._map[src] = dst;
  17800. },
  17801. lookup: function(code) {
  17802. return this._map[code];
  17803. },
  17804. contains: function(code) {
  17805. return this._map[code] !== undefined;
  17806. },
  17807. forEach: function(callback) {
  17808. // Most maps have fewer than 65536 entries, and for those we use normal
  17809. // array iteration. But really sparse tables are possible -- e.g. with
  17810. // indices in the *billions*. For such tables we use for..in, which isn't
  17811. // ideal because it stringifies the indices for all present elements, but
  17812. // it does avoid iterating over every undefined entry.
  17813. var map = this._map;
  17814. var length = map.length;
  17815. var i;
  17816. if (length <= 0x10000) {
  17817. for (i = 0; i < length; i++) {
  17818. if (map[i] !== undefined) {
  17819. callback(i, map[i]);
  17820. }
  17821. }
  17822. } else {
  17823. for (i in this._map) {
  17824. callback(i, map[i]);
  17825. }
  17826. }
  17827. },
  17828. charCodeOf: function(value) {
  17829. return this._map.indexOf(value);
  17830. },
  17831. getMap: function() {
  17832. return this._map;
  17833. },
  17834. readCharCode: function(str, offset, out) {
  17835. var c = 0;
  17836. var codespaceRanges = this.codespaceRanges;
  17837. var codespaceRangesLen = this.codespaceRanges.length;
  17838. // 9.7.6.2 CMap Mapping
  17839. // The code length is at most 4.
  17840. for (var n = 0; n < codespaceRangesLen; n++) {
  17841. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17842. // Check each codespace range to see if it falls within.
  17843. var codespaceRange = codespaceRanges[n];
  17844. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17845. var low = codespaceRange[k++];
  17846. var high = codespaceRange[k++];
  17847. if (c >= low && c <= high) {
  17848. out.charcode = c;
  17849. out.length = n + 1;
  17850. return;
  17851. }
  17852. }
  17853. }
  17854. out.charcode = 0;
  17855. out.length = 1;
  17856. }
  17857. };
  17858. return CMap;
  17859. })();
  17860. // A special case of CMap, where the _map array implicitly has a length of
  17861. // 65535 and each element is equal to its index.
  17862. var IdentityCMap = (function IdentityCMapClosure() {
  17863. function IdentityCMap(vertical, n) {
  17864. CMap.call(this);
  17865. this.vertical = vertical;
  17866. this.addCodespaceRange(n, 0, 0xffff);
  17867. }
  17868. Util.inherit(IdentityCMap, CMap, {});
  17869. IdentityCMap.prototype = {
  17870. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17871. mapCidRange: function(low, high, dstLow) {
  17872. error('should not call mapCidRange');
  17873. },
  17874. mapBfRange: function(low, high, dstLow) {
  17875. error('should not call mapBfRange');
  17876. },
  17877. mapBfRangeToArray: function(low, high, array) {
  17878. error('should not call mapBfRangeToArray');
  17879. },
  17880. mapOne: function(src, dst) {
  17881. error('should not call mapCidOne');
  17882. },
  17883. lookup: function(code) {
  17884. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17885. },
  17886. contains: function(code) {
  17887. return isInt(code) && code <= 0xffff;
  17888. },
  17889. forEach: function(callback) {
  17890. for (var i = 0; i <= 0xffff; i++) {
  17891. callback(i, i);
  17892. }
  17893. },
  17894. charCodeOf: function(value) {
  17895. return (isInt(value) && value <= 0xffff) ? value : -1;
  17896. },
  17897. getMap: function() {
  17898. // Sometimes identity maps must be instantiated, but it's rare.
  17899. var map = new Array(0x10000);
  17900. for (var i = 0; i <= 0xffff; i++) {
  17901. map[i] = i;
  17902. }
  17903. return map;
  17904. },
  17905. readCharCode: CMap.prototype.readCharCode
  17906. };
  17907. return IdentityCMap;
  17908. })();
  17909. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17910. function fetchBinaryData(url) {
  17911. var nonBinaryRequest = PDFJS.disableWorker;
  17912. var request = new XMLHttpRequest();
  17913. request.open('GET', url, false);
  17914. if (!nonBinaryRequest) {
  17915. try {
  17916. request.responseType = 'arraybuffer';
  17917. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17918. } catch (e) {
  17919. nonBinaryRequest = true;
  17920. }
  17921. }
  17922. if (nonBinaryRequest && request.overrideMimeType) {
  17923. request.overrideMimeType('text/plain; charset=x-user-defined');
  17924. }
  17925. request.send(null);
  17926. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17927. error('Unable to get binary cMap at: ' + url);
  17928. }
  17929. if (nonBinaryRequest) {
  17930. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17931. return ch.charCodeAt(0) & 255;
  17932. });
  17933. return new Uint8Array(data);
  17934. }
  17935. return new Uint8Array(request.response);
  17936. }
  17937. function hexToInt(a, size) {
  17938. var n = 0;
  17939. for (var i = 0; i <= size; i++) {
  17940. n = (n << 8) | a[i];
  17941. }
  17942. return n >>> 0;
  17943. }
  17944. function hexToStr(a, size) {
  17945. // This code is hot. Special-case some common values to avoid creating an
  17946. // object with subarray().
  17947. if (size === 1) {
  17948. return String.fromCharCode(a[0], a[1]);
  17949. }
  17950. if (size === 3) {
  17951. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17952. }
  17953. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17954. }
  17955. function addHex(a, b, size) {
  17956. var c = 0;
  17957. for (var i = size; i >= 0; i--) {
  17958. c += a[i] + b[i];
  17959. a[i] = c & 255;
  17960. c >>= 8;
  17961. }
  17962. }
  17963. function incHex(a, size) {
  17964. var c = 1;
  17965. for (var i = size; i >= 0 && c > 0; i--) {
  17966. c += a[i];
  17967. a[i] = c & 255;
  17968. c >>= 8;
  17969. }
  17970. }
  17971. var MAX_NUM_SIZE = 16;
  17972. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17973. function BinaryCMapStream(data) {
  17974. this.buffer = data;
  17975. this.pos = 0;
  17976. this.end = data.length;
  17977. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17978. }
  17979. BinaryCMapStream.prototype = {
  17980. readByte: function () {
  17981. if (this.pos >= this.end) {
  17982. return -1;
  17983. }
  17984. return this.buffer[this.pos++];
  17985. },
  17986. readNumber: function () {
  17987. var n = 0;
  17988. var last;
  17989. do {
  17990. var b = this.readByte();
  17991. if (b < 0) {
  17992. error('unexpected EOF in bcmap');
  17993. }
  17994. last = !(b & 0x80);
  17995. n = (n << 7) | (b & 0x7F);
  17996. } while (!last);
  17997. return n;
  17998. },
  17999. readSigned: function () {
  18000. var n = this.readNumber();
  18001. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18002. },
  18003. readHex: function (num, size) {
  18004. num.set(this.buffer.subarray(this.pos,
  18005. this.pos + size + 1));
  18006. this.pos += size + 1;
  18007. },
  18008. readHexNumber: function (num, size) {
  18009. var last;
  18010. var stack = this.tmpBuf, sp = 0;
  18011. do {
  18012. var b = this.readByte();
  18013. if (b < 0) {
  18014. error('unexpected EOF in bcmap');
  18015. }
  18016. last = !(b & 0x80);
  18017. stack[sp++] = b & 0x7F;
  18018. } while (!last);
  18019. var i = size, buffer = 0, bufferSize = 0;
  18020. while (i >= 0) {
  18021. while (bufferSize < 8 && stack.length > 0) {
  18022. buffer = (stack[--sp] << bufferSize) | buffer;
  18023. bufferSize += 7;
  18024. }
  18025. num[i] = buffer & 255;
  18026. i--;
  18027. buffer >>= 8;
  18028. bufferSize -= 8;
  18029. }
  18030. },
  18031. readHexSigned: function (num, size) {
  18032. this.readHexNumber(num, size);
  18033. var sign = num[size] & 1 ? 255 : 0;
  18034. var c = 0;
  18035. for (var i = 0; i <= size; i++) {
  18036. c = ((c & 1) << 8) | num[i];
  18037. num[i] = (c >> 1) ^ sign;
  18038. }
  18039. },
  18040. readString: function () {
  18041. var len = this.readNumber();
  18042. var s = '';
  18043. for (var i = 0; i < len; i++) {
  18044. s += String.fromCharCode(this.readNumber());
  18045. }
  18046. return s;
  18047. }
  18048. };
  18049. function processBinaryCMap(url, cMap, extend) {
  18050. var data = fetchBinaryData(url);
  18051. var stream = new BinaryCMapStream(data);
  18052. var header = stream.readByte();
  18053. cMap.vertical = !!(header & 1);
  18054. var useCMap = null;
  18055. var start = new Uint8Array(MAX_NUM_SIZE);
  18056. var end = new Uint8Array(MAX_NUM_SIZE);
  18057. var char = new Uint8Array(MAX_NUM_SIZE);
  18058. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18059. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18060. var code;
  18061. var b;
  18062. while ((b = stream.readByte()) >= 0) {
  18063. var type = b >> 5;
  18064. if (type === 7) { // metadata, e.g. comment or usecmap
  18065. switch (b & 0x1F) {
  18066. case 0:
  18067. stream.readString(); // skipping comment
  18068. break;
  18069. case 1:
  18070. useCMap = stream.readString();
  18071. break;
  18072. }
  18073. continue;
  18074. }
  18075. var sequence = !!(b & 0x10);
  18076. var dataSize = b & 15;
  18077. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18078. var ucs2DataSize = 1;
  18079. var subitemsCount = stream.readNumber();
  18080. var i;
  18081. switch (type) {
  18082. case 0: // codespacerange
  18083. stream.readHex(start, dataSize);
  18084. stream.readHexNumber(end, dataSize);
  18085. addHex(end, start, dataSize);
  18086. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18087. hexToInt(end, dataSize));
  18088. for (i = 1; i < subitemsCount; i++) {
  18089. incHex(end, dataSize);
  18090. stream.readHexNumber(start, dataSize);
  18091. addHex(start, end, dataSize);
  18092. stream.readHexNumber(end, dataSize);
  18093. addHex(end, start, dataSize);
  18094. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18095. hexToInt(end, dataSize));
  18096. }
  18097. break;
  18098. case 1: // notdefrange
  18099. stream.readHex(start, dataSize);
  18100. stream.readHexNumber(end, dataSize);
  18101. addHex(end, start, dataSize);
  18102. code = stream.readNumber();
  18103. // undefined range, skipping
  18104. for (i = 1; i < subitemsCount; i++) {
  18105. incHex(end, dataSize);
  18106. stream.readHexNumber(start, dataSize);
  18107. addHex(start, end, dataSize);
  18108. stream.readHexNumber(end, dataSize);
  18109. addHex(end, start, dataSize);
  18110. code = stream.readNumber();
  18111. // nop
  18112. }
  18113. break;
  18114. case 2: // cidchar
  18115. stream.readHex(char, dataSize);
  18116. code = stream.readNumber();
  18117. cMap.mapOne(hexToInt(char, dataSize), code);
  18118. for (i = 1; i < subitemsCount; i++) {
  18119. incHex(char, dataSize);
  18120. if (!sequence) {
  18121. stream.readHexNumber(tmp, dataSize);
  18122. addHex(char, tmp, dataSize);
  18123. }
  18124. code = stream.readSigned() + (code + 1);
  18125. cMap.mapOne(hexToInt(char, dataSize), code);
  18126. }
  18127. break;
  18128. case 3: // cidrange
  18129. stream.readHex(start, dataSize);
  18130. stream.readHexNumber(end, dataSize);
  18131. addHex(end, start, dataSize);
  18132. code = stream.readNumber();
  18133. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18134. code);
  18135. for (i = 1; i < subitemsCount; i++) {
  18136. incHex(end, dataSize);
  18137. if (!sequence) {
  18138. stream.readHexNumber(start, dataSize);
  18139. addHex(start, end, dataSize);
  18140. } else {
  18141. start.set(end);
  18142. }
  18143. stream.readHexNumber(end, dataSize);
  18144. addHex(end, start, dataSize);
  18145. code = stream.readNumber();
  18146. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18147. code);
  18148. }
  18149. break;
  18150. case 4: // bfchar
  18151. stream.readHex(char, ucs2DataSize);
  18152. stream.readHex(charCode, dataSize);
  18153. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18154. hexToStr(charCode, dataSize));
  18155. for (i = 1; i < subitemsCount; i++) {
  18156. incHex(char, ucs2DataSize);
  18157. if (!sequence) {
  18158. stream.readHexNumber(tmp, ucs2DataSize);
  18159. addHex(char, tmp, ucs2DataSize);
  18160. }
  18161. incHex(charCode, dataSize);
  18162. stream.readHexSigned(tmp, dataSize);
  18163. addHex(charCode, tmp, dataSize);
  18164. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18165. hexToStr(charCode, dataSize));
  18166. }
  18167. break;
  18168. case 5: // bfrange
  18169. stream.readHex(start, ucs2DataSize);
  18170. stream.readHexNumber(end, ucs2DataSize);
  18171. addHex(end, start, ucs2DataSize);
  18172. stream.readHex(charCode, dataSize);
  18173. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18174. hexToInt(end, ucs2DataSize),
  18175. hexToStr(charCode, dataSize));
  18176. for (i = 1; i < subitemsCount; i++) {
  18177. incHex(end, ucs2DataSize);
  18178. if (!sequence) {
  18179. stream.readHexNumber(start, ucs2DataSize);
  18180. addHex(start, end, ucs2DataSize);
  18181. } else {
  18182. start.set(end);
  18183. }
  18184. stream.readHexNumber(end, ucs2DataSize);
  18185. addHex(end, start, ucs2DataSize);
  18186. stream.readHex(charCode, dataSize);
  18187. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18188. hexToInt(end, ucs2DataSize),
  18189. hexToStr(charCode, dataSize));
  18190. }
  18191. break;
  18192. default:
  18193. error('Unknown type: ' + type);
  18194. break;
  18195. }
  18196. }
  18197. if (useCMap) {
  18198. extend(useCMap);
  18199. }
  18200. return cMap;
  18201. }
  18202. function BinaryCMapReader() {}
  18203. BinaryCMapReader.prototype = {
  18204. read: processBinaryCMap
  18205. };
  18206. return BinaryCMapReader;
  18207. })();
  18208. var CMapFactory = (function CMapFactoryClosure() {
  18209. function strToInt(str) {
  18210. var a = 0;
  18211. for (var i = 0; i < str.length; i++) {
  18212. a = (a << 8) | str.charCodeAt(i);
  18213. }
  18214. return a >>> 0;
  18215. }
  18216. function expectString(obj) {
  18217. if (!isString(obj)) {
  18218. error('Malformed CMap: expected string.');
  18219. }
  18220. }
  18221. function expectInt(obj) {
  18222. if (!isInt(obj)) {
  18223. error('Malformed CMap: expected int.');
  18224. }
  18225. }
  18226. function parseBfChar(cMap, lexer) {
  18227. while (true) {
  18228. var obj = lexer.getObj();
  18229. if (isEOF(obj)) {
  18230. break;
  18231. }
  18232. if (isCmd(obj, 'endbfchar')) {
  18233. return;
  18234. }
  18235. expectString(obj);
  18236. var src = strToInt(obj);
  18237. obj = lexer.getObj();
  18238. // TODO are /dstName used?
  18239. expectString(obj);
  18240. var dst = obj;
  18241. cMap.mapOne(src, dst);
  18242. }
  18243. }
  18244. function parseBfRange(cMap, lexer) {
  18245. while (true) {
  18246. var obj = lexer.getObj();
  18247. if (isEOF(obj)) {
  18248. break;
  18249. }
  18250. if (isCmd(obj, 'endbfrange')) {
  18251. return;
  18252. }
  18253. expectString(obj);
  18254. var low = strToInt(obj);
  18255. obj = lexer.getObj();
  18256. expectString(obj);
  18257. var high = strToInt(obj);
  18258. obj = lexer.getObj();
  18259. if (isInt(obj) || isString(obj)) {
  18260. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18261. cMap.mapBfRange(low, high, dstLow);
  18262. } else if (isCmd(obj, '[')) {
  18263. obj = lexer.getObj();
  18264. var array = [];
  18265. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18266. array.push(obj);
  18267. obj = lexer.getObj();
  18268. }
  18269. cMap.mapBfRangeToArray(low, high, array);
  18270. } else {
  18271. break;
  18272. }
  18273. }
  18274. error('Invalid bf range.');
  18275. }
  18276. function parseCidChar(cMap, lexer) {
  18277. while (true) {
  18278. var obj = lexer.getObj();
  18279. if (isEOF(obj)) {
  18280. break;
  18281. }
  18282. if (isCmd(obj, 'endcidchar')) {
  18283. return;
  18284. }
  18285. expectString(obj);
  18286. var src = strToInt(obj);
  18287. obj = lexer.getObj();
  18288. expectInt(obj);
  18289. var dst = obj;
  18290. cMap.mapOne(src, dst);
  18291. }
  18292. }
  18293. function parseCidRange(cMap, lexer) {
  18294. while (true) {
  18295. var obj = lexer.getObj();
  18296. if (isEOF(obj)) {
  18297. break;
  18298. }
  18299. if (isCmd(obj, 'endcidrange')) {
  18300. return;
  18301. }
  18302. expectString(obj);
  18303. var low = strToInt(obj);
  18304. obj = lexer.getObj();
  18305. expectString(obj);
  18306. var high = strToInt(obj);
  18307. obj = lexer.getObj();
  18308. expectInt(obj);
  18309. var dstLow = obj;
  18310. cMap.mapCidRange(low, high, dstLow);
  18311. }
  18312. }
  18313. function parseCodespaceRange(cMap, lexer) {
  18314. while (true) {
  18315. var obj = lexer.getObj();
  18316. if (isEOF(obj)) {
  18317. break;
  18318. }
  18319. if (isCmd(obj, 'endcodespacerange')) {
  18320. return;
  18321. }
  18322. if (!isString(obj)) {
  18323. break;
  18324. }
  18325. var low = strToInt(obj);
  18326. obj = lexer.getObj();
  18327. if (!isString(obj)) {
  18328. break;
  18329. }
  18330. var high = strToInt(obj);
  18331. cMap.addCodespaceRange(obj.length, low, high);
  18332. }
  18333. error('Invalid codespace range.');
  18334. }
  18335. function parseWMode(cMap, lexer) {
  18336. var obj = lexer.getObj();
  18337. if (isInt(obj)) {
  18338. cMap.vertical = !!obj;
  18339. }
  18340. }
  18341. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18342. var previous;
  18343. var embededUseCMap;
  18344. objLoop: while (true) {
  18345. var obj = lexer.getObj();
  18346. if (isEOF(obj)) {
  18347. break;
  18348. } else if (isName(obj)) {
  18349. if (obj.name === 'WMode') {
  18350. parseWMode(cMap, lexer);
  18351. }
  18352. previous = obj;
  18353. } else if (isCmd(obj)) {
  18354. switch (obj.cmd) {
  18355. case 'endcmap':
  18356. break objLoop;
  18357. case 'usecmap':
  18358. if (isName(previous)) {
  18359. embededUseCMap = previous.name;
  18360. }
  18361. break;
  18362. case 'begincodespacerange':
  18363. parseCodespaceRange(cMap, lexer);
  18364. break;
  18365. case 'beginbfchar':
  18366. parseBfChar(cMap, lexer);
  18367. break;
  18368. case 'begincidchar':
  18369. parseCidChar(cMap, lexer);
  18370. break;
  18371. case 'beginbfrange':
  18372. parseBfRange(cMap, lexer);
  18373. break;
  18374. case 'begincidrange':
  18375. parseCidRange(cMap, lexer);
  18376. break;
  18377. }
  18378. }
  18379. }
  18380. if (!useCMap && embededUseCMap) {
  18381. // Load the usecmap definition from the file only if there wasn't one
  18382. // specified.
  18383. useCMap = embededUseCMap;
  18384. }
  18385. if (useCMap) {
  18386. extendCMap(cMap, builtInCMapParams, useCMap);
  18387. }
  18388. }
  18389. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18390. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18391. // If there aren't any code space ranges defined clone all the parent ones
  18392. // into this cMap.
  18393. if (cMap.numCodespaceRanges === 0) {
  18394. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18395. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18396. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18397. }
  18398. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18399. }
  18400. // Merge the map into the current one, making sure not to override
  18401. // any previously defined entries.
  18402. cMap.useCMap.forEach(function(key, value) {
  18403. if (!cMap.contains(key)) {
  18404. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18405. }
  18406. });
  18407. }
  18408. function parseBinaryCMap(name, builtInCMapParams) {
  18409. var url = builtInCMapParams.url + name + '.bcmap';
  18410. var cMap = new CMap(true);
  18411. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18412. extendCMap(cMap, builtInCMapParams, useCMap);
  18413. });
  18414. return cMap;
  18415. }
  18416. function createBuiltInCMap(name, builtInCMapParams) {
  18417. if (name === 'Identity-H') {
  18418. return new IdentityCMap(false, 2);
  18419. } else if (name === 'Identity-V') {
  18420. return new IdentityCMap(true, 2);
  18421. }
  18422. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18423. error('Unknown cMap name: ' + name);
  18424. }
  18425. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18426. if (builtInCMapParams.packed) {
  18427. return parseBinaryCMap(name, builtInCMapParams);
  18428. }
  18429. var request = new XMLHttpRequest();
  18430. var url = builtInCMapParams.url + name;
  18431. request.open('GET', url, false);
  18432. request.send(null);
  18433. if (!request.responseText) {
  18434. error('Unable to get cMap at: ' + url);
  18435. }
  18436. var cMap = new CMap(true);
  18437. var lexer = new Lexer(new StringStream(request.responseText));
  18438. parseCMap(cMap, lexer, builtInCMapParams, null);
  18439. return cMap;
  18440. }
  18441. return {
  18442. create: function (encoding, builtInCMapParams, useCMap) {
  18443. if (isName(encoding)) {
  18444. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18445. } else if (isStream(encoding)) {
  18446. var cMap = new CMap();
  18447. var lexer = new Lexer(encoding);
  18448. try {
  18449. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18450. } catch (e) {
  18451. warn('Invalid CMap data. ' + e);
  18452. }
  18453. return cMap;
  18454. }
  18455. error('Encoding required.');
  18456. }
  18457. };
  18458. })();
  18459. // Unicode Private Use Area
  18460. var PRIVATE_USE_OFFSET_START = 0xE000;
  18461. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18462. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18463. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18464. // except for Type 3 fonts
  18465. var PDF_GLYPH_SPACE_UNITS = 1000;
  18466. // Hinting is currently disabled due to unknown problems on windows
  18467. // in tracemonkey and various other pdfs with type1 fonts.
  18468. var HINTING_ENABLED = false;
  18469. // Accented charactars are not displayed properly on windows, using this flag
  18470. // to control analysis of seac charstrings.
  18471. var SEAC_ANALYSIS_ENABLED = false;
  18472. var FontFlags = {
  18473. FixedPitch: 1,
  18474. Serif: 2,
  18475. Symbolic: 4,
  18476. Script: 8,
  18477. Nonsymbolic: 32,
  18478. Italic: 64,
  18479. AllCap: 65536,
  18480. SmallCap: 131072,
  18481. ForceBold: 262144
  18482. };
  18483. var Encodings = {
  18484. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18485. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18486. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18487. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18488. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18489. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18490. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18491. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18492. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18493. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18494. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18495. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18496. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18497. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18498. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18499. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18500. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18501. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18502. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18503. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18504. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18505. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18506. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18507. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18508. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18509. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18510. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18511. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18512. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18513. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18514. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18515. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18516. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18517. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18518. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18519. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18520. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18521. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18522. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18523. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18524. 'Ydieresissmall'],
  18525. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18526. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18527. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18528. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18529. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18530. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18531. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18532. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18533. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18534. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18535. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18536. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18537. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18538. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18539. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18540. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18541. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18542. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18543. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18544. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18545. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18546. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18547. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18548. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18549. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18550. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18551. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18552. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18553. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18554. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18555. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18556. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18557. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18558. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18559. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18560. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18561. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18562. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18563. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18564. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18565. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18566. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18567. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18568. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18569. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18570. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18571. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18572. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18573. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18574. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18575. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18576. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18577. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18578. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18579. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18580. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18581. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18582. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18583. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18584. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18585. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18586. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18587. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18588. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18589. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18590. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18591. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18592. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18593. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18594. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18595. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18596. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18597. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18598. 'ogonek', 'caron'],
  18599. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18600. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18601. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18602. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18603. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18604. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18605. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18606. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18607. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18608. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18609. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18610. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18611. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18612. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18613. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18614. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18615. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18616. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18617. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18618. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18619. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18620. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18621. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18622. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18623. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18624. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18625. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18626. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18627. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18628. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18629. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18630. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18631. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18632. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18633. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18634. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18635. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18636. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18637. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18638. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18639. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18640. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18641. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18642. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18643. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18644. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18645. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18646. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18647. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18648. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18649. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18650. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18651. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18652. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18653. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18654. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18655. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18656. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18657. 'ydieresis'],
  18658. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18659. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18660. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18661. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18662. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18663. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18664. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18665. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18666. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18667. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18668. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18669. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18670. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18671. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18672. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18673. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18674. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18675. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18676. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18677. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18678. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18679. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18680. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18681. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18682. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18683. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18684. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18685. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18686. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18687. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18688. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18689. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18690. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18691. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18692. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18693. 'bracerightbt'],
  18694. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18695. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18696. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18697. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18698. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18699. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18700. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18701. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18702. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18703. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18704. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18705. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18706. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18707. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18708. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18709. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18710. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18711. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18712. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18713. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18714. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18715. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18716. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18717. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18718. };
  18719. /**
  18720. * Hold a map of decoded fonts and of the standard fourteen Type1
  18721. * fonts and their acronyms.
  18722. */
  18723. var stdFontMap = {
  18724. 'ArialNarrow': 'Helvetica',
  18725. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18726. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18727. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18728. 'ArialBlack': 'Helvetica',
  18729. 'ArialBlack-Bold': 'Helvetica-Bold',
  18730. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18731. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18732. 'Arial': 'Helvetica',
  18733. 'Arial-Bold': 'Helvetica-Bold',
  18734. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18735. 'Arial-Italic': 'Helvetica-Oblique',
  18736. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18737. 'Arial-BoldMT': 'Helvetica-Bold',
  18738. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18739. 'ArialMT': 'Helvetica',
  18740. 'Courier-Bold': 'Courier-Bold',
  18741. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18742. 'Courier-Italic': 'Courier-Oblique',
  18743. 'CourierNew': 'Courier',
  18744. 'CourierNew-Bold': 'Courier-Bold',
  18745. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18746. 'CourierNew-Italic': 'Courier-Oblique',
  18747. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18748. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18749. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18750. 'CourierNewPSMT': 'Courier',
  18751. 'Helvetica': 'Helvetica',
  18752. 'Helvetica-Bold': 'Helvetica-Bold',
  18753. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18754. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18755. 'Helvetica-Italic': 'Helvetica-Oblique',
  18756. 'Helvetica-Oblique':'Helvetica-Oblique',
  18757. 'Symbol-Bold': 'Symbol',
  18758. 'Symbol-BoldItalic': 'Symbol',
  18759. 'Symbol-Italic': 'Symbol',
  18760. 'TimesNewRoman': 'Times-Roman',
  18761. 'TimesNewRoman-Bold': 'Times-Bold',
  18762. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18763. 'TimesNewRoman-Italic': 'Times-Italic',
  18764. 'TimesNewRomanPS': 'Times-Roman',
  18765. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18766. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18767. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18768. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18769. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18770. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18771. 'TimesNewRomanPSMT': 'Times-Roman',
  18772. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18773. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18774. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18775. };
  18776. /**
  18777. * Holds the map of the non-standard fonts that might be included as a standard
  18778. * fonts without glyph data.
  18779. */
  18780. var nonStdFontMap = {
  18781. 'CenturyGothic': 'Helvetica',
  18782. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18783. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18784. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18785. 'ComicSansMS': 'Comic Sans MS',
  18786. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18787. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18788. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18789. 'LucidaConsole': 'Courier',
  18790. 'LucidaConsole-Bold': 'Courier-Bold',
  18791. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18792. 'LucidaConsole-Italic': 'Courier-Oblique',
  18793. 'MS-Gothic': 'MS Gothic',
  18794. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18795. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18796. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18797. 'MS-Mincho': 'MS Mincho',
  18798. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18799. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18800. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18801. 'MS-PGothic': 'MS PGothic',
  18802. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18803. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18804. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18805. 'MS-PMincho': 'MS PMincho',
  18806. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18807. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18808. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18809. 'Wingdings': 'ZapfDingbats'
  18810. };
  18811. var serifFonts = {
  18812. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18813. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18814. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18815. 'Arno': true, 'Aster': true, 'Aurora': true,
  18816. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18817. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18818. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18819. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18820. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18821. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18822. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18823. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18824. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18825. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18826. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18827. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18828. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18829. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18830. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18831. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18832. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18833. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18834. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18835. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18836. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18837. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18838. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18839. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18840. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18841. 'Miller': true, 'Minion': true, 'Modern': true,
  18842. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18843. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18844. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18845. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18846. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18847. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18848. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18849. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18850. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18851. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18852. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18853. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18854. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18855. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18856. };
  18857. var symbolsFonts = {
  18858. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18859. };
  18860. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18861. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18862. // glyphs, but common for some set of the standard fonts.
  18863. var GlyphMapForStandardFonts = {
  18864. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18865. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18866. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18867. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18868. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18869. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18870. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18871. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18872. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18873. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18874. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18875. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18876. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18877. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18878. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18879. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18880. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18881. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18882. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18883. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18884. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18885. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18886. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18887. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18888. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18889. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18890. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18891. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18892. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18893. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18894. '298': 380, '305': 963,
  18895. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18896. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18897. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18898. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18899. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18900. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18901. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18902. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18903. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18904. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18905. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18906. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18907. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18908. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18909. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18910. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18911. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18912. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18913. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18914. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18915. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18916. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18917. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18918. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18919. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18920. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18921. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18922. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18923. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18924. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18925. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18926. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18927. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18928. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18929. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18930. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18931. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18932. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18933. };
  18934. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18935. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18936. // to the similar equivalents in the normal characters range.
  18937. var SpecialPUASymbols = {
  18938. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18939. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18940. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18941. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18942. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18943. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18944. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18945. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18946. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18947. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18948. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18949. '63742': 0x23AD, // bracerightbt (0xF8FE)
  18950. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18951. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18952. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18953. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18954. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18955. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18956. '63723': 0x239B, // parenlefttp (0xF8EB)
  18957. '63724': 0x239C, // parenleftex (0xF8EC)
  18958. '63725': 0x239D, // parenleftbt (0xF8ED)
  18959. '63734': 0x239E, // parenrighttp (0xF8F6)
  18960. '63735': 0x239F, // parenrightex (0xF8F7)
  18961. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18962. };
  18963. function mapSpecialUnicodeValues(code) {
  18964. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18965. return 0;
  18966. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18967. return (SpecialPUASymbols[code] || code);
  18968. }
  18969. return code;
  18970. }
  18971. var UnicodeRanges = [
  18972. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18973. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18974. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18975. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18976. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18977. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18978. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18979. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18980. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18981. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18982. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18983. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18984. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18985. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18986. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18987. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18988. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18989. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18990. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18991. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18992. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18993. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18994. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18995. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18996. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18997. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18998. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18999. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19000. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19001. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19002. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19003. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19004. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19005. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19006. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19007. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19008. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19009. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19010. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19011. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19012. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19013. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19014. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19015. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19016. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19017. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19018. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19019. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19020. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19021. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19022. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19023. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19024. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19025. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19026. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19027. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19028. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19029. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19030. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19031. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19032. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19033. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19034. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19035. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19036. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19037. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19038. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19039. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19040. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19041. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19042. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19043. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19044. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19045. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19046. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19047. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19048. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19049. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19050. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19051. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19052. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19053. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19054. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19055. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19056. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19057. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19058. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19059. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19060. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19061. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19062. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19063. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19064. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19065. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19066. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19067. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19068. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19069. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19070. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19071. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19072. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19073. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19074. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19075. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19076. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19077. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19078. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19079. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19080. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19081. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19082. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19083. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19084. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19085. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19086. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19087. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19088. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19089. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19090. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19091. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19092. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19093. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19094. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19095. ];
  19096. var MacStandardGlyphOrdering = [
  19097. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19098. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19099. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19100. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19101. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19102. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19103. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19104. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19105. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19106. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19107. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19108. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19109. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19110. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19111. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19112. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19113. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19114. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19115. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19116. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19117. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19118. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19119. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19120. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19121. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19122. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19123. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19124. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19125. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19126. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19127. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19128. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19129. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19130. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19131. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19132. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19133. function getUnicodeRangeFor(value) {
  19134. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19135. var range = UnicodeRanges[i];
  19136. if (value >= range.begin && value < range.end) {
  19137. return i;
  19138. }
  19139. }
  19140. return -1;
  19141. }
  19142. function isRTLRangeFor(value) {
  19143. var range = UnicodeRanges[13];
  19144. if (value >= range.begin && value < range.end) {
  19145. return true;
  19146. }
  19147. range = UnicodeRanges[11];
  19148. if (value >= range.begin && value < range.end) {
  19149. return true;
  19150. }
  19151. return false;
  19152. }
  19153. // The normalization table is obtained by filtering the Unicode characters
  19154. // database with <compat> entries.
  19155. var NormalizedUnicodes = {
  19156. '\u00A8': '\u0020\u0308',
  19157. '\u00AF': '\u0020\u0304',
  19158. '\u00B4': '\u0020\u0301',
  19159. '\u00B5': '\u03BC',
  19160. '\u00B8': '\u0020\u0327',
  19161. '\u0132': '\u0049\u004A',
  19162. '\u0133': '\u0069\u006A',
  19163. '\u013F': '\u004C\u00B7',
  19164. '\u0140': '\u006C\u00B7',
  19165. '\u0149': '\u02BC\u006E',
  19166. '\u017F': '\u0073',
  19167. '\u01C4': '\u0044\u017D',
  19168. '\u01C5': '\u0044\u017E',
  19169. '\u01C6': '\u0064\u017E',
  19170. '\u01C7': '\u004C\u004A',
  19171. '\u01C8': '\u004C\u006A',
  19172. '\u01C9': '\u006C\u006A',
  19173. '\u01CA': '\u004E\u004A',
  19174. '\u01CB': '\u004E\u006A',
  19175. '\u01CC': '\u006E\u006A',
  19176. '\u01F1': '\u0044\u005A',
  19177. '\u01F2': '\u0044\u007A',
  19178. '\u01F3': '\u0064\u007A',
  19179. '\u02D8': '\u0020\u0306',
  19180. '\u02D9': '\u0020\u0307',
  19181. '\u02DA': '\u0020\u030A',
  19182. '\u02DB': '\u0020\u0328',
  19183. '\u02DC': '\u0020\u0303',
  19184. '\u02DD': '\u0020\u030B',
  19185. '\u037A': '\u0020\u0345',
  19186. '\u0384': '\u0020\u0301',
  19187. '\u03D0': '\u03B2',
  19188. '\u03D1': '\u03B8',
  19189. '\u03D2': '\u03A5',
  19190. '\u03D5': '\u03C6',
  19191. '\u03D6': '\u03C0',
  19192. '\u03F0': '\u03BA',
  19193. '\u03F1': '\u03C1',
  19194. '\u03F2': '\u03C2',
  19195. '\u03F4': '\u0398',
  19196. '\u03F5': '\u03B5',
  19197. '\u03F9': '\u03A3',
  19198. '\u0587': '\u0565\u0582',
  19199. '\u0675': '\u0627\u0674',
  19200. '\u0676': '\u0648\u0674',
  19201. '\u0677': '\u06C7\u0674',
  19202. '\u0678': '\u064A\u0674',
  19203. '\u0E33': '\u0E4D\u0E32',
  19204. '\u0EB3': '\u0ECD\u0EB2',
  19205. '\u0EDC': '\u0EAB\u0E99',
  19206. '\u0EDD': '\u0EAB\u0EA1',
  19207. '\u0F77': '\u0FB2\u0F81',
  19208. '\u0F79': '\u0FB3\u0F81',
  19209. '\u1E9A': '\u0061\u02BE',
  19210. '\u1FBD': '\u0020\u0313',
  19211. '\u1FBF': '\u0020\u0313',
  19212. '\u1FC0': '\u0020\u0342',
  19213. '\u1FFE': '\u0020\u0314',
  19214. '\u2002': '\u0020',
  19215. '\u2003': '\u0020',
  19216. '\u2004': '\u0020',
  19217. '\u2005': '\u0020',
  19218. '\u2006': '\u0020',
  19219. '\u2008': '\u0020',
  19220. '\u2009': '\u0020',
  19221. '\u200A': '\u0020',
  19222. '\u2017': '\u0020\u0333',
  19223. '\u2024': '\u002E',
  19224. '\u2025': '\u002E\u002E',
  19225. '\u2026': '\u002E\u002E\u002E',
  19226. '\u2033': '\u2032\u2032',
  19227. '\u2034': '\u2032\u2032\u2032',
  19228. '\u2036': '\u2035\u2035',
  19229. '\u2037': '\u2035\u2035\u2035',
  19230. '\u203C': '\u0021\u0021',
  19231. '\u203E': '\u0020\u0305',
  19232. '\u2047': '\u003F\u003F',
  19233. '\u2048': '\u003F\u0021',
  19234. '\u2049': '\u0021\u003F',
  19235. '\u2057': '\u2032\u2032\u2032\u2032',
  19236. '\u205F': '\u0020',
  19237. '\u20A8': '\u0052\u0073',
  19238. '\u2100': '\u0061\u002F\u0063',
  19239. '\u2101': '\u0061\u002F\u0073',
  19240. '\u2103': '\u00B0\u0043',
  19241. '\u2105': '\u0063\u002F\u006F',
  19242. '\u2106': '\u0063\u002F\u0075',
  19243. '\u2107': '\u0190',
  19244. '\u2109': '\u00B0\u0046',
  19245. '\u2116': '\u004E\u006F',
  19246. '\u2121': '\u0054\u0045\u004C',
  19247. '\u2135': '\u05D0',
  19248. '\u2136': '\u05D1',
  19249. '\u2137': '\u05D2',
  19250. '\u2138': '\u05D3',
  19251. '\u213B': '\u0046\u0041\u0058',
  19252. '\u2160': '\u0049',
  19253. '\u2161': '\u0049\u0049',
  19254. '\u2162': '\u0049\u0049\u0049',
  19255. '\u2163': '\u0049\u0056',
  19256. '\u2164': '\u0056',
  19257. '\u2165': '\u0056\u0049',
  19258. '\u2166': '\u0056\u0049\u0049',
  19259. '\u2167': '\u0056\u0049\u0049\u0049',
  19260. '\u2168': '\u0049\u0058',
  19261. '\u2169': '\u0058',
  19262. '\u216A': '\u0058\u0049',
  19263. '\u216B': '\u0058\u0049\u0049',
  19264. '\u216C': '\u004C',
  19265. '\u216D': '\u0043',
  19266. '\u216E': '\u0044',
  19267. '\u216F': '\u004D',
  19268. '\u2170': '\u0069',
  19269. '\u2171': '\u0069\u0069',
  19270. '\u2172': '\u0069\u0069\u0069',
  19271. '\u2173': '\u0069\u0076',
  19272. '\u2174': '\u0076',
  19273. '\u2175': '\u0076\u0069',
  19274. '\u2176': '\u0076\u0069\u0069',
  19275. '\u2177': '\u0076\u0069\u0069\u0069',
  19276. '\u2178': '\u0069\u0078',
  19277. '\u2179': '\u0078',
  19278. '\u217A': '\u0078\u0069',
  19279. '\u217B': '\u0078\u0069\u0069',
  19280. '\u217C': '\u006C',
  19281. '\u217D': '\u0063',
  19282. '\u217E': '\u0064',
  19283. '\u217F': '\u006D',
  19284. '\u222C': '\u222B\u222B',
  19285. '\u222D': '\u222B\u222B\u222B',
  19286. '\u222F': '\u222E\u222E',
  19287. '\u2230': '\u222E\u222E\u222E',
  19288. '\u2474': '\u0028\u0031\u0029',
  19289. '\u2475': '\u0028\u0032\u0029',
  19290. '\u2476': '\u0028\u0033\u0029',
  19291. '\u2477': '\u0028\u0034\u0029',
  19292. '\u2478': '\u0028\u0035\u0029',
  19293. '\u2479': '\u0028\u0036\u0029',
  19294. '\u247A': '\u0028\u0037\u0029',
  19295. '\u247B': '\u0028\u0038\u0029',
  19296. '\u247C': '\u0028\u0039\u0029',
  19297. '\u247D': '\u0028\u0031\u0030\u0029',
  19298. '\u247E': '\u0028\u0031\u0031\u0029',
  19299. '\u247F': '\u0028\u0031\u0032\u0029',
  19300. '\u2480': '\u0028\u0031\u0033\u0029',
  19301. '\u2481': '\u0028\u0031\u0034\u0029',
  19302. '\u2482': '\u0028\u0031\u0035\u0029',
  19303. '\u2483': '\u0028\u0031\u0036\u0029',
  19304. '\u2484': '\u0028\u0031\u0037\u0029',
  19305. '\u2485': '\u0028\u0031\u0038\u0029',
  19306. '\u2486': '\u0028\u0031\u0039\u0029',
  19307. '\u2487': '\u0028\u0032\u0030\u0029',
  19308. '\u2488': '\u0031\u002E',
  19309. '\u2489': '\u0032\u002E',
  19310. '\u248A': '\u0033\u002E',
  19311. '\u248B': '\u0034\u002E',
  19312. '\u248C': '\u0035\u002E',
  19313. '\u248D': '\u0036\u002E',
  19314. '\u248E': '\u0037\u002E',
  19315. '\u248F': '\u0038\u002E',
  19316. '\u2490': '\u0039\u002E',
  19317. '\u2491': '\u0031\u0030\u002E',
  19318. '\u2492': '\u0031\u0031\u002E',
  19319. '\u2493': '\u0031\u0032\u002E',
  19320. '\u2494': '\u0031\u0033\u002E',
  19321. '\u2495': '\u0031\u0034\u002E',
  19322. '\u2496': '\u0031\u0035\u002E',
  19323. '\u2497': '\u0031\u0036\u002E',
  19324. '\u2498': '\u0031\u0037\u002E',
  19325. '\u2499': '\u0031\u0038\u002E',
  19326. '\u249A': '\u0031\u0039\u002E',
  19327. '\u249B': '\u0032\u0030\u002E',
  19328. '\u249C': '\u0028\u0061\u0029',
  19329. '\u249D': '\u0028\u0062\u0029',
  19330. '\u249E': '\u0028\u0063\u0029',
  19331. '\u249F': '\u0028\u0064\u0029',
  19332. '\u24A0': '\u0028\u0065\u0029',
  19333. '\u24A1': '\u0028\u0066\u0029',
  19334. '\u24A2': '\u0028\u0067\u0029',
  19335. '\u24A3': '\u0028\u0068\u0029',
  19336. '\u24A4': '\u0028\u0069\u0029',
  19337. '\u24A5': '\u0028\u006A\u0029',
  19338. '\u24A6': '\u0028\u006B\u0029',
  19339. '\u24A7': '\u0028\u006C\u0029',
  19340. '\u24A8': '\u0028\u006D\u0029',
  19341. '\u24A9': '\u0028\u006E\u0029',
  19342. '\u24AA': '\u0028\u006F\u0029',
  19343. '\u24AB': '\u0028\u0070\u0029',
  19344. '\u24AC': '\u0028\u0071\u0029',
  19345. '\u24AD': '\u0028\u0072\u0029',
  19346. '\u24AE': '\u0028\u0073\u0029',
  19347. '\u24AF': '\u0028\u0074\u0029',
  19348. '\u24B0': '\u0028\u0075\u0029',
  19349. '\u24B1': '\u0028\u0076\u0029',
  19350. '\u24B2': '\u0028\u0077\u0029',
  19351. '\u24B3': '\u0028\u0078\u0029',
  19352. '\u24B4': '\u0028\u0079\u0029',
  19353. '\u24B5': '\u0028\u007A\u0029',
  19354. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19355. '\u2A74': '\u003A\u003A\u003D',
  19356. '\u2A75': '\u003D\u003D',
  19357. '\u2A76': '\u003D\u003D\u003D',
  19358. '\u2E9F': '\u6BCD',
  19359. '\u2EF3': '\u9F9F',
  19360. '\u2F00': '\u4E00',
  19361. '\u2F01': '\u4E28',
  19362. '\u2F02': '\u4E36',
  19363. '\u2F03': '\u4E3F',
  19364. '\u2F04': '\u4E59',
  19365. '\u2F05': '\u4E85',
  19366. '\u2F06': '\u4E8C',
  19367. '\u2F07': '\u4EA0',
  19368. '\u2F08': '\u4EBA',
  19369. '\u2F09': '\u513F',
  19370. '\u2F0A': '\u5165',
  19371. '\u2F0B': '\u516B',
  19372. '\u2F0C': '\u5182',
  19373. '\u2F0D': '\u5196',
  19374. '\u2F0E': '\u51AB',
  19375. '\u2F0F': '\u51E0',
  19376. '\u2F10': '\u51F5',
  19377. '\u2F11': '\u5200',
  19378. '\u2F12': '\u529B',
  19379. '\u2F13': '\u52F9',
  19380. '\u2F14': '\u5315',
  19381. '\u2F15': '\u531A',
  19382. '\u2F16': '\u5338',
  19383. '\u2F17': '\u5341',
  19384. '\u2F18': '\u535C',
  19385. '\u2F19': '\u5369',
  19386. '\u2F1A': '\u5382',
  19387. '\u2F1B': '\u53B6',
  19388. '\u2F1C': '\u53C8',
  19389. '\u2F1D': '\u53E3',
  19390. '\u2F1E': '\u56D7',
  19391. '\u2F1F': '\u571F',
  19392. '\u2F20': '\u58EB',
  19393. '\u2F21': '\u5902',
  19394. '\u2F22': '\u590A',
  19395. '\u2F23': '\u5915',
  19396. '\u2F24': '\u5927',
  19397. '\u2F25': '\u5973',
  19398. '\u2F26': '\u5B50',
  19399. '\u2F27': '\u5B80',
  19400. '\u2F28': '\u5BF8',
  19401. '\u2F29': '\u5C0F',
  19402. '\u2F2A': '\u5C22',
  19403. '\u2F2B': '\u5C38',
  19404. '\u2F2C': '\u5C6E',
  19405. '\u2F2D': '\u5C71',
  19406. '\u2F2E': '\u5DDB',
  19407. '\u2F2F': '\u5DE5',
  19408. '\u2F30': '\u5DF1',
  19409. '\u2F31': '\u5DFE',
  19410. '\u2F32': '\u5E72',
  19411. '\u2F33': '\u5E7A',
  19412. '\u2F34': '\u5E7F',
  19413. '\u2F35': '\u5EF4',
  19414. '\u2F36': '\u5EFE',
  19415. '\u2F37': '\u5F0B',
  19416. '\u2F38': '\u5F13',
  19417. '\u2F39': '\u5F50',
  19418. '\u2F3A': '\u5F61',
  19419. '\u2F3B': '\u5F73',
  19420. '\u2F3C': '\u5FC3',
  19421. '\u2F3D': '\u6208',
  19422. '\u2F3E': '\u6236',
  19423. '\u2F3F': '\u624B',
  19424. '\u2F40': '\u652F',
  19425. '\u2F41': '\u6534',
  19426. '\u2F42': '\u6587',
  19427. '\u2F43': '\u6597',
  19428. '\u2F44': '\u65A4',
  19429. '\u2F45': '\u65B9',
  19430. '\u2F46': '\u65E0',
  19431. '\u2F47': '\u65E5',
  19432. '\u2F48': '\u66F0',
  19433. '\u2F49': '\u6708',
  19434. '\u2F4A': '\u6728',
  19435. '\u2F4B': '\u6B20',
  19436. '\u2F4C': '\u6B62',
  19437. '\u2F4D': '\u6B79',
  19438. '\u2F4E': '\u6BB3',
  19439. '\u2F4F': '\u6BCB',
  19440. '\u2F50': '\u6BD4',
  19441. '\u2F51': '\u6BDB',
  19442. '\u2F52': '\u6C0F',
  19443. '\u2F53': '\u6C14',
  19444. '\u2F54': '\u6C34',
  19445. '\u2F55': '\u706B',
  19446. '\u2F56': '\u722A',
  19447. '\u2F57': '\u7236',
  19448. '\u2F58': '\u723B',
  19449. '\u2F59': '\u723F',
  19450. '\u2F5A': '\u7247',
  19451. '\u2F5B': '\u7259',
  19452. '\u2F5C': '\u725B',
  19453. '\u2F5D': '\u72AC',
  19454. '\u2F5E': '\u7384',
  19455. '\u2F5F': '\u7389',
  19456. '\u2F60': '\u74DC',
  19457. '\u2F61': '\u74E6',
  19458. '\u2F62': '\u7518',
  19459. '\u2F63': '\u751F',
  19460. '\u2F64': '\u7528',
  19461. '\u2F65': '\u7530',
  19462. '\u2F66': '\u758B',
  19463. '\u2F67': '\u7592',
  19464. '\u2F68': '\u7676',
  19465. '\u2F69': '\u767D',
  19466. '\u2F6A': '\u76AE',
  19467. '\u2F6B': '\u76BF',
  19468. '\u2F6C': '\u76EE',
  19469. '\u2F6D': '\u77DB',
  19470. '\u2F6E': '\u77E2',
  19471. '\u2F6F': '\u77F3',
  19472. '\u2F70': '\u793A',
  19473. '\u2F71': '\u79B8',
  19474. '\u2F72': '\u79BE',
  19475. '\u2F73': '\u7A74',
  19476. '\u2F74': '\u7ACB',
  19477. '\u2F75': '\u7AF9',
  19478. '\u2F76': '\u7C73',
  19479. '\u2F77': '\u7CF8',
  19480. '\u2F78': '\u7F36',
  19481. '\u2F79': '\u7F51',
  19482. '\u2F7A': '\u7F8A',
  19483. '\u2F7B': '\u7FBD',
  19484. '\u2F7C': '\u8001',
  19485. '\u2F7D': '\u800C',
  19486. '\u2F7E': '\u8012',
  19487. '\u2F7F': '\u8033',
  19488. '\u2F80': '\u807F',
  19489. '\u2F81': '\u8089',
  19490. '\u2F82': '\u81E3',
  19491. '\u2F83': '\u81EA',
  19492. '\u2F84': '\u81F3',
  19493. '\u2F85': '\u81FC',
  19494. '\u2F86': '\u820C',
  19495. '\u2F87': '\u821B',
  19496. '\u2F88': '\u821F',
  19497. '\u2F89': '\u826E',
  19498. '\u2F8A': '\u8272',
  19499. '\u2F8B': '\u8278',
  19500. '\u2F8C': '\u864D',
  19501. '\u2F8D': '\u866B',
  19502. '\u2F8E': '\u8840',
  19503. '\u2F8F': '\u884C',
  19504. '\u2F90': '\u8863',
  19505. '\u2F91': '\u897E',
  19506. '\u2F92': '\u898B',
  19507. '\u2F93': '\u89D2',
  19508. '\u2F94': '\u8A00',
  19509. '\u2F95': '\u8C37',
  19510. '\u2F96': '\u8C46',
  19511. '\u2F97': '\u8C55',
  19512. '\u2F98': '\u8C78',
  19513. '\u2F99': '\u8C9D',
  19514. '\u2F9A': '\u8D64',
  19515. '\u2F9B': '\u8D70',
  19516. '\u2F9C': '\u8DB3',
  19517. '\u2F9D': '\u8EAB',
  19518. '\u2F9E': '\u8ECA',
  19519. '\u2F9F': '\u8F9B',
  19520. '\u2FA0': '\u8FB0',
  19521. '\u2FA1': '\u8FB5',
  19522. '\u2FA2': '\u9091',
  19523. '\u2FA3': '\u9149',
  19524. '\u2FA4': '\u91C6',
  19525. '\u2FA5': '\u91CC',
  19526. '\u2FA6': '\u91D1',
  19527. '\u2FA7': '\u9577',
  19528. '\u2FA8': '\u9580',
  19529. '\u2FA9': '\u961C',
  19530. '\u2FAA': '\u96B6',
  19531. '\u2FAB': '\u96B9',
  19532. '\u2FAC': '\u96E8',
  19533. '\u2FAD': '\u9751',
  19534. '\u2FAE': '\u975E',
  19535. '\u2FAF': '\u9762',
  19536. '\u2FB0': '\u9769',
  19537. '\u2FB1': '\u97CB',
  19538. '\u2FB2': '\u97ED',
  19539. '\u2FB3': '\u97F3',
  19540. '\u2FB4': '\u9801',
  19541. '\u2FB5': '\u98A8',
  19542. '\u2FB6': '\u98DB',
  19543. '\u2FB7': '\u98DF',
  19544. '\u2FB8': '\u9996',
  19545. '\u2FB9': '\u9999',
  19546. '\u2FBA': '\u99AC',
  19547. '\u2FBB': '\u9AA8',
  19548. '\u2FBC': '\u9AD8',
  19549. '\u2FBD': '\u9ADF',
  19550. '\u2FBE': '\u9B25',
  19551. '\u2FBF': '\u9B2F',
  19552. '\u2FC0': '\u9B32',
  19553. '\u2FC1': '\u9B3C',
  19554. '\u2FC2': '\u9B5A',
  19555. '\u2FC3': '\u9CE5',
  19556. '\u2FC4': '\u9E75',
  19557. '\u2FC5': '\u9E7F',
  19558. '\u2FC6': '\u9EA5',
  19559. '\u2FC7': '\u9EBB',
  19560. '\u2FC8': '\u9EC3',
  19561. '\u2FC9': '\u9ECD',
  19562. '\u2FCA': '\u9ED1',
  19563. '\u2FCB': '\u9EF9',
  19564. '\u2FCC': '\u9EFD',
  19565. '\u2FCD': '\u9F0E',
  19566. '\u2FCE': '\u9F13',
  19567. '\u2FCF': '\u9F20',
  19568. '\u2FD0': '\u9F3B',
  19569. '\u2FD1': '\u9F4A',
  19570. '\u2FD2': '\u9F52',
  19571. '\u2FD3': '\u9F8D',
  19572. '\u2FD4': '\u9F9C',
  19573. '\u2FD5': '\u9FA0',
  19574. '\u3036': '\u3012',
  19575. '\u3038': '\u5341',
  19576. '\u3039': '\u5344',
  19577. '\u303A': '\u5345',
  19578. '\u309B': '\u0020\u3099',
  19579. '\u309C': '\u0020\u309A',
  19580. '\u3131': '\u1100',
  19581. '\u3132': '\u1101',
  19582. '\u3133': '\u11AA',
  19583. '\u3134': '\u1102',
  19584. '\u3135': '\u11AC',
  19585. '\u3136': '\u11AD',
  19586. '\u3137': '\u1103',
  19587. '\u3138': '\u1104',
  19588. '\u3139': '\u1105',
  19589. '\u313A': '\u11B0',
  19590. '\u313B': '\u11B1',
  19591. '\u313C': '\u11B2',
  19592. '\u313D': '\u11B3',
  19593. '\u313E': '\u11B4',
  19594. '\u313F': '\u11B5',
  19595. '\u3140': '\u111A',
  19596. '\u3141': '\u1106',
  19597. '\u3142': '\u1107',
  19598. '\u3143': '\u1108',
  19599. '\u3144': '\u1121',
  19600. '\u3145': '\u1109',
  19601. '\u3146': '\u110A',
  19602. '\u3147': '\u110B',
  19603. '\u3148': '\u110C',
  19604. '\u3149': '\u110D',
  19605. '\u314A': '\u110E',
  19606. '\u314B': '\u110F',
  19607. '\u314C': '\u1110',
  19608. '\u314D': '\u1111',
  19609. '\u314E': '\u1112',
  19610. '\u314F': '\u1161',
  19611. '\u3150': '\u1162',
  19612. '\u3151': '\u1163',
  19613. '\u3152': '\u1164',
  19614. '\u3153': '\u1165',
  19615. '\u3154': '\u1166',
  19616. '\u3155': '\u1167',
  19617. '\u3156': '\u1168',
  19618. '\u3157': '\u1169',
  19619. '\u3158': '\u116A',
  19620. '\u3159': '\u116B',
  19621. '\u315A': '\u116C',
  19622. '\u315B': '\u116D',
  19623. '\u315C': '\u116E',
  19624. '\u315D': '\u116F',
  19625. '\u315E': '\u1170',
  19626. '\u315F': '\u1171',
  19627. '\u3160': '\u1172',
  19628. '\u3161': '\u1173',
  19629. '\u3162': '\u1174',
  19630. '\u3163': '\u1175',
  19631. '\u3164': '\u1160',
  19632. '\u3165': '\u1114',
  19633. '\u3166': '\u1115',
  19634. '\u3167': '\u11C7',
  19635. '\u3168': '\u11C8',
  19636. '\u3169': '\u11CC',
  19637. '\u316A': '\u11CE',
  19638. '\u316B': '\u11D3',
  19639. '\u316C': '\u11D7',
  19640. '\u316D': '\u11D9',
  19641. '\u316E': '\u111C',
  19642. '\u316F': '\u11DD',
  19643. '\u3170': '\u11DF',
  19644. '\u3171': '\u111D',
  19645. '\u3172': '\u111E',
  19646. '\u3173': '\u1120',
  19647. '\u3174': '\u1122',
  19648. '\u3175': '\u1123',
  19649. '\u3176': '\u1127',
  19650. '\u3177': '\u1129',
  19651. '\u3178': '\u112B',
  19652. '\u3179': '\u112C',
  19653. '\u317A': '\u112D',
  19654. '\u317B': '\u112E',
  19655. '\u317C': '\u112F',
  19656. '\u317D': '\u1132',
  19657. '\u317E': '\u1136',
  19658. '\u317F': '\u1140',
  19659. '\u3180': '\u1147',
  19660. '\u3181': '\u114C',
  19661. '\u3182': '\u11F1',
  19662. '\u3183': '\u11F2',
  19663. '\u3184': '\u1157',
  19664. '\u3185': '\u1158',
  19665. '\u3186': '\u1159',
  19666. '\u3187': '\u1184',
  19667. '\u3188': '\u1185',
  19668. '\u3189': '\u1188',
  19669. '\u318A': '\u1191',
  19670. '\u318B': '\u1192',
  19671. '\u318C': '\u1194',
  19672. '\u318D': '\u119E',
  19673. '\u318E': '\u11A1',
  19674. '\u3200': '\u0028\u1100\u0029',
  19675. '\u3201': '\u0028\u1102\u0029',
  19676. '\u3202': '\u0028\u1103\u0029',
  19677. '\u3203': '\u0028\u1105\u0029',
  19678. '\u3204': '\u0028\u1106\u0029',
  19679. '\u3205': '\u0028\u1107\u0029',
  19680. '\u3206': '\u0028\u1109\u0029',
  19681. '\u3207': '\u0028\u110B\u0029',
  19682. '\u3208': '\u0028\u110C\u0029',
  19683. '\u3209': '\u0028\u110E\u0029',
  19684. '\u320A': '\u0028\u110F\u0029',
  19685. '\u320B': '\u0028\u1110\u0029',
  19686. '\u320C': '\u0028\u1111\u0029',
  19687. '\u320D': '\u0028\u1112\u0029',
  19688. '\u320E': '\u0028\u1100\u1161\u0029',
  19689. '\u320F': '\u0028\u1102\u1161\u0029',
  19690. '\u3210': '\u0028\u1103\u1161\u0029',
  19691. '\u3211': '\u0028\u1105\u1161\u0029',
  19692. '\u3212': '\u0028\u1106\u1161\u0029',
  19693. '\u3213': '\u0028\u1107\u1161\u0029',
  19694. '\u3214': '\u0028\u1109\u1161\u0029',
  19695. '\u3215': '\u0028\u110B\u1161\u0029',
  19696. '\u3216': '\u0028\u110C\u1161\u0029',
  19697. '\u3217': '\u0028\u110E\u1161\u0029',
  19698. '\u3218': '\u0028\u110F\u1161\u0029',
  19699. '\u3219': '\u0028\u1110\u1161\u0029',
  19700. '\u321A': '\u0028\u1111\u1161\u0029',
  19701. '\u321B': '\u0028\u1112\u1161\u0029',
  19702. '\u321C': '\u0028\u110C\u116E\u0029',
  19703. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19704. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19705. '\u3220': '\u0028\u4E00\u0029',
  19706. '\u3221': '\u0028\u4E8C\u0029',
  19707. '\u3222': '\u0028\u4E09\u0029',
  19708. '\u3223': '\u0028\u56DB\u0029',
  19709. '\u3224': '\u0028\u4E94\u0029',
  19710. '\u3225': '\u0028\u516D\u0029',
  19711. '\u3226': '\u0028\u4E03\u0029',
  19712. '\u3227': '\u0028\u516B\u0029',
  19713. '\u3228': '\u0028\u4E5D\u0029',
  19714. '\u3229': '\u0028\u5341\u0029',
  19715. '\u322A': '\u0028\u6708\u0029',
  19716. '\u322B': '\u0028\u706B\u0029',
  19717. '\u322C': '\u0028\u6C34\u0029',
  19718. '\u322D': '\u0028\u6728\u0029',
  19719. '\u322E': '\u0028\u91D1\u0029',
  19720. '\u322F': '\u0028\u571F\u0029',
  19721. '\u3230': '\u0028\u65E5\u0029',
  19722. '\u3231': '\u0028\u682A\u0029',
  19723. '\u3232': '\u0028\u6709\u0029',
  19724. '\u3233': '\u0028\u793E\u0029',
  19725. '\u3234': '\u0028\u540D\u0029',
  19726. '\u3235': '\u0028\u7279\u0029',
  19727. '\u3236': '\u0028\u8CA1\u0029',
  19728. '\u3237': '\u0028\u795D\u0029',
  19729. '\u3238': '\u0028\u52B4\u0029',
  19730. '\u3239': '\u0028\u4EE3\u0029',
  19731. '\u323A': '\u0028\u547C\u0029',
  19732. '\u323B': '\u0028\u5B66\u0029',
  19733. '\u323C': '\u0028\u76E3\u0029',
  19734. '\u323D': '\u0028\u4F01\u0029',
  19735. '\u323E': '\u0028\u8CC7\u0029',
  19736. '\u323F': '\u0028\u5354\u0029',
  19737. '\u3240': '\u0028\u796D\u0029',
  19738. '\u3241': '\u0028\u4F11\u0029',
  19739. '\u3242': '\u0028\u81EA\u0029',
  19740. '\u3243': '\u0028\u81F3\u0029',
  19741. '\u32C0': '\u0031\u6708',
  19742. '\u32C1': '\u0032\u6708',
  19743. '\u32C2': '\u0033\u6708',
  19744. '\u32C3': '\u0034\u6708',
  19745. '\u32C4': '\u0035\u6708',
  19746. '\u32C5': '\u0036\u6708',
  19747. '\u32C6': '\u0037\u6708',
  19748. '\u32C7': '\u0038\u6708',
  19749. '\u32C8': '\u0039\u6708',
  19750. '\u32C9': '\u0031\u0030\u6708',
  19751. '\u32CA': '\u0031\u0031\u6708',
  19752. '\u32CB': '\u0031\u0032\u6708',
  19753. '\u3358': '\u0030\u70B9',
  19754. '\u3359': '\u0031\u70B9',
  19755. '\u335A': '\u0032\u70B9',
  19756. '\u335B': '\u0033\u70B9',
  19757. '\u335C': '\u0034\u70B9',
  19758. '\u335D': '\u0035\u70B9',
  19759. '\u335E': '\u0036\u70B9',
  19760. '\u335F': '\u0037\u70B9',
  19761. '\u3360': '\u0038\u70B9',
  19762. '\u3361': '\u0039\u70B9',
  19763. '\u3362': '\u0031\u0030\u70B9',
  19764. '\u3363': '\u0031\u0031\u70B9',
  19765. '\u3364': '\u0031\u0032\u70B9',
  19766. '\u3365': '\u0031\u0033\u70B9',
  19767. '\u3366': '\u0031\u0034\u70B9',
  19768. '\u3367': '\u0031\u0035\u70B9',
  19769. '\u3368': '\u0031\u0036\u70B9',
  19770. '\u3369': '\u0031\u0037\u70B9',
  19771. '\u336A': '\u0031\u0038\u70B9',
  19772. '\u336B': '\u0031\u0039\u70B9',
  19773. '\u336C': '\u0032\u0030\u70B9',
  19774. '\u336D': '\u0032\u0031\u70B9',
  19775. '\u336E': '\u0032\u0032\u70B9',
  19776. '\u336F': '\u0032\u0033\u70B9',
  19777. '\u3370': '\u0032\u0034\u70B9',
  19778. '\u33E0': '\u0031\u65E5',
  19779. '\u33E1': '\u0032\u65E5',
  19780. '\u33E2': '\u0033\u65E5',
  19781. '\u33E3': '\u0034\u65E5',
  19782. '\u33E4': '\u0035\u65E5',
  19783. '\u33E5': '\u0036\u65E5',
  19784. '\u33E6': '\u0037\u65E5',
  19785. '\u33E7': '\u0038\u65E5',
  19786. '\u33E8': '\u0039\u65E5',
  19787. '\u33E9': '\u0031\u0030\u65E5',
  19788. '\u33EA': '\u0031\u0031\u65E5',
  19789. '\u33EB': '\u0031\u0032\u65E5',
  19790. '\u33EC': '\u0031\u0033\u65E5',
  19791. '\u33ED': '\u0031\u0034\u65E5',
  19792. '\u33EE': '\u0031\u0035\u65E5',
  19793. '\u33EF': '\u0031\u0036\u65E5',
  19794. '\u33F0': '\u0031\u0037\u65E5',
  19795. '\u33F1': '\u0031\u0038\u65E5',
  19796. '\u33F2': '\u0031\u0039\u65E5',
  19797. '\u33F3': '\u0032\u0030\u65E5',
  19798. '\u33F4': '\u0032\u0031\u65E5',
  19799. '\u33F5': '\u0032\u0032\u65E5',
  19800. '\u33F6': '\u0032\u0033\u65E5',
  19801. '\u33F7': '\u0032\u0034\u65E5',
  19802. '\u33F8': '\u0032\u0035\u65E5',
  19803. '\u33F9': '\u0032\u0036\u65E5',
  19804. '\u33FA': '\u0032\u0037\u65E5',
  19805. '\u33FB': '\u0032\u0038\u65E5',
  19806. '\u33FC': '\u0032\u0039\u65E5',
  19807. '\u33FD': '\u0033\u0030\u65E5',
  19808. '\u33FE': '\u0033\u0031\u65E5',
  19809. '\uFB00': '\u0066\u0066',
  19810. '\uFB01': '\u0066\u0069',
  19811. '\uFB02': '\u0066\u006C',
  19812. '\uFB03': '\u0066\u0066\u0069',
  19813. '\uFB04': '\u0066\u0066\u006C',
  19814. '\uFB05': '\u017F\u0074',
  19815. '\uFB06': '\u0073\u0074',
  19816. '\uFB13': '\u0574\u0576',
  19817. '\uFB14': '\u0574\u0565',
  19818. '\uFB15': '\u0574\u056B',
  19819. '\uFB16': '\u057E\u0576',
  19820. '\uFB17': '\u0574\u056D',
  19821. '\uFB4F': '\u05D0\u05DC',
  19822. '\uFB50': '\u0671',
  19823. '\uFB51': '\u0671',
  19824. '\uFB52': '\u067B',
  19825. '\uFB53': '\u067B',
  19826. '\uFB54': '\u067B',
  19827. '\uFB55': '\u067B',
  19828. '\uFB56': '\u067E',
  19829. '\uFB57': '\u067E',
  19830. '\uFB58': '\u067E',
  19831. '\uFB59': '\u067E',
  19832. '\uFB5A': '\u0680',
  19833. '\uFB5B': '\u0680',
  19834. '\uFB5C': '\u0680',
  19835. '\uFB5D': '\u0680',
  19836. '\uFB5E': '\u067A',
  19837. '\uFB5F': '\u067A',
  19838. '\uFB60': '\u067A',
  19839. '\uFB61': '\u067A',
  19840. '\uFB62': '\u067F',
  19841. '\uFB63': '\u067F',
  19842. '\uFB64': '\u067F',
  19843. '\uFB65': '\u067F',
  19844. '\uFB66': '\u0679',
  19845. '\uFB67': '\u0679',
  19846. '\uFB68': '\u0679',
  19847. '\uFB69': '\u0679',
  19848. '\uFB6A': '\u06A4',
  19849. '\uFB6B': '\u06A4',
  19850. '\uFB6C': '\u06A4',
  19851. '\uFB6D': '\u06A4',
  19852. '\uFB6E': '\u06A6',
  19853. '\uFB6F': '\u06A6',
  19854. '\uFB70': '\u06A6',
  19855. '\uFB71': '\u06A6',
  19856. '\uFB72': '\u0684',
  19857. '\uFB73': '\u0684',
  19858. '\uFB74': '\u0684',
  19859. '\uFB75': '\u0684',
  19860. '\uFB76': '\u0683',
  19861. '\uFB77': '\u0683',
  19862. '\uFB78': '\u0683',
  19863. '\uFB79': '\u0683',
  19864. '\uFB7A': '\u0686',
  19865. '\uFB7B': '\u0686',
  19866. '\uFB7C': '\u0686',
  19867. '\uFB7D': '\u0686',
  19868. '\uFB7E': '\u0687',
  19869. '\uFB7F': '\u0687',
  19870. '\uFB80': '\u0687',
  19871. '\uFB81': '\u0687',
  19872. '\uFB82': '\u068D',
  19873. '\uFB83': '\u068D',
  19874. '\uFB84': '\u068C',
  19875. '\uFB85': '\u068C',
  19876. '\uFB86': '\u068E',
  19877. '\uFB87': '\u068E',
  19878. '\uFB88': '\u0688',
  19879. '\uFB89': '\u0688',
  19880. '\uFB8A': '\u0698',
  19881. '\uFB8B': '\u0698',
  19882. '\uFB8C': '\u0691',
  19883. '\uFB8D': '\u0691',
  19884. '\uFB8E': '\u06A9',
  19885. '\uFB8F': '\u06A9',
  19886. '\uFB90': '\u06A9',
  19887. '\uFB91': '\u06A9',
  19888. '\uFB92': '\u06AF',
  19889. '\uFB93': '\u06AF',
  19890. '\uFB94': '\u06AF',
  19891. '\uFB95': '\u06AF',
  19892. '\uFB96': '\u06B3',
  19893. '\uFB97': '\u06B3',
  19894. '\uFB98': '\u06B3',
  19895. '\uFB99': '\u06B3',
  19896. '\uFB9A': '\u06B1',
  19897. '\uFB9B': '\u06B1',
  19898. '\uFB9C': '\u06B1',
  19899. '\uFB9D': '\u06B1',
  19900. '\uFB9E': '\u06BA',
  19901. '\uFB9F': '\u06BA',
  19902. '\uFBA0': '\u06BB',
  19903. '\uFBA1': '\u06BB',
  19904. '\uFBA2': '\u06BB',
  19905. '\uFBA3': '\u06BB',
  19906. '\uFBA4': '\u06C0',
  19907. '\uFBA5': '\u06C0',
  19908. '\uFBA6': '\u06C1',
  19909. '\uFBA7': '\u06C1',
  19910. '\uFBA8': '\u06C1',
  19911. '\uFBA9': '\u06C1',
  19912. '\uFBAA': '\u06BE',
  19913. '\uFBAB': '\u06BE',
  19914. '\uFBAC': '\u06BE',
  19915. '\uFBAD': '\u06BE',
  19916. '\uFBAE': '\u06D2',
  19917. '\uFBAF': '\u06D2',
  19918. '\uFBB0': '\u06D3',
  19919. '\uFBB1': '\u06D3',
  19920. '\uFBD3': '\u06AD',
  19921. '\uFBD4': '\u06AD',
  19922. '\uFBD5': '\u06AD',
  19923. '\uFBD6': '\u06AD',
  19924. '\uFBD7': '\u06C7',
  19925. '\uFBD8': '\u06C7',
  19926. '\uFBD9': '\u06C6',
  19927. '\uFBDA': '\u06C6',
  19928. '\uFBDB': '\u06C8',
  19929. '\uFBDC': '\u06C8',
  19930. '\uFBDD': '\u0677',
  19931. '\uFBDE': '\u06CB',
  19932. '\uFBDF': '\u06CB',
  19933. '\uFBE0': '\u06C5',
  19934. '\uFBE1': '\u06C5',
  19935. '\uFBE2': '\u06C9',
  19936. '\uFBE3': '\u06C9',
  19937. '\uFBE4': '\u06D0',
  19938. '\uFBE5': '\u06D0',
  19939. '\uFBE6': '\u06D0',
  19940. '\uFBE7': '\u06D0',
  19941. '\uFBE8': '\u0649',
  19942. '\uFBE9': '\u0649',
  19943. '\uFBEA': '\u0626\u0627',
  19944. '\uFBEB': '\u0626\u0627',
  19945. '\uFBEC': '\u0626\u06D5',
  19946. '\uFBED': '\u0626\u06D5',
  19947. '\uFBEE': '\u0626\u0648',
  19948. '\uFBEF': '\u0626\u0648',
  19949. '\uFBF0': '\u0626\u06C7',
  19950. '\uFBF1': '\u0626\u06C7',
  19951. '\uFBF2': '\u0626\u06C6',
  19952. '\uFBF3': '\u0626\u06C6',
  19953. '\uFBF4': '\u0626\u06C8',
  19954. '\uFBF5': '\u0626\u06C8',
  19955. '\uFBF6': '\u0626\u06D0',
  19956. '\uFBF7': '\u0626\u06D0',
  19957. '\uFBF8': '\u0626\u06D0',
  19958. '\uFBF9': '\u0626\u0649',
  19959. '\uFBFA': '\u0626\u0649',
  19960. '\uFBFB': '\u0626\u0649',
  19961. '\uFBFC': '\u06CC',
  19962. '\uFBFD': '\u06CC',
  19963. '\uFBFE': '\u06CC',
  19964. '\uFBFF': '\u06CC',
  19965. '\uFC00': '\u0626\u062C',
  19966. '\uFC01': '\u0626\u062D',
  19967. '\uFC02': '\u0626\u0645',
  19968. '\uFC03': '\u0626\u0649',
  19969. '\uFC04': '\u0626\u064A',
  19970. '\uFC05': '\u0628\u062C',
  19971. '\uFC06': '\u0628\u062D',
  19972. '\uFC07': '\u0628\u062E',
  19973. '\uFC08': '\u0628\u0645',
  19974. '\uFC09': '\u0628\u0649',
  19975. '\uFC0A': '\u0628\u064A',
  19976. '\uFC0B': '\u062A\u062C',
  19977. '\uFC0C': '\u062A\u062D',
  19978. '\uFC0D': '\u062A\u062E',
  19979. '\uFC0E': '\u062A\u0645',
  19980. '\uFC0F': '\u062A\u0649',
  19981. '\uFC10': '\u062A\u064A',
  19982. '\uFC11': '\u062B\u062C',
  19983. '\uFC12': '\u062B\u0645',
  19984. '\uFC13': '\u062B\u0649',
  19985. '\uFC14': '\u062B\u064A',
  19986. '\uFC15': '\u062C\u062D',
  19987. '\uFC16': '\u062C\u0645',
  19988. '\uFC17': '\u062D\u062C',
  19989. '\uFC18': '\u062D\u0645',
  19990. '\uFC19': '\u062E\u062C',
  19991. '\uFC1A': '\u062E\u062D',
  19992. '\uFC1B': '\u062E\u0645',
  19993. '\uFC1C': '\u0633\u062C',
  19994. '\uFC1D': '\u0633\u062D',
  19995. '\uFC1E': '\u0633\u062E',
  19996. '\uFC1F': '\u0633\u0645',
  19997. '\uFC20': '\u0635\u062D',
  19998. '\uFC21': '\u0635\u0645',
  19999. '\uFC22': '\u0636\u062C',
  20000. '\uFC23': '\u0636\u062D',
  20001. '\uFC24': '\u0636\u062E',
  20002. '\uFC25': '\u0636\u0645',
  20003. '\uFC26': '\u0637\u062D',
  20004. '\uFC27': '\u0637\u0645',
  20005. '\uFC28': '\u0638\u0645',
  20006. '\uFC29': '\u0639\u062C',
  20007. '\uFC2A': '\u0639\u0645',
  20008. '\uFC2B': '\u063A\u062C',
  20009. '\uFC2C': '\u063A\u0645',
  20010. '\uFC2D': '\u0641\u062C',
  20011. '\uFC2E': '\u0641\u062D',
  20012. '\uFC2F': '\u0641\u062E',
  20013. '\uFC30': '\u0641\u0645',
  20014. '\uFC31': '\u0641\u0649',
  20015. '\uFC32': '\u0641\u064A',
  20016. '\uFC33': '\u0642\u062D',
  20017. '\uFC34': '\u0642\u0645',
  20018. '\uFC35': '\u0642\u0649',
  20019. '\uFC36': '\u0642\u064A',
  20020. '\uFC37': '\u0643\u0627',
  20021. '\uFC38': '\u0643\u062C',
  20022. '\uFC39': '\u0643\u062D',
  20023. '\uFC3A': '\u0643\u062E',
  20024. '\uFC3B': '\u0643\u0644',
  20025. '\uFC3C': '\u0643\u0645',
  20026. '\uFC3D': '\u0643\u0649',
  20027. '\uFC3E': '\u0643\u064A',
  20028. '\uFC3F': '\u0644\u062C',
  20029. '\uFC40': '\u0644\u062D',
  20030. '\uFC41': '\u0644\u062E',
  20031. '\uFC42': '\u0644\u0645',
  20032. '\uFC43': '\u0644\u0649',
  20033. '\uFC44': '\u0644\u064A',
  20034. '\uFC45': '\u0645\u062C',
  20035. '\uFC46': '\u0645\u062D',
  20036. '\uFC47': '\u0645\u062E',
  20037. '\uFC48': '\u0645\u0645',
  20038. '\uFC49': '\u0645\u0649',
  20039. '\uFC4A': '\u0645\u064A',
  20040. '\uFC4B': '\u0646\u062C',
  20041. '\uFC4C': '\u0646\u062D',
  20042. '\uFC4D': '\u0646\u062E',
  20043. '\uFC4E': '\u0646\u0645',
  20044. '\uFC4F': '\u0646\u0649',
  20045. '\uFC50': '\u0646\u064A',
  20046. '\uFC51': '\u0647\u062C',
  20047. '\uFC52': '\u0647\u0645',
  20048. '\uFC53': '\u0647\u0649',
  20049. '\uFC54': '\u0647\u064A',
  20050. '\uFC55': '\u064A\u062C',
  20051. '\uFC56': '\u064A\u062D',
  20052. '\uFC57': '\u064A\u062E',
  20053. '\uFC58': '\u064A\u0645',
  20054. '\uFC59': '\u064A\u0649',
  20055. '\uFC5A': '\u064A\u064A',
  20056. '\uFC5B': '\u0630\u0670',
  20057. '\uFC5C': '\u0631\u0670',
  20058. '\uFC5D': '\u0649\u0670',
  20059. '\uFC5E': '\u0020\u064C\u0651',
  20060. '\uFC5F': '\u0020\u064D\u0651',
  20061. '\uFC60': '\u0020\u064E\u0651',
  20062. '\uFC61': '\u0020\u064F\u0651',
  20063. '\uFC62': '\u0020\u0650\u0651',
  20064. '\uFC63': '\u0020\u0651\u0670',
  20065. '\uFC64': '\u0626\u0631',
  20066. '\uFC65': '\u0626\u0632',
  20067. '\uFC66': '\u0626\u0645',
  20068. '\uFC67': '\u0626\u0646',
  20069. '\uFC68': '\u0626\u0649',
  20070. '\uFC69': '\u0626\u064A',
  20071. '\uFC6A': '\u0628\u0631',
  20072. '\uFC6B': '\u0628\u0632',
  20073. '\uFC6C': '\u0628\u0645',
  20074. '\uFC6D': '\u0628\u0646',
  20075. '\uFC6E': '\u0628\u0649',
  20076. '\uFC6F': '\u0628\u064A',
  20077. '\uFC70': '\u062A\u0631',
  20078. '\uFC71': '\u062A\u0632',
  20079. '\uFC72': '\u062A\u0645',
  20080. '\uFC73': '\u062A\u0646',
  20081. '\uFC74': '\u062A\u0649',
  20082. '\uFC75': '\u062A\u064A',
  20083. '\uFC76': '\u062B\u0631',
  20084. '\uFC77': '\u062B\u0632',
  20085. '\uFC78': '\u062B\u0645',
  20086. '\uFC79': '\u062B\u0646',
  20087. '\uFC7A': '\u062B\u0649',
  20088. '\uFC7B': '\u062B\u064A',
  20089. '\uFC7C': '\u0641\u0649',
  20090. '\uFC7D': '\u0641\u064A',
  20091. '\uFC7E': '\u0642\u0649',
  20092. '\uFC7F': '\u0642\u064A',
  20093. '\uFC80': '\u0643\u0627',
  20094. '\uFC81': '\u0643\u0644',
  20095. '\uFC82': '\u0643\u0645',
  20096. '\uFC83': '\u0643\u0649',
  20097. '\uFC84': '\u0643\u064A',
  20098. '\uFC85': '\u0644\u0645',
  20099. '\uFC86': '\u0644\u0649',
  20100. '\uFC87': '\u0644\u064A',
  20101. '\uFC88': '\u0645\u0627',
  20102. '\uFC89': '\u0645\u0645',
  20103. '\uFC8A': '\u0646\u0631',
  20104. '\uFC8B': '\u0646\u0632',
  20105. '\uFC8C': '\u0646\u0645',
  20106. '\uFC8D': '\u0646\u0646',
  20107. '\uFC8E': '\u0646\u0649',
  20108. '\uFC8F': '\u0646\u064A',
  20109. '\uFC90': '\u0649\u0670',
  20110. '\uFC91': '\u064A\u0631',
  20111. '\uFC92': '\u064A\u0632',
  20112. '\uFC93': '\u064A\u0645',
  20113. '\uFC94': '\u064A\u0646',
  20114. '\uFC95': '\u064A\u0649',
  20115. '\uFC96': '\u064A\u064A',
  20116. '\uFC97': '\u0626\u062C',
  20117. '\uFC98': '\u0626\u062D',
  20118. '\uFC99': '\u0626\u062E',
  20119. '\uFC9A': '\u0626\u0645',
  20120. '\uFC9B': '\u0626\u0647',
  20121. '\uFC9C': '\u0628\u062C',
  20122. '\uFC9D': '\u0628\u062D',
  20123. '\uFC9E': '\u0628\u062E',
  20124. '\uFC9F': '\u0628\u0645',
  20125. '\uFCA0': '\u0628\u0647',
  20126. '\uFCA1': '\u062A\u062C',
  20127. '\uFCA2': '\u062A\u062D',
  20128. '\uFCA3': '\u062A\u062E',
  20129. '\uFCA4': '\u062A\u0645',
  20130. '\uFCA5': '\u062A\u0647',
  20131. '\uFCA6': '\u062B\u0645',
  20132. '\uFCA7': '\u062C\u062D',
  20133. '\uFCA8': '\u062C\u0645',
  20134. '\uFCA9': '\u062D\u062C',
  20135. '\uFCAA': '\u062D\u0645',
  20136. '\uFCAB': '\u062E\u062C',
  20137. '\uFCAC': '\u062E\u0645',
  20138. '\uFCAD': '\u0633\u062C',
  20139. '\uFCAE': '\u0633\u062D',
  20140. '\uFCAF': '\u0633\u062E',
  20141. '\uFCB0': '\u0633\u0645',
  20142. '\uFCB1': '\u0635\u062D',
  20143. '\uFCB2': '\u0635\u062E',
  20144. '\uFCB3': '\u0635\u0645',
  20145. '\uFCB4': '\u0636\u062C',
  20146. '\uFCB5': '\u0636\u062D',
  20147. '\uFCB6': '\u0636\u062E',
  20148. '\uFCB7': '\u0636\u0645',
  20149. '\uFCB8': '\u0637\u062D',
  20150. '\uFCB9': '\u0638\u0645',
  20151. '\uFCBA': '\u0639\u062C',
  20152. '\uFCBB': '\u0639\u0645',
  20153. '\uFCBC': '\u063A\u062C',
  20154. '\uFCBD': '\u063A\u0645',
  20155. '\uFCBE': '\u0641\u062C',
  20156. '\uFCBF': '\u0641\u062D',
  20157. '\uFCC0': '\u0641\u062E',
  20158. '\uFCC1': '\u0641\u0645',
  20159. '\uFCC2': '\u0642\u062D',
  20160. '\uFCC3': '\u0642\u0645',
  20161. '\uFCC4': '\u0643\u062C',
  20162. '\uFCC5': '\u0643\u062D',
  20163. '\uFCC6': '\u0643\u062E',
  20164. '\uFCC7': '\u0643\u0644',
  20165. '\uFCC8': '\u0643\u0645',
  20166. '\uFCC9': '\u0644\u062C',
  20167. '\uFCCA': '\u0644\u062D',
  20168. '\uFCCB': '\u0644\u062E',
  20169. '\uFCCC': '\u0644\u0645',
  20170. '\uFCCD': '\u0644\u0647',
  20171. '\uFCCE': '\u0645\u062C',
  20172. '\uFCCF': '\u0645\u062D',
  20173. '\uFCD0': '\u0645\u062E',
  20174. '\uFCD1': '\u0645\u0645',
  20175. '\uFCD2': '\u0646\u062C',
  20176. '\uFCD3': '\u0646\u062D',
  20177. '\uFCD4': '\u0646\u062E',
  20178. '\uFCD5': '\u0646\u0645',
  20179. '\uFCD6': '\u0646\u0647',
  20180. '\uFCD7': '\u0647\u062C',
  20181. '\uFCD8': '\u0647\u0645',
  20182. '\uFCD9': '\u0647\u0670',
  20183. '\uFCDA': '\u064A\u062C',
  20184. '\uFCDB': '\u064A\u062D',
  20185. '\uFCDC': '\u064A\u062E',
  20186. '\uFCDD': '\u064A\u0645',
  20187. '\uFCDE': '\u064A\u0647',
  20188. '\uFCDF': '\u0626\u0645',
  20189. '\uFCE0': '\u0626\u0647',
  20190. '\uFCE1': '\u0628\u0645',
  20191. '\uFCE2': '\u0628\u0647',
  20192. '\uFCE3': '\u062A\u0645',
  20193. '\uFCE4': '\u062A\u0647',
  20194. '\uFCE5': '\u062B\u0645',
  20195. '\uFCE6': '\u062B\u0647',
  20196. '\uFCE7': '\u0633\u0645',
  20197. '\uFCE8': '\u0633\u0647',
  20198. '\uFCE9': '\u0634\u0645',
  20199. '\uFCEA': '\u0634\u0647',
  20200. '\uFCEB': '\u0643\u0644',
  20201. '\uFCEC': '\u0643\u0645',
  20202. '\uFCED': '\u0644\u0645',
  20203. '\uFCEE': '\u0646\u0645',
  20204. '\uFCEF': '\u0646\u0647',
  20205. '\uFCF0': '\u064A\u0645',
  20206. '\uFCF1': '\u064A\u0647',
  20207. '\uFCF2': '\u0640\u064E\u0651',
  20208. '\uFCF3': '\u0640\u064F\u0651',
  20209. '\uFCF4': '\u0640\u0650\u0651',
  20210. '\uFCF5': '\u0637\u0649',
  20211. '\uFCF6': '\u0637\u064A',
  20212. '\uFCF7': '\u0639\u0649',
  20213. '\uFCF8': '\u0639\u064A',
  20214. '\uFCF9': '\u063A\u0649',
  20215. '\uFCFA': '\u063A\u064A',
  20216. '\uFCFB': '\u0633\u0649',
  20217. '\uFCFC': '\u0633\u064A',
  20218. '\uFCFD': '\u0634\u0649',
  20219. '\uFCFE': '\u0634\u064A',
  20220. '\uFCFF': '\u062D\u0649',
  20221. '\uFD00': '\u062D\u064A',
  20222. '\uFD01': '\u062C\u0649',
  20223. '\uFD02': '\u062C\u064A',
  20224. '\uFD03': '\u062E\u0649',
  20225. '\uFD04': '\u062E\u064A',
  20226. '\uFD05': '\u0635\u0649',
  20227. '\uFD06': '\u0635\u064A',
  20228. '\uFD07': '\u0636\u0649',
  20229. '\uFD08': '\u0636\u064A',
  20230. '\uFD09': '\u0634\u062C',
  20231. '\uFD0A': '\u0634\u062D',
  20232. '\uFD0B': '\u0634\u062E',
  20233. '\uFD0C': '\u0634\u0645',
  20234. '\uFD0D': '\u0634\u0631',
  20235. '\uFD0E': '\u0633\u0631',
  20236. '\uFD0F': '\u0635\u0631',
  20237. '\uFD10': '\u0636\u0631',
  20238. '\uFD11': '\u0637\u0649',
  20239. '\uFD12': '\u0637\u064A',
  20240. '\uFD13': '\u0639\u0649',
  20241. '\uFD14': '\u0639\u064A',
  20242. '\uFD15': '\u063A\u0649',
  20243. '\uFD16': '\u063A\u064A',
  20244. '\uFD17': '\u0633\u0649',
  20245. '\uFD18': '\u0633\u064A',
  20246. '\uFD19': '\u0634\u0649',
  20247. '\uFD1A': '\u0634\u064A',
  20248. '\uFD1B': '\u062D\u0649',
  20249. '\uFD1C': '\u062D\u064A',
  20250. '\uFD1D': '\u062C\u0649',
  20251. '\uFD1E': '\u062C\u064A',
  20252. '\uFD1F': '\u062E\u0649',
  20253. '\uFD20': '\u062E\u064A',
  20254. '\uFD21': '\u0635\u0649',
  20255. '\uFD22': '\u0635\u064A',
  20256. '\uFD23': '\u0636\u0649',
  20257. '\uFD24': '\u0636\u064A',
  20258. '\uFD25': '\u0634\u062C',
  20259. '\uFD26': '\u0634\u062D',
  20260. '\uFD27': '\u0634\u062E',
  20261. '\uFD28': '\u0634\u0645',
  20262. '\uFD29': '\u0634\u0631',
  20263. '\uFD2A': '\u0633\u0631',
  20264. '\uFD2B': '\u0635\u0631',
  20265. '\uFD2C': '\u0636\u0631',
  20266. '\uFD2D': '\u0634\u062C',
  20267. '\uFD2E': '\u0634\u062D',
  20268. '\uFD2F': '\u0634\u062E',
  20269. '\uFD30': '\u0634\u0645',
  20270. '\uFD31': '\u0633\u0647',
  20271. '\uFD32': '\u0634\u0647',
  20272. '\uFD33': '\u0637\u0645',
  20273. '\uFD34': '\u0633\u062C',
  20274. '\uFD35': '\u0633\u062D',
  20275. '\uFD36': '\u0633\u062E',
  20276. '\uFD37': '\u0634\u062C',
  20277. '\uFD38': '\u0634\u062D',
  20278. '\uFD39': '\u0634\u062E',
  20279. '\uFD3A': '\u0637\u0645',
  20280. '\uFD3B': '\u0638\u0645',
  20281. '\uFD3C': '\u0627\u064B',
  20282. '\uFD3D': '\u0627\u064B',
  20283. '\uFD50': '\u062A\u062C\u0645',
  20284. '\uFD51': '\u062A\u062D\u062C',
  20285. '\uFD52': '\u062A\u062D\u062C',
  20286. '\uFD53': '\u062A\u062D\u0645',
  20287. '\uFD54': '\u062A\u062E\u0645',
  20288. '\uFD55': '\u062A\u0645\u062C',
  20289. '\uFD56': '\u062A\u0645\u062D',
  20290. '\uFD57': '\u062A\u0645\u062E',
  20291. '\uFD58': '\u062C\u0645\u062D',
  20292. '\uFD59': '\u062C\u0645\u062D',
  20293. '\uFD5A': '\u062D\u0645\u064A',
  20294. '\uFD5B': '\u062D\u0645\u0649',
  20295. '\uFD5C': '\u0633\u062D\u062C',
  20296. '\uFD5D': '\u0633\u062C\u062D',
  20297. '\uFD5E': '\u0633\u062C\u0649',
  20298. '\uFD5F': '\u0633\u0645\u062D',
  20299. '\uFD60': '\u0633\u0645\u062D',
  20300. '\uFD61': '\u0633\u0645\u062C',
  20301. '\uFD62': '\u0633\u0645\u0645',
  20302. '\uFD63': '\u0633\u0645\u0645',
  20303. '\uFD64': '\u0635\u062D\u062D',
  20304. '\uFD65': '\u0635\u062D\u062D',
  20305. '\uFD66': '\u0635\u0645\u0645',
  20306. '\uFD67': '\u0634\u062D\u0645',
  20307. '\uFD68': '\u0634\u062D\u0645',
  20308. '\uFD69': '\u0634\u062C\u064A',
  20309. '\uFD6A': '\u0634\u0645\u062E',
  20310. '\uFD6B': '\u0634\u0645\u062E',
  20311. '\uFD6C': '\u0634\u0645\u0645',
  20312. '\uFD6D': '\u0634\u0645\u0645',
  20313. '\uFD6E': '\u0636\u062D\u0649',
  20314. '\uFD6F': '\u0636\u062E\u0645',
  20315. '\uFD70': '\u0636\u062E\u0645',
  20316. '\uFD71': '\u0637\u0645\u062D',
  20317. '\uFD72': '\u0637\u0645\u062D',
  20318. '\uFD73': '\u0637\u0645\u0645',
  20319. '\uFD74': '\u0637\u0645\u064A',
  20320. '\uFD75': '\u0639\u062C\u0645',
  20321. '\uFD76': '\u0639\u0645\u0645',
  20322. '\uFD77': '\u0639\u0645\u0645',
  20323. '\uFD78': '\u0639\u0645\u0649',
  20324. '\uFD79': '\u063A\u0645\u0645',
  20325. '\uFD7A': '\u063A\u0645\u064A',
  20326. '\uFD7B': '\u063A\u0645\u0649',
  20327. '\uFD7C': '\u0641\u062E\u0645',
  20328. '\uFD7D': '\u0641\u062E\u0645',
  20329. '\uFD7E': '\u0642\u0645\u062D',
  20330. '\uFD7F': '\u0642\u0645\u0645',
  20331. '\uFD80': '\u0644\u062D\u0645',
  20332. '\uFD81': '\u0644\u062D\u064A',
  20333. '\uFD82': '\u0644\u062D\u0649',
  20334. '\uFD83': '\u0644\u062C\u062C',
  20335. '\uFD84': '\u0644\u062C\u062C',
  20336. '\uFD85': '\u0644\u062E\u0645',
  20337. '\uFD86': '\u0644\u062E\u0645',
  20338. '\uFD87': '\u0644\u0645\u062D',
  20339. '\uFD88': '\u0644\u0645\u062D',
  20340. '\uFD89': '\u0645\u062D\u062C',
  20341. '\uFD8A': '\u0645\u062D\u0645',
  20342. '\uFD8B': '\u0645\u062D\u064A',
  20343. '\uFD8C': '\u0645\u062C\u062D',
  20344. '\uFD8D': '\u0645\u062C\u0645',
  20345. '\uFD8E': '\u0645\u062E\u062C',
  20346. '\uFD8F': '\u0645\u062E\u0645',
  20347. '\uFD92': '\u0645\u062C\u062E',
  20348. '\uFD93': '\u0647\u0645\u062C',
  20349. '\uFD94': '\u0647\u0645\u0645',
  20350. '\uFD95': '\u0646\u062D\u0645',
  20351. '\uFD96': '\u0646\u062D\u0649',
  20352. '\uFD97': '\u0646\u062C\u0645',
  20353. '\uFD98': '\u0646\u062C\u0645',
  20354. '\uFD99': '\u0646\u062C\u0649',
  20355. '\uFD9A': '\u0646\u0645\u064A',
  20356. '\uFD9B': '\u0646\u0645\u0649',
  20357. '\uFD9C': '\u064A\u0645\u0645',
  20358. '\uFD9D': '\u064A\u0645\u0645',
  20359. '\uFD9E': '\u0628\u062E\u064A',
  20360. '\uFD9F': '\u062A\u062C\u064A',
  20361. '\uFDA0': '\u062A\u062C\u0649',
  20362. '\uFDA1': '\u062A\u062E\u064A',
  20363. '\uFDA2': '\u062A\u062E\u0649',
  20364. '\uFDA3': '\u062A\u0645\u064A',
  20365. '\uFDA4': '\u062A\u0645\u0649',
  20366. '\uFDA5': '\u062C\u0645\u064A',
  20367. '\uFDA6': '\u062C\u062D\u0649',
  20368. '\uFDA7': '\u062C\u0645\u0649',
  20369. '\uFDA8': '\u0633\u062E\u0649',
  20370. '\uFDA9': '\u0635\u062D\u064A',
  20371. '\uFDAA': '\u0634\u062D\u064A',
  20372. '\uFDAB': '\u0636\u062D\u064A',
  20373. '\uFDAC': '\u0644\u062C\u064A',
  20374. '\uFDAD': '\u0644\u0645\u064A',
  20375. '\uFDAE': '\u064A\u062D\u064A',
  20376. '\uFDAF': '\u064A\u062C\u064A',
  20377. '\uFDB0': '\u064A\u0645\u064A',
  20378. '\uFDB1': '\u0645\u0645\u064A',
  20379. '\uFDB2': '\u0642\u0645\u064A',
  20380. '\uFDB3': '\u0646\u062D\u064A',
  20381. '\uFDB4': '\u0642\u0645\u062D',
  20382. '\uFDB5': '\u0644\u062D\u0645',
  20383. '\uFDB6': '\u0639\u0645\u064A',
  20384. '\uFDB7': '\u0643\u0645\u064A',
  20385. '\uFDB8': '\u0646\u062C\u062D',
  20386. '\uFDB9': '\u0645\u062E\u064A',
  20387. '\uFDBA': '\u0644\u062C\u0645',
  20388. '\uFDBB': '\u0643\u0645\u0645',
  20389. '\uFDBC': '\u0644\u062C\u0645',
  20390. '\uFDBD': '\u0646\u062C\u062D',
  20391. '\uFDBE': '\u062C\u062D\u064A',
  20392. '\uFDBF': '\u062D\u062C\u064A',
  20393. '\uFDC0': '\u0645\u062C\u064A',
  20394. '\uFDC1': '\u0641\u0645\u064A',
  20395. '\uFDC2': '\u0628\u062D\u064A',
  20396. '\uFDC3': '\u0643\u0645\u0645',
  20397. '\uFDC4': '\u0639\u062C\u0645',
  20398. '\uFDC5': '\u0635\u0645\u0645',
  20399. '\uFDC6': '\u0633\u062E\u064A',
  20400. '\uFDC7': '\u0646\u062C\u064A',
  20401. '\uFE49': '\u203E',
  20402. '\uFE4A': '\u203E',
  20403. '\uFE4B': '\u203E',
  20404. '\uFE4C': '\u203E',
  20405. '\uFE4D': '\u005F',
  20406. '\uFE4E': '\u005F',
  20407. '\uFE4F': '\u005F',
  20408. '\uFE80': '\u0621',
  20409. '\uFE81': '\u0622',
  20410. '\uFE82': '\u0622',
  20411. '\uFE83': '\u0623',
  20412. '\uFE84': '\u0623',
  20413. '\uFE85': '\u0624',
  20414. '\uFE86': '\u0624',
  20415. '\uFE87': '\u0625',
  20416. '\uFE88': '\u0625',
  20417. '\uFE89': '\u0626',
  20418. '\uFE8A': '\u0626',
  20419. '\uFE8B': '\u0626',
  20420. '\uFE8C': '\u0626',
  20421. '\uFE8D': '\u0627',
  20422. '\uFE8E': '\u0627',
  20423. '\uFE8F': '\u0628',
  20424. '\uFE90': '\u0628',
  20425. '\uFE91': '\u0628',
  20426. '\uFE92': '\u0628',
  20427. '\uFE93': '\u0629',
  20428. '\uFE94': '\u0629',
  20429. '\uFE95': '\u062A',
  20430. '\uFE96': '\u062A',
  20431. '\uFE97': '\u062A',
  20432. '\uFE98': '\u062A',
  20433. '\uFE99': '\u062B',
  20434. '\uFE9A': '\u062B',
  20435. '\uFE9B': '\u062B',
  20436. '\uFE9C': '\u062B',
  20437. '\uFE9D': '\u062C',
  20438. '\uFE9E': '\u062C',
  20439. '\uFE9F': '\u062C',
  20440. '\uFEA0': '\u062C',
  20441. '\uFEA1': '\u062D',
  20442. '\uFEA2': '\u062D',
  20443. '\uFEA3': '\u062D',
  20444. '\uFEA4': '\u062D',
  20445. '\uFEA5': '\u062E',
  20446. '\uFEA6': '\u062E',
  20447. '\uFEA7': '\u062E',
  20448. '\uFEA8': '\u062E',
  20449. '\uFEA9': '\u062F',
  20450. '\uFEAA': '\u062F',
  20451. '\uFEAB': '\u0630',
  20452. '\uFEAC': '\u0630',
  20453. '\uFEAD': '\u0631',
  20454. '\uFEAE': '\u0631',
  20455. '\uFEAF': '\u0632',
  20456. '\uFEB0': '\u0632',
  20457. '\uFEB1': '\u0633',
  20458. '\uFEB2': '\u0633',
  20459. '\uFEB3': '\u0633',
  20460. '\uFEB4': '\u0633',
  20461. '\uFEB5': '\u0634',
  20462. '\uFEB6': '\u0634',
  20463. '\uFEB7': '\u0634',
  20464. '\uFEB8': '\u0634',
  20465. '\uFEB9': '\u0635',
  20466. '\uFEBA': '\u0635',
  20467. '\uFEBB': '\u0635',
  20468. '\uFEBC': '\u0635',
  20469. '\uFEBD': '\u0636',
  20470. '\uFEBE': '\u0636',
  20471. '\uFEBF': '\u0636',
  20472. '\uFEC0': '\u0636',
  20473. '\uFEC1': '\u0637',
  20474. '\uFEC2': '\u0637',
  20475. '\uFEC3': '\u0637',
  20476. '\uFEC4': '\u0637',
  20477. '\uFEC5': '\u0638',
  20478. '\uFEC6': '\u0638',
  20479. '\uFEC7': '\u0638',
  20480. '\uFEC8': '\u0638',
  20481. '\uFEC9': '\u0639',
  20482. '\uFECA': '\u0639',
  20483. '\uFECB': '\u0639',
  20484. '\uFECC': '\u0639',
  20485. '\uFECD': '\u063A',
  20486. '\uFECE': '\u063A',
  20487. '\uFECF': '\u063A',
  20488. '\uFED0': '\u063A',
  20489. '\uFED1': '\u0641',
  20490. '\uFED2': '\u0641',
  20491. '\uFED3': '\u0641',
  20492. '\uFED4': '\u0641',
  20493. '\uFED5': '\u0642',
  20494. '\uFED6': '\u0642',
  20495. '\uFED7': '\u0642',
  20496. '\uFED8': '\u0642',
  20497. '\uFED9': '\u0643',
  20498. '\uFEDA': '\u0643',
  20499. '\uFEDB': '\u0643',
  20500. '\uFEDC': '\u0643',
  20501. '\uFEDD': '\u0644',
  20502. '\uFEDE': '\u0644',
  20503. '\uFEDF': '\u0644',
  20504. '\uFEE0': '\u0644',
  20505. '\uFEE1': '\u0645',
  20506. '\uFEE2': '\u0645',
  20507. '\uFEE3': '\u0645',
  20508. '\uFEE4': '\u0645',
  20509. '\uFEE5': '\u0646',
  20510. '\uFEE6': '\u0646',
  20511. '\uFEE7': '\u0646',
  20512. '\uFEE8': '\u0646',
  20513. '\uFEE9': '\u0647',
  20514. '\uFEEA': '\u0647',
  20515. '\uFEEB': '\u0647',
  20516. '\uFEEC': '\u0647',
  20517. '\uFEED': '\u0648',
  20518. '\uFEEE': '\u0648',
  20519. '\uFEEF': '\u0649',
  20520. '\uFEF0': '\u0649',
  20521. '\uFEF1': '\u064A',
  20522. '\uFEF2': '\u064A',
  20523. '\uFEF3': '\u064A',
  20524. '\uFEF4': '\u064A',
  20525. '\uFEF5': '\u0644\u0622',
  20526. '\uFEF6': '\u0644\u0622',
  20527. '\uFEF7': '\u0644\u0623',
  20528. '\uFEF8': '\u0644\u0623',
  20529. '\uFEF9': '\u0644\u0625',
  20530. '\uFEFA': '\u0644\u0625',
  20531. '\uFEFB': '\u0644\u0627',
  20532. '\uFEFC': '\u0644\u0627'
  20533. };
  20534. function reverseIfRtl(chars) {
  20535. var charsLength = chars.length;
  20536. //reverse an arabic ligature
  20537. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20538. return chars;
  20539. }
  20540. var s = '';
  20541. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20542. s += chars[ii];
  20543. }
  20544. return s;
  20545. }
  20546. function adjustWidths(properties) {
  20547. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20548. return;
  20549. }
  20550. // adjusting width to fontMatrix scale
  20551. var scale = 0.001 / properties.fontMatrix[0];
  20552. var glyphsWidths = properties.widths;
  20553. for (var glyph in glyphsWidths) {
  20554. glyphsWidths[glyph] *= scale;
  20555. }
  20556. properties.defaultWidth *= scale;
  20557. }
  20558. function getFontType(type, subtype) {
  20559. switch (type) {
  20560. case 'Type1':
  20561. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20562. case 'CIDFontType0':
  20563. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20564. FontType.CIDFONTTYPE0;
  20565. case 'OpenType':
  20566. return FontType.OPENTYPE;
  20567. case 'TrueType':
  20568. return FontType.TRUETYPE;
  20569. case 'CIDFontType2':
  20570. return FontType.CIDFONTTYPE2;
  20571. case 'MMType1':
  20572. return FontType.MMTYPE1;
  20573. case 'Type0':
  20574. return FontType.TYPE0;
  20575. default:
  20576. return FontType.UNKNOWN;
  20577. }
  20578. }
  20579. var Glyph = (function GlyphClosure() {
  20580. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20581. this.fontChar = fontChar;
  20582. this.unicode = unicode;
  20583. this.accent = accent;
  20584. this.width = width;
  20585. this.vmetric = vmetric;
  20586. this.operatorListId = operatorListId;
  20587. }
  20588. Glyph.prototype.matchesForCache =
  20589. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20590. return this.fontChar === fontChar &&
  20591. this.unicode === unicode &&
  20592. this.accent === accent &&
  20593. this.width === width &&
  20594. this.vmetric === vmetric &&
  20595. this.operatorListId === operatorListId;
  20596. };
  20597. return Glyph;
  20598. })();
  20599. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20600. function ToUnicodeMap(cmap) {
  20601. // The elements of this._map can be integers or strings, depending on how
  20602. // |cmap| was created.
  20603. this._map = cmap;
  20604. }
  20605. ToUnicodeMap.prototype = {
  20606. get length() {
  20607. return this._map.length;
  20608. },
  20609. forEach: function(callback) {
  20610. for (var charCode in this._map) {
  20611. callback(charCode, this._map[charCode].charCodeAt(0));
  20612. }
  20613. },
  20614. has: function(i) {
  20615. return this._map[i] !== undefined;
  20616. },
  20617. get: function(i) {
  20618. return this._map[i];
  20619. },
  20620. charCodeOf: function(v) {
  20621. return this._map.indexOf(v);
  20622. }
  20623. };
  20624. return ToUnicodeMap;
  20625. })();
  20626. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20627. function IdentityToUnicodeMap(firstChar, lastChar) {
  20628. this.firstChar = firstChar;
  20629. this.lastChar = lastChar;
  20630. }
  20631. IdentityToUnicodeMap.prototype = {
  20632. get length() {
  20633. error('should not access .length');
  20634. },
  20635. forEach: function (callback) {
  20636. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20637. callback(i, i);
  20638. }
  20639. },
  20640. has: function (i) {
  20641. return this.firstChar <= i && i <= this.lastChar;
  20642. },
  20643. get: function (i) {
  20644. if (this.firstChar <= i && i <= this.lastChar) {
  20645. return String.fromCharCode(i);
  20646. }
  20647. return undefined;
  20648. },
  20649. charCodeOf: function (v) {
  20650. error('should not call .charCodeOf');
  20651. }
  20652. };
  20653. return IdentityToUnicodeMap;
  20654. })();
  20655. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20656. function writeInt16(dest, offset, num) {
  20657. dest[offset] = (num >> 8) & 0xFF;
  20658. dest[offset + 1] = num & 0xFF;
  20659. }
  20660. function writeInt32(dest, offset, num) {
  20661. dest[offset] = (num >> 24) & 0xFF;
  20662. dest[offset + 1] = (num >> 16) & 0xFF;
  20663. dest[offset + 2] = (num >> 8) & 0xFF;
  20664. dest[offset + 3] = num & 0xFF;
  20665. }
  20666. function writeData(dest, offset, data) {
  20667. var i, ii;
  20668. if (data instanceof Uint8Array) {
  20669. dest.set(data, offset);
  20670. } else if (typeof data === 'string') {
  20671. for (i = 0, ii = data.length; i < ii; i++) {
  20672. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20673. }
  20674. } else {
  20675. // treating everything else as array
  20676. for (i = 0, ii = data.length; i < ii; i++) {
  20677. dest[offset++] = data[i] & 0xFF;
  20678. }
  20679. }
  20680. }
  20681. function OpenTypeFileBuilder(sfnt) {
  20682. this.sfnt = sfnt;
  20683. this.tables = Object.create(null);
  20684. }
  20685. OpenTypeFileBuilder.getSearchParams =
  20686. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20687. var maxPower2 = 1, log2 = 0;
  20688. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20689. maxPower2 <<= 1;
  20690. log2++;
  20691. }
  20692. var searchRange = maxPower2 * entrySize;
  20693. return {
  20694. range: searchRange,
  20695. entry: log2,
  20696. rangeShift: entrySize * entriesCount - searchRange
  20697. };
  20698. };
  20699. var OTF_HEADER_SIZE = 12;
  20700. var OTF_TABLE_ENTRY_SIZE = 16;
  20701. OpenTypeFileBuilder.prototype = {
  20702. toArray: function OpenTypeFileBuilder_toArray() {
  20703. var sfnt = this.sfnt;
  20704. // Tables needs to be written by ascendant alphabetic order
  20705. var tables = this.tables;
  20706. var tablesNames = Object.keys(tables);
  20707. tablesNames.sort();
  20708. var numTables = tablesNames.length;
  20709. var i, j, jj, table, tableName;
  20710. // layout the tables data
  20711. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20712. var tableOffsets = [offset];
  20713. for (i = 0; i < numTables; i++) {
  20714. table = tables[tablesNames[i]];
  20715. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20716. offset += paddedLength;
  20717. tableOffsets.push(offset);
  20718. }
  20719. var file = new Uint8Array(offset);
  20720. // write the table data first (mostly for checksum)
  20721. for (i = 0; i < numTables; i++) {
  20722. table = tables[tablesNames[i]];
  20723. writeData(file, tableOffsets[i], table);
  20724. }
  20725. // sfnt version (4 bytes)
  20726. if (sfnt === 'true') {
  20727. // Windows hates the Mac TrueType sfnt version number
  20728. sfnt = string32(0x00010000);
  20729. }
  20730. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20731. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20732. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20733. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20734. // numTables (2 bytes)
  20735. writeInt16(file, 4, numTables);
  20736. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20737. // searchRange (2 bytes)
  20738. writeInt16(file, 6, searchParams.range);
  20739. // entrySelector (2 bytes)
  20740. writeInt16(file, 8, searchParams.entry);
  20741. // rangeShift (2 bytes)
  20742. writeInt16(file, 10, searchParams.rangeShift);
  20743. offset = OTF_HEADER_SIZE;
  20744. // writing table entries
  20745. for (i = 0; i < numTables; i++) {
  20746. tableName = tablesNames[i];
  20747. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20748. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20749. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20750. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20751. // checksum
  20752. var checksum = 0;
  20753. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20754. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20755. (file[j + 2] << 8) + file[j + 3];
  20756. checksum = (checksum + quad) | 0;
  20757. }
  20758. writeInt32(file, offset + 4, checksum);
  20759. // offset
  20760. writeInt32(file, offset + 8, tableOffsets[i]);
  20761. // length
  20762. writeInt32(file, offset + 12, tables[tableName].length);
  20763. offset += OTF_TABLE_ENTRY_SIZE;
  20764. }
  20765. return file;
  20766. },
  20767. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20768. if (tag in this.tables) {
  20769. throw new Error('Table ' + tag + ' already exists');
  20770. }
  20771. this.tables[tag] = data;
  20772. }
  20773. };
  20774. return OpenTypeFileBuilder;
  20775. })();
  20776. /**
  20777. * 'Font' is the class the outside world should use, it encapsulate all the font
  20778. * decoding logics whatever type it is (assuming the font type is supported).
  20779. *
  20780. * For example to read a Type1 font and to attach it to the document:
  20781. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20782. * type1Font.bind();
  20783. */
  20784. var Font = (function FontClosure() {
  20785. function Font(name, file, properties) {
  20786. var charCode, glyphName, fontChar;
  20787. this.name = name;
  20788. this.loadedName = properties.loadedName;
  20789. this.isType3Font = properties.isType3Font;
  20790. this.sizes = [];
  20791. this.glyphCache = {};
  20792. var names = name.split('+');
  20793. names = names.length > 1 ? names[1] : names[0];
  20794. names = names.split(/[-,_]/g)[0];
  20795. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20796. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20797. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20798. var type = properties.type;
  20799. var subtype = properties.subtype;
  20800. this.type = type;
  20801. this.fallbackName = (this.isMonospace ? 'monospace' :
  20802. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20803. this.differences = properties.differences;
  20804. this.widths = properties.widths;
  20805. this.defaultWidth = properties.defaultWidth;
  20806. this.composite = properties.composite;
  20807. this.wideChars = properties.wideChars;
  20808. this.cMap = properties.cMap;
  20809. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20810. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20811. this.fontMatrix = properties.fontMatrix;
  20812. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20813. this.toFontChar = [];
  20814. if (properties.type === 'Type3') {
  20815. for (charCode = 0; charCode < 256; charCode++) {
  20816. this.toFontChar[charCode] = (this.differences[charCode] ||
  20817. properties.defaultEncoding[charCode]);
  20818. }
  20819. this.fontType = FontType.TYPE3;
  20820. return;
  20821. }
  20822. this.cidEncoding = properties.cidEncoding;
  20823. this.vertical = properties.vertical;
  20824. if (this.vertical) {
  20825. this.vmetrics = properties.vmetrics;
  20826. this.defaultVMetrics = properties.defaultVMetrics;
  20827. }
  20828. if (!file || file.isEmpty) {
  20829. if (file) {
  20830. // Some bad PDF generators will include empty font files,
  20831. // attempting to recover by assuming that no file exists.
  20832. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20833. }
  20834. this.missingFile = true;
  20835. // The file data is not specified. Trying to fix the font name
  20836. // to be used with the canvas.font.
  20837. var fontName = name.replace(/[,_]/g, '-');
  20838. var isStandardFont = !!stdFontMap[fontName] ||
  20839. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20840. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20841. this.bold = (fontName.search(/bold/gi) !== -1);
  20842. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20843. (fontName.search(/italic/gi) !== -1));
  20844. // Use 'name' instead of 'fontName' here because the original
  20845. // name ArialBlack for example will be replaced by Helvetica.
  20846. this.black = (name.search(/Black/g) !== -1);
  20847. // if at least one width is present, remeasure all chars when exists
  20848. this.remeasure = Object.keys(this.widths).length > 0;
  20849. if (isStandardFont && type === 'CIDFontType2' &&
  20850. properties.cidEncoding.indexOf('Identity-') === 0) {
  20851. // Standard fonts might be embedded as CID font without glyph mapping.
  20852. // Building one based on GlyphMapForStandardFonts.
  20853. var map = [];
  20854. for (var code in GlyphMapForStandardFonts) {
  20855. map[+code] = GlyphMapForStandardFonts[code];
  20856. }
  20857. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20858. if (!isIdentityUnicode) {
  20859. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20860. map[+charCode] = unicodeCharCode;
  20861. });
  20862. }
  20863. this.toFontChar = map;
  20864. this.toUnicode = new ToUnicodeMap(map);
  20865. } else if (/Symbol/i.test(fontName)) {
  20866. var symbols = Encodings.SymbolSetEncoding;
  20867. for (charCode in symbols) {
  20868. fontChar = GlyphsUnicode[symbols[charCode]];
  20869. if (!fontChar) {
  20870. continue;
  20871. }
  20872. this.toFontChar[charCode] = fontChar;
  20873. }
  20874. for (charCode in properties.differences) {
  20875. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20876. if (!fontChar) {
  20877. continue;
  20878. }
  20879. this.toFontChar[charCode] = fontChar;
  20880. }
  20881. } else if (/Dingbats/i.test(fontName)) {
  20882. if (/Wingdings/i.test(name)) {
  20883. warn('Wingdings font without embedded font file, ' +
  20884. 'falling back to the ZapfDingbats encoding.');
  20885. }
  20886. var dingbats = Encodings.ZapfDingbatsEncoding;
  20887. for (charCode in dingbats) {
  20888. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20889. if (!fontChar) {
  20890. continue;
  20891. }
  20892. this.toFontChar[charCode] = fontChar;
  20893. }
  20894. for (charCode in properties.differences) {
  20895. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20896. if (!fontChar) {
  20897. continue;
  20898. }
  20899. this.toFontChar[charCode] = fontChar;
  20900. }
  20901. } else if (isStandardFont) {
  20902. this.toFontChar = [];
  20903. for (charCode in properties.defaultEncoding) {
  20904. glyphName = (properties.differences[charCode] ||
  20905. properties.defaultEncoding[charCode]);
  20906. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20907. }
  20908. } else {
  20909. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20910. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20911. if (notCidFont) {
  20912. glyphName = (properties.differences[charCode] ||
  20913. properties.defaultEncoding[charCode]);
  20914. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20915. }
  20916. this.toFontChar[charCode] = unicodeCharCode;
  20917. }.bind(this));
  20918. }
  20919. this.loadedName = fontName.split('-')[0];
  20920. this.loading = false;
  20921. this.fontType = getFontType(type, subtype);
  20922. return;
  20923. }
  20924. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20925. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20926. // Some TrueType fonts by mistake claim Type1C
  20927. if (isTrueTypeFile(file)) {
  20928. subtype = 'TrueType';
  20929. } else {
  20930. type = 'Type1';
  20931. }
  20932. }
  20933. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20934. type = 'CIDFontType0';
  20935. }
  20936. if (subtype === 'OpenType') {
  20937. type = 'OpenType';
  20938. }
  20939. var data;
  20940. switch (type) {
  20941. case 'MMType1':
  20942. info('MMType1 font (' + name + '), falling back to Type1.');
  20943. /* falls through */
  20944. case 'Type1':
  20945. case 'CIDFontType0':
  20946. this.mimetype = 'font/opentype';
  20947. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20948. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20949. adjustWidths(properties);
  20950. // Wrap the CFF data inside an OTF font file
  20951. data = this.convert(name, cff, properties);
  20952. break;
  20953. case 'OpenType':
  20954. case 'TrueType':
  20955. case 'CIDFontType2':
  20956. this.mimetype = 'font/opentype';
  20957. // Repair the TrueType file. It is can be damaged in the point of
  20958. // view of the sanitizer
  20959. data = this.checkAndRepair(name, file, properties);
  20960. if (this.isOpenType) {
  20961. type = 'OpenType';
  20962. }
  20963. break;
  20964. default:
  20965. error('Font ' + type + ' is not supported');
  20966. break;
  20967. }
  20968. this.data = data;
  20969. this.fontType = getFontType(type, subtype);
  20970. // Transfer some properties again that could change during font conversion
  20971. this.fontMatrix = properties.fontMatrix;
  20972. this.widths = properties.widths;
  20973. this.defaultWidth = properties.defaultWidth;
  20974. this.encoding = properties.baseEncoding;
  20975. this.seacMap = properties.seacMap;
  20976. this.loading = true;
  20977. }
  20978. Font.getFontID = (function () {
  20979. var ID = 1;
  20980. return function Font_getFontID() {
  20981. return String(ID++);
  20982. };
  20983. })();
  20984. function int16(b0, b1) {
  20985. return (b0 << 8) + b1;
  20986. }
  20987. function int32(b0, b1, b2, b3) {
  20988. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20989. }
  20990. function string16(value) {
  20991. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20992. }
  20993. function safeString16(value) {
  20994. // clamp value to the 16-bit int range
  20995. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20996. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20997. }
  20998. function isTrueTypeFile(file) {
  20999. var header = file.peekBytes(4);
  21000. return readUint32(header, 0) === 0x00010000;
  21001. }
  21002. /**
  21003. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  21004. * with their unicode value. It also moves char codes that are in known
  21005. * problematic locations.
  21006. * @return {Object} Two properties:
  21007. * 'toFontChar' - maps original char codes(the value that will be read
  21008. * from commands such as show text) to the char codes that will be used in the
  21009. * font that we build
  21010. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  21011. */
  21012. function adjustMapping(charCodeToGlyphId, properties) {
  21013. var toUnicode = properties.toUnicode;
  21014. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  21015. var isIdentityUnicode =
  21016. properties.toUnicode instanceof IdentityToUnicodeMap;
  21017. var newMap = Object.create(null);
  21018. var toFontChar = [];
  21019. var usedFontCharCodes = [];
  21020. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21021. for (var originalCharCode in charCodeToGlyphId) {
  21022. originalCharCode |= 0;
  21023. var glyphId = charCodeToGlyphId[originalCharCode];
  21024. var fontCharCode = originalCharCode;
  21025. // First try to map the value to a unicode position if a non identity map
  21026. // was created.
  21027. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21028. var unicode = toUnicode.get(fontCharCode);
  21029. // TODO: Try to map ligatures to the correct spot.
  21030. if (unicode.length === 1) {
  21031. fontCharCode = unicode.charCodeAt(0);
  21032. }
  21033. }
  21034. // Try to move control characters, special characters and already mapped
  21035. // characters to the private use area since they will not be drawn by
  21036. // canvas if left in their current position. Also, move characters if the
  21037. // font was symbolic and there is only an identity unicode map since the
  21038. // characters probably aren't in the correct position (fixes an issue
  21039. // with firefox and thuluthfont).
  21040. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21041. fontCharCode <= 0x1f || // Control chars
  21042. fontCharCode === 0x7F || // Control char
  21043. fontCharCode === 0xAD || // Soft hyphen
  21044. fontCharCode === 0xA0 || // Non breaking space
  21045. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  21046. // Prevent drawing characters in the specials unicode block.
  21047. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  21048. (isSymbolic && isIdentityUnicode)) &&
  21049. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21050. // Loop to try and find a free spot in the private use area.
  21051. do {
  21052. fontCharCode = nextAvailableFontCharCode++;
  21053. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21054. fontCharCode = 0xF020;
  21055. nextAvailableFontCharCode = fontCharCode + 1;
  21056. }
  21057. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21058. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21059. }
  21060. newMap[fontCharCode] = glyphId;
  21061. toFontChar[originalCharCode] = fontCharCode;
  21062. usedFontCharCodes[fontCharCode] = true;
  21063. }
  21064. return {
  21065. toFontChar: toFontChar,
  21066. charCodeToGlyphId: newMap,
  21067. nextAvailableFontCharCode: nextAvailableFontCharCode
  21068. };
  21069. }
  21070. function getRanges(glyphs) {
  21071. // Array.sort() sorts by characters, not numerically, so convert to an
  21072. // array of characters.
  21073. var codes = [];
  21074. for (var charCode in glyphs) {
  21075. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21076. }
  21077. codes.sort(function fontGetRangesSort(a, b) {
  21078. return a.fontCharCode - b.fontCharCode;
  21079. });
  21080. // Split the sorted codes into ranges.
  21081. var ranges = [];
  21082. var length = codes.length;
  21083. for (var n = 0; n < length; ) {
  21084. var start = codes[n].fontCharCode;
  21085. var codeIndices = [codes[n].glyphId];
  21086. ++n;
  21087. var end = start;
  21088. while (n < length && end + 1 === codes[n].fontCharCode) {
  21089. codeIndices.push(codes[n].glyphId);
  21090. ++end;
  21091. ++n;
  21092. if (end === 0xFFFF) {
  21093. break;
  21094. }
  21095. }
  21096. ranges.push([start, end, codeIndices]);
  21097. }
  21098. return ranges;
  21099. }
  21100. function createCmapTable(glyphs) {
  21101. var ranges = getRanges(glyphs);
  21102. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21103. var cmap = '\x00\x00' + // version
  21104. string16(numTables) + // numTables
  21105. '\x00\x03' + // platformID
  21106. '\x00\x01' + // encodingID
  21107. string32(4 + numTables * 8); // start of the table record
  21108. var i, ii, j, jj;
  21109. for (i = ranges.length - 1; i >= 0; --i) {
  21110. if (ranges[i][0] <= 0xFFFF) { break; }
  21111. }
  21112. var bmpLength = i + 1;
  21113. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21114. ranges[i][1] = 0xFFFE;
  21115. }
  21116. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21117. var segCount = bmpLength + trailingRangesCount;
  21118. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21119. // Fill up the 4 parallel arrays describing the segments.
  21120. var startCount = '';
  21121. var endCount = '';
  21122. var idDeltas = '';
  21123. var idRangeOffsets = '';
  21124. var glyphsIds = '';
  21125. var bias = 0;
  21126. var range, start, end, codes;
  21127. for (i = 0, ii = bmpLength; i < ii; i++) {
  21128. range = ranges[i];
  21129. start = range[0];
  21130. end = range[1];
  21131. startCount += string16(start);
  21132. endCount += string16(end);
  21133. codes = range[2];
  21134. var contiguous = true;
  21135. for (j = 1, jj = codes.length; j < jj; ++j) {
  21136. if (codes[j] !== codes[j - 1] + 1) {
  21137. contiguous = false;
  21138. break;
  21139. }
  21140. }
  21141. if (!contiguous) {
  21142. var offset = (segCount - i) * 2 + bias * 2;
  21143. bias += (end - start + 1);
  21144. idDeltas += string16(0);
  21145. idRangeOffsets += string16(offset);
  21146. for (j = 0, jj = codes.length; j < jj; ++j) {
  21147. glyphsIds += string16(codes[j]);
  21148. }
  21149. } else {
  21150. var startCode = codes[0];
  21151. idDeltas += string16((startCode - start) & 0xFFFF);
  21152. idRangeOffsets += string16(0);
  21153. }
  21154. }
  21155. if (trailingRangesCount > 0) {
  21156. endCount += '\xFF\xFF';
  21157. startCount += '\xFF\xFF';
  21158. idDeltas += '\x00\x01';
  21159. idRangeOffsets += '\x00\x00';
  21160. }
  21161. var format314 = '\x00\x00' + // language
  21162. string16(2 * segCount) +
  21163. string16(searchParams.range) +
  21164. string16(searchParams.entry) +
  21165. string16(searchParams.rangeShift) +
  21166. endCount + '\x00\x00' + startCount +
  21167. idDeltas + idRangeOffsets + glyphsIds;
  21168. var format31012 = '';
  21169. var header31012 = '';
  21170. if (numTables > 1) {
  21171. cmap += '\x00\x03' + // platformID
  21172. '\x00\x0A' + // encodingID
  21173. string32(4 + numTables * 8 +
  21174. 4 + format314.length); // start of the table record
  21175. format31012 = '';
  21176. for (i = 0, ii = ranges.length; i < ii; i++) {
  21177. range = ranges[i];
  21178. start = range[0];
  21179. codes = range[2];
  21180. var code = codes[0];
  21181. for (j = 1, jj = codes.length; j < jj; ++j) {
  21182. if (codes[j] !== codes[j - 1] + 1) {
  21183. end = range[0] + j - 1;
  21184. format31012 += string32(start) + // startCharCode
  21185. string32(end) + // endCharCode
  21186. string32(code); // startGlyphID
  21187. start = end + 1;
  21188. code = codes[j];
  21189. }
  21190. }
  21191. format31012 += string32(start) + // startCharCode
  21192. string32(range[1]) + // endCharCode
  21193. string32(code); // startGlyphID
  21194. }
  21195. header31012 = '\x00\x0C' + // format
  21196. '\x00\x00' + // reserved
  21197. string32(format31012.length + 16) + // length
  21198. '\x00\x00\x00\x00' + // language
  21199. string32(format31012.length / 12); // nGroups
  21200. }
  21201. return cmap + '\x00\x04' + // format
  21202. string16(format314.length + 4) + // length
  21203. format314 + header31012 + format31012;
  21204. }
  21205. function validateOS2Table(os2) {
  21206. var stream = new Stream(os2.data);
  21207. var version = stream.getUint16();
  21208. // TODO verify all OS/2 tables fields, but currently we validate only those
  21209. // that give us issues
  21210. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21211. var selection = stream.getUint16();
  21212. if (version < 4 && (selection & 0x0300)) {
  21213. return false;
  21214. }
  21215. var firstChar = stream.getUint16();
  21216. var lastChar = stream.getUint16();
  21217. if (firstChar > lastChar) {
  21218. return false;
  21219. }
  21220. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21221. var usWinAscent = stream.getUint16();
  21222. if (usWinAscent === 0) { // makes font unreadable by windows
  21223. return false;
  21224. }
  21225. // OS/2 appears to be valid, resetting some fields
  21226. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21227. return true;
  21228. }
  21229. function createOS2Table(properties, charstrings, override) {
  21230. override = override || {
  21231. unitsPerEm: 0,
  21232. yMax: 0,
  21233. yMin: 0,
  21234. ascent: 0,
  21235. descent: 0
  21236. };
  21237. var ulUnicodeRange1 = 0;
  21238. var ulUnicodeRange2 = 0;
  21239. var ulUnicodeRange3 = 0;
  21240. var ulUnicodeRange4 = 0;
  21241. var firstCharIndex = null;
  21242. var lastCharIndex = 0;
  21243. if (charstrings) {
  21244. for (var code in charstrings) {
  21245. code |= 0;
  21246. if (firstCharIndex > code || !firstCharIndex) {
  21247. firstCharIndex = code;
  21248. }
  21249. if (lastCharIndex < code) {
  21250. lastCharIndex = code;
  21251. }
  21252. var position = getUnicodeRangeFor(code);
  21253. if (position < 32) {
  21254. ulUnicodeRange1 |= 1 << position;
  21255. } else if (position < 64) {
  21256. ulUnicodeRange2 |= 1 << position - 32;
  21257. } else if (position < 96) {
  21258. ulUnicodeRange3 |= 1 << position - 64;
  21259. } else if (position < 123) {
  21260. ulUnicodeRange4 |= 1 << position - 96;
  21261. } else {
  21262. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21263. }
  21264. }
  21265. } else {
  21266. // TODO
  21267. firstCharIndex = 0;
  21268. lastCharIndex = 255;
  21269. }
  21270. var bbox = properties.bbox || [0, 0, 0, 0];
  21271. var unitsPerEm = (override.unitsPerEm ||
  21272. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21273. // if the font units differ to the PDF glyph space units
  21274. // then scale up the values
  21275. var scale = (properties.ascentScaled ? 1.0 :
  21276. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21277. var typoAscent = (override.ascent ||
  21278. Math.round(scale * (properties.ascent || bbox[3])));
  21279. var typoDescent = (override.descent ||
  21280. Math.round(scale * (properties.descent || bbox[1])));
  21281. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21282. typoDescent = -typoDescent; // fixing incorrect descent
  21283. }
  21284. var winAscent = override.yMax || typoAscent;
  21285. var winDescent = -override.yMin || -typoDescent;
  21286. return '\x00\x03' + // version
  21287. '\x02\x24' + // xAvgCharWidth
  21288. '\x01\xF4' + // usWeightClass
  21289. '\x00\x05' + // usWidthClass
  21290. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21291. '\x02\x8A' + // ySubscriptXSize
  21292. '\x02\xBB' + // ySubscriptYSize
  21293. '\x00\x00' + // ySubscriptXOffset
  21294. '\x00\x8C' + // ySubscriptYOffset
  21295. '\x02\x8A' + // ySuperScriptXSize
  21296. '\x02\xBB' + // ySuperScriptYSize
  21297. '\x00\x00' + // ySuperScriptXOffset
  21298. '\x01\xDF' + // ySuperScriptYOffset
  21299. '\x00\x31' + // yStrikeOutSize
  21300. '\x01\x02' + // yStrikeOutPosition
  21301. '\x00\x00' + // sFamilyClass
  21302. '\x00\x00\x06' +
  21303. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21304. '\x00\x00\x00\x00\x00\x00' + // Panose
  21305. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21306. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21307. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21308. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21309. '\x2A\x32\x31\x2A' + // achVendID
  21310. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21311. string16(firstCharIndex ||
  21312. properties.firstChar) + // usFirstCharIndex
  21313. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21314. string16(typoAscent) + // sTypoAscender
  21315. string16(typoDescent) + // sTypoDescender
  21316. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21317. string16(winAscent) + // usWinAscent
  21318. string16(winDescent) + // usWinDescent
  21319. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21320. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21321. string16(properties.xHeight) + // sxHeight
  21322. string16(properties.capHeight) + // sCapHeight
  21323. string16(0) + // usDefaultChar
  21324. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21325. '\x00\x03'; // usMaxContext
  21326. }
  21327. function createPostTable(properties) {
  21328. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21329. return ('\x00\x03\x00\x00' + // Version number
  21330. string32(angle) + // italicAngle
  21331. '\x00\x00' + // underlinePosition
  21332. '\x00\x00' + // underlineThickness
  21333. string32(properties.fixedPitch) + // isFixedPitch
  21334. '\x00\x00\x00\x00' + // minMemType42
  21335. '\x00\x00\x00\x00' + // maxMemType42
  21336. '\x00\x00\x00\x00' + // minMemType1
  21337. '\x00\x00\x00\x00'); // maxMemType1
  21338. }
  21339. function createNameTable(name, proto) {
  21340. if (!proto) {
  21341. proto = [[], []]; // no strings and unicode strings
  21342. }
  21343. var strings = [
  21344. proto[0][0] || 'Original licence', // 0.Copyright
  21345. proto[0][1] || name, // 1.Font family
  21346. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21347. proto[0][3] || 'uniqueID', // 3.Unique ID
  21348. proto[0][4] || name, // 4.Full font name
  21349. proto[0][5] || 'Version 0.11', // 5.Version
  21350. proto[0][6] || '', // 6.Postscript name
  21351. proto[0][7] || 'Unknown', // 7.Trademark
  21352. proto[0][8] || 'Unknown', // 8.Manufacturer
  21353. proto[0][9] || 'Unknown' // 9.Designer
  21354. ];
  21355. // Mac want 1-byte per character strings while Windows want
  21356. // 2-bytes per character, so duplicate the names table
  21357. var stringsUnicode = [];
  21358. var i, ii, j, jj, str;
  21359. for (i = 0, ii = strings.length; i < ii; i++) {
  21360. str = proto[1][i] || strings[i];
  21361. var strBufUnicode = [];
  21362. for (j = 0, jj = str.length; j < jj; j++) {
  21363. strBufUnicode.push(string16(str.charCodeAt(j)));
  21364. }
  21365. stringsUnicode.push(strBufUnicode.join(''));
  21366. }
  21367. var names = [strings, stringsUnicode];
  21368. var platforms = ['\x00\x01', '\x00\x03'];
  21369. var encodings = ['\x00\x00', '\x00\x01'];
  21370. var languages = ['\x00\x00', '\x04\x09'];
  21371. var namesRecordCount = strings.length * platforms.length;
  21372. var nameTable =
  21373. '\x00\x00' + // format
  21374. string16(namesRecordCount) + // Number of names Record
  21375. string16(namesRecordCount * 12 + 6); // Storage
  21376. // Build the name records field
  21377. var strOffset = 0;
  21378. for (i = 0, ii = platforms.length; i < ii; i++) {
  21379. var strs = names[i];
  21380. for (j = 0, jj = strs.length; j < jj; j++) {
  21381. str = strs[j];
  21382. var nameRecord =
  21383. platforms[i] + // platform ID
  21384. encodings[i] + // encoding ID
  21385. languages[i] + // language ID
  21386. string16(j) + // name ID
  21387. string16(str.length) +
  21388. string16(strOffset);
  21389. nameTable += nameRecord;
  21390. strOffset += str.length;
  21391. }
  21392. }
  21393. nameTable += strings.join('') + stringsUnicode.join('');
  21394. return nameTable;
  21395. }
  21396. Font.prototype = {
  21397. name: null,
  21398. font: null,
  21399. mimetype: null,
  21400. encoding: null,
  21401. get renderer() {
  21402. var renderer = FontRendererFactory.create(this);
  21403. return shadow(this, 'renderer', renderer);
  21404. },
  21405. exportData: function Font_exportData() {
  21406. var data = {};
  21407. for (var i in this) {
  21408. if (this.hasOwnProperty(i)) {
  21409. data[i] = this[i];
  21410. }
  21411. }
  21412. return data;
  21413. },
  21414. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21415. function readTableEntry(file) {
  21416. var tag = bytesToString(file.getBytes(4));
  21417. var checksum = file.getInt32();
  21418. var offset = file.getInt32() >>> 0;
  21419. var length = file.getInt32() >>> 0;
  21420. // Read the table associated data
  21421. var previousPosition = file.pos;
  21422. file.pos = file.start ? file.start : 0;
  21423. file.skip(offset);
  21424. var data = file.getBytes(length);
  21425. file.pos = previousPosition;
  21426. if (tag === 'head') {
  21427. // clearing checksum adjustment
  21428. data[8] = data[9] = data[10] = data[11] = 0;
  21429. data[17] |= 0x20; //Set font optimized for cleartype flag
  21430. }
  21431. return {
  21432. tag: tag,
  21433. checksum: checksum,
  21434. length: length,
  21435. offset: offset,
  21436. data: data
  21437. };
  21438. }
  21439. function readOpenTypeHeader(ttf) {
  21440. return {
  21441. version: bytesToString(ttf.getBytes(4)),
  21442. numTables: ttf.getUint16(),
  21443. searchRange: ttf.getUint16(),
  21444. entrySelector: ttf.getUint16(),
  21445. rangeShift: ttf.getUint16()
  21446. };
  21447. }
  21448. /**
  21449. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21450. * PDF spec
  21451. */
  21452. function readCmapTable(cmap, font, isSymbolicFont) {
  21453. var segment;
  21454. var start = (font.start ? font.start : 0) + cmap.offset;
  21455. font.pos = start;
  21456. var version = font.getUint16();
  21457. var numTables = font.getUint16();
  21458. var potentialTable;
  21459. var canBreak = false;
  21460. // There's an order of preference in terms of which cmap subtable to
  21461. // use:
  21462. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21463. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21464. // The following takes advantage of the fact that the tables are sorted
  21465. // to work.
  21466. for (var i = 0; i < numTables; i++) {
  21467. var platformId = font.getUint16();
  21468. var encodingId = font.getUint16();
  21469. var offset = font.getInt32() >>> 0;
  21470. var useTable = false;
  21471. if (platformId === 0 && encodingId === 0) {
  21472. useTable = true;
  21473. // Continue the loop since there still may be a higher priority
  21474. // table.
  21475. } else if (platformId === 1 && encodingId === 0) {
  21476. useTable = true;
  21477. // Continue the loop since there still may be a higher priority
  21478. // table.
  21479. } else if (platformId === 3 && encodingId === 1 &&
  21480. (!isSymbolicFont || !potentialTable)) {
  21481. useTable = true;
  21482. if (!isSymbolicFont) {
  21483. canBreak = true;
  21484. }
  21485. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21486. useTable = true;
  21487. canBreak = true;
  21488. }
  21489. if (useTable) {
  21490. potentialTable = {
  21491. platformId: platformId,
  21492. encodingId: encodingId,
  21493. offset: offset
  21494. };
  21495. }
  21496. if (canBreak) {
  21497. break;
  21498. }
  21499. }
  21500. if (!potentialTable) {
  21501. warn('Could not find a preferred cmap table.');
  21502. return {
  21503. platformId: -1,
  21504. encodingId: -1,
  21505. mappings: [],
  21506. hasShortCmap: false
  21507. };
  21508. }
  21509. font.pos = start + potentialTable.offset;
  21510. var format = font.getUint16();
  21511. var length = font.getUint16();
  21512. var language = font.getUint16();
  21513. var hasShortCmap = false;
  21514. var mappings = [];
  21515. var j, glyphId;
  21516. // TODO(mack): refactor this cmap subtable reading logic out
  21517. if (format === 0) {
  21518. for (j = 0; j < 256; j++) {
  21519. var index = font.getByte();
  21520. if (!index) {
  21521. continue;
  21522. }
  21523. mappings.push({
  21524. charCode: j,
  21525. glyphId: index
  21526. });
  21527. }
  21528. hasShortCmap = true;
  21529. } else if (format === 4) {
  21530. // re-creating the table in format 4 since the encoding
  21531. // might be changed
  21532. var segCount = (font.getUint16() >> 1);
  21533. font.getBytes(6); // skipping range fields
  21534. var segIndex, segments = [];
  21535. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21536. segments.push({ end: font.getUint16() });
  21537. }
  21538. font.getUint16();
  21539. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21540. segments[segIndex].start = font.getUint16();
  21541. }
  21542. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21543. segments[segIndex].delta = font.getUint16();
  21544. }
  21545. var offsetsCount = 0;
  21546. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21547. segment = segments[segIndex];
  21548. var rangeOffset = font.getUint16();
  21549. if (!rangeOffset) {
  21550. segment.offsetIndex = -1;
  21551. continue;
  21552. }
  21553. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21554. segment.offsetIndex = offsetIndex;
  21555. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21556. segment.end - segment.start + 1);
  21557. }
  21558. var offsets = [];
  21559. for (j = 0; j < offsetsCount; j++) {
  21560. offsets.push(font.getUint16());
  21561. }
  21562. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21563. segment = segments[segIndex];
  21564. start = segment.start;
  21565. var end = segment.end;
  21566. var delta = segment.delta;
  21567. offsetIndex = segment.offsetIndex;
  21568. for (j = start; j <= end; j++) {
  21569. if (j === 0xFFFF) {
  21570. continue;
  21571. }
  21572. glyphId = (offsetIndex < 0 ?
  21573. j : offsets[offsetIndex + j - start]);
  21574. glyphId = (glyphId + delta) & 0xFFFF;
  21575. if (glyphId === 0) {
  21576. continue;
  21577. }
  21578. mappings.push({
  21579. charCode: j,
  21580. glyphId: glyphId
  21581. });
  21582. }
  21583. }
  21584. } else if (format === 6) {
  21585. // Format 6 is a 2-bytes dense mapping, which means the font data
  21586. // lives glue together even if they are pretty far in the unicode
  21587. // table. (This looks weird, so I can have missed something), this
  21588. // works on Linux but seems to fails on Mac so let's rewrite the
  21589. // cmap table to a 3-1-4 style
  21590. var firstCode = font.getUint16();
  21591. var entryCount = font.getUint16();
  21592. for (j = 0; j < entryCount; j++) {
  21593. glyphId = font.getUint16();
  21594. var charCode = firstCode + j;
  21595. mappings.push({
  21596. charCode: charCode,
  21597. glyphId: glyphId
  21598. });
  21599. }
  21600. } else {
  21601. error('cmap table has unsupported format: ' + format);
  21602. }
  21603. // removing duplicate entries
  21604. mappings.sort(function (a, b) {
  21605. return a.charCode - b.charCode;
  21606. });
  21607. for (i = 1; i < mappings.length; i++) {
  21608. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21609. mappings.splice(i, 1);
  21610. i--;
  21611. }
  21612. }
  21613. return {
  21614. platformId: potentialTable.platformId,
  21615. encodingId: potentialTable.encodingId,
  21616. mappings: mappings,
  21617. hasShortCmap: hasShortCmap
  21618. };
  21619. }
  21620. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21621. if (!header) {
  21622. if (metrics) {
  21623. metrics.data = null;
  21624. }
  21625. return;
  21626. }
  21627. font.pos = (font.start ? font.start : 0) + header.offset;
  21628. font.pos += header.length - 2;
  21629. var numOfMetrics = font.getUint16();
  21630. if (numOfMetrics > numGlyphs) {
  21631. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21632. 'greater than the numGlyphs (' + numGlyphs + ')');
  21633. // Reduce numOfMetrics if it is greater than numGlyphs
  21634. numOfMetrics = numGlyphs;
  21635. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21636. header.data[35] = numOfMetrics & 0x00ff;
  21637. }
  21638. var numOfSidebearings = numGlyphs - numOfMetrics;
  21639. var numMissing = numOfSidebearings -
  21640. ((metrics.length - numOfMetrics * 4) >> 1);
  21641. if (numMissing > 0) {
  21642. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21643. // Since we need to add two properties for each glyph, this explains
  21644. // the use of |numMissing * 2| when initializing the typed array.
  21645. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21646. entries.set(metrics.data);
  21647. metrics.data = entries;
  21648. }
  21649. }
  21650. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21651. hintsValid) {
  21652. if (sourceEnd - sourceStart <= 12) {
  21653. // glyph with data less than 12 is invalid one
  21654. return 0;
  21655. }
  21656. var glyf = source.subarray(sourceStart, sourceEnd);
  21657. var contoursCount = (glyf[0] << 8) | glyf[1];
  21658. if (contoursCount & 0x8000) {
  21659. // complex glyph, writing as is
  21660. dest.set(glyf, destStart);
  21661. return glyf.length;
  21662. }
  21663. var i, j = 10, flagsCount = 0;
  21664. for (i = 0; i < contoursCount; i++) {
  21665. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21666. flagsCount = endPoint + 1;
  21667. j += 2;
  21668. }
  21669. // skipping instructions
  21670. var instructionsStart = j;
  21671. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21672. j += 2 + instructionsLength;
  21673. var instructionsEnd = j;
  21674. // validating flags
  21675. var coordinatesLength = 0;
  21676. for (i = 0; i < flagsCount; i++) {
  21677. var flag = glyf[j++];
  21678. if (flag & 0xC0) {
  21679. // reserved flags must be zero, cleaning up
  21680. glyf[j - 1] = flag & 0x3F;
  21681. }
  21682. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21683. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21684. coordinatesLength += xyLength;
  21685. if (flag & 8) {
  21686. var repeat = glyf[j++];
  21687. i += repeat;
  21688. coordinatesLength += repeat * xyLength;
  21689. }
  21690. }
  21691. // glyph without coordinates will be rejected
  21692. if (coordinatesLength === 0) {
  21693. return 0;
  21694. }
  21695. var glyphDataLength = j + coordinatesLength;
  21696. if (glyphDataLength > glyf.length) {
  21697. // not enough data for coordinates
  21698. return 0;
  21699. }
  21700. if (!hintsValid && instructionsLength > 0) {
  21701. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21702. dest.set([0, 0], destStart + instructionsStart);
  21703. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21704. destStart + instructionsStart + 2);
  21705. glyphDataLength -= instructionsLength;
  21706. if (glyf.length - glyphDataLength > 3) {
  21707. glyphDataLength = (glyphDataLength + 3) & ~3;
  21708. }
  21709. return glyphDataLength;
  21710. }
  21711. if (glyf.length - glyphDataLength > 3) {
  21712. // truncating and aligning to 4 bytes the long glyph data
  21713. glyphDataLength = (glyphDataLength + 3) & ~3;
  21714. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21715. return glyphDataLength;
  21716. }
  21717. // glyph data is fine
  21718. dest.set(glyf, destStart);
  21719. return glyf.length;
  21720. }
  21721. function sanitizeHead(head, numGlyphs, locaLength) {
  21722. var data = head.data;
  21723. // Validate version:
  21724. // Should always be 0x00010000
  21725. var version = int32(data[0], data[1], data[2], data[3]);
  21726. if (version >> 16 !== 1) {
  21727. info('Attempting to fix invalid version in head table: ' + version);
  21728. data[0] = 0;
  21729. data[1] = 1;
  21730. data[2] = 0;
  21731. data[3] = 0;
  21732. }
  21733. var indexToLocFormat = int16(data[50], data[51]);
  21734. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21735. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21736. indexToLocFormat);
  21737. // The value of indexToLocFormat should be 0 if the loca table
  21738. // consists of short offsets, and should be 1 if the loca table
  21739. // consists of long offsets.
  21740. //
  21741. // The number of entries in the loca table should be numGlyphs + 1.
  21742. //
  21743. // Using this information, we can work backwards to deduce if the
  21744. // size of each offset in the loca table, and thus figure out the
  21745. // appropriate value for indexToLocFormat.
  21746. var numGlyphsPlusOne = numGlyphs + 1;
  21747. if (locaLength === numGlyphsPlusOne << 1) {
  21748. // 0x0000 indicates the loca table consists of short offsets
  21749. data[50] = 0;
  21750. data[51] = 0;
  21751. } else if (locaLength === numGlyphsPlusOne << 2) {
  21752. // 0x0001 indicates the loca table consists of long offsets
  21753. data[50] = 0;
  21754. data[51] = 1;
  21755. } else {
  21756. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21757. }
  21758. }
  21759. }
  21760. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21761. isGlyphLocationsLong, hintsValid,
  21762. dupFirstEntry) {
  21763. var itemSize, itemDecode, itemEncode;
  21764. if (isGlyphLocationsLong) {
  21765. itemSize = 4;
  21766. itemDecode = function fontItemDecodeLong(data, offset) {
  21767. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21768. (data[offset + 2] << 8) | data[offset + 3];
  21769. };
  21770. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21771. data[offset] = (value >>> 24) & 0xFF;
  21772. data[offset + 1] = (value >> 16) & 0xFF;
  21773. data[offset + 2] = (value >> 8) & 0xFF;
  21774. data[offset + 3] = value & 0xFF;
  21775. };
  21776. } else {
  21777. itemSize = 2;
  21778. itemDecode = function fontItemDecode(data, offset) {
  21779. return (data[offset] << 9) | (data[offset + 1] << 1);
  21780. };
  21781. itemEncode = function fontItemEncode(data, offset, value) {
  21782. data[offset] = (value >> 9) & 0xFF;
  21783. data[offset + 1] = (value >> 1) & 0xFF;
  21784. };
  21785. }
  21786. var locaData = loca.data;
  21787. var locaDataSize = itemSize * (1 + numGlyphs);
  21788. // is loca.data too short or long?
  21789. if (locaData.length !== locaDataSize) {
  21790. locaData = new Uint8Array(locaDataSize);
  21791. locaData.set(loca.data.subarray(0, locaDataSize));
  21792. loca.data = locaData;
  21793. }
  21794. // removing the invalid glyphs
  21795. var oldGlyfData = glyf.data;
  21796. var oldGlyfDataLength = oldGlyfData.length;
  21797. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21798. var startOffset = itemDecode(locaData, 0);
  21799. var writeOffset = 0;
  21800. var missingGlyphData = {};
  21801. itemEncode(locaData, 0, writeOffset);
  21802. var i, j;
  21803. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21804. var endOffset = itemDecode(locaData, j);
  21805. if (endOffset > oldGlyfDataLength &&
  21806. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21807. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21808. // the glyf table size, which makes last glyph out of range.
  21809. endOffset = oldGlyfDataLength;
  21810. }
  21811. if (endOffset > oldGlyfDataLength) {
  21812. // glyph end offset points outside glyf data, rejecting the glyph
  21813. itemEncode(locaData, j, writeOffset);
  21814. startOffset = endOffset;
  21815. continue;
  21816. }
  21817. if (startOffset === endOffset) {
  21818. missingGlyphData[i] = true;
  21819. }
  21820. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21821. newGlyfData, writeOffset, hintsValid);
  21822. writeOffset += newLength;
  21823. itemEncode(locaData, j, writeOffset);
  21824. startOffset = endOffset;
  21825. }
  21826. if (writeOffset === 0) {
  21827. // glyf table cannot be empty -- redoing the glyf and loca tables
  21828. // to have single glyph with one point
  21829. var simpleGlyph = new Uint8Array(
  21830. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21831. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21832. itemEncode(locaData, j, simpleGlyph.length);
  21833. }
  21834. glyf.data = simpleGlyph;
  21835. return missingGlyphData;
  21836. }
  21837. if (dupFirstEntry) {
  21838. var firstEntryLength = itemDecode(locaData, itemSize);
  21839. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21840. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21841. } else {
  21842. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21843. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21844. }
  21845. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21846. itemEncode(loca.data, locaData.length - itemSize,
  21847. writeOffset + firstEntryLength);
  21848. } else {
  21849. glyf.data = newGlyfData.subarray(0, writeOffset);
  21850. }
  21851. return missingGlyphData;
  21852. }
  21853. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21854. var start = (font.start ? font.start : 0) + post.offset;
  21855. font.pos = start;
  21856. var length = post.length, end = start + length;
  21857. var version = font.getInt32();
  21858. // skip rest to the tables
  21859. font.getBytes(28);
  21860. var glyphNames;
  21861. var valid = true;
  21862. var i;
  21863. switch (version) {
  21864. case 0x00010000:
  21865. glyphNames = MacStandardGlyphOrdering;
  21866. break;
  21867. case 0x00020000:
  21868. var numGlyphs = font.getUint16();
  21869. if (numGlyphs !== maxpNumGlyphs) {
  21870. valid = false;
  21871. break;
  21872. }
  21873. var glyphNameIndexes = [];
  21874. for (i = 0; i < numGlyphs; ++i) {
  21875. var index = font.getUint16();
  21876. if (index >= 32768) {
  21877. valid = false;
  21878. break;
  21879. }
  21880. glyphNameIndexes.push(index);
  21881. }
  21882. if (!valid) {
  21883. break;
  21884. }
  21885. var customNames = [];
  21886. var strBuf = [];
  21887. while (font.pos < end) {
  21888. var stringLength = font.getByte();
  21889. strBuf.length = stringLength;
  21890. for (i = 0; i < stringLength; ++i) {
  21891. strBuf[i] = String.fromCharCode(font.getByte());
  21892. }
  21893. customNames.push(strBuf.join(''));
  21894. }
  21895. glyphNames = [];
  21896. for (i = 0; i < numGlyphs; ++i) {
  21897. var j = glyphNameIndexes[i];
  21898. if (j < 258) {
  21899. glyphNames.push(MacStandardGlyphOrdering[j]);
  21900. continue;
  21901. }
  21902. glyphNames.push(customNames[j - 258]);
  21903. }
  21904. break;
  21905. case 0x00030000:
  21906. break;
  21907. default:
  21908. warn('Unknown/unsupported post table version ' + version);
  21909. valid = false;
  21910. break;
  21911. }
  21912. properties.glyphNames = glyphNames;
  21913. return valid;
  21914. }
  21915. function readNameTable(nameTable) {
  21916. var start = (font.start ? font.start : 0) + nameTable.offset;
  21917. font.pos = start;
  21918. var names = [[], []];
  21919. var length = nameTable.length, end = start + length;
  21920. var format = font.getUint16();
  21921. var FORMAT_0_HEADER_LENGTH = 6;
  21922. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21923. // unsupported name table format or table "too" small
  21924. return names;
  21925. }
  21926. var numRecords = font.getUint16();
  21927. var stringsStart = font.getUint16();
  21928. var records = [];
  21929. var NAME_RECORD_LENGTH = 12;
  21930. var i, ii;
  21931. for (i = 0; i < numRecords &&
  21932. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21933. var r = {
  21934. platform: font.getUint16(),
  21935. encoding: font.getUint16(),
  21936. language: font.getUint16(),
  21937. name: font.getUint16(),
  21938. length: font.getUint16(),
  21939. offset: font.getUint16()
  21940. };
  21941. // using only Macintosh and Windows platform/encoding names
  21942. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21943. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21944. records.push(r);
  21945. }
  21946. }
  21947. for (i = 0, ii = records.length; i < ii; i++) {
  21948. var record = records[i];
  21949. var pos = start + stringsStart + record.offset;
  21950. if (pos + record.length > end) {
  21951. continue; // outside of name table, ignoring
  21952. }
  21953. font.pos = pos;
  21954. var nameIndex = record.name;
  21955. if (record.encoding) {
  21956. // unicode
  21957. var str = '';
  21958. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21959. str += String.fromCharCode(font.getUint16());
  21960. }
  21961. names[1][nameIndex] = str;
  21962. } else {
  21963. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21964. }
  21965. }
  21966. return names;
  21967. }
  21968. var TTOpsStackDeltas = [
  21969. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21970. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21971. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21972. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21973. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21974. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21975. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21976. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21977. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21978. // 0xC0-DF == -1 and 0xE0-FF == -2
  21979. function sanitizeTTProgram(table, ttContext) {
  21980. var data = table.data;
  21981. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21982. var stack = [];
  21983. var callstack = [];
  21984. var functionsCalled = [];
  21985. var tooComplexToFollowFunctions =
  21986. ttContext.tooComplexToFollowFunctions;
  21987. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21988. for (var ii = data.length; i < ii;) {
  21989. var op = data[i++];
  21990. // The TrueType instruction set docs can be found at
  21991. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21992. if (op === 0x40) { // NPUSHB - pushes n bytes
  21993. n = data[i++];
  21994. if (inFDEF || inELSE) {
  21995. i += n;
  21996. } else {
  21997. for (j = 0; j < n; j++) {
  21998. stack.push(data[i++]);
  21999. }
  22000. }
  22001. } else if (op === 0x41) { // NPUSHW - pushes n words
  22002. n = data[i++];
  22003. if (inFDEF || inELSE) {
  22004. i += n * 2;
  22005. } else {
  22006. for (j = 0; j < n; j++) {
  22007. b = data[i++];
  22008. stack.push((b << 8) | data[i++]);
  22009. }
  22010. }
  22011. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  22012. n = op - 0xB0 + 1;
  22013. if (inFDEF || inELSE) {
  22014. i += n;
  22015. } else {
  22016. for (j = 0; j < n; j++) {
  22017. stack.push(data[i++]);
  22018. }
  22019. }
  22020. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22021. n = op - 0xB8 + 1;
  22022. if (inFDEF || inELSE) {
  22023. i += n * 2;
  22024. } else {
  22025. for (j = 0; j < n; j++) {
  22026. b = data[i++];
  22027. stack.push((b << 8) | data[i++]);
  22028. }
  22029. }
  22030. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22031. if (!inFDEF && !inELSE) {
  22032. // collecting inforamtion about which functions are used
  22033. funcId = stack[stack.length - 1];
  22034. ttContext.functionsUsed[funcId] = true;
  22035. if (funcId in ttContext.functionsStackDeltas) {
  22036. stack.length += ttContext.functionsStackDeltas[funcId];
  22037. } else if (funcId in ttContext.functionsDefined &&
  22038. functionsCalled.indexOf(funcId) < 0) {
  22039. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22040. functionsCalled.push(funcId);
  22041. pc = ttContext.functionsDefined[funcId];
  22042. if (!pc) {
  22043. warn('TT: CALL non-existent function');
  22044. ttContext.hintsValid = false;
  22045. return;
  22046. }
  22047. data = pc.data;
  22048. i = pc.i;
  22049. }
  22050. }
  22051. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22052. if (inFDEF || inELSE) {
  22053. warn('TT: nested FDEFs not allowed');
  22054. tooComplexToFollowFunctions = true;
  22055. }
  22056. inFDEF = true;
  22057. // collecting inforamtion about which functions are defined
  22058. lastDeff = i;
  22059. funcId = stack.pop();
  22060. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22061. } else if (op === 0x2D) { // ENDF - end of function
  22062. if (inFDEF) {
  22063. inFDEF = false;
  22064. lastEndf = i;
  22065. } else {
  22066. pc = callstack.pop();
  22067. if (!pc) {
  22068. warn('TT: ENDF bad stack');
  22069. ttContext.hintsValid = false;
  22070. return;
  22071. }
  22072. funcId = functionsCalled.pop();
  22073. data = pc.data;
  22074. i = pc.i;
  22075. ttContext.functionsStackDeltas[funcId] =
  22076. stack.length - pc.stackTop;
  22077. }
  22078. } else if (op === 0x89) { // IDEF - instruction definition
  22079. if (inFDEF || inELSE) {
  22080. warn('TT: nested IDEFs not allowed');
  22081. tooComplexToFollowFunctions = true;
  22082. }
  22083. inFDEF = true;
  22084. // recording it as a function to track ENDF
  22085. lastDeff = i;
  22086. } else if (op === 0x58) { // IF
  22087. ++ifLevel;
  22088. } else if (op === 0x1B) { // ELSE
  22089. inELSE = ifLevel;
  22090. } else if (op === 0x59) { // EIF
  22091. if (inELSE === ifLevel) {
  22092. inELSE = 0;
  22093. }
  22094. --ifLevel;
  22095. } else if (op === 0x1C) { // JMPR
  22096. if (!inFDEF && !inELSE) {
  22097. var offset = stack[stack.length - 1];
  22098. // only jumping forward to prevent infinite loop
  22099. if (offset > 0) {
  22100. i += offset - 1;
  22101. }
  22102. }
  22103. }
  22104. // Adjusting stack not extactly, but just enough to get function id
  22105. if (!inFDEF && !inELSE) {
  22106. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22107. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22108. if (op >= 0x71 && op <= 0x75) {
  22109. n = stack.pop();
  22110. if (n === n) {
  22111. stackDelta = -n * 2;
  22112. }
  22113. }
  22114. while (stackDelta < 0 && stack.length > 0) {
  22115. stack.pop();
  22116. stackDelta++;
  22117. }
  22118. while (stackDelta > 0) {
  22119. stack.push(NaN); // pushing any number into stack
  22120. stackDelta--;
  22121. }
  22122. }
  22123. }
  22124. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22125. var content = [data];
  22126. if (i > data.length) {
  22127. content.push(new Uint8Array(i - data.length));
  22128. }
  22129. if (lastDeff > lastEndf) {
  22130. warn('TT: complementing a missing function tail');
  22131. // new function definition started, but not finished
  22132. // complete function by [CLEAR, ENDF]
  22133. content.push(new Uint8Array([0x22, 0x2D]));
  22134. }
  22135. foldTTTable(table, content);
  22136. }
  22137. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22138. if (ttContext.tooComplexToFollowFunctions) {
  22139. return;
  22140. }
  22141. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22142. warn('TT: more functions defined than expected');
  22143. ttContext.hintsValid = false;
  22144. return;
  22145. }
  22146. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22147. if (j > maxFunctionDefs) {
  22148. warn('TT: invalid function id: ' + j);
  22149. ttContext.hintsValid = false;
  22150. return;
  22151. }
  22152. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22153. warn('TT: undefined function: ' + j);
  22154. ttContext.hintsValid = false;
  22155. return;
  22156. }
  22157. }
  22158. }
  22159. function foldTTTable(table, content) {
  22160. if (content.length > 1) {
  22161. // concatenating the content items
  22162. var newLength = 0;
  22163. var j, jj;
  22164. for (j = 0, jj = content.length; j < jj; j++) {
  22165. newLength += content[j].length;
  22166. }
  22167. newLength = (newLength + 3) & ~3;
  22168. var result = new Uint8Array(newLength);
  22169. var pos = 0;
  22170. for (j = 0, jj = content.length; j < jj; j++) {
  22171. result.set(content[j], pos);
  22172. pos += content[j].length;
  22173. }
  22174. table.data = result;
  22175. table.length = newLength;
  22176. }
  22177. }
  22178. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22179. var ttContext = {
  22180. functionsDefined: [],
  22181. functionsUsed: [],
  22182. functionsStackDeltas: [],
  22183. tooComplexToFollowFunctions: false,
  22184. hintsValid: true
  22185. };
  22186. if (fpgm) {
  22187. sanitizeTTProgram(fpgm, ttContext);
  22188. }
  22189. if (prep) {
  22190. sanitizeTTProgram(prep, ttContext);
  22191. }
  22192. if (fpgm) {
  22193. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22194. }
  22195. if (cvt && (cvt.length & 1)) {
  22196. var cvtData = new Uint8Array(cvt.length + 1);
  22197. cvtData.set(cvt.data);
  22198. cvt.data = cvtData;
  22199. }
  22200. return ttContext.hintsValid;
  22201. }
  22202. // The following steps modify the original font data, making copy
  22203. font = new Stream(new Uint8Array(font.getBytes()));
  22204. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22205. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22206. var header = readOpenTypeHeader(font);
  22207. var numTables = header.numTables;
  22208. var cff, cffFile;
  22209. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22210. hmtx: null, maxp: null, name: null, post: null };
  22211. var table;
  22212. for (var i = 0; i < numTables; i++) {
  22213. table = readTableEntry(font);
  22214. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22215. continue; // skipping table if it's not a required or optional table
  22216. }
  22217. if (table.length === 0) {
  22218. continue; // skipping empty tables
  22219. }
  22220. tables[table.tag] = table;
  22221. }
  22222. var isTrueType = !tables['CFF '];
  22223. if (!isTrueType) {
  22224. // OpenType font
  22225. if (header.version === 'OTTO' ||
  22226. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22227. // no major tables: throwing everything at CFFFont
  22228. cffFile = new Stream(tables['CFF '].data);
  22229. cff = new CFFFont(cffFile, properties);
  22230. return this.convert(name, cff, properties);
  22231. }
  22232. delete tables.glyf;
  22233. delete tables.loca;
  22234. delete tables.fpgm;
  22235. delete tables.prep;
  22236. delete tables['cvt '];
  22237. this.isOpenType = true;
  22238. } else {
  22239. if (!tables.glyf || !tables.loca) {
  22240. error('Required "glyf" or "loca" tables are not found');
  22241. }
  22242. this.isOpenType = false;
  22243. }
  22244. if (!tables.maxp) {
  22245. error('Required "maxp" table is not found');
  22246. }
  22247. font.pos = (font.start || 0) + tables.maxp.offset;
  22248. var version = font.getInt32();
  22249. var numGlyphs = font.getUint16();
  22250. var maxFunctionDefs = 0;
  22251. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22252. // maxZones can be invalid
  22253. font.pos += 8;
  22254. var maxZones = font.getUint16();
  22255. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22256. tables.maxp.data[14] = 0;
  22257. tables.maxp.data[15] = 2;
  22258. }
  22259. font.pos += 4;
  22260. maxFunctionDefs = font.getUint16();
  22261. }
  22262. var dupFirstEntry = false;
  22263. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22264. properties.toUnicode.get(0) > '\u0000') {
  22265. // oracle's defect (see 3427), duplicating first entry
  22266. dupFirstEntry = true;
  22267. numGlyphs++;
  22268. tables.maxp.data[4] = numGlyphs >> 8;
  22269. tables.maxp.data[5] = numGlyphs & 255;
  22270. }
  22271. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22272. tables['cvt '], maxFunctionDefs);
  22273. if (!hintsValid) {
  22274. delete tables.fpgm;
  22275. delete tables.prep;
  22276. delete tables['cvt '];
  22277. }
  22278. // Ensure the hmtx table contains the advance width and
  22279. // sidebearings information for numGlyphs in the maxp table
  22280. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22281. if (!tables.head) {
  22282. error('Required "head" table is not found');
  22283. }
  22284. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22285. var missingGlyphs = {};
  22286. if (isTrueType) {
  22287. var isGlyphLocationsLong = int16(tables.head.data[50],
  22288. tables.head.data[51]);
  22289. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22290. numGlyphs, isGlyphLocationsLong,
  22291. hintsValid, dupFirstEntry);
  22292. }
  22293. if (!tables.hhea) {
  22294. error('Required "hhea" table is not found');
  22295. }
  22296. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22297. // Sometimes it's 0. That needs to be fixed
  22298. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22299. tables.hhea.data[10] = 0xFF;
  22300. tables.hhea.data[11] = 0xFF;
  22301. }
  22302. // The 'post' table has glyphs names.
  22303. if (tables.post) {
  22304. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22305. if (!valid) {
  22306. tables.post = null;
  22307. }
  22308. }
  22309. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  22310. function hasGlyph(glyphId, charCode) {
  22311. if (!missingGlyphs[glyphId]) {
  22312. return true;
  22313. }
  22314. if (charCode >= 0 && toUnicode.has(charCode)) {
  22315. return true;
  22316. }
  22317. return false;
  22318. }
  22319. if (properties.type === 'CIDFontType2') {
  22320. var cidToGidMap = properties.cidToGidMap || [];
  22321. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22322. properties.cMap.forEach(function(charCode, cid) {
  22323. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22324. var glyphId = -1;
  22325. if (isCidToGidMapEmpty) {
  22326. glyphId = charCode;
  22327. } else if (cidToGidMap[cid] !== undefined) {
  22328. glyphId = cidToGidMap[cid];
  22329. }
  22330. if (glyphId >= 0 && glyphId < numGlyphs &&
  22331. hasGlyph(glyphId, charCode)) {
  22332. charCodeToGlyphId[charCode] = glyphId;
  22333. }
  22334. });
  22335. if (dupFirstEntry) {
  22336. charCodeToGlyphId[0] = numGlyphs - 1;
  22337. }
  22338. } else {
  22339. // Most of the following logic in this code branch is based on the
  22340. // 9.6.6.4 of the PDF spec.
  22341. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22342. var cmapPlatformId = cmapTable.platformId;
  22343. var cmapEncodingId = cmapTable.encodingId;
  22344. var cmapMappings = cmapTable.mappings;
  22345. var cmapMappingsLength = cmapMappings.length;
  22346. var hasEncoding = properties.differences.length ||
  22347. !!properties.baseEncodingName;
  22348. // The spec seems to imply that if the font is symbolic the encoding
  22349. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22350. // where the the font is symbolic and it has an encoding.
  22351. if (hasEncoding &&
  22352. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22353. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22354. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22355. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22356. // When no preferred cmap table was found and |baseEncodingName| is
  22357. // one of the predefined encodings, we seem to obtain a better
  22358. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22359. // TODO: Note that this is a hack which should be removed as soon as
  22360. // we have proper support for more exotic cmap tables.
  22361. var baseEncoding = [];
  22362. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22363. properties.baseEncodingName === 'WinAnsiEncoding') {
  22364. baseEncoding = Encodings[properties.baseEncodingName];
  22365. }
  22366. for (charCode = 0; charCode < 256; charCode++) {
  22367. var glyphName;
  22368. if (this.differences && charCode in this.differences) {
  22369. glyphName = this.differences[charCode];
  22370. } else if (charCode in baseEncoding &&
  22371. baseEncoding[charCode] !== '') {
  22372. glyphName = baseEncoding[charCode];
  22373. } else {
  22374. glyphName = Encodings.StandardEncoding[charCode];
  22375. }
  22376. if (!glyphName) {
  22377. continue;
  22378. }
  22379. var unicodeOrCharCode;
  22380. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22381. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22382. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22383. // TODO: the encoding needs to be updated with mac os table.
  22384. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22385. }
  22386. var found = false;
  22387. for (i = 0; i < cmapMappingsLength; ++i) {
  22388. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  22389. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  22390. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22391. found = true;
  22392. break;
  22393. }
  22394. }
  22395. if (!found && properties.glyphNames) {
  22396. // Try to map using the post table. There are currently no known
  22397. // pdfs that this fixes.
  22398. var glyphId = properties.glyphNames.indexOf(glyphName);
  22399. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  22400. charCodeToGlyphId[charCode] = glyphId;
  22401. }
  22402. }
  22403. }
  22404. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22405. // Default Unicode semantics, use the charcodes as is.
  22406. for (i = 0; i < cmapMappingsLength; ++i) {
  22407. charCodeToGlyphId[cmapMappings[i].charCode] =
  22408. cmapMappings[i].glyphId;
  22409. }
  22410. } else {
  22411. // For (3, 0) cmap tables:
  22412. // The charcode key being stored in charCodeToGlyphId is the lower
  22413. // byte of the two-byte charcodes of the cmap table since according to
  22414. // the spec: 'each byte from the string shall be prepended with the
  22415. // high byte of the range [of charcodes in the cmap table], to form
  22416. // a two-byte character, which shall be used to select the
  22417. // associated glyph description from the subtable'.
  22418. //
  22419. // For (1, 0) cmap tables:
  22420. // 'single bytes from the string shall be used to look up the
  22421. // associated glyph descriptions from the subtable'. This means
  22422. // charcodes in the cmap will be single bytes, so no-op since
  22423. // glyph.charCode & 0xFF === glyph.charCode
  22424. for (i = 0; i < cmapMappingsLength; ++i) {
  22425. charCode = cmapMappings[i].charCode & 0xFF;
  22426. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22427. }
  22428. }
  22429. }
  22430. if (charCodeToGlyphId.length === 0) {
  22431. // defines at least one glyph
  22432. charCodeToGlyphId[0] = 0;
  22433. }
  22434. // Converting glyphs and ids into font's cmap table
  22435. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22436. this.toFontChar = newMapping.toFontChar;
  22437. tables.cmap = {
  22438. tag: 'cmap',
  22439. data: createCmapTable(newMapping.charCodeToGlyphId)
  22440. };
  22441. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22442. // extract some more font properties from the OpenType head and
  22443. // hhea tables; yMin and descent value are always negative
  22444. var override = {
  22445. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22446. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22447. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22448. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22449. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22450. };
  22451. tables['OS/2'] = {
  22452. tag: 'OS/2',
  22453. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22454. override)
  22455. };
  22456. }
  22457. // Rewrite the 'post' table if needed
  22458. if (!tables.post) {
  22459. tables.post = {
  22460. tag: 'post',
  22461. data: createPostTable(properties)
  22462. };
  22463. }
  22464. if (!isTrueType) {
  22465. try {
  22466. // Trying to repair CFF file
  22467. cffFile = new Stream(tables['CFF '].data);
  22468. var parser = new CFFParser(cffFile, properties);
  22469. cff = parser.parse();
  22470. var compiler = new CFFCompiler(cff);
  22471. tables['CFF '].data = compiler.compile();
  22472. } catch (e) {
  22473. warn('Failed to compile font ' + properties.loadedName);
  22474. }
  22475. }
  22476. // Re-creating 'name' table
  22477. if (!tables.name) {
  22478. tables.name = {
  22479. tag: 'name',
  22480. data: createNameTable(this.name)
  22481. };
  22482. } else {
  22483. // ... using existing 'name' table as prototype
  22484. var namePrototype = readNameTable(tables.name);
  22485. tables.name.data = createNameTable(name, namePrototype);
  22486. }
  22487. var builder = new OpenTypeFileBuilder(header.version);
  22488. for (var tableTag in tables) {
  22489. builder.addTable(tableTag, tables[tableTag].data);
  22490. }
  22491. return builder.toArray();
  22492. },
  22493. convert: function Font_convert(fontName, font, properties) {
  22494. // TODO: Check the charstring widths to determine this.
  22495. properties.fixedPitch = false;
  22496. var mapping = font.getGlyphMapping(properties);
  22497. var newMapping = adjustMapping(mapping, properties);
  22498. this.toFontChar = newMapping.toFontChar;
  22499. var numGlyphs = font.numGlyphs;
  22500. function getCharCodes(charCodeToGlyphId, glyphId) {
  22501. var charCodes = null;
  22502. for (var charCode in charCodeToGlyphId) {
  22503. if (glyphId === charCodeToGlyphId[charCode]) {
  22504. if (!charCodes) {
  22505. charCodes = [];
  22506. }
  22507. charCodes.push(charCode | 0);
  22508. }
  22509. }
  22510. return charCodes;
  22511. }
  22512. function createCharCode(charCodeToGlyphId, glyphId) {
  22513. for (var charCode in charCodeToGlyphId) {
  22514. if (glyphId === charCodeToGlyphId[charCode]) {
  22515. return charCode | 0;
  22516. }
  22517. }
  22518. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22519. glyphId;
  22520. return newMapping.nextAvailableFontCharCode++;
  22521. }
  22522. var seacs = font.seacs;
  22523. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22524. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22525. var charset = font.getCharset();
  22526. var seacMap = Object.create(null);
  22527. for (var glyphId in seacs) {
  22528. glyphId |= 0;
  22529. var seac = seacs[glyphId];
  22530. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22531. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22532. var baseGlyphId = charset.indexOf(baseGlyphName);
  22533. var accentGlyphId = charset.indexOf(accentGlyphName);
  22534. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22535. continue;
  22536. }
  22537. var accentOffset = {
  22538. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22539. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22540. };
  22541. var charCodes = getCharCodes(mapping, glyphId);
  22542. if (!charCodes) {
  22543. // There's no point in mapping it if the char code was never mapped
  22544. // to begin with.
  22545. continue;
  22546. }
  22547. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22548. var charCode = charCodes[i];
  22549. // Find a fontCharCode that maps to the base and accent glyphs.
  22550. // If one doesn't exists, create it.
  22551. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22552. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22553. baseGlyphId);
  22554. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22555. accentGlyphId);
  22556. seacMap[charCode] = {
  22557. baseFontCharCode: baseFontCharCode,
  22558. accentFontCharCode: accentFontCharCode,
  22559. accentOffset: accentOffset
  22560. };
  22561. }
  22562. }
  22563. properties.seacMap = seacMap;
  22564. }
  22565. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22566. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22567. // PostScript Font Program
  22568. builder.addTable('CFF ', font.data);
  22569. // OS/2 and Windows Specific metrics
  22570. builder.addTable('OS/2', createOS2Table(properties,
  22571. newMapping.charCodeToGlyphId));
  22572. // Character to glyphs mapping
  22573. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22574. // Font header
  22575. builder.addTable('head',
  22576. '\x00\x01\x00\x00' + // Version number
  22577. '\x00\x00\x10\x00' + // fontRevision
  22578. '\x00\x00\x00\x00' + // checksumAdjustement
  22579. '\x5F\x0F\x3C\xF5' + // magicNumber
  22580. '\x00\x00' + // Flags
  22581. safeString16(unitsPerEm) + // unitsPerEM
  22582. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22583. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22584. '\x00\x00' + // xMin
  22585. safeString16(properties.descent) + // yMin
  22586. '\x0F\xFF' + // xMax
  22587. safeString16(properties.ascent) + // yMax
  22588. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22589. '\x00\x11' + // lowestRecPPEM
  22590. '\x00\x00' + // fontDirectionHint
  22591. '\x00\x00' + // indexToLocFormat
  22592. '\x00\x00'); // glyphDataFormat
  22593. // Horizontal header
  22594. builder.addTable('hhea',
  22595. '\x00\x01\x00\x00' + // Version number
  22596. safeString16(properties.ascent) + // Typographic Ascent
  22597. safeString16(properties.descent) + // Typographic Descent
  22598. '\x00\x00' + // Line Gap
  22599. '\xFF\xFF' + // advanceWidthMax
  22600. '\x00\x00' + // minLeftSidebearing
  22601. '\x00\x00' + // minRightSidebearing
  22602. '\x00\x00' + // xMaxExtent
  22603. safeString16(properties.capHeight) + // caretSlopeRise
  22604. safeString16(Math.tan(properties.italicAngle) *
  22605. properties.xHeight) + // caretSlopeRun
  22606. '\x00\x00' + // caretOffset
  22607. '\x00\x00' + // -reserved-
  22608. '\x00\x00' + // -reserved-
  22609. '\x00\x00' + // -reserved-
  22610. '\x00\x00' + // -reserved-
  22611. '\x00\x00' + // metricDataFormat
  22612. string16(numGlyphs)); // Number of HMetrics
  22613. // Horizontal metrics
  22614. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22615. var charstrings = font.charstrings;
  22616. var cffWidths = font.cff ? font.cff.widths : null;
  22617. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22618. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22619. var width = 0;
  22620. if (charstrings) {
  22621. var charstring = charstrings[i - 1];
  22622. width = 'width' in charstring ? charstring.width : 0;
  22623. } else if (cffWidths) {
  22624. width = Math.ceil(cffWidths[i] || 0);
  22625. }
  22626. hmtx += string16(width) + string16(0);
  22627. }
  22628. return hmtx;
  22629. })());
  22630. // Maximum profile
  22631. builder.addTable('maxp',
  22632. '\x00\x00\x50\x00' + // Version number
  22633. string16(numGlyphs)); // Num of glyphs
  22634. // Naming tables
  22635. builder.addTable('name', createNameTable(fontName));
  22636. // PostScript informations
  22637. builder.addTable('post', createPostTable(properties));
  22638. return builder.toArray();
  22639. },
  22640. /**
  22641. * Builds a char code to unicode map based on section 9.10 of the spec.
  22642. * @param {Object} properties Font properties object.
  22643. * @return {Object} A ToUnicodeMap object.
  22644. */
  22645. buildToUnicode: function Font_buildToUnicode(properties) {
  22646. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22647. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22648. return properties.toUnicode;
  22649. }
  22650. // According to the spec if the font is a simple font we should only map
  22651. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22652. // the differences array only contains adobe standard or symbol set names,
  22653. // in pratice it seems better to always try to create a toUnicode
  22654. // map based of the default encoding.
  22655. var toUnicode, charcode;
  22656. if (!properties.composite /* is simple font */) {
  22657. toUnicode = [];
  22658. var encoding = properties.defaultEncoding.slice();
  22659. var baseEncodingName = properties.baseEncodingName;
  22660. // Merge in the differences array.
  22661. var differences = properties.differences;
  22662. for (charcode in differences) {
  22663. encoding[charcode] = differences[charcode];
  22664. }
  22665. for (charcode in encoding) {
  22666. // a) Map the character code to a character name.
  22667. var glyphName = encoding[charcode];
  22668. // b) Look up the character name in the Adobe Glyph List (see the
  22669. // Bibliography) to obtain the corresponding Unicode value.
  22670. if (glyphName === '') {
  22671. continue;
  22672. } else if (GlyphsUnicode[glyphName] === undefined) {
  22673. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22674. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22675. var code = 0;
  22676. switch (glyphName[0]) {
  22677. case 'G': // Gxx glyph
  22678. if (glyphName.length === 3) {
  22679. code = parseInt(glyphName.substr(1), 16);
  22680. }
  22681. break;
  22682. case 'g': // g00xx glyph
  22683. if (glyphName.length === 5) {
  22684. code = parseInt(glyphName.substr(1), 16);
  22685. }
  22686. break;
  22687. case 'C': // Cddd glyph
  22688. case 'c': // cddd glyph
  22689. if (glyphName.length >= 3) {
  22690. code = +glyphName.substr(1);
  22691. }
  22692. break;
  22693. }
  22694. if (code) {
  22695. // If |baseEncodingName| is one the predefined encodings,
  22696. // and |code| equals |charcode|, using the glyph defined in the
  22697. // baseEncoding seems to yield a better |toUnicode| mapping
  22698. // (fixes issue 5070).
  22699. if (baseEncodingName && code === +charcode) {
  22700. var baseEncoding = Encodings[baseEncodingName];
  22701. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22702. toUnicode[charcode] =
  22703. String.fromCharCode(GlyphsUnicode[glyphName]);
  22704. continue;
  22705. }
  22706. }
  22707. toUnicode[charcode] = String.fromCharCode(code);
  22708. }
  22709. continue;
  22710. }
  22711. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22712. }
  22713. return new ToUnicodeMap(toUnicode);
  22714. }
  22715. // If the font is a composite font that uses one of the predefined CMaps
  22716. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22717. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22718. // Adobe-Korea1 character collection:
  22719. if (properties.composite && (
  22720. (properties.cMap.builtInCMap &&
  22721. !(properties.cMap instanceof IdentityCMap)) ||
  22722. (properties.cidSystemInfo.registry === 'Adobe' &&
  22723. (properties.cidSystemInfo.ordering === 'GB1' ||
  22724. properties.cidSystemInfo.ordering === 'CNS1' ||
  22725. properties.cidSystemInfo.ordering === 'Japan1' ||
  22726. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22727. // Then:
  22728. // a) Map the character code to a character identifier (CID) according
  22729. // to the font’s CMap.
  22730. // b) Obtain the registry and ordering of the character collection used
  22731. // by the font’s CMap (for example, Adobe and Japan1) from its
  22732. // CIDSystemInfo dictionary.
  22733. var registry = properties.cidSystemInfo.registry;
  22734. var ordering = properties.cidSystemInfo.ordering;
  22735. // c) Construct a second CMap name by concatenating the registry and
  22736. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22737. // (for example, Adobe–Japan1–UCS2).
  22738. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22739. // d) Obtain the CMap with the name constructed in step (c) (available
  22740. // from the ASN Web site; see the Bibliography).
  22741. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22742. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22743. var cMap = properties.cMap;
  22744. toUnicode = [];
  22745. cMap.forEach(function(charcode, cid) {
  22746. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22747. // e) Map the CID obtained in step (a) according to the CMap obtained
  22748. // in step (d), producing a Unicode value.
  22749. var ucs2 = ucs2CMap.lookup(cid);
  22750. if (ucs2) {
  22751. toUnicode[charcode] =
  22752. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22753. ucs2.charCodeAt(1));
  22754. }
  22755. });
  22756. return new ToUnicodeMap(toUnicode);
  22757. }
  22758. // The viewer's choice, just use an identity map.
  22759. return new IdentityToUnicodeMap(properties.firstChar,
  22760. properties.lastChar);
  22761. },
  22762. get spaceWidth() {
  22763. if ('_shadowWidth' in this) {
  22764. return this._shadowWidth;
  22765. }
  22766. // trying to estimate space character width
  22767. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22768. var width;
  22769. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22770. var glyphName = possibleSpaceReplacements[i];
  22771. // if possible, getting width by glyph name
  22772. if (glyphName in this.widths) {
  22773. width = this.widths[glyphName];
  22774. break;
  22775. }
  22776. var glyphUnicode = GlyphsUnicode[glyphName];
  22777. // finding the charcode via unicodeToCID map
  22778. var charcode = 0;
  22779. if (this.composite) {
  22780. if (this.cMap.contains(glyphUnicode)) {
  22781. charcode = this.cMap.lookup(glyphUnicode);
  22782. }
  22783. }
  22784. // ... via toUnicode map
  22785. if (!charcode && 'toUnicode' in this) {
  22786. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22787. }
  22788. // setting it to unicode if negative or undefined
  22789. if (charcode <= 0) {
  22790. charcode = glyphUnicode;
  22791. }
  22792. // trying to get width via charcode
  22793. width = this.widths[charcode];
  22794. if (width) {
  22795. break; // the non-zero width found
  22796. }
  22797. }
  22798. width = width || this.defaultWidth;
  22799. // Do not shadow the property here. See discussion:
  22800. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22801. this._shadowWidth = width;
  22802. return width;
  22803. },
  22804. charToGlyph: function Font_charToGlyph(charcode) {
  22805. var fontCharCode, width, operatorListId;
  22806. var widthCode = charcode;
  22807. if (this.cMap && this.cMap.contains(charcode)) {
  22808. widthCode = this.cMap.lookup(charcode);
  22809. }
  22810. width = this.widths[widthCode];
  22811. width = isNum(width) ? width : this.defaultWidth;
  22812. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22813. var unicode = this.toUnicode.get(charcode) || charcode;
  22814. if (typeof unicode === 'number') {
  22815. unicode = String.fromCharCode(unicode);
  22816. }
  22817. // First try the toFontChar map, if it's not there then try falling
  22818. // back to the char code.
  22819. fontCharCode = this.toFontChar[charcode] || charcode;
  22820. if (this.missingFile) {
  22821. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22822. }
  22823. if (this.isType3Font) {
  22824. // Font char code in this case is actually a glyph name.
  22825. operatorListId = fontCharCode;
  22826. }
  22827. var accent = null;
  22828. if (this.seacMap && this.seacMap[charcode]) {
  22829. var seac = this.seacMap[charcode];
  22830. fontCharCode = seac.baseFontCharCode;
  22831. accent = {
  22832. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22833. offset: seac.accentOffset
  22834. };
  22835. }
  22836. var fontChar = String.fromCharCode(fontCharCode);
  22837. var glyph = this.glyphCache[charcode];
  22838. if (!glyph ||
  22839. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22840. operatorListId)) {
  22841. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22842. operatorListId);
  22843. this.glyphCache[charcode] = glyph;
  22844. }
  22845. return glyph;
  22846. },
  22847. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22848. var charsCache = this.charsCache;
  22849. var glyphs, glyph, charcode;
  22850. // if we translated this string before, just grab it from the cache
  22851. if (charsCache) {
  22852. glyphs = charsCache[chars];
  22853. if (glyphs) {
  22854. return glyphs;
  22855. }
  22856. }
  22857. // lazily create the translation cache
  22858. if (!charsCache) {
  22859. charsCache = this.charsCache = Object.create(null);
  22860. }
  22861. glyphs = [];
  22862. var charsCacheKey = chars;
  22863. var i = 0, ii;
  22864. if (this.cMap) {
  22865. // composite fonts have multi-byte strings convert the string from
  22866. // single-byte to multi-byte
  22867. var c = {};
  22868. while (i < chars.length) {
  22869. this.cMap.readCharCode(chars, i, c);
  22870. charcode = c.charcode;
  22871. var length = c.length;
  22872. i += length;
  22873. glyph = this.charToGlyph(charcode);
  22874. glyphs.push(glyph);
  22875. // placing null after each word break charcode (ASCII SPACE)
  22876. // Ignore occurences of 0x20 in multiple-byte codes.
  22877. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22878. glyphs.push(null);
  22879. }
  22880. }
  22881. } else {
  22882. for (i = 0, ii = chars.length; i < ii; ++i) {
  22883. charcode = chars.charCodeAt(i);
  22884. glyph = this.charToGlyph(charcode);
  22885. glyphs.push(glyph);
  22886. if (charcode === 0x20) {
  22887. glyphs.push(null);
  22888. }
  22889. }
  22890. }
  22891. // Enter the translated string into the cache
  22892. return (charsCache[charsCacheKey] = glyphs);
  22893. }
  22894. };
  22895. return Font;
  22896. })();
  22897. var ErrorFont = (function ErrorFontClosure() {
  22898. function ErrorFont(error) {
  22899. this.error = error;
  22900. this.loadedName = 'g_font_error';
  22901. this.loading = false;
  22902. }
  22903. ErrorFont.prototype = {
  22904. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22905. return [];
  22906. },
  22907. exportData: function ErrorFont_exportData() {
  22908. return {error: this.error};
  22909. }
  22910. };
  22911. return ErrorFont;
  22912. })();
  22913. /**
  22914. * Shared logic for building a char code to glyph id mapping for Type1 and
  22915. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22916. * @param {Object} properties Font properties object.
  22917. * @param {Object} builtInEncoding The encoding contained within the actual font
  22918. * data.
  22919. * @param {Array} Array of glyph names where the index is the glyph ID.
  22920. * @returns {Object} A char code to glyph ID map.
  22921. */
  22922. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22923. var charCodeToGlyphId = Object.create(null);
  22924. var glyphId, charCode, baseEncoding;
  22925. if (properties.baseEncodingName) {
  22926. // If a valid base encoding name was used, the mapping is initialized with
  22927. // that.
  22928. baseEncoding = Encodings[properties.baseEncodingName];
  22929. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22930. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22931. if (glyphId >= 0) {
  22932. charCodeToGlyphId[charCode] = glyphId;
  22933. } else {
  22934. charCodeToGlyphId[charCode] = 0; // notdef
  22935. }
  22936. }
  22937. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22938. // For a symbolic font the encoding should be the fonts built-in
  22939. // encoding.
  22940. for (charCode in builtInEncoding) {
  22941. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22942. }
  22943. } else {
  22944. // For non-symbolic fonts that don't have a base encoding the standard
  22945. // encoding should be used.
  22946. baseEncoding = Encodings.StandardEncoding;
  22947. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22948. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22949. if (glyphId >= 0) {
  22950. charCodeToGlyphId[charCode] = glyphId;
  22951. } else {
  22952. charCodeToGlyphId[charCode] = 0; // notdef
  22953. }
  22954. }
  22955. }
  22956. // Lastly, merge in the differences.
  22957. var differences = properties.differences;
  22958. if (differences) {
  22959. for (charCode in differences) {
  22960. var glyphName = differences[charCode];
  22961. glyphId = glyphNames.indexOf(glyphName);
  22962. if (glyphId >= 0) {
  22963. charCodeToGlyphId[charCode] = glyphId;
  22964. } else {
  22965. charCodeToGlyphId[charCode] = 0; // notdef
  22966. }
  22967. }
  22968. }
  22969. return charCodeToGlyphId;
  22970. }
  22971. /*
  22972. * CharStrings are encoded following the the CharString Encoding sequence
  22973. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22974. * The value in a byte indicates a command, a number, or subsequent bytes
  22975. * that are to be interpreted in a special way.
  22976. *
  22977. * CharString Number Encoding:
  22978. * A CharString byte containing the values from 32 through 255 inclusive
  22979. * indicate an integer. These values are decoded in four ranges.
  22980. *
  22981. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22982. * indicate the integer v - 139. Thus, the integer values from -107 through
  22983. * 107 inclusive may be encoded in single byte.
  22984. *
  22985. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22986. * indicates an integer involving the next byte, w, according to the formula:
  22987. * [(v - 247) x 256] + w + 108
  22988. *
  22989. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22990. * indicates an integer involving the next byte, w, according to the formula:
  22991. * -[(v - 251) * 256] - w - 108
  22992. *
  22993. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22994. * are a two complement signed integer. The first of these bytes contains the
  22995. * highest order bits, the second byte contains the next higher order bits
  22996. * and the fourth byte contain the lowest order bits.
  22997. *
  22998. *
  22999. * CharString Command Encoding:
  23000. * CharStrings commands are encoded in 1 or 2 bytes.
  23001. *
  23002. * Single byte commands are encoded in 1 byte that contains a value between
  23003. * 0 and 31 inclusive.
  23004. * If a command byte contains the value 12, then the value in the next byte
  23005. * indicates a command. This "escape" mechanism allows many extra commands
  23006. * to be encoded and this encoding technique helps to minimize the length of
  23007. * the charStrings.
  23008. */
  23009. var Type1CharString = (function Type1CharStringClosure() {
  23010. var COMMAND_MAP = {
  23011. 'hstem': [1],
  23012. 'vstem': [3],
  23013. 'vmoveto': [4],
  23014. 'rlineto': [5],
  23015. 'hlineto': [6],
  23016. 'vlineto': [7],
  23017. 'rrcurveto': [8],
  23018. 'callsubr': [10],
  23019. 'flex': [12, 35],
  23020. 'drop' : [12, 18],
  23021. 'endchar': [14],
  23022. 'rmoveto': [21],
  23023. 'hmoveto': [22],
  23024. 'vhcurveto': [30],
  23025. 'hvcurveto': [31]
  23026. };
  23027. function Type1CharString() {
  23028. this.width = 0;
  23029. this.lsb = 0;
  23030. this.flexing = false;
  23031. this.output = [];
  23032. this.stack = [];
  23033. }
  23034. Type1CharString.prototype = {
  23035. convert: function Type1CharString_convert(encoded, subrs) {
  23036. var count = encoded.length;
  23037. var error = false;
  23038. var wx, sbx, subrNumber;
  23039. for (var i = 0; i < count; i++) {
  23040. var value = encoded[i];
  23041. if (value < 32) {
  23042. if (value === 12) {
  23043. value = (value << 8) + encoded[++i];
  23044. }
  23045. switch (value) {
  23046. case 1: // hstem
  23047. if (!HINTING_ENABLED) {
  23048. this.stack = [];
  23049. break;
  23050. }
  23051. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23052. break;
  23053. case 3: // vstem
  23054. if (!HINTING_ENABLED) {
  23055. this.stack = [];
  23056. break;
  23057. }
  23058. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23059. break;
  23060. case 4: // vmoveto
  23061. if (this.flexing) {
  23062. if (this.stack.length < 1) {
  23063. error = true;
  23064. break;
  23065. }
  23066. // Add the dx for flex and but also swap the values so they are
  23067. // the right order.
  23068. var dy = this.stack.pop();
  23069. this.stack.push(0, dy);
  23070. break;
  23071. }
  23072. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23073. break;
  23074. case 5: // rlineto
  23075. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23076. break;
  23077. case 6: // hlineto
  23078. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23079. break;
  23080. case 7: // vlineto
  23081. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23082. break;
  23083. case 8: // rrcurveto
  23084. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23085. break;
  23086. case 9: // closepath
  23087. // closepath is a Type1 command that does not take argument and is
  23088. // useless in Type2 and it can simply be ignored.
  23089. this.stack = [];
  23090. break;
  23091. case 10: // callsubr
  23092. if (this.stack.length < 1) {
  23093. error = true;
  23094. break;
  23095. }
  23096. subrNumber = this.stack.pop();
  23097. error = this.convert(subrs[subrNumber], subrs);
  23098. break;
  23099. case 11: // return
  23100. return error;
  23101. case 13: // hsbw
  23102. if (this.stack.length < 2) {
  23103. error = true;
  23104. break;
  23105. }
  23106. // To convert to type2 we have to move the width value to the
  23107. // first part of the charstring and then use hmoveto with lsb.
  23108. wx = this.stack.pop();
  23109. sbx = this.stack.pop();
  23110. this.lsb = sbx;
  23111. this.width = wx;
  23112. this.stack.push(wx, sbx);
  23113. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23114. break;
  23115. case 14: // endchar
  23116. this.output.push(COMMAND_MAP.endchar[0]);
  23117. break;
  23118. case 21: // rmoveto
  23119. if (this.flexing) {
  23120. break;
  23121. }
  23122. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23123. break;
  23124. case 22: // hmoveto
  23125. if (this.flexing) {
  23126. // Add the dy for flex.
  23127. this.stack.push(0);
  23128. break;
  23129. }
  23130. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23131. break;
  23132. case 30: // vhcurveto
  23133. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23134. break;
  23135. case 31: // hvcurveto
  23136. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23137. break;
  23138. case (12 << 8) + 0: // dotsection
  23139. // dotsection is a Type1 command to specify some hinting feature
  23140. // for dots that do not take a parameter and it can safely be
  23141. // ignored for Type2.
  23142. this.stack = [];
  23143. break;
  23144. case (12 << 8) + 1: // vstem3
  23145. if (!HINTING_ENABLED) {
  23146. this.stack = [];
  23147. break;
  23148. }
  23149. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23150. // multiple parameters, so instead of returning [vh]stem3 take a
  23151. // shortcut and return [vhstem] instead.
  23152. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23153. break;
  23154. case (12 << 8) + 2: // hstem3
  23155. if (!HINTING_ENABLED) {
  23156. this.stack = [];
  23157. break;
  23158. }
  23159. // See vstem3.
  23160. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23161. break;
  23162. case (12 << 8) + 6: // seac
  23163. // seac is like type 2's special endchar but it doesn't use the
  23164. // first argument asb, so remove it.
  23165. if (SEAC_ANALYSIS_ENABLED) {
  23166. this.seac = this.stack.splice(-4, 4);
  23167. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23168. } else {
  23169. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23170. }
  23171. break;
  23172. case (12 << 8) + 7: // sbw
  23173. if (this.stack.length < 4) {
  23174. error = true;
  23175. break;
  23176. }
  23177. // To convert to type2 we have to move the width value to the
  23178. // first part of the charstring and then use rmoveto with
  23179. // (dx, dy). The height argument will not be used for vmtx and
  23180. // vhea tables reconstruction -- ignoring it.
  23181. var wy = this.stack.pop();
  23182. wx = this.stack.pop();
  23183. var sby = this.stack.pop();
  23184. sbx = this.stack.pop();
  23185. this.lsb = sbx;
  23186. this.width = wx;
  23187. this.stack.push(wx, sbx, sby);
  23188. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23189. break;
  23190. case (12 << 8) + 12: // div
  23191. if (this.stack.length < 2) {
  23192. error = true;
  23193. break;
  23194. }
  23195. var num2 = this.stack.pop();
  23196. var num1 = this.stack.pop();
  23197. this.stack.push(num1 / num2);
  23198. break;
  23199. case (12 << 8) + 16: // callothersubr
  23200. if (this.stack.length < 2) {
  23201. error = true;
  23202. break;
  23203. }
  23204. subrNumber = this.stack.pop();
  23205. var numArgs = this.stack.pop();
  23206. if (subrNumber === 0 && numArgs === 3) {
  23207. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23208. this.stack.push(
  23209. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23210. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23211. flexArgs[4], // bcp2x
  23212. flexArgs[5], // bcp2y
  23213. flexArgs[6], // p2x
  23214. flexArgs[7], // p2y
  23215. flexArgs[8], // bcp3x
  23216. flexArgs[9], // bcp3y
  23217. flexArgs[10], // bcp4x
  23218. flexArgs[11], // bcp4y
  23219. flexArgs[12], // p3x
  23220. flexArgs[13], // p3y
  23221. flexArgs[14] // flexDepth
  23222. // 15 = finalx unused by flex
  23223. // 16 = finaly unused by flex
  23224. );
  23225. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23226. this.flexing = false;
  23227. this.stack.push(flexArgs[15], flexArgs[16]);
  23228. } else if (subrNumber === 1 && numArgs === 0) {
  23229. this.flexing = true;
  23230. }
  23231. break;
  23232. case (12 << 8) + 17: // pop
  23233. // Ignore this since it is only used with othersubr.
  23234. break;
  23235. case (12 << 8) + 33: // setcurrentpoint
  23236. // Ignore for now.
  23237. this.stack = [];
  23238. break;
  23239. default:
  23240. warn('Unknown type 1 charstring command of "' + value + '"');
  23241. break;
  23242. }
  23243. if (error) {
  23244. break;
  23245. }
  23246. continue;
  23247. } else if (value <= 246) {
  23248. value = value - 139;
  23249. } else if (value <= 250) {
  23250. value = ((value - 247) * 256) + encoded[++i] + 108;
  23251. } else if (value <= 254) {
  23252. value = -((value - 251) * 256) - encoded[++i] - 108;
  23253. } else {
  23254. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23255. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23256. }
  23257. this.stack.push(value);
  23258. }
  23259. return error;
  23260. },
  23261. executeCommand: function(howManyArgs, command, keepStack) {
  23262. var stackLength = this.stack.length;
  23263. if (howManyArgs > stackLength) {
  23264. return true;
  23265. }
  23266. var start = stackLength - howManyArgs;
  23267. for (var i = start; i < stackLength; i++) {
  23268. var value = this.stack[i];
  23269. if (value === (value | 0)) { // int
  23270. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23271. } else { // fixed point
  23272. value = (65536 * value) | 0;
  23273. this.output.push(255,
  23274. (value >> 24) & 0xFF,
  23275. (value >> 16) & 0xFF,
  23276. (value >> 8) & 0xFF,
  23277. value & 0xFF);
  23278. }
  23279. }
  23280. this.output.push.apply(this.output, command);
  23281. if (keepStack) {
  23282. this.stack.splice(start, howManyArgs);
  23283. } else {
  23284. this.stack.length = 0;
  23285. }
  23286. return false;
  23287. }
  23288. };
  23289. return Type1CharString;
  23290. })();
  23291. /*
  23292. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23293. * program. Some of its logic depends on the Type2 charstrings
  23294. * structure.
  23295. * Note: this doesn't really parse the font since that would require evaluation
  23296. * of PostScript, but it is possible in most cases to extract what we need
  23297. * without a full parse.
  23298. */
  23299. var Type1Parser = (function Type1ParserClosure() {
  23300. /*
  23301. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23302. * of Plaintext Bytes. The function took a key as a parameter which can be
  23303. * for decrypting the eexec block of for decoding charStrings.
  23304. */
  23305. var EEXEC_ENCRYPT_KEY = 55665;
  23306. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23307. function isHexDigit(code) {
  23308. return code >= 48 && code <= 57 || // '0'-'9'
  23309. code >= 65 && code <= 70 || // 'A'-'F'
  23310. code >= 97 && code <= 102; // 'a'-'f'
  23311. }
  23312. function decrypt(data, key, discardNumber) {
  23313. var r = key | 0, c1 = 52845, c2 = 22719;
  23314. var count = data.length;
  23315. var decrypted = new Uint8Array(count);
  23316. for (var i = 0; i < count; i++) {
  23317. var value = data[i];
  23318. decrypted[i] = value ^ (r >> 8);
  23319. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23320. }
  23321. return Array.prototype.slice.call(decrypted, discardNumber);
  23322. }
  23323. function decryptAscii(data, key, discardNumber) {
  23324. var r = key | 0, c1 = 52845, c2 = 22719;
  23325. var count = data.length, maybeLength = count >>> 1;
  23326. var decrypted = new Uint8Array(maybeLength);
  23327. var i, j;
  23328. for (i = 0, j = 0; i < count; i++) {
  23329. var digit1 = data[i];
  23330. if (!isHexDigit(digit1)) {
  23331. continue;
  23332. }
  23333. i++;
  23334. var digit2;
  23335. while (i < count && !isHexDigit(digit2 = data[i])) {
  23336. i++;
  23337. }
  23338. if (i < count) {
  23339. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23340. decrypted[j++] = value ^ (r >> 8);
  23341. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23342. }
  23343. }
  23344. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23345. }
  23346. function isSpecial(c) {
  23347. return c === 0x2F || // '/'
  23348. c === 0x5B || c === 0x5D || // '[', ']'
  23349. c === 0x7B || c === 0x7D || // '{', '}'
  23350. c === 0x28 || c === 0x29; // '(', ')'
  23351. }
  23352. function Type1Parser(stream, encrypted) {
  23353. if (encrypted) {
  23354. var data = stream.getBytes();
  23355. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23356. isHexDigit(data[2]) && isHexDigit(data[3]));
  23357. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23358. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23359. }
  23360. this.stream = stream;
  23361. this.nextChar();
  23362. }
  23363. Type1Parser.prototype = {
  23364. readNumberArray: function Type1Parser_readNumberArray() {
  23365. this.getToken(); // read '[' or '{' (arrays can start with either)
  23366. var array = [];
  23367. while (true) {
  23368. var token = this.getToken();
  23369. if (token === null || token === ']' || token === '}') {
  23370. break;
  23371. }
  23372. array.push(parseFloat(token || 0));
  23373. }
  23374. return array;
  23375. },
  23376. readNumber: function Type1Parser_readNumber() {
  23377. var token = this.getToken();
  23378. return parseFloat(token || 0);
  23379. },
  23380. readInt: function Type1Parser_readInt() {
  23381. // Use '| 0' to prevent setting a double into length such as the double
  23382. // does not flow into the loop variable.
  23383. var token = this.getToken();
  23384. return parseInt(token || 0, 10) | 0;
  23385. },
  23386. readBoolean: function Type1Parser_readBoolean() {
  23387. var token = this.getToken();
  23388. // Use 1 and 0 since that's what type2 charstrings use.
  23389. return token === 'true' ? 1 : 0;
  23390. },
  23391. nextChar : function Type1_nextChar() {
  23392. return (this.currentChar = this.stream.getByte());
  23393. },
  23394. getToken: function Type1Parser_getToken() {
  23395. // Eat whitespace and comments.
  23396. var comment = false;
  23397. var ch = this.currentChar;
  23398. while (true) {
  23399. if (ch === -1) {
  23400. return null;
  23401. }
  23402. if (comment) {
  23403. if (ch === 0x0A || ch === 0x0D) {
  23404. comment = false;
  23405. }
  23406. } else if (ch === 0x25) { // '%'
  23407. comment = true;
  23408. } else if (!Lexer.isSpace(ch)) {
  23409. break;
  23410. }
  23411. ch = this.nextChar();
  23412. }
  23413. if (isSpecial(ch)) {
  23414. this.nextChar();
  23415. return String.fromCharCode(ch);
  23416. }
  23417. var token = '';
  23418. do {
  23419. token += String.fromCharCode(ch);
  23420. ch = this.nextChar();
  23421. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23422. return token;
  23423. },
  23424. /*
  23425. * Returns an object containing a Subrs array and a CharStrings
  23426. * array extracted from and eexec encrypted block of data
  23427. */
  23428. extractFontProgram: function Type1Parser_extractFontProgram() {
  23429. var stream = this.stream;
  23430. var subrs = [], charstrings = [];
  23431. var program = {
  23432. subrs: [],
  23433. charstrings: [],
  23434. properties: {
  23435. 'privateData': {
  23436. 'lenIV': 4
  23437. }
  23438. }
  23439. };
  23440. var token, length, data, lenIV, encoded;
  23441. while ((token = this.getToken()) !== null) {
  23442. if (token !== '/') {
  23443. continue;
  23444. }
  23445. token = this.getToken();
  23446. switch (token) {
  23447. case 'CharStrings':
  23448. // The number immediately following CharStrings must be greater or
  23449. // equal to the number of CharStrings.
  23450. this.getToken();
  23451. this.getToken(); // read in 'dict'
  23452. this.getToken(); // read in 'dup'
  23453. this.getToken(); // read in 'begin'
  23454. while(true) {
  23455. token = this.getToken();
  23456. if (token === null || token === 'end') {
  23457. break;
  23458. }
  23459. if (token !== '/') {
  23460. continue;
  23461. }
  23462. var glyph = this.getToken();
  23463. length = this.readInt();
  23464. this.getToken(); // read in 'RD' or '-|'
  23465. data = stream.makeSubStream(stream.pos, length);
  23466. lenIV = program.properties.privateData['lenIV'];
  23467. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23468. // Skip past the required space and binary data.
  23469. stream.skip(length);
  23470. this.nextChar();
  23471. token = this.getToken(); // read in 'ND' or '|-'
  23472. if (token === 'noaccess') {
  23473. this.getToken(); // read in 'def'
  23474. }
  23475. charstrings.push({
  23476. glyph: glyph,
  23477. encoded: encoded
  23478. });
  23479. }
  23480. break;
  23481. case 'Subrs':
  23482. var num = this.readInt();
  23483. this.getToken(); // read in 'array'
  23484. while ((token = this.getToken()) === 'dup') {
  23485. var index = this.readInt();
  23486. length = this.readInt();
  23487. this.getToken(); // read in 'RD' or '-|'
  23488. data = stream.makeSubStream(stream.pos, length);
  23489. lenIV = program.properties.privateData['lenIV'];
  23490. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23491. // Skip past the required space and binary data.
  23492. stream.skip(length);
  23493. this.nextChar();
  23494. token = this.getToken(); // read in 'NP' or '|'
  23495. if (token === 'noaccess') {
  23496. this.getToken(); // read in 'put'
  23497. }
  23498. subrs[index] = encoded;
  23499. }
  23500. break;
  23501. case 'BlueValues':
  23502. case 'OtherBlues':
  23503. case 'FamilyBlues':
  23504. case 'FamilyOtherBlues':
  23505. var blueArray = this.readNumberArray();
  23506. // *Blue* values may contain invalid data: disables reading of
  23507. // those values when hinting is disabled.
  23508. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23509. HINTING_ENABLED) {
  23510. program.properties.privateData[token] = blueArray;
  23511. }
  23512. break;
  23513. case 'StemSnapH':
  23514. case 'StemSnapV':
  23515. program.properties.privateData[token] = this.readNumberArray();
  23516. break;
  23517. case 'StdHW':
  23518. case 'StdVW':
  23519. program.properties.privateData[token] =
  23520. this.readNumberArray()[0];
  23521. break;
  23522. case 'BlueShift':
  23523. case 'lenIV':
  23524. case 'BlueFuzz':
  23525. case 'BlueScale':
  23526. case 'LanguageGroup':
  23527. case 'ExpansionFactor':
  23528. program.properties.privateData[token] = this.readNumber();
  23529. break;
  23530. case 'ForceBold':
  23531. program.properties.privateData[token] = this.readBoolean();
  23532. break;
  23533. }
  23534. }
  23535. for (var i = 0; i < charstrings.length; i++) {
  23536. glyph = charstrings[i].glyph;
  23537. encoded = charstrings[i].encoded;
  23538. var charString = new Type1CharString();
  23539. var error = charString.convert(encoded, subrs);
  23540. var output = charString.output;
  23541. if (error) {
  23542. // It seems when FreeType encounters an error while evaluating a glyph
  23543. // that it completely ignores the glyph so we'll mimic that behaviour
  23544. // here and put an endchar to make the validator happy.
  23545. output = [14];
  23546. }
  23547. program.charstrings.push({
  23548. glyphName: glyph,
  23549. charstring: output,
  23550. width: charString.width,
  23551. lsb: charString.lsb,
  23552. seac: charString.seac
  23553. });
  23554. }
  23555. return program;
  23556. },
  23557. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23558. var token;
  23559. while ((token = this.getToken()) !== null) {
  23560. if (token !== '/') {
  23561. continue;
  23562. }
  23563. token = this.getToken();
  23564. switch (token) {
  23565. case 'FontMatrix':
  23566. var matrix = this.readNumberArray();
  23567. properties.fontMatrix = matrix;
  23568. break;
  23569. case 'Encoding':
  23570. var encodingArg = this.getToken();
  23571. var encoding;
  23572. if (!/^\d+$/.test(encodingArg)) {
  23573. // encoding name is specified
  23574. encoding = Encodings[encodingArg];
  23575. } else {
  23576. encoding = [];
  23577. var size = parseInt(encodingArg, 10) | 0;
  23578. this.getToken(); // read in 'array'
  23579. for (var j = 0; j < size; j++) {
  23580. token = this.getToken();
  23581. // skipping till first dup or def (e.g. ignoring for statement)
  23582. while (token !== 'dup' && token !== 'def') {
  23583. token = this.getToken();
  23584. if (token === null) {
  23585. return; // invalid header
  23586. }
  23587. }
  23588. if (token === 'def') {
  23589. break; // read all array data
  23590. }
  23591. var index = this.readInt();
  23592. this.getToken(); // read in '/'
  23593. var glyph = this.getToken();
  23594. encoding[index] = glyph;
  23595. this.getToken(); // read the in 'put'
  23596. }
  23597. }
  23598. properties.builtInEncoding = encoding;
  23599. break;
  23600. case 'FontBBox':
  23601. var fontBBox = this.readNumberArray();
  23602. // adjusting ascent/descent
  23603. properties.ascent = fontBBox[3];
  23604. properties.descent = fontBBox[1];
  23605. properties.ascentScaled = true;
  23606. break;
  23607. }
  23608. }
  23609. }
  23610. };
  23611. return Type1Parser;
  23612. })();
  23613. /**
  23614. * The CFF class takes a Type1 file and wrap it into a
  23615. * 'Compact Font Format' which itself embed Type2 charstrings.
  23616. */
  23617. var CFFStandardStrings = [
  23618. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23619. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23620. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23621. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23622. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23623. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23624. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23625. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23626. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23627. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23628. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23629. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23630. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23631. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23632. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23633. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23634. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23635. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23636. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23637. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23638. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23639. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23640. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23641. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23642. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23643. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23644. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23645. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23646. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23647. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23648. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23649. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23650. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23651. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23652. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23653. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23654. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23655. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23656. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23657. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23658. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23659. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23660. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23661. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23662. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23663. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23664. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23665. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23666. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23667. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23668. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23669. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23670. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23671. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23672. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23673. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23674. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23675. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23676. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23677. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23678. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23679. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23680. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23681. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23682. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23683. ];
  23684. // Type1Font is also a CIDFontType0.
  23685. var Type1Font = function Type1Font(name, file, properties) {
  23686. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23687. // Also, length1 and length2 might be off by 6 bytes as well.
  23688. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23689. var PFB_HEADER_SIZE = 6;
  23690. var headerBlockLength = properties.length1;
  23691. var eexecBlockLength = properties.length2;
  23692. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23693. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23694. if (pfbHeaderPresent) {
  23695. file.skip(PFB_HEADER_SIZE);
  23696. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23697. (pfbHeader[3] << 8) | pfbHeader[2];
  23698. }
  23699. // Get the data block containing glyphs and subrs informations
  23700. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23701. var headerBlockParser = new Type1Parser(headerBlock);
  23702. headerBlockParser.extractFontHeader(properties);
  23703. if (pfbHeaderPresent) {
  23704. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23705. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23706. (pfbHeader[3] << 8) | pfbHeader[2];
  23707. }
  23708. // Decrypt the data blocks and retrieve it's content
  23709. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23710. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23711. var data = eexecBlockParser.extractFontProgram();
  23712. for (var info in data.properties) {
  23713. properties[info] = data.properties[info];
  23714. }
  23715. var charstrings = data.charstrings;
  23716. var type2Charstrings = this.getType2Charstrings(charstrings);
  23717. var subrs = this.getType2Subrs(data.subrs);
  23718. this.charstrings = charstrings;
  23719. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23720. subrs, properties);
  23721. this.seacs = this.getSeacs(data.charstrings);
  23722. };
  23723. Type1Font.prototype = {
  23724. get numGlyphs() {
  23725. return this.charstrings.length + 1;
  23726. },
  23727. getCharset: function Type1Font_getCharset() {
  23728. var charset = ['.notdef'];
  23729. var charstrings = this.charstrings;
  23730. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23731. charset.push(charstrings[glyphId].glyphName);
  23732. }
  23733. return charset;
  23734. },
  23735. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23736. var charstrings = this.charstrings;
  23737. var glyphNames = ['.notdef'], glyphId;
  23738. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23739. glyphNames.push(charstrings[glyphId].glyphName);
  23740. }
  23741. var encoding = properties.builtInEncoding;
  23742. if (encoding) {
  23743. var builtInEncoding = {};
  23744. for (var charCode in encoding) {
  23745. glyphId = glyphNames.indexOf(encoding[charCode]);
  23746. if (glyphId >= 0) {
  23747. builtInEncoding[charCode] = glyphId;
  23748. }
  23749. }
  23750. }
  23751. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23752. },
  23753. getSeacs: function Type1Font_getSeacs(charstrings) {
  23754. var i, ii;
  23755. var seacMap = [];
  23756. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23757. var charstring = charstrings[i];
  23758. if (charstring.seac) {
  23759. // Offset by 1 for .notdef
  23760. seacMap[i + 1] = charstring.seac;
  23761. }
  23762. }
  23763. return seacMap;
  23764. },
  23765. getType2Charstrings: function Type1Font_getType2Charstrings(
  23766. type1Charstrings) {
  23767. var type2Charstrings = [];
  23768. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23769. type2Charstrings.push(type1Charstrings[i].charstring);
  23770. }
  23771. return type2Charstrings;
  23772. },
  23773. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23774. var bias = 0;
  23775. var count = type1Subrs.length;
  23776. if (count < 1133) {
  23777. bias = 107;
  23778. } else if (count < 33769) {
  23779. bias = 1131;
  23780. } else {
  23781. bias = 32768;
  23782. }
  23783. // Add a bunch of empty subrs to deal with the Type2 bias
  23784. var type2Subrs = [];
  23785. var i;
  23786. for (i = 0; i < bias; i++) {
  23787. type2Subrs.push([0x0B]);
  23788. }
  23789. for (i = 0; i < count; i++) {
  23790. type2Subrs.push(type1Subrs[i]);
  23791. }
  23792. return type2Subrs;
  23793. },
  23794. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23795. var cff = new CFF();
  23796. cff.header = new CFFHeader(1, 0, 4, 4);
  23797. cff.names = [name];
  23798. var topDict = new CFFTopDict();
  23799. // CFF strings IDs 0...390 are predefined names, so refering
  23800. // to entries in our own String INDEX starts at SID 391.
  23801. topDict.setByName('version', 391);
  23802. topDict.setByName('Notice', 392);
  23803. topDict.setByName('FullName', 393);
  23804. topDict.setByName('FamilyName', 394);
  23805. topDict.setByName('Weight', 395);
  23806. topDict.setByName('Encoding', null); // placeholder
  23807. topDict.setByName('FontMatrix', properties.fontMatrix);
  23808. topDict.setByName('FontBBox', properties.bbox);
  23809. topDict.setByName('charset', null); // placeholder
  23810. topDict.setByName('CharStrings', null); // placeholder
  23811. topDict.setByName('Private', null); // placeholder
  23812. cff.topDict = topDict;
  23813. var strings = new CFFStrings();
  23814. strings.add('Version 0.11'); // Version
  23815. strings.add('See original notice'); // Notice
  23816. strings.add(name); // FullName
  23817. strings.add(name); // FamilyName
  23818. strings.add('Medium'); // Weight
  23819. cff.strings = strings;
  23820. cff.globalSubrIndex = new CFFIndex();
  23821. var count = glyphs.length;
  23822. var charsetArray = [0];
  23823. var i, ii;
  23824. for (i = 0; i < count; i++) {
  23825. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23826. // TODO: Insert the string and correctly map it. Previously it was
  23827. // thought mapping names that aren't in the standard strings to .notdef
  23828. // was fine, however in issue818 when mapping them all to .notdef the
  23829. // adieresis glyph no longer worked.
  23830. if (index === -1) {
  23831. index = 0;
  23832. }
  23833. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23834. }
  23835. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23836. var charStringsIndex = new CFFIndex();
  23837. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23838. for (i = 0; i < count; i++) {
  23839. charStringsIndex.add(glyphs[i]);
  23840. }
  23841. cff.charStrings = charStringsIndex;
  23842. var privateDict = new CFFPrivateDict();
  23843. privateDict.setByName('Subrs', null); // placeholder
  23844. var fields = [
  23845. 'BlueValues',
  23846. 'OtherBlues',
  23847. 'FamilyBlues',
  23848. 'FamilyOtherBlues',
  23849. 'StemSnapH',
  23850. 'StemSnapV',
  23851. 'BlueShift',
  23852. 'BlueFuzz',
  23853. 'BlueScale',
  23854. 'LanguageGroup',
  23855. 'ExpansionFactor',
  23856. 'ForceBold',
  23857. 'StdHW',
  23858. 'StdVW'
  23859. ];
  23860. for (i = 0, ii = fields.length; i < ii; i++) {
  23861. var field = fields[i];
  23862. if (!properties.privateData.hasOwnProperty(field)) {
  23863. continue;
  23864. }
  23865. var value = properties.privateData[field];
  23866. if (isArray(value)) {
  23867. // All of the private dictionary array data in CFF must be stored as
  23868. // "delta-encoded" numbers.
  23869. for (var j = value.length - 1; j > 0; j--) {
  23870. value[j] -= value[j - 1]; // ... difference from previous value
  23871. }
  23872. }
  23873. privateDict.setByName(field, value);
  23874. }
  23875. cff.topDict.privateDict = privateDict;
  23876. var subrIndex = new CFFIndex();
  23877. for (i = 0, ii = subrs.length; i < ii; i++) {
  23878. subrIndex.add(subrs[i]);
  23879. }
  23880. privateDict.subrsIndex = subrIndex;
  23881. var compiler = new CFFCompiler(cff);
  23882. return compiler.compile();
  23883. }
  23884. };
  23885. var CFFFont = (function CFFFontClosure() {
  23886. function CFFFont(file, properties) {
  23887. this.properties = properties;
  23888. var parser = new CFFParser(file, properties);
  23889. this.cff = parser.parse();
  23890. var compiler = new CFFCompiler(this.cff);
  23891. this.seacs = this.cff.seacs;
  23892. try {
  23893. this.data = compiler.compile();
  23894. } catch (e) {
  23895. warn('Failed to compile font ' + properties.loadedName);
  23896. // There may have just been an issue with the compiler, set the data
  23897. // anyway and hope the font loaded.
  23898. this.data = file;
  23899. }
  23900. }
  23901. CFFFont.prototype = {
  23902. get numGlyphs() {
  23903. return this.cff.charStrings.count;
  23904. },
  23905. getCharset: function CFFFont_getCharset() {
  23906. return this.cff.charset.charset;
  23907. },
  23908. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23909. var cff = this.cff;
  23910. var properties = this.properties;
  23911. var charsets = cff.charset.charset;
  23912. var charCodeToGlyphId;
  23913. var glyphId;
  23914. if (properties.composite) {
  23915. charCodeToGlyphId = Object.create(null);
  23916. if (cff.isCIDFont) {
  23917. // If the font is actually a CID font then we should use the charset
  23918. // to map CIDs to GIDs.
  23919. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23920. var cid = charsets[glyphId];
  23921. var charCode = properties.cMap.charCodeOf(cid);
  23922. charCodeToGlyphId[charCode] = glyphId;
  23923. }
  23924. } else {
  23925. // If it is NOT actually a CID font then CIDs should be mapped
  23926. // directly to GIDs.
  23927. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23928. charCodeToGlyphId[glyphId] = glyphId;
  23929. }
  23930. }
  23931. return charCodeToGlyphId;
  23932. }
  23933. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23934. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23935. return charCodeToGlyphId;
  23936. }
  23937. };
  23938. return CFFFont;
  23939. })();
  23940. var CFFParser = (function CFFParserClosure() {
  23941. var CharstringValidationData = [
  23942. null,
  23943. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23944. null,
  23945. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23946. { id: 'vmoveto', min: 1, stackClearing: true },
  23947. { id: 'rlineto', min: 2, resetStack: true },
  23948. { id: 'hlineto', min: 1, resetStack: true },
  23949. { id: 'vlineto', min: 1, resetStack: true },
  23950. { id: 'rrcurveto', min: 6, resetStack: true },
  23951. null,
  23952. { id: 'callsubr', min: 1, undefStack: true },
  23953. { id: 'return', min: 0, undefStack: true },
  23954. null, // 12
  23955. null,
  23956. { id: 'endchar', min: 0, stackClearing: true },
  23957. null,
  23958. null,
  23959. null,
  23960. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23961. { id: 'hintmask', min: 0, stackClearing: true },
  23962. { id: 'cntrmask', min: 0, stackClearing: true },
  23963. { id: 'rmoveto', min: 2, stackClearing: true },
  23964. { id: 'hmoveto', min: 1, stackClearing: true },
  23965. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23966. { id: 'rcurveline', min: 8, resetStack: true },
  23967. { id: 'rlinecurve', min: 8, resetStack: true },
  23968. { id: 'vvcurveto', min: 4, resetStack: true },
  23969. { id: 'hhcurveto', min: 4, resetStack: true },
  23970. null, // shortint
  23971. { id: 'callgsubr', min: 1, undefStack: true },
  23972. { id: 'vhcurveto', min: 4, resetStack: true },
  23973. { id: 'hvcurveto', min: 4, resetStack: true }
  23974. ];
  23975. var CharstringValidationData12 = [
  23976. null,
  23977. null,
  23978. null,
  23979. { id: 'and', min: 2, stackDelta: -1 },
  23980. { id: 'or', min: 2, stackDelta: -1 },
  23981. { id: 'not', min: 1, stackDelta: 0 },
  23982. null,
  23983. null,
  23984. null,
  23985. { id: 'abs', min: 1, stackDelta: 0 },
  23986. { id: 'add', min: 2, stackDelta: -1,
  23987. stackFn: function stack_div(stack, index) {
  23988. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23989. }
  23990. },
  23991. { id: 'sub', min: 2, stackDelta: -1,
  23992. stackFn: function stack_div(stack, index) {
  23993. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23994. }
  23995. },
  23996. { id: 'div', min: 2, stackDelta: -1,
  23997. stackFn: function stack_div(stack, index) {
  23998. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23999. }
  24000. },
  24001. null,
  24002. { id: 'neg', min: 1, stackDelta: 0,
  24003. stackFn: function stack_div(stack, index) {
  24004. stack[index - 1] = -stack[index - 1];
  24005. }
  24006. },
  24007. { id: 'eq', min: 2, stackDelta: -1 },
  24008. null,
  24009. null,
  24010. { id: 'drop', min: 1, stackDelta: -1 },
  24011. null,
  24012. { id: 'put', min: 2, stackDelta: -2 },
  24013. { id: 'get', min: 1, stackDelta: 0 },
  24014. { id: 'ifelse', min: 4, stackDelta: -3 },
  24015. { id: 'random', min: 0, stackDelta: 1 },
  24016. { id: 'mul', min: 2, stackDelta: -1,
  24017. stackFn: function stack_div(stack, index) {
  24018. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24019. }
  24020. },
  24021. null,
  24022. { id: 'sqrt', min: 1, stackDelta: 0 },
  24023. { id: 'dup', min: 1, stackDelta: 1 },
  24024. { id: 'exch', min: 2, stackDelta: 0 },
  24025. { id: 'index', min: 2, stackDelta: 0 },
  24026. { id: 'roll', min: 3, stackDelta: -2 },
  24027. null,
  24028. null,
  24029. null,
  24030. { id: 'hflex', min: 7, resetStack: true },
  24031. { id: 'flex', min: 13, resetStack: true },
  24032. { id: 'hflex1', min: 9, resetStack: true },
  24033. { id: 'flex1', min: 11, resetStack: true }
  24034. ];
  24035. function CFFParser(file, properties) {
  24036. this.bytes = file.getBytes();
  24037. this.properties = properties;
  24038. }
  24039. CFFParser.prototype = {
  24040. parse: function CFFParser_parse() {
  24041. var properties = this.properties;
  24042. var cff = new CFF();
  24043. this.cff = cff;
  24044. // The first five sections must be in order, all the others are reached
  24045. // via offsets contained in one of the below.
  24046. var header = this.parseHeader();
  24047. var nameIndex = this.parseIndex(header.endPos);
  24048. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24049. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24050. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24051. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24052. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24053. cff.header = header.obj;
  24054. cff.names = this.parseNameIndex(nameIndex.obj);
  24055. cff.strings = this.parseStringIndex(stringIndex.obj);
  24056. cff.topDict = topDict;
  24057. cff.globalSubrIndex = globalSubrIndex.obj;
  24058. this.parsePrivateDict(cff.topDict);
  24059. cff.isCIDFont = topDict.hasName('ROS');
  24060. var charStringOffset = topDict.getByName('CharStrings');
  24061. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24062. cff.charStrings = charStringsAndSeacs.charStrings;
  24063. cff.seacs = charStringsAndSeacs.seacs;
  24064. cff.widths = charStringsAndSeacs.widths;
  24065. var fontMatrix = topDict.getByName('FontMatrix');
  24066. if (fontMatrix) {
  24067. properties.fontMatrix = fontMatrix;
  24068. }
  24069. var fontBBox = topDict.getByName('FontBBox');
  24070. if (fontBBox) {
  24071. // adjusting ascent/descent
  24072. properties.ascent = fontBBox[3];
  24073. properties.descent = fontBBox[1];
  24074. properties.ascentScaled = true;
  24075. }
  24076. var charset, encoding;
  24077. if (cff.isCIDFont) {
  24078. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24079. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24080. var dictRaw = fdArrayIndex.get(i);
  24081. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24082. cff.strings);
  24083. this.parsePrivateDict(fontDict);
  24084. cff.fdArray.push(fontDict);
  24085. }
  24086. // cid fonts don't have an encoding
  24087. encoding = null;
  24088. charset = this.parseCharsets(topDict.getByName('charset'),
  24089. cff.charStrings.count, cff.strings, true);
  24090. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24091. cff.charStrings.count);
  24092. } else {
  24093. charset = this.parseCharsets(topDict.getByName('charset'),
  24094. cff.charStrings.count, cff.strings, false);
  24095. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24096. properties,
  24097. cff.strings, charset.charset);
  24098. }
  24099. cff.charset = charset;
  24100. cff.encoding = encoding;
  24101. return cff;
  24102. },
  24103. parseHeader: function CFFParser_parseHeader() {
  24104. var bytes = this.bytes;
  24105. var bytesLength = bytes.length;
  24106. var offset = 0;
  24107. // Prevent an infinite loop, by checking that the offset is within the
  24108. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24109. while (offset < bytesLength && bytes[offset] !== 1) {
  24110. ++offset;
  24111. }
  24112. if (offset >= bytesLength) {
  24113. error('Invalid CFF header');
  24114. } else if (offset !== 0) {
  24115. info('cff data is shifted');
  24116. bytes = bytes.subarray(offset);
  24117. this.bytes = bytes;
  24118. }
  24119. var major = bytes[0];
  24120. var minor = bytes[1];
  24121. var hdrSize = bytes[2];
  24122. var offSize = bytes[3];
  24123. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24124. return { obj: header, endPos: hdrSize };
  24125. },
  24126. parseDict: function CFFParser_parseDict(dict) {
  24127. var pos = 0;
  24128. function parseOperand() {
  24129. var value = dict[pos++];
  24130. if (value === 30) {
  24131. return parseFloatOperand(pos);
  24132. } else if (value === 28) {
  24133. value = dict[pos++];
  24134. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24135. return value;
  24136. } else if (value === 29) {
  24137. value = dict[pos++];
  24138. value = (value << 8) | dict[pos++];
  24139. value = (value << 8) | dict[pos++];
  24140. value = (value << 8) | dict[pos++];
  24141. return value;
  24142. } else if (value >= 32 && value <= 246) {
  24143. return value - 139;
  24144. } else if (value >= 247 && value <= 250) {
  24145. return ((value - 247) * 256) + dict[pos++] + 108;
  24146. } else if (value >= 251 && value <= 254) {
  24147. return -((value - 251) * 256) - dict[pos++] - 108;
  24148. } else {
  24149. error('255 is not a valid DICT command');
  24150. }
  24151. return -1;
  24152. }
  24153. function parseFloatOperand() {
  24154. var str = '';
  24155. var eof = 15;
  24156. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24157. '9', '.', 'E', 'E-', null, '-'];
  24158. var length = dict.length;
  24159. while (pos < length) {
  24160. var b = dict[pos++];
  24161. var b1 = b >> 4;
  24162. var b2 = b & 15;
  24163. if (b1 === eof) {
  24164. break;
  24165. }
  24166. str += lookup[b1];
  24167. if (b2 === eof) {
  24168. break;
  24169. }
  24170. str += lookup[b2];
  24171. }
  24172. return parseFloat(str);
  24173. }
  24174. var operands = [];
  24175. var entries = [];
  24176. pos = 0;
  24177. var end = dict.length;
  24178. while (pos < end) {
  24179. var b = dict[pos];
  24180. if (b <= 21) {
  24181. if (b === 12) {
  24182. b = (b << 8) | dict[++pos];
  24183. }
  24184. entries.push([b, operands]);
  24185. operands = [];
  24186. ++pos;
  24187. } else {
  24188. operands.push(parseOperand());
  24189. }
  24190. }
  24191. return entries;
  24192. },
  24193. parseIndex: function CFFParser_parseIndex(pos) {
  24194. var cffIndex = new CFFIndex();
  24195. var bytes = this.bytes;
  24196. var count = (bytes[pos++] << 8) | bytes[pos++];
  24197. var offsets = [];
  24198. var end = pos;
  24199. var i, ii;
  24200. if (count !== 0) {
  24201. var offsetSize = bytes[pos++];
  24202. // add 1 for offset to determine size of last object
  24203. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24204. for (i = 0, ii = count + 1; i < ii; ++i) {
  24205. var offset = 0;
  24206. for (var j = 0; j < offsetSize; ++j) {
  24207. offset <<= 8;
  24208. offset += bytes[pos++];
  24209. }
  24210. offsets.push(startPos + offset);
  24211. }
  24212. end = offsets[count];
  24213. }
  24214. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24215. var offsetStart = offsets[i];
  24216. var offsetEnd = offsets[i + 1];
  24217. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24218. }
  24219. return {obj: cffIndex, endPos: end};
  24220. },
  24221. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24222. var names = [];
  24223. for (var i = 0, ii = index.count; i < ii; ++i) {
  24224. var name = index.get(i);
  24225. // OTS doesn't allow names to be over 127 characters.
  24226. var length = Math.min(name.length, 127);
  24227. var data = [];
  24228. // OTS also only permits certain characters in the name.
  24229. for (var j = 0; j < length; ++j) {
  24230. var c = name[j];
  24231. if (j === 0 && c === 0) {
  24232. data[j] = c;
  24233. continue;
  24234. }
  24235. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24236. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24237. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24238. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24239. data[j] = 95;
  24240. continue;
  24241. }
  24242. data[j] = c;
  24243. }
  24244. names.push(bytesToString(data));
  24245. }
  24246. return names;
  24247. },
  24248. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24249. var strings = new CFFStrings();
  24250. for (var i = 0, ii = index.count; i < ii; ++i) {
  24251. var data = index.get(i);
  24252. strings.add(bytesToString(data));
  24253. }
  24254. return strings;
  24255. },
  24256. createDict: function CFFParser_createDict(Type, dict, strings) {
  24257. var cffDict = new Type(strings);
  24258. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24259. var pair = dict[i];
  24260. var key = pair[0];
  24261. var value = pair[1];
  24262. cffDict.setByKey(key, value);
  24263. }
  24264. return cffDict;
  24265. },
  24266. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24267. var charStrings = this.parseIndex(charStringOffset).obj;
  24268. var seacs = [];
  24269. var widths = [];
  24270. var count = charStrings.count;
  24271. for (var i = 0; i < count; i++) {
  24272. var charstring = charStrings.get(i);
  24273. var stackSize = 0;
  24274. var stack = [];
  24275. var undefStack = true;
  24276. var hints = 0;
  24277. var valid = true;
  24278. var data = charstring;
  24279. var length = data.length;
  24280. var firstStackClearing = true;
  24281. for (var j = 0; j < length;) {
  24282. var value = data[j++];
  24283. var validationCommand = null;
  24284. if (value === 12) {
  24285. var q = data[j++];
  24286. if (q === 0) {
  24287. // The CFF specification state that the 'dotsection' command
  24288. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24289. // charstrings processors should support them. Unfortunately
  24290. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24291. // is replaced by a useless (0, hmoveto).
  24292. data[j - 2] = 139;
  24293. data[j - 1] = 22;
  24294. stackSize = 0;
  24295. } else {
  24296. validationCommand = CharstringValidationData12[q];
  24297. }
  24298. } else if (value === 28) { // number (16 bit)
  24299. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24300. j += 2;
  24301. stackSize++;
  24302. } else if (value === 14) {
  24303. if (stackSize >= 4) {
  24304. stackSize -= 4;
  24305. if (SEAC_ANALYSIS_ENABLED) {
  24306. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24307. valid = false;
  24308. }
  24309. }
  24310. validationCommand = CharstringValidationData[value];
  24311. } else if (value >= 32 && value <= 246) { // number
  24312. stack[stackSize] = value - 139;
  24313. stackSize++;
  24314. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24315. stack[stackSize] = (value < 251 ?
  24316. ((value - 247) << 8) + data[j] + 108 :
  24317. -((value - 251) << 8) - data[j] - 108);
  24318. j++;
  24319. stackSize++;
  24320. } else if (value === 255) { // number (32 bit)
  24321. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24322. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24323. j += 4;
  24324. stackSize++;
  24325. } else if (value === 19 || value === 20) {
  24326. hints += stackSize >> 1;
  24327. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24328. stackSize %= 2;
  24329. validationCommand = CharstringValidationData[value];
  24330. } else {
  24331. validationCommand = CharstringValidationData[value];
  24332. }
  24333. if (validationCommand) {
  24334. if (validationCommand.stem) {
  24335. hints += stackSize >> 1;
  24336. }
  24337. if ('min' in validationCommand) {
  24338. if (!undefStack && stackSize < validationCommand.min) {
  24339. warn('Not enough parameters for ' + validationCommand.id +
  24340. '; actual: ' + stackSize +
  24341. ', expected: ' + validationCommand.min);
  24342. valid = false;
  24343. break;
  24344. }
  24345. }
  24346. if (firstStackClearing && validationCommand.stackClearing) {
  24347. firstStackClearing = false;
  24348. // the optional character width can be found before the first
  24349. // stack-clearing command arguments
  24350. stackSize -= validationCommand.min;
  24351. if (stackSize >= 2 && validationCommand.stem) {
  24352. // there are even amount of arguments for stem commands
  24353. stackSize %= 2;
  24354. } else if (stackSize > 1) {
  24355. warn('Found too many parameters for stack-clearing command');
  24356. }
  24357. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24358. widths[i] = stack[stackSize - 1];
  24359. }
  24360. }
  24361. if ('stackDelta' in validationCommand) {
  24362. if ('stackFn' in validationCommand) {
  24363. validationCommand.stackFn(stack, stackSize);
  24364. }
  24365. stackSize += validationCommand.stackDelta;
  24366. } else if (validationCommand.stackClearing) {
  24367. stackSize = 0;
  24368. } else if (validationCommand.resetStack) {
  24369. stackSize = 0;
  24370. undefStack = false;
  24371. } else if (validationCommand.undefStack) {
  24372. stackSize = 0;
  24373. undefStack = true;
  24374. firstStackClearing = false;
  24375. }
  24376. }
  24377. }
  24378. if (!valid) {
  24379. // resetting invalid charstring to single 'endchar'
  24380. charStrings.set(i, new Uint8Array([14]));
  24381. }
  24382. }
  24383. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24384. },
  24385. emptyPrivateDictionary:
  24386. function CFFParser_emptyPrivateDictionary(parentDict) {
  24387. var privateDict = this.createDict(CFFPrivateDict, [],
  24388. parentDict.strings);
  24389. parentDict.setByKey(18, [0, 0]);
  24390. parentDict.privateDict = privateDict;
  24391. },
  24392. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24393. // no private dict, do nothing
  24394. if (!parentDict.hasName('Private')) {
  24395. this.emptyPrivateDictionary(parentDict);
  24396. return;
  24397. }
  24398. var privateOffset = parentDict.getByName('Private');
  24399. // make sure the params are formatted correctly
  24400. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24401. parentDict.removeByName('Private');
  24402. return;
  24403. }
  24404. var size = privateOffset[0];
  24405. var offset = privateOffset[1];
  24406. // remove empty dicts or ones that refer to invalid location
  24407. if (size === 0 || offset >= this.bytes.length) {
  24408. this.emptyPrivateDictionary(parentDict);
  24409. return;
  24410. }
  24411. var privateDictEnd = offset + size;
  24412. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24413. var dict = this.parseDict(dictData);
  24414. var privateDict = this.createDict(CFFPrivateDict, dict,
  24415. parentDict.strings);
  24416. parentDict.privateDict = privateDict;
  24417. // Parse the Subrs index also since it's relative to the private dict.
  24418. if (!privateDict.getByName('Subrs')) {
  24419. return;
  24420. }
  24421. var subrsOffset = privateDict.getByName('Subrs');
  24422. var relativeOffset = offset + subrsOffset;
  24423. // Validate the offset.
  24424. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24425. this.emptyPrivateDictionary(parentDict);
  24426. return;
  24427. }
  24428. var subrsIndex = this.parseIndex(relativeOffset);
  24429. privateDict.subrsIndex = subrsIndex.obj;
  24430. },
  24431. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24432. if (pos === 0) {
  24433. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24434. ISOAdobeCharset);
  24435. } else if (pos === 1) {
  24436. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24437. ExpertCharset);
  24438. } else if (pos === 2) {
  24439. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24440. ExpertSubsetCharset);
  24441. }
  24442. var bytes = this.bytes;
  24443. var start = pos;
  24444. var format = bytes[pos++];
  24445. var charset = ['.notdef'];
  24446. var id, count, i;
  24447. // subtract 1 for the .notdef glyph
  24448. length -= 1;
  24449. switch (format) {
  24450. case 0:
  24451. for (i = 0; i < length; i++) {
  24452. id = (bytes[pos++] << 8) | bytes[pos++];
  24453. charset.push(cid ? id : strings.get(id));
  24454. }
  24455. break;
  24456. case 1:
  24457. while (charset.length <= length) {
  24458. id = (bytes[pos++] << 8) | bytes[pos++];
  24459. count = bytes[pos++];
  24460. for (i = 0; i <= count; i++) {
  24461. charset.push(cid ? id++ : strings.get(id++));
  24462. }
  24463. }
  24464. break;
  24465. case 2:
  24466. while (charset.length <= length) {
  24467. id = (bytes[pos++] << 8) | bytes[pos++];
  24468. count = (bytes[pos++] << 8) | bytes[pos++];
  24469. for (i = 0; i <= count; i++) {
  24470. charset.push(cid ? id++ : strings.get(id++));
  24471. }
  24472. }
  24473. break;
  24474. default:
  24475. error('Unknown charset format');
  24476. }
  24477. // Raw won't be needed if we actually compile the charset.
  24478. var end = pos;
  24479. var raw = bytes.subarray(start, end);
  24480. return new CFFCharset(false, format, charset, raw);
  24481. },
  24482. parseEncoding: function CFFParser_parseEncoding(pos,
  24483. properties,
  24484. strings,
  24485. charset) {
  24486. var encoding = {};
  24487. var bytes = this.bytes;
  24488. var predefined = false;
  24489. var hasSupplement = false;
  24490. var format, i, ii;
  24491. var raw = null;
  24492. function readSupplement() {
  24493. var supplementsCount = bytes[pos++];
  24494. for (i = 0; i < supplementsCount; i++) {
  24495. var code = bytes[pos++];
  24496. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24497. encoding[code] = charset.indexOf(strings.get(sid));
  24498. }
  24499. }
  24500. if (pos === 0 || pos === 1) {
  24501. predefined = true;
  24502. format = pos;
  24503. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24504. Encodings.StandardEncoding;
  24505. for (i = 0, ii = charset.length; i < ii; i++) {
  24506. var index = baseEncoding.indexOf(charset[i]);
  24507. if (index !== -1) {
  24508. encoding[index] = i;
  24509. }
  24510. }
  24511. } else {
  24512. var dataStart = pos;
  24513. format = bytes[pos++];
  24514. switch (format & 0x7f) {
  24515. case 0:
  24516. var glyphsCount = bytes[pos++];
  24517. for (i = 1; i <= glyphsCount; i++) {
  24518. encoding[bytes[pos++]] = i;
  24519. }
  24520. break;
  24521. case 1:
  24522. var rangesCount = bytes[pos++];
  24523. var gid = 1;
  24524. for (i = 0; i < rangesCount; i++) {
  24525. var start = bytes[pos++];
  24526. var left = bytes[pos++];
  24527. for (var j = start; j <= start + left; j++) {
  24528. encoding[j] = gid++;
  24529. }
  24530. }
  24531. break;
  24532. default:
  24533. error('Unknow encoding format: ' + format + ' in CFF');
  24534. break;
  24535. }
  24536. var dataEnd = pos;
  24537. if (format & 0x80) {
  24538. // The font sanitizer does not support CFF encoding with a
  24539. // supplement, since the encoding is not really used to map
  24540. // between gid to glyph, let's overwrite what is declared in
  24541. // the top dictionary to let the sanitizer think the font use
  24542. // StandardEncoding, that's a lie but that's ok.
  24543. bytes[dataStart] &= 0x7f;
  24544. readSupplement();
  24545. hasSupplement = true;
  24546. }
  24547. raw = bytes.subarray(dataStart, dataEnd);
  24548. }
  24549. format = format & 0x7f;
  24550. return new CFFEncoding(predefined, format, encoding, raw);
  24551. },
  24552. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24553. var start = pos;
  24554. var bytes = this.bytes;
  24555. var format = bytes[pos++];
  24556. var fdSelect = [];
  24557. var i;
  24558. switch (format) {
  24559. case 0:
  24560. for (i = 0; i < length; ++i) {
  24561. var id = bytes[pos++];
  24562. fdSelect.push(id);
  24563. }
  24564. break;
  24565. case 3:
  24566. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24567. for (i = 0; i < rangesCount; ++i) {
  24568. var first = (bytes[pos++] << 8) | bytes[pos++];
  24569. var fdIndex = bytes[pos++];
  24570. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24571. for (var j = first; j < next; ++j) {
  24572. fdSelect.push(fdIndex);
  24573. }
  24574. }
  24575. // Advance past the sentinel(next).
  24576. pos += 2;
  24577. break;
  24578. default:
  24579. error('Unknown fdselect format ' + format);
  24580. break;
  24581. }
  24582. var end = pos;
  24583. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24584. }
  24585. };
  24586. return CFFParser;
  24587. })();
  24588. // Compact Font Format
  24589. var CFF = (function CFFClosure() {
  24590. function CFF() {
  24591. this.header = null;
  24592. this.names = [];
  24593. this.topDict = null;
  24594. this.strings = new CFFStrings();
  24595. this.globalSubrIndex = null;
  24596. // The following could really be per font, but since we only have one font
  24597. // store them here.
  24598. this.encoding = null;
  24599. this.charset = null;
  24600. this.charStrings = null;
  24601. this.fdArray = [];
  24602. this.fdSelect = null;
  24603. this.isCIDFont = false;
  24604. }
  24605. return CFF;
  24606. })();
  24607. var CFFHeader = (function CFFHeaderClosure() {
  24608. function CFFHeader(major, minor, hdrSize, offSize) {
  24609. this.major = major;
  24610. this.minor = minor;
  24611. this.hdrSize = hdrSize;
  24612. this.offSize = offSize;
  24613. }
  24614. return CFFHeader;
  24615. })();
  24616. var CFFStrings = (function CFFStringsClosure() {
  24617. function CFFStrings() {
  24618. this.strings = [];
  24619. }
  24620. CFFStrings.prototype = {
  24621. get: function CFFStrings_get(index) {
  24622. if (index >= 0 && index <= 390) {
  24623. return CFFStandardStrings[index];
  24624. }
  24625. if (index - 391 <= this.strings.length) {
  24626. return this.strings[index - 391];
  24627. }
  24628. return CFFStandardStrings[0];
  24629. },
  24630. add: function CFFStrings_add(value) {
  24631. this.strings.push(value);
  24632. },
  24633. get count() {
  24634. return this.strings.length;
  24635. }
  24636. };
  24637. return CFFStrings;
  24638. })();
  24639. var CFFIndex = (function CFFIndexClosure() {
  24640. function CFFIndex() {
  24641. this.objects = [];
  24642. this.length = 0;
  24643. }
  24644. CFFIndex.prototype = {
  24645. add: function CFFIndex_add(data) {
  24646. this.length += data.length;
  24647. this.objects.push(data);
  24648. },
  24649. set: function CFFIndex_set(index, data) {
  24650. this.length += data.length - this.objects[index].length;
  24651. this.objects[index] = data;
  24652. },
  24653. get: function CFFIndex_get(index) {
  24654. return this.objects[index];
  24655. },
  24656. get count() {
  24657. return this.objects.length;
  24658. }
  24659. };
  24660. return CFFIndex;
  24661. })();
  24662. var CFFDict = (function CFFDictClosure() {
  24663. function CFFDict(tables, strings) {
  24664. this.keyToNameMap = tables.keyToNameMap;
  24665. this.nameToKeyMap = tables.nameToKeyMap;
  24666. this.defaults = tables.defaults;
  24667. this.types = tables.types;
  24668. this.opcodes = tables.opcodes;
  24669. this.order = tables.order;
  24670. this.strings = strings;
  24671. this.values = {};
  24672. }
  24673. CFFDict.prototype = {
  24674. // value should always be an array
  24675. setByKey: function CFFDict_setByKey(key, value) {
  24676. if (!(key in this.keyToNameMap)) {
  24677. return false;
  24678. }
  24679. // ignore empty values
  24680. if (value.length === 0) {
  24681. return true;
  24682. }
  24683. var type = this.types[key];
  24684. // remove the array wrapping these types of values
  24685. if (type === 'num' || type === 'sid' || type === 'offset') {
  24686. value = value[0];
  24687. }
  24688. this.values[key] = value;
  24689. return true;
  24690. },
  24691. setByName: function CFFDict_setByName(name, value) {
  24692. if (!(name in this.nameToKeyMap)) {
  24693. error('Invalid dictionary name "' + name + '"');
  24694. }
  24695. this.values[this.nameToKeyMap[name]] = value;
  24696. },
  24697. hasName: function CFFDict_hasName(name) {
  24698. return this.nameToKeyMap[name] in this.values;
  24699. },
  24700. getByName: function CFFDict_getByName(name) {
  24701. if (!(name in this.nameToKeyMap)) {
  24702. error('Invalid dictionary name "' + name + '"');
  24703. }
  24704. var key = this.nameToKeyMap[name];
  24705. if (!(key in this.values)) {
  24706. return this.defaults[key];
  24707. }
  24708. return this.values[key];
  24709. },
  24710. removeByName: function CFFDict_removeByName(name) {
  24711. delete this.values[this.nameToKeyMap[name]];
  24712. }
  24713. };
  24714. CFFDict.createTables = function CFFDict_createTables(layout) {
  24715. var tables = {
  24716. keyToNameMap: {},
  24717. nameToKeyMap: {},
  24718. defaults: {},
  24719. types: {},
  24720. opcodes: {},
  24721. order: []
  24722. };
  24723. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24724. var entry = layout[i];
  24725. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24726. tables.keyToNameMap[key] = entry[1];
  24727. tables.nameToKeyMap[entry[1]] = key;
  24728. tables.types[key] = entry[2];
  24729. tables.defaults[key] = entry[3];
  24730. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24731. tables.order.push(key);
  24732. }
  24733. return tables;
  24734. };
  24735. return CFFDict;
  24736. })();
  24737. var CFFTopDict = (function CFFTopDictClosure() {
  24738. var layout = [
  24739. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24740. [[12, 20], 'SyntheticBase', 'num', null],
  24741. [0, 'version', 'sid', null],
  24742. [1, 'Notice', 'sid', null],
  24743. [[12, 0], 'Copyright', 'sid', null],
  24744. [2, 'FullName', 'sid', null],
  24745. [3, 'FamilyName', 'sid', null],
  24746. [4, 'Weight', 'sid', null],
  24747. [[12, 1], 'isFixedPitch', 'num', 0],
  24748. [[12, 2], 'ItalicAngle', 'num', 0],
  24749. [[12, 3], 'UnderlinePosition', 'num', -100],
  24750. [[12, 4], 'UnderlineThickness', 'num', 50],
  24751. [[12, 5], 'PaintType', 'num', 0],
  24752. [[12, 6], 'CharstringType', 'num', 2],
  24753. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24754. [0.001, 0, 0, 0.001, 0, 0]],
  24755. [13, 'UniqueID', 'num', null],
  24756. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24757. [[12, 8], 'StrokeWidth', 'num', 0],
  24758. [14, 'XUID', 'array', null],
  24759. [15, 'charset', 'offset', 0],
  24760. [16, 'Encoding', 'offset', 0],
  24761. [17, 'CharStrings', 'offset', 0],
  24762. [18, 'Private', ['offset', 'offset'], null],
  24763. [[12, 21], 'PostScript', 'sid', null],
  24764. [[12, 22], 'BaseFontName', 'sid', null],
  24765. [[12, 23], 'BaseFontBlend', 'delta', null],
  24766. [[12, 31], 'CIDFontVersion', 'num', 0],
  24767. [[12, 32], 'CIDFontRevision', 'num', 0],
  24768. [[12, 33], 'CIDFontType', 'num', 0],
  24769. [[12, 34], 'CIDCount', 'num', 8720],
  24770. [[12, 35], 'UIDBase', 'num', null],
  24771. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24772. // before FDArray.
  24773. [[12, 37], 'FDSelect', 'offset', null],
  24774. [[12, 36], 'FDArray', 'offset', null],
  24775. [[12, 38], 'FontName', 'sid', null]
  24776. ];
  24777. var tables = null;
  24778. function CFFTopDict(strings) {
  24779. if (tables === null) {
  24780. tables = CFFDict.createTables(layout);
  24781. }
  24782. CFFDict.call(this, tables, strings);
  24783. this.privateDict = null;
  24784. }
  24785. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24786. return CFFTopDict;
  24787. })();
  24788. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24789. var layout = [
  24790. [6, 'BlueValues', 'delta', null],
  24791. [7, 'OtherBlues', 'delta', null],
  24792. [8, 'FamilyBlues', 'delta', null],
  24793. [9, 'FamilyOtherBlues', 'delta', null],
  24794. [[12, 9], 'BlueScale', 'num', 0.039625],
  24795. [[12, 10], 'BlueShift', 'num', 7],
  24796. [[12, 11], 'BlueFuzz', 'num', 1],
  24797. [10, 'StdHW', 'num', null],
  24798. [11, 'StdVW', 'num', null],
  24799. [[12, 12], 'StemSnapH', 'delta', null],
  24800. [[12, 13], 'StemSnapV', 'delta', null],
  24801. [[12, 14], 'ForceBold', 'num', 0],
  24802. [[12, 17], 'LanguageGroup', 'num', 0],
  24803. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24804. [[12, 19], 'initialRandomSeed', 'num', 0],
  24805. [20, 'defaultWidthX', 'num', 0],
  24806. [21, 'nominalWidthX', 'num', 0],
  24807. [19, 'Subrs', 'offset', null]
  24808. ];
  24809. var tables = null;
  24810. function CFFPrivateDict(strings) {
  24811. if (tables === null) {
  24812. tables = CFFDict.createTables(layout);
  24813. }
  24814. CFFDict.call(this, tables, strings);
  24815. this.subrsIndex = null;
  24816. }
  24817. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24818. return CFFPrivateDict;
  24819. })();
  24820. var CFFCharsetPredefinedTypes = {
  24821. ISO_ADOBE: 0,
  24822. EXPERT: 1,
  24823. EXPERT_SUBSET: 2
  24824. };
  24825. var CFFCharset = (function CFFCharsetClosure() {
  24826. function CFFCharset(predefined, format, charset, raw) {
  24827. this.predefined = predefined;
  24828. this.format = format;
  24829. this.charset = charset;
  24830. this.raw = raw;
  24831. }
  24832. return CFFCharset;
  24833. })();
  24834. var CFFEncoding = (function CFFEncodingClosure() {
  24835. function CFFEncoding(predefined, format, encoding, raw) {
  24836. this.predefined = predefined;
  24837. this.format = format;
  24838. this.encoding = encoding;
  24839. this.raw = raw;
  24840. }
  24841. return CFFEncoding;
  24842. })();
  24843. var CFFFDSelect = (function CFFFDSelectClosure() {
  24844. function CFFFDSelect(fdSelect, raw) {
  24845. this.fdSelect = fdSelect;
  24846. this.raw = raw;
  24847. }
  24848. return CFFFDSelect;
  24849. })();
  24850. // Helper class to keep track of where an offset is within the data and helps
  24851. // filling in that offset once it's known.
  24852. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24853. function CFFOffsetTracker() {
  24854. this.offsets = {};
  24855. }
  24856. CFFOffsetTracker.prototype = {
  24857. isTracking: function CFFOffsetTracker_isTracking(key) {
  24858. return key in this.offsets;
  24859. },
  24860. track: function CFFOffsetTracker_track(key, location) {
  24861. if (key in this.offsets) {
  24862. error('Already tracking location of ' + key);
  24863. }
  24864. this.offsets[key] = location;
  24865. },
  24866. offset: function CFFOffsetTracker_offset(value) {
  24867. for (var key in this.offsets) {
  24868. this.offsets[key] += value;
  24869. }
  24870. },
  24871. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24872. values,
  24873. output) {
  24874. if (!(key in this.offsets)) {
  24875. error('Not tracking location of ' + key);
  24876. }
  24877. var data = output.data;
  24878. var dataOffset = this.offsets[key];
  24879. var size = 5;
  24880. for (var i = 0, ii = values.length; i < ii; ++i) {
  24881. var offset0 = i * size + dataOffset;
  24882. var offset1 = offset0 + 1;
  24883. var offset2 = offset0 + 2;
  24884. var offset3 = offset0 + 3;
  24885. var offset4 = offset0 + 4;
  24886. // It's easy to screw up offsets so perform this sanity check.
  24887. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24888. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24889. error('writing to an offset that is not empty');
  24890. }
  24891. var value = values[i];
  24892. data[offset0] = 0x1d;
  24893. data[offset1] = (value >> 24) & 0xFF;
  24894. data[offset2] = (value >> 16) & 0xFF;
  24895. data[offset3] = (value >> 8) & 0xFF;
  24896. data[offset4] = value & 0xFF;
  24897. }
  24898. }
  24899. };
  24900. return CFFOffsetTracker;
  24901. })();
  24902. // Takes a CFF and converts it to the binary representation.
  24903. var CFFCompiler = (function CFFCompilerClosure() {
  24904. function CFFCompiler(cff) {
  24905. this.cff = cff;
  24906. }
  24907. CFFCompiler.prototype = {
  24908. compile: function CFFCompiler_compile() {
  24909. var cff = this.cff;
  24910. var output = {
  24911. data: [],
  24912. length: 0,
  24913. add: function CFFCompiler_add(data) {
  24914. this.data = this.data.concat(data);
  24915. this.length = this.data.length;
  24916. }
  24917. };
  24918. // Compile the five entries that must be in order.
  24919. var header = this.compileHeader(cff.header);
  24920. output.add(header);
  24921. var nameIndex = this.compileNameIndex(cff.names);
  24922. output.add(nameIndex);
  24923. if (cff.isCIDFont) {
  24924. // The spec is unclear on how font matrices should relate to each other
  24925. // when there is one in the main top dict and the sub top dicts.
  24926. // Windows handles this differently than linux and osx so we have to
  24927. // normalize to work on all.
  24928. // Rules based off of some mailing list discussions:
  24929. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24930. // - If no main font matrix and there is a subfont matrix, use the
  24931. // subfont matrix.
  24932. // - If both have matrices, concat together.
  24933. // - If neither have matrices, use default.
  24934. // To make this work on all platforms we move the top matrix into each
  24935. // sub top dict and concat if necessary.
  24936. if (cff.topDict.hasName('FontMatrix')) {
  24937. var base = cff.topDict.getByName('FontMatrix');
  24938. cff.topDict.removeByName('FontMatrix');
  24939. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24940. var subDict = cff.fdArray[i];
  24941. var matrix = base.slice(0);
  24942. if (subDict.hasName('FontMatrix')) {
  24943. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24944. }
  24945. subDict.setByName('FontMatrix', matrix);
  24946. }
  24947. }
  24948. }
  24949. var compiled = this.compileTopDicts([cff.topDict],
  24950. output.length,
  24951. cff.isCIDFont);
  24952. output.add(compiled.output);
  24953. var topDictTracker = compiled.trackers[0];
  24954. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24955. output.add(stringIndex);
  24956. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24957. output.add(globalSubrIndex);
  24958. // Now start on the other entries that have no specfic order.
  24959. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24960. if (cff.encoding.predefined) {
  24961. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24962. output);
  24963. } else {
  24964. var encoding = this.compileEncoding(cff.encoding);
  24965. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24966. output.add(encoding);
  24967. }
  24968. }
  24969. if (cff.charset && cff.topDict.hasName('charset')) {
  24970. if (cff.charset.predefined) {
  24971. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24972. output);
  24973. } else {
  24974. var charset = this.compileCharset(cff.charset);
  24975. topDictTracker.setEntryLocation('charset', [output.length], output);
  24976. output.add(charset);
  24977. }
  24978. }
  24979. var charStrings = this.compileCharStrings(cff.charStrings);
  24980. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24981. output.add(charStrings);
  24982. if (cff.isCIDFont) {
  24983. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24984. // and linux don't seem to care.
  24985. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24986. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24987. output.add(fdSelect);
  24988. // It is unclear if the sub font dictionary can have CID related
  24989. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24990. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24991. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24992. output.add(compiled.output);
  24993. var fontDictTrackers = compiled.trackers;
  24994. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24995. }
  24996. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24997. // If the font data ends with INDEX whose object data is zero-length,
  24998. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24999. output.add([0]);
  25000. return output.data;
  25001. },
  25002. encodeNumber: function CFFCompiler_encodeNumber(value) {
  25003. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  25004. return this.encodeInteger(value);
  25005. } else {
  25006. return this.encodeFloat(value);
  25007. }
  25008. },
  25009. encodeFloat: function CFFCompiler_encodeFloat(num) {
  25010. var value = num.toString();
  25011. // rounding inaccurate doubles
  25012. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  25013. if (m) {
  25014. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  25015. value = (Math.round(num * epsilon) / epsilon).toString();
  25016. }
  25017. var nibbles = '';
  25018. var i, ii;
  25019. for (i = 0, ii = value.length; i < ii; ++i) {
  25020. var a = value[i];
  25021. if (a === 'e') {
  25022. nibbles += value[++i] === '-' ? 'c' : 'b';
  25023. } else if (a === '.') {
  25024. nibbles += 'a';
  25025. } else if (a === '-') {
  25026. nibbles += 'e';
  25027. } else {
  25028. nibbles += a;
  25029. }
  25030. }
  25031. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25032. var out = [30];
  25033. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25034. out.push(parseInt(nibbles.substr(i, 2), 16));
  25035. }
  25036. return out;
  25037. },
  25038. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25039. var code;
  25040. if (value >= -107 && value <= 107) {
  25041. code = [value + 139];
  25042. } else if (value >= 108 && value <= 1131) {
  25043. value = [value - 108];
  25044. code = [(value >> 8) + 247, value & 0xFF];
  25045. } else if (value >= -1131 && value <= -108) {
  25046. value = -value - 108;
  25047. code = [(value >> 8) + 251, value & 0xFF];
  25048. } else if (value >= -32768 && value <= 32767) {
  25049. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25050. } else {
  25051. code = [0x1d,
  25052. (value >> 24) & 0xFF,
  25053. (value >> 16) & 0xFF,
  25054. (value >> 8) & 0xFF,
  25055. value & 0xFF];
  25056. }
  25057. return code;
  25058. },
  25059. compileHeader: function CFFCompiler_compileHeader(header) {
  25060. return [
  25061. header.major,
  25062. header.minor,
  25063. header.hdrSize,
  25064. header.offSize
  25065. ];
  25066. },
  25067. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25068. var nameIndex = new CFFIndex();
  25069. for (var i = 0, ii = names.length; i < ii; ++i) {
  25070. nameIndex.add(stringToBytes(names[i]));
  25071. }
  25072. return this.compileIndex(nameIndex);
  25073. },
  25074. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25075. length,
  25076. removeCidKeys) {
  25077. var fontDictTrackers = [];
  25078. var fdArrayIndex = new CFFIndex();
  25079. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25080. var fontDict = dicts[i];
  25081. if (removeCidKeys) {
  25082. fontDict.removeByName('CIDFontVersion');
  25083. fontDict.removeByName('CIDFontRevision');
  25084. fontDict.removeByName('CIDFontType');
  25085. fontDict.removeByName('CIDCount');
  25086. fontDict.removeByName('UIDBase');
  25087. }
  25088. var fontDictTracker = new CFFOffsetTracker();
  25089. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25090. fontDictTrackers.push(fontDictTracker);
  25091. fdArrayIndex.add(fontDictData);
  25092. fontDictTracker.offset(length);
  25093. }
  25094. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25095. return {
  25096. trackers: fontDictTrackers,
  25097. output: fdArrayIndex
  25098. };
  25099. },
  25100. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25101. trackers,
  25102. output) {
  25103. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25104. var fontDict = dicts[i];
  25105. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25106. 'There must be an private dictionary.');
  25107. var privateDict = fontDict.privateDict;
  25108. var privateDictTracker = new CFFOffsetTracker();
  25109. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25110. var outputLength = output.length;
  25111. privateDictTracker.offset(outputLength);
  25112. if (!privateDictData.length) {
  25113. // The private dictionary was empty, set the output length to zero to
  25114. // ensure the offset length isn't out of bounds in the eyes of the
  25115. // sanitizer.
  25116. outputLength = 0;
  25117. }
  25118. trackers[i].setEntryLocation('Private',
  25119. [privateDictData.length, outputLength],
  25120. output);
  25121. output.add(privateDictData);
  25122. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25123. var subrs = this.compileIndex(privateDict.subrsIndex);
  25124. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25125. output);
  25126. output.add(subrs);
  25127. }
  25128. }
  25129. },
  25130. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25131. var out = [];
  25132. // The dictionary keys must be in a certain order.
  25133. var order = dict.order;
  25134. for (var i = 0; i < order.length; ++i) {
  25135. var key = order[i];
  25136. if (!(key in dict.values)) {
  25137. continue;
  25138. }
  25139. var values = dict.values[key];
  25140. var types = dict.types[key];
  25141. if (!isArray(types)) {
  25142. types = [types];
  25143. }
  25144. if (!isArray(values)) {
  25145. values = [values];
  25146. }
  25147. // Remove any empty dict values.
  25148. if (values.length === 0) {
  25149. continue;
  25150. }
  25151. for (var j = 0, jj = types.length; j < jj; ++j) {
  25152. var type = types[j];
  25153. var value = values[j];
  25154. switch (type) {
  25155. case 'num':
  25156. case 'sid':
  25157. out = out.concat(this.encodeNumber(value));
  25158. break;
  25159. case 'offset':
  25160. // For offsets we just insert a 32bit integer so we don't have to
  25161. // deal with figuring out the length of the offset when it gets
  25162. // replaced later on by the compiler.
  25163. var name = dict.keyToNameMap[key];
  25164. // Some offsets have the offset and the length, so just record the
  25165. // position of the first one.
  25166. if (!offsetTracker.isTracking(name)) {
  25167. offsetTracker.track(name, out.length);
  25168. }
  25169. out = out.concat([0x1d, 0, 0, 0, 0]);
  25170. break;
  25171. case 'array':
  25172. case 'delta':
  25173. out = out.concat(this.encodeNumber(value));
  25174. for (var k = 1, kk = values.length; k < kk; ++k) {
  25175. out = out.concat(this.encodeNumber(values[k]));
  25176. }
  25177. break;
  25178. default:
  25179. error('Unknown data type of ' + type);
  25180. break;
  25181. }
  25182. }
  25183. out = out.concat(dict.opcodes[key]);
  25184. }
  25185. return out;
  25186. },
  25187. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25188. var stringIndex = new CFFIndex();
  25189. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25190. stringIndex.add(stringToBytes(strings[i]));
  25191. }
  25192. return this.compileIndex(stringIndex);
  25193. },
  25194. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25195. var globalSubrIndex = this.cff.globalSubrIndex;
  25196. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25197. },
  25198. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25199. return this.compileIndex(charStrings);
  25200. },
  25201. compileCharset: function CFFCompiler_compileCharset(charset) {
  25202. return this.compileTypedArray(charset.raw);
  25203. },
  25204. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25205. return this.compileTypedArray(encoding.raw);
  25206. },
  25207. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25208. return this.compileTypedArray(fdSelect);
  25209. },
  25210. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25211. var out = [];
  25212. for (var i = 0, ii = data.length; i < ii; ++i) {
  25213. out[i] = data[i];
  25214. }
  25215. return out;
  25216. },
  25217. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25218. trackers = trackers || [];
  25219. var objects = index.objects;
  25220. // First 2 bytes contains the number of objects contained into this index
  25221. var count = objects.length;
  25222. // If there is no object, just create an index. This technically
  25223. // should just be [0, 0] but OTS has an issue with that.
  25224. if (count === 0) {
  25225. return [0, 0, 0];
  25226. }
  25227. var data = [(count >> 8) & 0xFF, count & 0xff];
  25228. var lastOffset = 1, i;
  25229. for (i = 0; i < count; ++i) {
  25230. lastOffset += objects[i].length;
  25231. }
  25232. var offsetSize;
  25233. if (lastOffset < 0x100) {
  25234. offsetSize = 1;
  25235. } else if (lastOffset < 0x10000) {
  25236. offsetSize = 2;
  25237. } else if (lastOffset < 0x1000000) {
  25238. offsetSize = 3;
  25239. } else {
  25240. offsetSize = 4;
  25241. }
  25242. // Next byte contains the offset size use to reference object in the file
  25243. data.push(offsetSize);
  25244. // Add another offset after this one because we need a new offset
  25245. var relativeOffset = 1;
  25246. for (i = 0; i < count + 1; i++) {
  25247. if (offsetSize === 1) {
  25248. data.push(relativeOffset & 0xFF);
  25249. } else if (offsetSize === 2) {
  25250. data.push((relativeOffset >> 8) & 0xFF,
  25251. relativeOffset & 0xFF);
  25252. } else if (offsetSize === 3) {
  25253. data.push((relativeOffset >> 16) & 0xFF,
  25254. (relativeOffset >> 8) & 0xFF,
  25255. relativeOffset & 0xFF);
  25256. } else {
  25257. data.push((relativeOffset >>> 24) & 0xFF,
  25258. (relativeOffset >> 16) & 0xFF,
  25259. (relativeOffset >> 8) & 0xFF,
  25260. relativeOffset & 0xFF);
  25261. }
  25262. if (objects[i]) {
  25263. relativeOffset += objects[i].length;
  25264. }
  25265. }
  25266. for (i = 0; i < count; i++) {
  25267. // Notify the tracker where the object will be offset in the data.
  25268. if (trackers[i]) {
  25269. trackers[i].offset(data.length);
  25270. }
  25271. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25272. data.push(objects[i][j]);
  25273. }
  25274. }
  25275. return data;
  25276. }
  25277. };
  25278. return CFFCompiler;
  25279. })();
  25280. // Workaround for seac on Windows.
  25281. (function checkSeacSupport() {
  25282. if (/Windows/.test(navigator.userAgent)) {
  25283. SEAC_ANALYSIS_ENABLED = true;
  25284. }
  25285. })();
  25286. // Workaround for Private Use Area characters in Chrome on Windows
  25287. // http://code.google.com/p/chromium/issues/detail?id=122465
  25288. // https://github.com/mozilla/pdf.js/issues/1689
  25289. (function checkChromeWindows() {
  25290. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25291. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25292. }
  25293. })();
  25294. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25295. function getLong(data, offset) {
  25296. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25297. (data[offset + 2] << 8) | data[offset + 3];
  25298. }
  25299. function getUshort(data, offset) {
  25300. return (data[offset] << 8) | data[offset + 1];
  25301. }
  25302. function parseCmap(data, start, end) {
  25303. var offset = (getUshort(data, start + 2) === 1 ?
  25304. getLong(data, start + 8) : getLong(data, start + 16));
  25305. var format = getUshort(data, start + offset);
  25306. var length, ranges, p, i;
  25307. if (format === 4) {
  25308. length = getUshort(data, start + offset + 2);
  25309. var segCount = getUshort(data, start + offset + 6) >> 1;
  25310. p = start + offset + 14;
  25311. ranges = [];
  25312. for (i = 0; i < segCount; i++, p += 2) {
  25313. ranges[i] = {end: getUshort(data, p)};
  25314. }
  25315. p += 2;
  25316. for (i = 0; i < segCount; i++, p += 2) {
  25317. ranges[i].start = getUshort(data, p);
  25318. }
  25319. for (i = 0; i < segCount; i++, p += 2) {
  25320. ranges[i].idDelta = getUshort(data, p);
  25321. }
  25322. for (i = 0; i < segCount; i++, p += 2) {
  25323. var idOffset = getUshort(data, p);
  25324. if (idOffset === 0) {
  25325. continue;
  25326. }
  25327. ranges[i].ids = [];
  25328. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25329. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25330. idOffset += 2;
  25331. }
  25332. }
  25333. return ranges;
  25334. } else if (format === 12) {
  25335. length = getLong(data, start + offset + 4);
  25336. var groups = getLong(data, start + offset + 12);
  25337. p = start + offset + 16;
  25338. ranges = [];
  25339. for (i = 0; i < groups; i++) {
  25340. ranges.push({
  25341. start: getLong(data, p),
  25342. end: getLong(data, p + 4),
  25343. idDelta: getLong(data, p + 8) - getLong(data, p)
  25344. });
  25345. p += 12;
  25346. }
  25347. return ranges;
  25348. }
  25349. error('not supported cmap: ' + format);
  25350. }
  25351. function parseCff(data, start, end) {
  25352. var properties = {};
  25353. var parser = new CFFParser(new Stream(data, start, end - start),
  25354. properties);
  25355. var cff = parser.parse();
  25356. return {
  25357. glyphs: cff.charStrings.objects,
  25358. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25359. cff.topDict.privateDict.subrsIndex.objects),
  25360. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25361. };
  25362. }
  25363. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25364. var itemSize, itemDecode;
  25365. if (isGlyphLocationsLong) {
  25366. itemSize = 4;
  25367. itemDecode = function fontItemDecodeLong(data, offset) {
  25368. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25369. (data[offset + 2] << 8) | data[offset + 3];
  25370. };
  25371. } else {
  25372. itemSize = 2;
  25373. itemDecode = function fontItemDecode(data, offset) {
  25374. return (data[offset] << 9) | (data[offset + 1] << 1);
  25375. };
  25376. }
  25377. var glyphs = [];
  25378. var startOffset = itemDecode(loca, 0);
  25379. for (var j = itemSize; j < loca.length; j += itemSize) {
  25380. var endOffset = itemDecode(loca, j);
  25381. glyphs.push(glyf.subarray(startOffset, endOffset));
  25382. startOffset = endOffset;
  25383. }
  25384. return glyphs;
  25385. }
  25386. function lookupCmap(ranges, unicode) {
  25387. var code = unicode.charCodeAt(0);
  25388. var l = 0, r = ranges.length - 1;
  25389. while (l < r) {
  25390. var c = (l + r + 1) >> 1;
  25391. if (code < ranges[c].start) {
  25392. r = c - 1;
  25393. } else {
  25394. l = c;
  25395. }
  25396. }
  25397. if (ranges[l].start <= code && code <= ranges[l].end) {
  25398. return (ranges[l].idDelta + (ranges[l].ids ?
  25399. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25400. }
  25401. return 0;
  25402. }
  25403. function compileGlyf(code, js, font) {
  25404. function moveTo(x, y) {
  25405. js.push('c.moveTo(' + x + ',' + y + ');');
  25406. }
  25407. function lineTo(x, y) {
  25408. js.push('c.lineTo(' + x + ',' + y + ');');
  25409. }
  25410. function quadraticCurveTo(xa, ya, x, y) {
  25411. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25412. x + ',' + y + ');');
  25413. }
  25414. var i = 0;
  25415. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25416. var flags;
  25417. var x = 0, y = 0;
  25418. i += 10;
  25419. if (numberOfContours < 0) {
  25420. // composite glyph
  25421. do {
  25422. flags = (code[i] << 8) | code[i + 1];
  25423. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25424. i += 4;
  25425. var arg1, arg2;
  25426. if ((flags & 0x01)) {
  25427. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25428. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25429. i += 4;
  25430. } else {
  25431. arg1 = code[i++]; arg2 = code[i++];
  25432. }
  25433. if ((flags & 0x02)) {
  25434. x = arg1;
  25435. y = arg2;
  25436. } else {
  25437. x = 0; y = 0; // TODO "they are points" ?
  25438. }
  25439. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25440. if ((flags & 0x08)) {
  25441. scaleX =
  25442. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25443. i += 2;
  25444. } else if ((flags & 0x40)) {
  25445. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25446. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25447. i += 4;
  25448. } else if ((flags & 0x80)) {
  25449. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25450. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25451. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25452. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25453. i += 8;
  25454. }
  25455. var subglyph = font.glyphs[glyphIndex];
  25456. if (subglyph) {
  25457. js.push('c.save();');
  25458. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25459. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25460. compileGlyf(subglyph, js, font);
  25461. js.push('c.restore();');
  25462. }
  25463. } while ((flags & 0x20));
  25464. } else {
  25465. // simple glyph
  25466. var endPtsOfContours = [];
  25467. var j, jj;
  25468. for (j = 0; j < numberOfContours; j++) {
  25469. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25470. i += 2;
  25471. }
  25472. var instructionLength = (code[i] << 8) | code[i + 1];
  25473. i += 2 + instructionLength; // skipping the instructions
  25474. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25475. var points = [];
  25476. while (points.length < numberOfPoints) {
  25477. flags = code[i++];
  25478. var repeat = 1;
  25479. if ((flags & 0x08)) {
  25480. repeat += code[i++];
  25481. }
  25482. while (repeat-- > 0) {
  25483. points.push({flags: flags});
  25484. }
  25485. }
  25486. for (j = 0; j < numberOfPoints; j++) {
  25487. switch (points[j].flags & 0x12) {
  25488. case 0x00:
  25489. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25490. i += 2;
  25491. break;
  25492. case 0x02:
  25493. x -= code[i++];
  25494. break;
  25495. case 0x12:
  25496. x += code[i++];
  25497. break;
  25498. }
  25499. points[j].x = x;
  25500. }
  25501. for (j = 0; j < numberOfPoints; j++) {
  25502. switch (points[j].flags & 0x24) {
  25503. case 0x00:
  25504. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25505. i += 2;
  25506. break;
  25507. case 0x04:
  25508. y -= code[i++];
  25509. break;
  25510. case 0x24:
  25511. y += code[i++];
  25512. break;
  25513. }
  25514. points[j].y = y;
  25515. }
  25516. var startPoint = 0;
  25517. for (i = 0; i < numberOfContours; i++) {
  25518. var endPoint = endPtsOfContours[i];
  25519. // contours might have implicit points, which is located in the middle
  25520. // between two neighboring off-curve points
  25521. var contour = points.slice(startPoint, endPoint + 1);
  25522. if ((contour[0].flags & 1)) {
  25523. contour.push(contour[0]); // using start point at the contour end
  25524. } else if ((contour[contour.length - 1].flags & 1)) {
  25525. // first is off-curve point, trying to use one from the end
  25526. contour.unshift(contour[contour.length - 1]);
  25527. } else {
  25528. // start and end are off-curve points, creating implicit one
  25529. var p = {
  25530. flags: 1,
  25531. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25532. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25533. };
  25534. contour.unshift(p);
  25535. contour.push(p);
  25536. }
  25537. moveTo(contour[0].x, contour[0].y);
  25538. for (j = 1, jj = contour.length; j < jj; j++) {
  25539. if ((contour[j].flags & 1)) {
  25540. lineTo(contour[j].x, contour[j].y);
  25541. } else if ((contour[j + 1].flags & 1)){
  25542. quadraticCurveTo(contour[j].x, contour[j].y,
  25543. contour[j + 1].x, contour[j + 1].y);
  25544. j++;
  25545. } else {
  25546. quadraticCurveTo(contour[j].x, contour[j].y,
  25547. (contour[j].x + contour[j + 1].x) / 2,
  25548. (contour[j].y + contour[j + 1].y) / 2);
  25549. }
  25550. }
  25551. startPoint = endPoint + 1;
  25552. }
  25553. }
  25554. }
  25555. function compileCharString(code, js, font) {
  25556. var stack = [];
  25557. var x = 0, y = 0;
  25558. var stems = 0;
  25559. function moveTo(x, y) {
  25560. js.push('c.moveTo(' + x + ',' + y + ');');
  25561. }
  25562. function lineTo(x, y) {
  25563. js.push('c.lineTo(' + x + ',' + y + ');');
  25564. }
  25565. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25566. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25567. x + ',' + y + ');');
  25568. }
  25569. function parse(code) {
  25570. var i = 0;
  25571. while (i < code.length) {
  25572. var stackClean = false;
  25573. var v = code[i++];
  25574. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25575. switch (v) {
  25576. case 1: // hstem
  25577. stems += stack.length >> 1;
  25578. stackClean = true;
  25579. break;
  25580. case 3: // vstem
  25581. stems += stack.length >> 1;
  25582. stackClean = true;
  25583. break;
  25584. case 4: // vmoveto
  25585. y += stack.pop();
  25586. moveTo(x, y);
  25587. stackClean = true;
  25588. break;
  25589. case 5: // rlineto
  25590. while (stack.length > 0) {
  25591. x += stack.shift();
  25592. y += stack.shift();
  25593. lineTo(x, y);
  25594. }
  25595. break;
  25596. case 6: // hlineto
  25597. while (stack.length > 0) {
  25598. x += stack.shift();
  25599. lineTo(x, y);
  25600. if (stack.length === 0) {
  25601. break;
  25602. }
  25603. y += stack.shift();
  25604. lineTo(x, y);
  25605. }
  25606. break;
  25607. case 7: // vlineto
  25608. while (stack.length > 0) {
  25609. y += stack.shift();
  25610. lineTo(x, y);
  25611. if (stack.length === 0) {
  25612. break;
  25613. }
  25614. x += stack.shift();
  25615. lineTo(x, y);
  25616. }
  25617. break;
  25618. case 8: // rrcurveto
  25619. while (stack.length > 0) {
  25620. xa = x + stack.shift(); ya = y + stack.shift();
  25621. xb = xa + stack.shift(); yb = ya + stack.shift();
  25622. x = xb + stack.shift(); y = yb + stack.shift();
  25623. bezierCurveTo(xa, ya, xb, yb, x, y);
  25624. }
  25625. break;
  25626. case 10: // callsubr
  25627. n = stack.pop() + font.subrsBias;
  25628. subrCode = font.subrs[n];
  25629. if (subrCode) {
  25630. parse(subrCode);
  25631. }
  25632. break;
  25633. case 11: // return
  25634. return;
  25635. case 12:
  25636. v = code[i++];
  25637. switch (v) {
  25638. case 34: // flex
  25639. xa = x + stack.shift();
  25640. xb = xa + stack.shift(); y1 = y + stack.shift();
  25641. x = xb + stack.shift();
  25642. bezierCurveTo(xa, y, xb, y1, x, y1);
  25643. xa = x + stack.shift();
  25644. xb = xa + stack.shift();
  25645. x = xb + stack.shift();
  25646. bezierCurveTo(xa, y1, xb, y, x, y);
  25647. break;
  25648. case 35: // flex
  25649. xa = x + stack.shift(); ya = y + stack.shift();
  25650. xb = xa + stack.shift(); yb = ya + stack.shift();
  25651. x = xb + stack.shift(); y = yb + stack.shift();
  25652. bezierCurveTo(xa, ya, xb, yb, x, y);
  25653. xa = x + stack.shift(); ya = y + stack.shift();
  25654. xb = xa + stack.shift(); yb = ya + stack.shift();
  25655. x = xb + stack.shift(); y = yb + stack.shift();
  25656. bezierCurveTo(xa, ya, xb, yb, x, y);
  25657. stack.pop(); // fd
  25658. break;
  25659. case 36: // hflex1
  25660. xa = x + stack.shift(); y1 = y + stack.shift();
  25661. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25662. x = xb + stack.shift();
  25663. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25664. xa = x + stack.shift();
  25665. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25666. x = xb + stack.shift();
  25667. bezierCurveTo(xa, y2, xb, y3, x, y);
  25668. break;
  25669. case 37: // flex1
  25670. var x0 = x, y0 = y;
  25671. xa = x + stack.shift(); ya = y + stack.shift();
  25672. xb = xa + stack.shift(); yb = ya + stack.shift();
  25673. x = xb + stack.shift(); y = yb + stack.shift();
  25674. bezierCurveTo(xa, ya, xb, yb, x, y);
  25675. xa = x + stack.shift(); ya = y + stack.shift();
  25676. xb = xa + stack.shift(); yb = ya + stack.shift();
  25677. x = xb; y = yb;
  25678. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25679. x += stack.shift();
  25680. } else {
  25681. y += stack.shift();
  25682. }
  25683. bezierCurveTo(xa, ya, xb, yb, x, y);
  25684. break;
  25685. default:
  25686. error('unknown operator: 12 ' + v);
  25687. }
  25688. break;
  25689. case 14: // endchar
  25690. if (stack.length >= 4) {
  25691. var achar = stack.pop();
  25692. var bchar = stack.pop();
  25693. y = stack.pop();
  25694. x = stack.pop();
  25695. js.push('c.save();');
  25696. js.push('c.translate('+ x + ',' + y + ');');
  25697. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25698. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25699. compileCharString(font.glyphs[gid], js, font);
  25700. js.push('c.restore();');
  25701. gid = lookupCmap(font.cmap, String.fromCharCode(
  25702. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25703. compileCharString(font.glyphs[gid], js, font);
  25704. }
  25705. return;
  25706. case 18: // hstemhm
  25707. stems += stack.length >> 1;
  25708. stackClean = true;
  25709. break;
  25710. case 19: // hintmask
  25711. stems += stack.length >> 1;
  25712. i += (stems + 7) >> 3;
  25713. stackClean = true;
  25714. break;
  25715. case 20: // cntrmask
  25716. stems += stack.length >> 1;
  25717. i += (stems + 7) >> 3;
  25718. stackClean = true;
  25719. break;
  25720. case 21: // rmoveto
  25721. y += stack.pop();
  25722. x += stack.pop();
  25723. moveTo(x, y);
  25724. stackClean = true;
  25725. break;
  25726. case 22: // hmoveto
  25727. x += stack.pop();
  25728. moveTo(x, y);
  25729. stackClean = true;
  25730. break;
  25731. case 23: // vstemhm
  25732. stems += stack.length >> 1;
  25733. stackClean = true;
  25734. break;
  25735. case 24: // rcurveline
  25736. while (stack.length > 2) {
  25737. xa = x + stack.shift(); ya = y + stack.shift();
  25738. xb = xa + stack.shift(); yb = ya + stack.shift();
  25739. x = xb + stack.shift(); y = yb + stack.shift();
  25740. bezierCurveTo(xa, ya, xb, yb, x, y);
  25741. }
  25742. x += stack.shift();
  25743. y += stack.shift();
  25744. lineTo(x, y);
  25745. break;
  25746. case 25: // rlinecurve
  25747. while (stack.length > 6) {
  25748. x += stack.shift();
  25749. y += stack.shift();
  25750. lineTo(x, y);
  25751. }
  25752. xa = x + stack.shift(); ya = y + stack.shift();
  25753. xb = xa + stack.shift(); yb = ya + stack.shift();
  25754. x = xb + stack.shift(); y = yb + stack.shift();
  25755. bezierCurveTo(xa, ya, xb, yb, x, y);
  25756. break;
  25757. case 26: // vvcurveto
  25758. if (stack.length % 2) {
  25759. x += stack.shift();
  25760. }
  25761. while (stack.length > 0) {
  25762. xa = x; ya = y + stack.shift();
  25763. xb = xa + stack.shift(); yb = ya + stack.shift();
  25764. x = xb; y = yb + stack.shift();
  25765. bezierCurveTo(xa, ya, xb, yb, x, y);
  25766. }
  25767. break;
  25768. case 27: // hhcurveto
  25769. if (stack.length % 2) {
  25770. y += stack.shift();
  25771. }
  25772. while (stack.length > 0) {
  25773. xa = x + stack.shift(); ya = y;
  25774. xb = xa + stack.shift(); yb = ya + stack.shift();
  25775. x = xb + stack.shift(); y = yb;
  25776. bezierCurveTo(xa, ya, xb, yb, x, y);
  25777. }
  25778. break;
  25779. case 28:
  25780. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25781. i += 2;
  25782. break;
  25783. case 29: // callgsubr
  25784. n = stack.pop() + font.gsubrsBias;
  25785. subrCode = font.gsubrs[n];
  25786. if (subrCode) {
  25787. parse(subrCode);
  25788. }
  25789. break;
  25790. case 30: // vhcurveto
  25791. while (stack.length > 0) {
  25792. xa = x; ya = y + stack.shift();
  25793. xb = xa + stack.shift(); yb = ya + stack.shift();
  25794. x = xb + stack.shift();
  25795. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25796. bezierCurveTo(xa, ya, xb, yb, x, y);
  25797. if (stack.length === 0) {
  25798. break;
  25799. }
  25800. xa = x + stack.shift(); ya = y;
  25801. xb = xa + stack.shift(); yb = ya + stack.shift();
  25802. y = yb + stack.shift();
  25803. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25804. bezierCurveTo(xa, ya, xb, yb, x, y);
  25805. }
  25806. break;
  25807. case 31: // hvcurveto
  25808. while (stack.length > 0) {
  25809. xa = x + stack.shift(); ya = y;
  25810. xb = xa + stack.shift(); yb = ya + stack.shift();
  25811. y = yb + stack.shift();
  25812. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25813. bezierCurveTo(xa, ya, xb, yb, x, y);
  25814. if (stack.length === 0) {
  25815. break;
  25816. }
  25817. xa = x; ya = y + stack.shift();
  25818. xb = xa + stack.shift(); yb = ya + stack.shift();
  25819. x = xb + stack.shift();
  25820. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25821. bezierCurveTo(xa, ya, xb, yb, x, y);
  25822. }
  25823. break;
  25824. default:
  25825. if (v < 32) {
  25826. error('unknown operator: ' + v);
  25827. }
  25828. if (v < 247) {
  25829. stack.push(v - 139);
  25830. } else if (v < 251) {
  25831. stack.push((v - 247) * 256 + code[i++] + 108);
  25832. } else if (v < 255) {
  25833. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25834. } else {
  25835. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25836. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25837. i += 4;
  25838. }
  25839. break;
  25840. }
  25841. if (stackClean) {
  25842. stack.length = 0;
  25843. }
  25844. }
  25845. }
  25846. parse(code);
  25847. }
  25848. var noop = '';
  25849. function CompiledFont(fontMatrix) {
  25850. this.compiledGlyphs = {};
  25851. this.fontMatrix = fontMatrix;
  25852. }
  25853. CompiledFont.prototype = {
  25854. getPathJs: function (unicode) {
  25855. var gid = lookupCmap(this.cmap, unicode);
  25856. var fn = this.compiledGlyphs[gid];
  25857. if (!fn) {
  25858. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25859. }
  25860. return fn;
  25861. },
  25862. compileGlyph: function (code) {
  25863. if (!code || code.length === 0 || code[0] === 14) {
  25864. return noop;
  25865. }
  25866. var js = [];
  25867. js.push('c.save();');
  25868. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25869. js.push('c.scale(size, -size);');
  25870. this.compileGlyphImpl(code, js);
  25871. js.push('c.restore();');
  25872. return js.join('\n');
  25873. },
  25874. compileGlyphImpl: function () {
  25875. error('Children classes should implement this.');
  25876. },
  25877. hasBuiltPath: function (unicode) {
  25878. var gid = lookupCmap(this.cmap, unicode);
  25879. return gid in this.compiledGlyphs;
  25880. }
  25881. };
  25882. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25883. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25884. CompiledFont.call(this, fontMatrix);
  25885. this.glyphs = glyphs;
  25886. this.cmap = cmap;
  25887. this.compiledGlyphs = [];
  25888. }
  25889. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25890. compileGlyphImpl: function (code, js) {
  25891. compileGlyf(code, js, this);
  25892. }
  25893. });
  25894. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25895. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25896. CompiledFont.call(this, fontMatrix);
  25897. this.glyphs = cffInfo.glyphs;
  25898. this.gsubrs = cffInfo.gsubrs || [];
  25899. this.subrs = cffInfo.subrs || [];
  25900. this.cmap = cmap;
  25901. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25902. this.compiledGlyphs = [];
  25903. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25904. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25905. this.subrsBias = (this.subrs.length < 1240 ?
  25906. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25907. }
  25908. Util.inherit(Type2Compiled, CompiledFont, {
  25909. compileGlyphImpl: function (code, js) {
  25910. compileCharString(code, js, this);
  25911. }
  25912. });
  25913. return {
  25914. create: function FontRendererFactory_create(font) {
  25915. var data = new Uint8Array(font.data);
  25916. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25917. var numTables = getUshort(data, 4);
  25918. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25919. var tag = bytesToString(data.subarray(p, p + 4));
  25920. var offset = getLong(data, p + 8);
  25921. var length = getLong(data, p + 12);
  25922. switch (tag) {
  25923. case 'cmap':
  25924. cmap = parseCmap(data, offset, offset + length);
  25925. break;
  25926. case 'glyf':
  25927. glyf = data.subarray(offset, offset + length);
  25928. break;
  25929. case 'loca':
  25930. loca = data.subarray(offset, offset + length);
  25931. break;
  25932. case 'head':
  25933. unitsPerEm = getUshort(data, offset + 18);
  25934. indexToLocFormat = getUshort(data, offset + 50);
  25935. break;
  25936. case 'CFF ':
  25937. cff = parseCff(data, offset, offset + length);
  25938. break;
  25939. }
  25940. }
  25941. if (glyf) {
  25942. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25943. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25944. return new TrueTypeCompiled(
  25945. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25946. } else {
  25947. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25948. }
  25949. }
  25950. };
  25951. })();
  25952. var GlyphsUnicode = {
  25953. A: 0x0041,
  25954. AE: 0x00C6,
  25955. AEacute: 0x01FC,
  25956. AEmacron: 0x01E2,
  25957. AEsmall: 0xF7E6,
  25958. Aacute: 0x00C1,
  25959. Aacutesmall: 0xF7E1,
  25960. Abreve: 0x0102,
  25961. Abreveacute: 0x1EAE,
  25962. Abrevecyrillic: 0x04D0,
  25963. Abrevedotbelow: 0x1EB6,
  25964. Abrevegrave: 0x1EB0,
  25965. Abrevehookabove: 0x1EB2,
  25966. Abrevetilde: 0x1EB4,
  25967. Acaron: 0x01CD,
  25968. Acircle: 0x24B6,
  25969. Acircumflex: 0x00C2,
  25970. Acircumflexacute: 0x1EA4,
  25971. Acircumflexdotbelow: 0x1EAC,
  25972. Acircumflexgrave: 0x1EA6,
  25973. Acircumflexhookabove: 0x1EA8,
  25974. Acircumflexsmall: 0xF7E2,
  25975. Acircumflextilde: 0x1EAA,
  25976. Acute: 0xF6C9,
  25977. Acutesmall: 0xF7B4,
  25978. Acyrillic: 0x0410,
  25979. Adblgrave: 0x0200,
  25980. Adieresis: 0x00C4,
  25981. Adieresiscyrillic: 0x04D2,
  25982. Adieresismacron: 0x01DE,
  25983. Adieresissmall: 0xF7E4,
  25984. Adotbelow: 0x1EA0,
  25985. Adotmacron: 0x01E0,
  25986. Agrave: 0x00C0,
  25987. Agravesmall: 0xF7E0,
  25988. Ahookabove: 0x1EA2,
  25989. Aiecyrillic: 0x04D4,
  25990. Ainvertedbreve: 0x0202,
  25991. Alpha: 0x0391,
  25992. Alphatonos: 0x0386,
  25993. Amacron: 0x0100,
  25994. Amonospace: 0xFF21,
  25995. Aogonek: 0x0104,
  25996. Aring: 0x00C5,
  25997. Aringacute: 0x01FA,
  25998. Aringbelow: 0x1E00,
  25999. Aringsmall: 0xF7E5,
  26000. Asmall: 0xF761,
  26001. Atilde: 0x00C3,
  26002. Atildesmall: 0xF7E3,
  26003. Aybarmenian: 0x0531,
  26004. B: 0x0042,
  26005. Bcircle: 0x24B7,
  26006. Bdotaccent: 0x1E02,
  26007. Bdotbelow: 0x1E04,
  26008. Becyrillic: 0x0411,
  26009. Benarmenian: 0x0532,
  26010. Beta: 0x0392,
  26011. Bhook: 0x0181,
  26012. Blinebelow: 0x1E06,
  26013. Bmonospace: 0xFF22,
  26014. Brevesmall: 0xF6F4,
  26015. Bsmall: 0xF762,
  26016. Btopbar: 0x0182,
  26017. C: 0x0043,
  26018. Caarmenian: 0x053E,
  26019. Cacute: 0x0106,
  26020. Caron: 0xF6CA,
  26021. Caronsmall: 0xF6F5,
  26022. Ccaron: 0x010C,
  26023. Ccedilla: 0x00C7,
  26024. Ccedillaacute: 0x1E08,
  26025. Ccedillasmall: 0xF7E7,
  26026. Ccircle: 0x24B8,
  26027. Ccircumflex: 0x0108,
  26028. Cdot: 0x010A,
  26029. Cdotaccent: 0x010A,
  26030. Cedillasmall: 0xF7B8,
  26031. Chaarmenian: 0x0549,
  26032. Cheabkhasiancyrillic: 0x04BC,
  26033. Checyrillic: 0x0427,
  26034. Chedescenderabkhasiancyrillic: 0x04BE,
  26035. Chedescendercyrillic: 0x04B6,
  26036. Chedieresiscyrillic: 0x04F4,
  26037. Cheharmenian: 0x0543,
  26038. Chekhakassiancyrillic: 0x04CB,
  26039. Cheverticalstrokecyrillic: 0x04B8,
  26040. Chi: 0x03A7,
  26041. Chook: 0x0187,
  26042. Circumflexsmall: 0xF6F6,
  26043. Cmonospace: 0xFF23,
  26044. Coarmenian: 0x0551,
  26045. Csmall: 0xF763,
  26046. D: 0x0044,
  26047. DZ: 0x01F1,
  26048. DZcaron: 0x01C4,
  26049. Daarmenian: 0x0534,
  26050. Dafrican: 0x0189,
  26051. Dcaron: 0x010E,
  26052. Dcedilla: 0x1E10,
  26053. Dcircle: 0x24B9,
  26054. Dcircumflexbelow: 0x1E12,
  26055. Dcroat: 0x0110,
  26056. Ddotaccent: 0x1E0A,
  26057. Ddotbelow: 0x1E0C,
  26058. Decyrillic: 0x0414,
  26059. Deicoptic: 0x03EE,
  26060. Delta: 0x2206,
  26061. Deltagreek: 0x0394,
  26062. Dhook: 0x018A,
  26063. Dieresis: 0xF6CB,
  26064. DieresisAcute: 0xF6CC,
  26065. DieresisGrave: 0xF6CD,
  26066. Dieresissmall: 0xF7A8,
  26067. Digammagreek: 0x03DC,
  26068. Djecyrillic: 0x0402,
  26069. Dlinebelow: 0x1E0E,
  26070. Dmonospace: 0xFF24,
  26071. Dotaccentsmall: 0xF6F7,
  26072. Dslash: 0x0110,
  26073. Dsmall: 0xF764,
  26074. Dtopbar: 0x018B,
  26075. Dz: 0x01F2,
  26076. Dzcaron: 0x01C5,
  26077. Dzeabkhasiancyrillic: 0x04E0,
  26078. Dzecyrillic: 0x0405,
  26079. Dzhecyrillic: 0x040F,
  26080. E: 0x0045,
  26081. Eacute: 0x00C9,
  26082. Eacutesmall: 0xF7E9,
  26083. Ebreve: 0x0114,
  26084. Ecaron: 0x011A,
  26085. Ecedillabreve: 0x1E1C,
  26086. Echarmenian: 0x0535,
  26087. Ecircle: 0x24BA,
  26088. Ecircumflex: 0x00CA,
  26089. Ecircumflexacute: 0x1EBE,
  26090. Ecircumflexbelow: 0x1E18,
  26091. Ecircumflexdotbelow: 0x1EC6,
  26092. Ecircumflexgrave: 0x1EC0,
  26093. Ecircumflexhookabove: 0x1EC2,
  26094. Ecircumflexsmall: 0xF7EA,
  26095. Ecircumflextilde: 0x1EC4,
  26096. Ecyrillic: 0x0404,
  26097. Edblgrave: 0x0204,
  26098. Edieresis: 0x00CB,
  26099. Edieresissmall: 0xF7EB,
  26100. Edot: 0x0116,
  26101. Edotaccent: 0x0116,
  26102. Edotbelow: 0x1EB8,
  26103. Efcyrillic: 0x0424,
  26104. Egrave: 0x00C8,
  26105. Egravesmall: 0xF7E8,
  26106. Eharmenian: 0x0537,
  26107. Ehookabove: 0x1EBA,
  26108. Eightroman: 0x2167,
  26109. Einvertedbreve: 0x0206,
  26110. Eiotifiedcyrillic: 0x0464,
  26111. Elcyrillic: 0x041B,
  26112. Elevenroman: 0x216A,
  26113. Emacron: 0x0112,
  26114. Emacronacute: 0x1E16,
  26115. Emacrongrave: 0x1E14,
  26116. Emcyrillic: 0x041C,
  26117. Emonospace: 0xFF25,
  26118. Encyrillic: 0x041D,
  26119. Endescendercyrillic: 0x04A2,
  26120. Eng: 0x014A,
  26121. Enghecyrillic: 0x04A4,
  26122. Enhookcyrillic: 0x04C7,
  26123. Eogonek: 0x0118,
  26124. Eopen: 0x0190,
  26125. Epsilon: 0x0395,
  26126. Epsilontonos: 0x0388,
  26127. Ercyrillic: 0x0420,
  26128. Ereversed: 0x018E,
  26129. Ereversedcyrillic: 0x042D,
  26130. Escyrillic: 0x0421,
  26131. Esdescendercyrillic: 0x04AA,
  26132. Esh: 0x01A9,
  26133. Esmall: 0xF765,
  26134. Eta: 0x0397,
  26135. Etarmenian: 0x0538,
  26136. Etatonos: 0x0389,
  26137. Eth: 0x00D0,
  26138. Ethsmall: 0xF7F0,
  26139. Etilde: 0x1EBC,
  26140. Etildebelow: 0x1E1A,
  26141. Euro: 0x20AC,
  26142. Ezh: 0x01B7,
  26143. Ezhcaron: 0x01EE,
  26144. Ezhreversed: 0x01B8,
  26145. F: 0x0046,
  26146. Fcircle: 0x24BB,
  26147. Fdotaccent: 0x1E1E,
  26148. Feharmenian: 0x0556,
  26149. Feicoptic: 0x03E4,
  26150. Fhook: 0x0191,
  26151. Fitacyrillic: 0x0472,
  26152. Fiveroman: 0x2164,
  26153. Fmonospace: 0xFF26,
  26154. Fourroman: 0x2163,
  26155. Fsmall: 0xF766,
  26156. G: 0x0047,
  26157. GBsquare: 0x3387,
  26158. Gacute: 0x01F4,
  26159. Gamma: 0x0393,
  26160. Gammaafrican: 0x0194,
  26161. Gangiacoptic: 0x03EA,
  26162. Gbreve: 0x011E,
  26163. Gcaron: 0x01E6,
  26164. Gcedilla: 0x0122,
  26165. Gcircle: 0x24BC,
  26166. Gcircumflex: 0x011C,
  26167. Gcommaaccent: 0x0122,
  26168. Gdot: 0x0120,
  26169. Gdotaccent: 0x0120,
  26170. Gecyrillic: 0x0413,
  26171. Ghadarmenian: 0x0542,
  26172. Ghemiddlehookcyrillic: 0x0494,
  26173. Ghestrokecyrillic: 0x0492,
  26174. Gheupturncyrillic: 0x0490,
  26175. Ghook: 0x0193,
  26176. Gimarmenian: 0x0533,
  26177. Gjecyrillic: 0x0403,
  26178. Gmacron: 0x1E20,
  26179. Gmonospace: 0xFF27,
  26180. Grave: 0xF6CE,
  26181. Gravesmall: 0xF760,
  26182. Gsmall: 0xF767,
  26183. Gsmallhook: 0x029B,
  26184. Gstroke: 0x01E4,
  26185. H: 0x0048,
  26186. H18533: 0x25CF,
  26187. H18543: 0x25AA,
  26188. H18551: 0x25AB,
  26189. H22073: 0x25A1,
  26190. HPsquare: 0x33CB,
  26191. Haabkhasiancyrillic: 0x04A8,
  26192. Hadescendercyrillic: 0x04B2,
  26193. Hardsigncyrillic: 0x042A,
  26194. Hbar: 0x0126,
  26195. Hbrevebelow: 0x1E2A,
  26196. Hcedilla: 0x1E28,
  26197. Hcircle: 0x24BD,
  26198. Hcircumflex: 0x0124,
  26199. Hdieresis: 0x1E26,
  26200. Hdotaccent: 0x1E22,
  26201. Hdotbelow: 0x1E24,
  26202. Hmonospace: 0xFF28,
  26203. Hoarmenian: 0x0540,
  26204. Horicoptic: 0x03E8,
  26205. Hsmall: 0xF768,
  26206. Hungarumlaut: 0xF6CF,
  26207. Hungarumlautsmall: 0xF6F8,
  26208. Hzsquare: 0x3390,
  26209. I: 0x0049,
  26210. IAcyrillic: 0x042F,
  26211. IJ: 0x0132,
  26212. IUcyrillic: 0x042E,
  26213. Iacute: 0x00CD,
  26214. Iacutesmall: 0xF7ED,
  26215. Ibreve: 0x012C,
  26216. Icaron: 0x01CF,
  26217. Icircle: 0x24BE,
  26218. Icircumflex: 0x00CE,
  26219. Icircumflexsmall: 0xF7EE,
  26220. Icyrillic: 0x0406,
  26221. Idblgrave: 0x0208,
  26222. Idieresis: 0x00CF,
  26223. Idieresisacute: 0x1E2E,
  26224. Idieresiscyrillic: 0x04E4,
  26225. Idieresissmall: 0xF7EF,
  26226. Idot: 0x0130,
  26227. Idotaccent: 0x0130,
  26228. Idotbelow: 0x1ECA,
  26229. Iebrevecyrillic: 0x04D6,
  26230. Iecyrillic: 0x0415,
  26231. Ifraktur: 0x2111,
  26232. Igrave: 0x00CC,
  26233. Igravesmall: 0xF7EC,
  26234. Ihookabove: 0x1EC8,
  26235. Iicyrillic: 0x0418,
  26236. Iinvertedbreve: 0x020A,
  26237. Iishortcyrillic: 0x0419,
  26238. Imacron: 0x012A,
  26239. Imacroncyrillic: 0x04E2,
  26240. Imonospace: 0xFF29,
  26241. Iniarmenian: 0x053B,
  26242. Iocyrillic: 0x0401,
  26243. Iogonek: 0x012E,
  26244. Iota: 0x0399,
  26245. Iotaafrican: 0x0196,
  26246. Iotadieresis: 0x03AA,
  26247. Iotatonos: 0x038A,
  26248. Ismall: 0xF769,
  26249. Istroke: 0x0197,
  26250. Itilde: 0x0128,
  26251. Itildebelow: 0x1E2C,
  26252. Izhitsacyrillic: 0x0474,
  26253. Izhitsadblgravecyrillic: 0x0476,
  26254. J: 0x004A,
  26255. Jaarmenian: 0x0541,
  26256. Jcircle: 0x24BF,
  26257. Jcircumflex: 0x0134,
  26258. Jecyrillic: 0x0408,
  26259. Jheharmenian: 0x054B,
  26260. Jmonospace: 0xFF2A,
  26261. Jsmall: 0xF76A,
  26262. K: 0x004B,
  26263. KBsquare: 0x3385,
  26264. KKsquare: 0x33CD,
  26265. Kabashkircyrillic: 0x04A0,
  26266. Kacute: 0x1E30,
  26267. Kacyrillic: 0x041A,
  26268. Kadescendercyrillic: 0x049A,
  26269. Kahookcyrillic: 0x04C3,
  26270. Kappa: 0x039A,
  26271. Kastrokecyrillic: 0x049E,
  26272. Kaverticalstrokecyrillic: 0x049C,
  26273. Kcaron: 0x01E8,
  26274. Kcedilla: 0x0136,
  26275. Kcircle: 0x24C0,
  26276. Kcommaaccent: 0x0136,
  26277. Kdotbelow: 0x1E32,
  26278. Keharmenian: 0x0554,
  26279. Kenarmenian: 0x053F,
  26280. Khacyrillic: 0x0425,
  26281. Kheicoptic: 0x03E6,
  26282. Khook: 0x0198,
  26283. Kjecyrillic: 0x040C,
  26284. Klinebelow: 0x1E34,
  26285. Kmonospace: 0xFF2B,
  26286. Koppacyrillic: 0x0480,
  26287. Koppagreek: 0x03DE,
  26288. Ksicyrillic: 0x046E,
  26289. Ksmall: 0xF76B,
  26290. L: 0x004C,
  26291. LJ: 0x01C7,
  26292. LL: 0xF6BF,
  26293. Lacute: 0x0139,
  26294. Lambda: 0x039B,
  26295. Lcaron: 0x013D,
  26296. Lcedilla: 0x013B,
  26297. Lcircle: 0x24C1,
  26298. Lcircumflexbelow: 0x1E3C,
  26299. Lcommaaccent: 0x013B,
  26300. Ldot: 0x013F,
  26301. Ldotaccent: 0x013F,
  26302. Ldotbelow: 0x1E36,
  26303. Ldotbelowmacron: 0x1E38,
  26304. Liwnarmenian: 0x053C,
  26305. Lj: 0x01C8,
  26306. Ljecyrillic: 0x0409,
  26307. Llinebelow: 0x1E3A,
  26308. Lmonospace: 0xFF2C,
  26309. Lslash: 0x0141,
  26310. Lslashsmall: 0xF6F9,
  26311. Lsmall: 0xF76C,
  26312. M: 0x004D,
  26313. MBsquare: 0x3386,
  26314. Macron: 0xF6D0,
  26315. Macronsmall: 0xF7AF,
  26316. Macute: 0x1E3E,
  26317. Mcircle: 0x24C2,
  26318. Mdotaccent: 0x1E40,
  26319. Mdotbelow: 0x1E42,
  26320. Menarmenian: 0x0544,
  26321. Mmonospace: 0xFF2D,
  26322. Msmall: 0xF76D,
  26323. Mturned: 0x019C,
  26324. Mu: 0x039C,
  26325. N: 0x004E,
  26326. NJ: 0x01CA,
  26327. Nacute: 0x0143,
  26328. Ncaron: 0x0147,
  26329. Ncedilla: 0x0145,
  26330. Ncircle: 0x24C3,
  26331. Ncircumflexbelow: 0x1E4A,
  26332. Ncommaaccent: 0x0145,
  26333. Ndotaccent: 0x1E44,
  26334. Ndotbelow: 0x1E46,
  26335. Nhookleft: 0x019D,
  26336. Nineroman: 0x2168,
  26337. Nj: 0x01CB,
  26338. Njecyrillic: 0x040A,
  26339. Nlinebelow: 0x1E48,
  26340. Nmonospace: 0xFF2E,
  26341. Nowarmenian: 0x0546,
  26342. Nsmall: 0xF76E,
  26343. Ntilde: 0x00D1,
  26344. Ntildesmall: 0xF7F1,
  26345. Nu: 0x039D,
  26346. O: 0x004F,
  26347. OE: 0x0152,
  26348. OEsmall: 0xF6FA,
  26349. Oacute: 0x00D3,
  26350. Oacutesmall: 0xF7F3,
  26351. Obarredcyrillic: 0x04E8,
  26352. Obarreddieresiscyrillic: 0x04EA,
  26353. Obreve: 0x014E,
  26354. Ocaron: 0x01D1,
  26355. Ocenteredtilde: 0x019F,
  26356. Ocircle: 0x24C4,
  26357. Ocircumflex: 0x00D4,
  26358. Ocircumflexacute: 0x1ED0,
  26359. Ocircumflexdotbelow: 0x1ED8,
  26360. Ocircumflexgrave: 0x1ED2,
  26361. Ocircumflexhookabove: 0x1ED4,
  26362. Ocircumflexsmall: 0xF7F4,
  26363. Ocircumflextilde: 0x1ED6,
  26364. Ocyrillic: 0x041E,
  26365. Odblacute: 0x0150,
  26366. Odblgrave: 0x020C,
  26367. Odieresis: 0x00D6,
  26368. Odieresiscyrillic: 0x04E6,
  26369. Odieresissmall: 0xF7F6,
  26370. Odotbelow: 0x1ECC,
  26371. Ogoneksmall: 0xF6FB,
  26372. Ograve: 0x00D2,
  26373. Ogravesmall: 0xF7F2,
  26374. Oharmenian: 0x0555,
  26375. Ohm: 0x2126,
  26376. Ohookabove: 0x1ECE,
  26377. Ohorn: 0x01A0,
  26378. Ohornacute: 0x1EDA,
  26379. Ohorndotbelow: 0x1EE2,
  26380. Ohorngrave: 0x1EDC,
  26381. Ohornhookabove: 0x1EDE,
  26382. Ohorntilde: 0x1EE0,
  26383. Ohungarumlaut: 0x0150,
  26384. Oi: 0x01A2,
  26385. Oinvertedbreve: 0x020E,
  26386. Omacron: 0x014C,
  26387. Omacronacute: 0x1E52,
  26388. Omacrongrave: 0x1E50,
  26389. Omega: 0x2126,
  26390. Omegacyrillic: 0x0460,
  26391. Omegagreek: 0x03A9,
  26392. Omegaroundcyrillic: 0x047A,
  26393. Omegatitlocyrillic: 0x047C,
  26394. Omegatonos: 0x038F,
  26395. Omicron: 0x039F,
  26396. Omicrontonos: 0x038C,
  26397. Omonospace: 0xFF2F,
  26398. Oneroman: 0x2160,
  26399. Oogonek: 0x01EA,
  26400. Oogonekmacron: 0x01EC,
  26401. Oopen: 0x0186,
  26402. Oslash: 0x00D8,
  26403. Oslashacute: 0x01FE,
  26404. Oslashsmall: 0xF7F8,
  26405. Osmall: 0xF76F,
  26406. Ostrokeacute: 0x01FE,
  26407. Otcyrillic: 0x047E,
  26408. Otilde: 0x00D5,
  26409. Otildeacute: 0x1E4C,
  26410. Otildedieresis: 0x1E4E,
  26411. Otildesmall: 0xF7F5,
  26412. P: 0x0050,
  26413. Pacute: 0x1E54,
  26414. Pcircle: 0x24C5,
  26415. Pdotaccent: 0x1E56,
  26416. Pecyrillic: 0x041F,
  26417. Peharmenian: 0x054A,
  26418. Pemiddlehookcyrillic: 0x04A6,
  26419. Phi: 0x03A6,
  26420. Phook: 0x01A4,
  26421. Pi: 0x03A0,
  26422. Piwrarmenian: 0x0553,
  26423. Pmonospace: 0xFF30,
  26424. Psi: 0x03A8,
  26425. Psicyrillic: 0x0470,
  26426. Psmall: 0xF770,
  26427. Q: 0x0051,
  26428. Qcircle: 0x24C6,
  26429. Qmonospace: 0xFF31,
  26430. Qsmall: 0xF771,
  26431. R: 0x0052,
  26432. Raarmenian: 0x054C,
  26433. Racute: 0x0154,
  26434. Rcaron: 0x0158,
  26435. Rcedilla: 0x0156,
  26436. Rcircle: 0x24C7,
  26437. Rcommaaccent: 0x0156,
  26438. Rdblgrave: 0x0210,
  26439. Rdotaccent: 0x1E58,
  26440. Rdotbelow: 0x1E5A,
  26441. Rdotbelowmacron: 0x1E5C,
  26442. Reharmenian: 0x0550,
  26443. Rfraktur: 0x211C,
  26444. Rho: 0x03A1,
  26445. Ringsmall: 0xF6FC,
  26446. Rinvertedbreve: 0x0212,
  26447. Rlinebelow: 0x1E5E,
  26448. Rmonospace: 0xFF32,
  26449. Rsmall: 0xF772,
  26450. Rsmallinverted: 0x0281,
  26451. Rsmallinvertedsuperior: 0x02B6,
  26452. S: 0x0053,
  26453. SF010000: 0x250C,
  26454. SF020000: 0x2514,
  26455. SF030000: 0x2510,
  26456. SF040000: 0x2518,
  26457. SF050000: 0x253C,
  26458. SF060000: 0x252C,
  26459. SF070000: 0x2534,
  26460. SF080000: 0x251C,
  26461. SF090000: 0x2524,
  26462. SF100000: 0x2500,
  26463. SF110000: 0x2502,
  26464. SF190000: 0x2561,
  26465. SF200000: 0x2562,
  26466. SF210000: 0x2556,
  26467. SF220000: 0x2555,
  26468. SF230000: 0x2563,
  26469. SF240000: 0x2551,
  26470. SF250000: 0x2557,
  26471. SF260000: 0x255D,
  26472. SF270000: 0x255C,
  26473. SF280000: 0x255B,
  26474. SF360000: 0x255E,
  26475. SF370000: 0x255F,
  26476. SF380000: 0x255A,
  26477. SF390000: 0x2554,
  26478. SF400000: 0x2569,
  26479. SF410000: 0x2566,
  26480. SF420000: 0x2560,
  26481. SF430000: 0x2550,
  26482. SF440000: 0x256C,
  26483. SF450000: 0x2567,
  26484. SF460000: 0x2568,
  26485. SF470000: 0x2564,
  26486. SF480000: 0x2565,
  26487. SF490000: 0x2559,
  26488. SF500000: 0x2558,
  26489. SF510000: 0x2552,
  26490. SF520000: 0x2553,
  26491. SF530000: 0x256B,
  26492. SF540000: 0x256A,
  26493. Sacute: 0x015A,
  26494. Sacutedotaccent: 0x1E64,
  26495. Sampigreek: 0x03E0,
  26496. Scaron: 0x0160,
  26497. Scarondotaccent: 0x1E66,
  26498. Scaronsmall: 0xF6FD,
  26499. Scedilla: 0x015E,
  26500. Schwa: 0x018F,
  26501. Schwacyrillic: 0x04D8,
  26502. Schwadieresiscyrillic: 0x04DA,
  26503. Scircle: 0x24C8,
  26504. Scircumflex: 0x015C,
  26505. Scommaaccent: 0x0218,
  26506. Sdotaccent: 0x1E60,
  26507. Sdotbelow: 0x1E62,
  26508. Sdotbelowdotaccent: 0x1E68,
  26509. Seharmenian: 0x054D,
  26510. Sevenroman: 0x2166,
  26511. Shaarmenian: 0x0547,
  26512. Shacyrillic: 0x0428,
  26513. Shchacyrillic: 0x0429,
  26514. Sheicoptic: 0x03E2,
  26515. Shhacyrillic: 0x04BA,
  26516. Shimacoptic: 0x03EC,
  26517. Sigma: 0x03A3,
  26518. Sixroman: 0x2165,
  26519. Smonospace: 0xFF33,
  26520. Softsigncyrillic: 0x042C,
  26521. Ssmall: 0xF773,
  26522. Stigmagreek: 0x03DA,
  26523. T: 0x0054,
  26524. Tau: 0x03A4,
  26525. Tbar: 0x0166,
  26526. Tcaron: 0x0164,
  26527. Tcedilla: 0x0162,
  26528. Tcircle: 0x24C9,
  26529. Tcircumflexbelow: 0x1E70,
  26530. Tcommaaccent: 0x0162,
  26531. Tdotaccent: 0x1E6A,
  26532. Tdotbelow: 0x1E6C,
  26533. Tecyrillic: 0x0422,
  26534. Tedescendercyrillic: 0x04AC,
  26535. Tenroman: 0x2169,
  26536. Tetsecyrillic: 0x04B4,
  26537. Theta: 0x0398,
  26538. Thook: 0x01AC,
  26539. Thorn: 0x00DE,
  26540. Thornsmall: 0xF7FE,
  26541. Threeroman: 0x2162,
  26542. Tildesmall: 0xF6FE,
  26543. Tiwnarmenian: 0x054F,
  26544. Tlinebelow: 0x1E6E,
  26545. Tmonospace: 0xFF34,
  26546. Toarmenian: 0x0539,
  26547. Tonefive: 0x01BC,
  26548. Tonesix: 0x0184,
  26549. Tonetwo: 0x01A7,
  26550. Tretroflexhook: 0x01AE,
  26551. Tsecyrillic: 0x0426,
  26552. Tshecyrillic: 0x040B,
  26553. Tsmall: 0xF774,
  26554. Twelveroman: 0x216B,
  26555. Tworoman: 0x2161,
  26556. U: 0x0055,
  26557. Uacute: 0x00DA,
  26558. Uacutesmall: 0xF7FA,
  26559. Ubreve: 0x016C,
  26560. Ucaron: 0x01D3,
  26561. Ucircle: 0x24CA,
  26562. Ucircumflex: 0x00DB,
  26563. Ucircumflexbelow: 0x1E76,
  26564. Ucircumflexsmall: 0xF7FB,
  26565. Ucyrillic: 0x0423,
  26566. Udblacute: 0x0170,
  26567. Udblgrave: 0x0214,
  26568. Udieresis: 0x00DC,
  26569. Udieresisacute: 0x01D7,
  26570. Udieresisbelow: 0x1E72,
  26571. Udieresiscaron: 0x01D9,
  26572. Udieresiscyrillic: 0x04F0,
  26573. Udieresisgrave: 0x01DB,
  26574. Udieresismacron: 0x01D5,
  26575. Udieresissmall: 0xF7FC,
  26576. Udotbelow: 0x1EE4,
  26577. Ugrave: 0x00D9,
  26578. Ugravesmall: 0xF7F9,
  26579. Uhookabove: 0x1EE6,
  26580. Uhorn: 0x01AF,
  26581. Uhornacute: 0x1EE8,
  26582. Uhorndotbelow: 0x1EF0,
  26583. Uhorngrave: 0x1EEA,
  26584. Uhornhookabove: 0x1EEC,
  26585. Uhorntilde: 0x1EEE,
  26586. Uhungarumlaut: 0x0170,
  26587. Uhungarumlautcyrillic: 0x04F2,
  26588. Uinvertedbreve: 0x0216,
  26589. Ukcyrillic: 0x0478,
  26590. Umacron: 0x016A,
  26591. Umacroncyrillic: 0x04EE,
  26592. Umacrondieresis: 0x1E7A,
  26593. Umonospace: 0xFF35,
  26594. Uogonek: 0x0172,
  26595. Upsilon: 0x03A5,
  26596. Upsilon1: 0x03D2,
  26597. Upsilonacutehooksymbolgreek: 0x03D3,
  26598. Upsilonafrican: 0x01B1,
  26599. Upsilondieresis: 0x03AB,
  26600. Upsilondieresishooksymbolgreek: 0x03D4,
  26601. Upsilonhooksymbol: 0x03D2,
  26602. Upsilontonos: 0x038E,
  26603. Uring: 0x016E,
  26604. Ushortcyrillic: 0x040E,
  26605. Usmall: 0xF775,
  26606. Ustraightcyrillic: 0x04AE,
  26607. Ustraightstrokecyrillic: 0x04B0,
  26608. Utilde: 0x0168,
  26609. Utildeacute: 0x1E78,
  26610. Utildebelow: 0x1E74,
  26611. V: 0x0056,
  26612. Vcircle: 0x24CB,
  26613. Vdotbelow: 0x1E7E,
  26614. Vecyrillic: 0x0412,
  26615. Vewarmenian: 0x054E,
  26616. Vhook: 0x01B2,
  26617. Vmonospace: 0xFF36,
  26618. Voarmenian: 0x0548,
  26619. Vsmall: 0xF776,
  26620. Vtilde: 0x1E7C,
  26621. W: 0x0057,
  26622. Wacute: 0x1E82,
  26623. Wcircle: 0x24CC,
  26624. Wcircumflex: 0x0174,
  26625. Wdieresis: 0x1E84,
  26626. Wdotaccent: 0x1E86,
  26627. Wdotbelow: 0x1E88,
  26628. Wgrave: 0x1E80,
  26629. Wmonospace: 0xFF37,
  26630. Wsmall: 0xF777,
  26631. X: 0x0058,
  26632. Xcircle: 0x24CD,
  26633. Xdieresis: 0x1E8C,
  26634. Xdotaccent: 0x1E8A,
  26635. Xeharmenian: 0x053D,
  26636. Xi: 0x039E,
  26637. Xmonospace: 0xFF38,
  26638. Xsmall: 0xF778,
  26639. Y: 0x0059,
  26640. Yacute: 0x00DD,
  26641. Yacutesmall: 0xF7FD,
  26642. Yatcyrillic: 0x0462,
  26643. Ycircle: 0x24CE,
  26644. Ycircumflex: 0x0176,
  26645. Ydieresis: 0x0178,
  26646. Ydieresissmall: 0xF7FF,
  26647. Ydotaccent: 0x1E8E,
  26648. Ydotbelow: 0x1EF4,
  26649. Yericyrillic: 0x042B,
  26650. Yerudieresiscyrillic: 0x04F8,
  26651. Ygrave: 0x1EF2,
  26652. Yhook: 0x01B3,
  26653. Yhookabove: 0x1EF6,
  26654. Yiarmenian: 0x0545,
  26655. Yicyrillic: 0x0407,
  26656. Yiwnarmenian: 0x0552,
  26657. Ymonospace: 0xFF39,
  26658. Ysmall: 0xF779,
  26659. Ytilde: 0x1EF8,
  26660. Yusbigcyrillic: 0x046A,
  26661. Yusbigiotifiedcyrillic: 0x046C,
  26662. Yuslittlecyrillic: 0x0466,
  26663. Yuslittleiotifiedcyrillic: 0x0468,
  26664. Z: 0x005A,
  26665. Zaarmenian: 0x0536,
  26666. Zacute: 0x0179,
  26667. Zcaron: 0x017D,
  26668. Zcaronsmall: 0xF6FF,
  26669. Zcircle: 0x24CF,
  26670. Zcircumflex: 0x1E90,
  26671. Zdot: 0x017B,
  26672. Zdotaccent: 0x017B,
  26673. Zdotbelow: 0x1E92,
  26674. Zecyrillic: 0x0417,
  26675. Zedescendercyrillic: 0x0498,
  26676. Zedieresiscyrillic: 0x04DE,
  26677. Zeta: 0x0396,
  26678. Zhearmenian: 0x053A,
  26679. Zhebrevecyrillic: 0x04C1,
  26680. Zhecyrillic: 0x0416,
  26681. Zhedescendercyrillic: 0x0496,
  26682. Zhedieresiscyrillic: 0x04DC,
  26683. Zlinebelow: 0x1E94,
  26684. Zmonospace: 0xFF3A,
  26685. Zsmall: 0xF77A,
  26686. Zstroke: 0x01B5,
  26687. a: 0x0061,
  26688. aabengali: 0x0986,
  26689. aacute: 0x00E1,
  26690. aadeva: 0x0906,
  26691. aagujarati: 0x0A86,
  26692. aagurmukhi: 0x0A06,
  26693. aamatragurmukhi: 0x0A3E,
  26694. aarusquare: 0x3303,
  26695. aavowelsignbengali: 0x09BE,
  26696. aavowelsigndeva: 0x093E,
  26697. aavowelsigngujarati: 0x0ABE,
  26698. abbreviationmarkarmenian: 0x055F,
  26699. abbreviationsigndeva: 0x0970,
  26700. abengali: 0x0985,
  26701. abopomofo: 0x311A,
  26702. abreve: 0x0103,
  26703. abreveacute: 0x1EAF,
  26704. abrevecyrillic: 0x04D1,
  26705. abrevedotbelow: 0x1EB7,
  26706. abrevegrave: 0x1EB1,
  26707. abrevehookabove: 0x1EB3,
  26708. abrevetilde: 0x1EB5,
  26709. acaron: 0x01CE,
  26710. acircle: 0x24D0,
  26711. acircumflex: 0x00E2,
  26712. acircumflexacute: 0x1EA5,
  26713. acircumflexdotbelow: 0x1EAD,
  26714. acircumflexgrave: 0x1EA7,
  26715. acircumflexhookabove: 0x1EA9,
  26716. acircumflextilde: 0x1EAB,
  26717. acute: 0x00B4,
  26718. acutebelowcmb: 0x0317,
  26719. acutecmb: 0x0301,
  26720. acutecomb: 0x0301,
  26721. acutedeva: 0x0954,
  26722. acutelowmod: 0x02CF,
  26723. acutetonecmb: 0x0341,
  26724. acyrillic: 0x0430,
  26725. adblgrave: 0x0201,
  26726. addakgurmukhi: 0x0A71,
  26727. adeva: 0x0905,
  26728. adieresis: 0x00E4,
  26729. adieresiscyrillic: 0x04D3,
  26730. adieresismacron: 0x01DF,
  26731. adotbelow: 0x1EA1,
  26732. adotmacron: 0x01E1,
  26733. ae: 0x00E6,
  26734. aeacute: 0x01FD,
  26735. aekorean: 0x3150,
  26736. aemacron: 0x01E3,
  26737. afii00208: 0x2015,
  26738. afii08941: 0x20A4,
  26739. afii10017: 0x0410,
  26740. afii10018: 0x0411,
  26741. afii10019: 0x0412,
  26742. afii10020: 0x0413,
  26743. afii10021: 0x0414,
  26744. afii10022: 0x0415,
  26745. afii10023: 0x0401,
  26746. afii10024: 0x0416,
  26747. afii10025: 0x0417,
  26748. afii10026: 0x0418,
  26749. afii10027: 0x0419,
  26750. afii10028: 0x041A,
  26751. afii10029: 0x041B,
  26752. afii10030: 0x041C,
  26753. afii10031: 0x041D,
  26754. afii10032: 0x041E,
  26755. afii10033: 0x041F,
  26756. afii10034: 0x0420,
  26757. afii10035: 0x0421,
  26758. afii10036: 0x0422,
  26759. afii10037: 0x0423,
  26760. afii10038: 0x0424,
  26761. afii10039: 0x0425,
  26762. afii10040: 0x0426,
  26763. afii10041: 0x0427,
  26764. afii10042: 0x0428,
  26765. afii10043: 0x0429,
  26766. afii10044: 0x042A,
  26767. afii10045: 0x042B,
  26768. afii10046: 0x042C,
  26769. afii10047: 0x042D,
  26770. afii10048: 0x042E,
  26771. afii10049: 0x042F,
  26772. afii10050: 0x0490,
  26773. afii10051: 0x0402,
  26774. afii10052: 0x0403,
  26775. afii10053: 0x0404,
  26776. afii10054: 0x0405,
  26777. afii10055: 0x0406,
  26778. afii10056: 0x0407,
  26779. afii10057: 0x0408,
  26780. afii10058: 0x0409,
  26781. afii10059: 0x040A,
  26782. afii10060: 0x040B,
  26783. afii10061: 0x040C,
  26784. afii10062: 0x040E,
  26785. afii10063: 0xF6C4,
  26786. afii10064: 0xF6C5,
  26787. afii10065: 0x0430,
  26788. afii10066: 0x0431,
  26789. afii10067: 0x0432,
  26790. afii10068: 0x0433,
  26791. afii10069: 0x0434,
  26792. afii10070: 0x0435,
  26793. afii10071: 0x0451,
  26794. afii10072: 0x0436,
  26795. afii10073: 0x0437,
  26796. afii10074: 0x0438,
  26797. afii10075: 0x0439,
  26798. afii10076: 0x043A,
  26799. afii10077: 0x043B,
  26800. afii10078: 0x043C,
  26801. afii10079: 0x043D,
  26802. afii10080: 0x043E,
  26803. afii10081: 0x043F,
  26804. afii10082: 0x0440,
  26805. afii10083: 0x0441,
  26806. afii10084: 0x0442,
  26807. afii10085: 0x0443,
  26808. afii10086: 0x0444,
  26809. afii10087: 0x0445,
  26810. afii10088: 0x0446,
  26811. afii10089: 0x0447,
  26812. afii10090: 0x0448,
  26813. afii10091: 0x0449,
  26814. afii10092: 0x044A,
  26815. afii10093: 0x044B,
  26816. afii10094: 0x044C,
  26817. afii10095: 0x044D,
  26818. afii10096: 0x044E,
  26819. afii10097: 0x044F,
  26820. afii10098: 0x0491,
  26821. afii10099: 0x0452,
  26822. afii10100: 0x0453,
  26823. afii10101: 0x0454,
  26824. afii10102: 0x0455,
  26825. afii10103: 0x0456,
  26826. afii10104: 0x0457,
  26827. afii10105: 0x0458,
  26828. afii10106: 0x0459,
  26829. afii10107: 0x045A,
  26830. afii10108: 0x045B,
  26831. afii10109: 0x045C,
  26832. afii10110: 0x045E,
  26833. afii10145: 0x040F,
  26834. afii10146: 0x0462,
  26835. afii10147: 0x0472,
  26836. afii10148: 0x0474,
  26837. afii10192: 0xF6C6,
  26838. afii10193: 0x045F,
  26839. afii10194: 0x0463,
  26840. afii10195: 0x0473,
  26841. afii10196: 0x0475,
  26842. afii10831: 0xF6C7,
  26843. afii10832: 0xF6C8,
  26844. afii10846: 0x04D9,
  26845. afii299: 0x200E,
  26846. afii300: 0x200F,
  26847. afii301: 0x200D,
  26848. afii57381: 0x066A,
  26849. afii57388: 0x060C,
  26850. afii57392: 0x0660,
  26851. afii57393: 0x0661,
  26852. afii57394: 0x0662,
  26853. afii57395: 0x0663,
  26854. afii57396: 0x0664,
  26855. afii57397: 0x0665,
  26856. afii57398: 0x0666,
  26857. afii57399: 0x0667,
  26858. afii57400: 0x0668,
  26859. afii57401: 0x0669,
  26860. afii57403: 0x061B,
  26861. afii57407: 0x061F,
  26862. afii57409: 0x0621,
  26863. afii57410: 0x0622,
  26864. afii57411: 0x0623,
  26865. afii57412: 0x0624,
  26866. afii57413: 0x0625,
  26867. afii57414: 0x0626,
  26868. afii57415: 0x0627,
  26869. afii57416: 0x0628,
  26870. afii57417: 0x0629,
  26871. afii57418: 0x062A,
  26872. afii57419: 0x062B,
  26873. afii57420: 0x062C,
  26874. afii57421: 0x062D,
  26875. afii57422: 0x062E,
  26876. afii57423: 0x062F,
  26877. afii57424: 0x0630,
  26878. afii57425: 0x0631,
  26879. afii57426: 0x0632,
  26880. afii57427: 0x0633,
  26881. afii57428: 0x0634,
  26882. afii57429: 0x0635,
  26883. afii57430: 0x0636,
  26884. afii57431: 0x0637,
  26885. afii57432: 0x0638,
  26886. afii57433: 0x0639,
  26887. afii57434: 0x063A,
  26888. afii57440: 0x0640,
  26889. afii57441: 0x0641,
  26890. afii57442: 0x0642,
  26891. afii57443: 0x0643,
  26892. afii57444: 0x0644,
  26893. afii57445: 0x0645,
  26894. afii57446: 0x0646,
  26895. afii57448: 0x0648,
  26896. afii57449: 0x0649,
  26897. afii57450: 0x064A,
  26898. afii57451: 0x064B,
  26899. afii57452: 0x064C,
  26900. afii57453: 0x064D,
  26901. afii57454: 0x064E,
  26902. afii57455: 0x064F,
  26903. afii57456: 0x0650,
  26904. afii57457: 0x0651,
  26905. afii57458: 0x0652,
  26906. afii57470: 0x0647,
  26907. afii57505: 0x06A4,
  26908. afii57506: 0x067E,
  26909. afii57507: 0x0686,
  26910. afii57508: 0x0698,
  26911. afii57509: 0x06AF,
  26912. afii57511: 0x0679,
  26913. afii57512: 0x0688,
  26914. afii57513: 0x0691,
  26915. afii57514: 0x06BA,
  26916. afii57519: 0x06D2,
  26917. afii57534: 0x06D5,
  26918. afii57636: 0x20AA,
  26919. afii57645: 0x05BE,
  26920. afii57658: 0x05C3,
  26921. afii57664: 0x05D0,
  26922. afii57665: 0x05D1,
  26923. afii57666: 0x05D2,
  26924. afii57667: 0x05D3,
  26925. afii57668: 0x05D4,
  26926. afii57669: 0x05D5,
  26927. afii57670: 0x05D6,
  26928. afii57671: 0x05D7,
  26929. afii57672: 0x05D8,
  26930. afii57673: 0x05D9,
  26931. afii57674: 0x05DA,
  26932. afii57675: 0x05DB,
  26933. afii57676: 0x05DC,
  26934. afii57677: 0x05DD,
  26935. afii57678: 0x05DE,
  26936. afii57679: 0x05DF,
  26937. afii57680: 0x05E0,
  26938. afii57681: 0x05E1,
  26939. afii57682: 0x05E2,
  26940. afii57683: 0x05E3,
  26941. afii57684: 0x05E4,
  26942. afii57685: 0x05E5,
  26943. afii57686: 0x05E6,
  26944. afii57687: 0x05E7,
  26945. afii57688: 0x05E8,
  26946. afii57689: 0x05E9,
  26947. afii57690: 0x05EA,
  26948. afii57694: 0xFB2A,
  26949. afii57695: 0xFB2B,
  26950. afii57700: 0xFB4B,
  26951. afii57705: 0xFB1F,
  26952. afii57716: 0x05F0,
  26953. afii57717: 0x05F1,
  26954. afii57718: 0x05F2,
  26955. afii57723: 0xFB35,
  26956. afii57793: 0x05B4,
  26957. afii57794: 0x05B5,
  26958. afii57795: 0x05B6,
  26959. afii57796: 0x05BB,
  26960. afii57797: 0x05B8,
  26961. afii57798: 0x05B7,
  26962. afii57799: 0x05B0,
  26963. afii57800: 0x05B2,
  26964. afii57801: 0x05B1,
  26965. afii57802: 0x05B3,
  26966. afii57803: 0x05C2,
  26967. afii57804: 0x05C1,
  26968. afii57806: 0x05B9,
  26969. afii57807: 0x05BC,
  26970. afii57839: 0x05BD,
  26971. afii57841: 0x05BF,
  26972. afii57842: 0x05C0,
  26973. afii57929: 0x02BC,
  26974. afii61248: 0x2105,
  26975. afii61289: 0x2113,
  26976. afii61352: 0x2116,
  26977. afii61573: 0x202C,
  26978. afii61574: 0x202D,
  26979. afii61575: 0x202E,
  26980. afii61664: 0x200C,
  26981. afii63167: 0x066D,
  26982. afii64937: 0x02BD,
  26983. agrave: 0x00E0,
  26984. agujarati: 0x0A85,
  26985. agurmukhi: 0x0A05,
  26986. ahiragana: 0x3042,
  26987. ahookabove: 0x1EA3,
  26988. aibengali: 0x0990,
  26989. aibopomofo: 0x311E,
  26990. aideva: 0x0910,
  26991. aiecyrillic: 0x04D5,
  26992. aigujarati: 0x0A90,
  26993. aigurmukhi: 0x0A10,
  26994. aimatragurmukhi: 0x0A48,
  26995. ainarabic: 0x0639,
  26996. ainfinalarabic: 0xFECA,
  26997. aininitialarabic: 0xFECB,
  26998. ainmedialarabic: 0xFECC,
  26999. ainvertedbreve: 0x0203,
  27000. aivowelsignbengali: 0x09C8,
  27001. aivowelsigndeva: 0x0948,
  27002. aivowelsigngujarati: 0x0AC8,
  27003. akatakana: 0x30A2,
  27004. akatakanahalfwidth: 0xFF71,
  27005. akorean: 0x314F,
  27006. alef: 0x05D0,
  27007. alefarabic: 0x0627,
  27008. alefdageshhebrew: 0xFB30,
  27009. aleffinalarabic: 0xFE8E,
  27010. alefhamzaabovearabic: 0x0623,
  27011. alefhamzaabovefinalarabic: 0xFE84,
  27012. alefhamzabelowarabic: 0x0625,
  27013. alefhamzabelowfinalarabic: 0xFE88,
  27014. alefhebrew: 0x05D0,
  27015. aleflamedhebrew: 0xFB4F,
  27016. alefmaddaabovearabic: 0x0622,
  27017. alefmaddaabovefinalarabic: 0xFE82,
  27018. alefmaksuraarabic: 0x0649,
  27019. alefmaksurafinalarabic: 0xFEF0,
  27020. alefmaksurainitialarabic: 0xFEF3,
  27021. alefmaksuramedialarabic: 0xFEF4,
  27022. alefpatahhebrew: 0xFB2E,
  27023. alefqamatshebrew: 0xFB2F,
  27024. aleph: 0x2135,
  27025. allequal: 0x224C,
  27026. alpha: 0x03B1,
  27027. alphatonos: 0x03AC,
  27028. amacron: 0x0101,
  27029. amonospace: 0xFF41,
  27030. ampersand: 0x0026,
  27031. ampersandmonospace: 0xFF06,
  27032. ampersandsmall: 0xF726,
  27033. amsquare: 0x33C2,
  27034. anbopomofo: 0x3122,
  27035. angbopomofo: 0x3124,
  27036. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27037. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27038. angkhankhuthai: 0x0E5A,
  27039. angle: 0x2220,
  27040. anglebracketleft: 0x3008,
  27041. anglebracketleftvertical: 0xFE3F,
  27042. anglebracketright: 0x3009,
  27043. anglebracketrightvertical: 0xFE40,
  27044. angleleft: 0x2329,
  27045. angleright: 0x232A,
  27046. angstrom: 0x212B,
  27047. anoteleia: 0x0387,
  27048. anudattadeva: 0x0952,
  27049. anusvarabengali: 0x0982,
  27050. anusvaradeva: 0x0902,
  27051. anusvaragujarati: 0x0A82,
  27052. aogonek: 0x0105,
  27053. apaatosquare: 0x3300,
  27054. aparen: 0x249C,
  27055. apostrophearmenian: 0x055A,
  27056. apostrophemod: 0x02BC,
  27057. apple: 0xF8FF,
  27058. approaches: 0x2250,
  27059. approxequal: 0x2248,
  27060. approxequalorimage: 0x2252,
  27061. approximatelyequal: 0x2245,
  27062. araeaekorean: 0x318E,
  27063. araeakorean: 0x318D,
  27064. arc: 0x2312,
  27065. arighthalfring: 0x1E9A,
  27066. aring: 0x00E5,
  27067. aringacute: 0x01FB,
  27068. aringbelow: 0x1E01,
  27069. arrowboth: 0x2194,
  27070. arrowdashdown: 0x21E3,
  27071. arrowdashleft: 0x21E0,
  27072. arrowdashright: 0x21E2,
  27073. arrowdashup: 0x21E1,
  27074. arrowdblboth: 0x21D4,
  27075. arrowdbldown: 0x21D3,
  27076. arrowdblleft: 0x21D0,
  27077. arrowdblright: 0x21D2,
  27078. arrowdblup: 0x21D1,
  27079. arrowdown: 0x2193,
  27080. arrowdownleft: 0x2199,
  27081. arrowdownright: 0x2198,
  27082. arrowdownwhite: 0x21E9,
  27083. arrowheaddownmod: 0x02C5,
  27084. arrowheadleftmod: 0x02C2,
  27085. arrowheadrightmod: 0x02C3,
  27086. arrowheadupmod: 0x02C4,
  27087. arrowhorizex: 0xF8E7,
  27088. arrowleft: 0x2190,
  27089. arrowleftdbl: 0x21D0,
  27090. arrowleftdblstroke: 0x21CD,
  27091. arrowleftoverright: 0x21C6,
  27092. arrowleftwhite: 0x21E6,
  27093. arrowright: 0x2192,
  27094. arrowrightdblstroke: 0x21CF,
  27095. arrowrightheavy: 0x279E,
  27096. arrowrightoverleft: 0x21C4,
  27097. arrowrightwhite: 0x21E8,
  27098. arrowtableft: 0x21E4,
  27099. arrowtabright: 0x21E5,
  27100. arrowup: 0x2191,
  27101. arrowupdn: 0x2195,
  27102. arrowupdnbse: 0x21A8,
  27103. arrowupdownbase: 0x21A8,
  27104. arrowupleft: 0x2196,
  27105. arrowupleftofdown: 0x21C5,
  27106. arrowupright: 0x2197,
  27107. arrowupwhite: 0x21E7,
  27108. arrowvertex: 0xF8E6,
  27109. asciicircum: 0x005E,
  27110. asciicircummonospace: 0xFF3E,
  27111. asciitilde: 0x007E,
  27112. asciitildemonospace: 0xFF5E,
  27113. ascript: 0x0251,
  27114. ascriptturned: 0x0252,
  27115. asmallhiragana: 0x3041,
  27116. asmallkatakana: 0x30A1,
  27117. asmallkatakanahalfwidth: 0xFF67,
  27118. asterisk: 0x002A,
  27119. asteriskaltonearabic: 0x066D,
  27120. asteriskarabic: 0x066D,
  27121. asteriskmath: 0x2217,
  27122. asteriskmonospace: 0xFF0A,
  27123. asterisksmall: 0xFE61,
  27124. asterism: 0x2042,
  27125. asuperior: 0xF6E9,
  27126. asymptoticallyequal: 0x2243,
  27127. at: 0x0040,
  27128. atilde: 0x00E3,
  27129. atmonospace: 0xFF20,
  27130. atsmall: 0xFE6B,
  27131. aturned: 0x0250,
  27132. aubengali: 0x0994,
  27133. aubopomofo: 0x3120,
  27134. audeva: 0x0914,
  27135. augujarati: 0x0A94,
  27136. augurmukhi: 0x0A14,
  27137. aulengthmarkbengali: 0x09D7,
  27138. aumatragurmukhi: 0x0A4C,
  27139. auvowelsignbengali: 0x09CC,
  27140. auvowelsigndeva: 0x094C,
  27141. auvowelsigngujarati: 0x0ACC,
  27142. avagrahadeva: 0x093D,
  27143. aybarmenian: 0x0561,
  27144. ayin: 0x05E2,
  27145. ayinaltonehebrew: 0xFB20,
  27146. ayinhebrew: 0x05E2,
  27147. b: 0x0062,
  27148. babengali: 0x09AC,
  27149. backslash: 0x005C,
  27150. backslashmonospace: 0xFF3C,
  27151. badeva: 0x092C,
  27152. bagujarati: 0x0AAC,
  27153. bagurmukhi: 0x0A2C,
  27154. bahiragana: 0x3070,
  27155. bahtthai: 0x0E3F,
  27156. bakatakana: 0x30D0,
  27157. bar: 0x007C,
  27158. barmonospace: 0xFF5C,
  27159. bbopomofo: 0x3105,
  27160. bcircle: 0x24D1,
  27161. bdotaccent: 0x1E03,
  27162. bdotbelow: 0x1E05,
  27163. beamedsixteenthnotes: 0x266C,
  27164. because: 0x2235,
  27165. becyrillic: 0x0431,
  27166. beharabic: 0x0628,
  27167. behfinalarabic: 0xFE90,
  27168. behinitialarabic: 0xFE91,
  27169. behiragana: 0x3079,
  27170. behmedialarabic: 0xFE92,
  27171. behmeeminitialarabic: 0xFC9F,
  27172. behmeemisolatedarabic: 0xFC08,
  27173. behnoonfinalarabic: 0xFC6D,
  27174. bekatakana: 0x30D9,
  27175. benarmenian: 0x0562,
  27176. bet: 0x05D1,
  27177. beta: 0x03B2,
  27178. betasymbolgreek: 0x03D0,
  27179. betdagesh: 0xFB31,
  27180. betdageshhebrew: 0xFB31,
  27181. bethebrew: 0x05D1,
  27182. betrafehebrew: 0xFB4C,
  27183. bhabengali: 0x09AD,
  27184. bhadeva: 0x092D,
  27185. bhagujarati: 0x0AAD,
  27186. bhagurmukhi: 0x0A2D,
  27187. bhook: 0x0253,
  27188. bihiragana: 0x3073,
  27189. bikatakana: 0x30D3,
  27190. bilabialclick: 0x0298,
  27191. bindigurmukhi: 0x0A02,
  27192. birusquare: 0x3331,
  27193. blackcircle: 0x25CF,
  27194. blackdiamond: 0x25C6,
  27195. blackdownpointingtriangle: 0x25BC,
  27196. blackleftpointingpointer: 0x25C4,
  27197. blackleftpointingtriangle: 0x25C0,
  27198. blacklenticularbracketleft: 0x3010,
  27199. blacklenticularbracketleftvertical: 0xFE3B,
  27200. blacklenticularbracketright: 0x3011,
  27201. blacklenticularbracketrightvertical: 0xFE3C,
  27202. blacklowerlefttriangle: 0x25E3,
  27203. blacklowerrighttriangle: 0x25E2,
  27204. blackrectangle: 0x25AC,
  27205. blackrightpointingpointer: 0x25BA,
  27206. blackrightpointingtriangle: 0x25B6,
  27207. blacksmallsquare: 0x25AA,
  27208. blacksmilingface: 0x263B,
  27209. blacksquare: 0x25A0,
  27210. blackstar: 0x2605,
  27211. blackupperlefttriangle: 0x25E4,
  27212. blackupperrighttriangle: 0x25E5,
  27213. blackuppointingsmalltriangle: 0x25B4,
  27214. blackuppointingtriangle: 0x25B2,
  27215. blank: 0x2423,
  27216. blinebelow: 0x1E07,
  27217. block: 0x2588,
  27218. bmonospace: 0xFF42,
  27219. bobaimaithai: 0x0E1A,
  27220. bohiragana: 0x307C,
  27221. bokatakana: 0x30DC,
  27222. bparen: 0x249D,
  27223. bqsquare: 0x33C3,
  27224. braceex: 0xF8F4,
  27225. braceleft: 0x007B,
  27226. braceleftbt: 0xF8F3,
  27227. braceleftmid: 0xF8F2,
  27228. braceleftmonospace: 0xFF5B,
  27229. braceleftsmall: 0xFE5B,
  27230. bracelefttp: 0xF8F1,
  27231. braceleftvertical: 0xFE37,
  27232. braceright: 0x007D,
  27233. bracerightbt: 0xF8FE,
  27234. bracerightmid: 0xF8FD,
  27235. bracerightmonospace: 0xFF5D,
  27236. bracerightsmall: 0xFE5C,
  27237. bracerighttp: 0xF8FC,
  27238. bracerightvertical: 0xFE38,
  27239. bracketleft: 0x005B,
  27240. bracketleftbt: 0xF8F0,
  27241. bracketleftex: 0xF8EF,
  27242. bracketleftmonospace: 0xFF3B,
  27243. bracketlefttp: 0xF8EE,
  27244. bracketright: 0x005D,
  27245. bracketrightbt: 0xF8FB,
  27246. bracketrightex: 0xF8FA,
  27247. bracketrightmonospace: 0xFF3D,
  27248. bracketrighttp: 0xF8F9,
  27249. breve: 0x02D8,
  27250. brevebelowcmb: 0x032E,
  27251. brevecmb: 0x0306,
  27252. breveinvertedbelowcmb: 0x032F,
  27253. breveinvertedcmb: 0x0311,
  27254. breveinverteddoublecmb: 0x0361,
  27255. bridgebelowcmb: 0x032A,
  27256. bridgeinvertedbelowcmb: 0x033A,
  27257. brokenbar: 0x00A6,
  27258. bstroke: 0x0180,
  27259. bsuperior: 0xF6EA,
  27260. btopbar: 0x0183,
  27261. buhiragana: 0x3076,
  27262. bukatakana: 0x30D6,
  27263. bullet: 0x2022,
  27264. bulletinverse: 0x25D8,
  27265. bulletoperator: 0x2219,
  27266. bullseye: 0x25CE,
  27267. c: 0x0063,
  27268. caarmenian: 0x056E,
  27269. cabengali: 0x099A,
  27270. cacute: 0x0107,
  27271. cadeva: 0x091A,
  27272. cagujarati: 0x0A9A,
  27273. cagurmukhi: 0x0A1A,
  27274. calsquare: 0x3388,
  27275. candrabindubengali: 0x0981,
  27276. candrabinducmb: 0x0310,
  27277. candrabindudeva: 0x0901,
  27278. candrabindugujarati: 0x0A81,
  27279. capslock: 0x21EA,
  27280. careof: 0x2105,
  27281. caron: 0x02C7,
  27282. caronbelowcmb: 0x032C,
  27283. caroncmb: 0x030C,
  27284. carriagereturn: 0x21B5,
  27285. cbopomofo: 0x3118,
  27286. ccaron: 0x010D,
  27287. ccedilla: 0x00E7,
  27288. ccedillaacute: 0x1E09,
  27289. ccircle: 0x24D2,
  27290. ccircumflex: 0x0109,
  27291. ccurl: 0x0255,
  27292. cdot: 0x010B,
  27293. cdotaccent: 0x010B,
  27294. cdsquare: 0x33C5,
  27295. cedilla: 0x00B8,
  27296. cedillacmb: 0x0327,
  27297. cent: 0x00A2,
  27298. centigrade: 0x2103,
  27299. centinferior: 0xF6DF,
  27300. centmonospace: 0xFFE0,
  27301. centoldstyle: 0xF7A2,
  27302. centsuperior: 0xF6E0,
  27303. chaarmenian: 0x0579,
  27304. chabengali: 0x099B,
  27305. chadeva: 0x091B,
  27306. chagujarati: 0x0A9B,
  27307. chagurmukhi: 0x0A1B,
  27308. chbopomofo: 0x3114,
  27309. cheabkhasiancyrillic: 0x04BD,
  27310. checkmark: 0x2713,
  27311. checyrillic: 0x0447,
  27312. chedescenderabkhasiancyrillic: 0x04BF,
  27313. chedescendercyrillic: 0x04B7,
  27314. chedieresiscyrillic: 0x04F5,
  27315. cheharmenian: 0x0573,
  27316. chekhakassiancyrillic: 0x04CC,
  27317. cheverticalstrokecyrillic: 0x04B9,
  27318. chi: 0x03C7,
  27319. chieuchacirclekorean: 0x3277,
  27320. chieuchaparenkorean: 0x3217,
  27321. chieuchcirclekorean: 0x3269,
  27322. chieuchkorean: 0x314A,
  27323. chieuchparenkorean: 0x3209,
  27324. chochangthai: 0x0E0A,
  27325. chochanthai: 0x0E08,
  27326. chochingthai: 0x0E09,
  27327. chochoethai: 0x0E0C,
  27328. chook: 0x0188,
  27329. cieucacirclekorean: 0x3276,
  27330. cieucaparenkorean: 0x3216,
  27331. cieuccirclekorean: 0x3268,
  27332. cieuckorean: 0x3148,
  27333. cieucparenkorean: 0x3208,
  27334. cieucuparenkorean: 0x321C,
  27335. circle: 0x25CB,
  27336. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27337. circlemultiply: 0x2297,
  27338. circleot: 0x2299,
  27339. circleplus: 0x2295,
  27340. circlepostalmark: 0x3036,
  27341. circlewithlefthalfblack: 0x25D0,
  27342. circlewithrighthalfblack: 0x25D1,
  27343. circumflex: 0x02C6,
  27344. circumflexbelowcmb: 0x032D,
  27345. circumflexcmb: 0x0302,
  27346. clear: 0x2327,
  27347. clickalveolar: 0x01C2,
  27348. clickdental: 0x01C0,
  27349. clicklateral: 0x01C1,
  27350. clickretroflex: 0x01C3,
  27351. club: 0x2663,
  27352. clubsuitblack: 0x2663,
  27353. clubsuitwhite: 0x2667,
  27354. cmcubedsquare: 0x33A4,
  27355. cmonospace: 0xFF43,
  27356. cmsquaredsquare: 0x33A0,
  27357. coarmenian: 0x0581,
  27358. colon: 0x003A,
  27359. colonmonetary: 0x20A1,
  27360. colonmonospace: 0xFF1A,
  27361. colonsign: 0x20A1,
  27362. colonsmall: 0xFE55,
  27363. colontriangularhalfmod: 0x02D1,
  27364. colontriangularmod: 0x02D0,
  27365. comma: 0x002C,
  27366. commaabovecmb: 0x0313,
  27367. commaaboverightcmb: 0x0315,
  27368. commaaccent: 0xF6C3,
  27369. commaarabic: 0x060C,
  27370. commaarmenian: 0x055D,
  27371. commainferior: 0xF6E1,
  27372. commamonospace: 0xFF0C,
  27373. commareversedabovecmb: 0x0314,
  27374. commareversedmod: 0x02BD,
  27375. commasmall: 0xFE50,
  27376. commasuperior: 0xF6E2,
  27377. commaturnedabovecmb: 0x0312,
  27378. commaturnedmod: 0x02BB,
  27379. compass: 0x263C,
  27380. congruent: 0x2245,
  27381. contourintegral: 0x222E,
  27382. control: 0x2303,
  27383. controlACK: 0x0006,
  27384. controlBEL: 0x0007,
  27385. controlBS: 0x0008,
  27386. controlCAN: 0x0018,
  27387. controlCR: 0x000D,
  27388. controlDC1: 0x0011,
  27389. controlDC2: 0x0012,
  27390. controlDC3: 0x0013,
  27391. controlDC4: 0x0014,
  27392. controlDEL: 0x007F,
  27393. controlDLE: 0x0010,
  27394. controlEM: 0x0019,
  27395. controlENQ: 0x0005,
  27396. controlEOT: 0x0004,
  27397. controlESC: 0x001B,
  27398. controlETB: 0x0017,
  27399. controlETX: 0x0003,
  27400. controlFF: 0x000C,
  27401. controlFS: 0x001C,
  27402. controlGS: 0x001D,
  27403. controlHT: 0x0009,
  27404. controlLF: 0x000A,
  27405. controlNAK: 0x0015,
  27406. controlRS: 0x001E,
  27407. controlSI: 0x000F,
  27408. controlSO: 0x000E,
  27409. controlSOT: 0x0002,
  27410. controlSTX: 0x0001,
  27411. controlSUB: 0x001A,
  27412. controlSYN: 0x0016,
  27413. controlUS: 0x001F,
  27414. controlVT: 0x000B,
  27415. copyright: 0x00A9,
  27416. copyrightsans: 0xF8E9,
  27417. copyrightserif: 0xF6D9,
  27418. cornerbracketleft: 0x300C,
  27419. cornerbracketlefthalfwidth: 0xFF62,
  27420. cornerbracketleftvertical: 0xFE41,
  27421. cornerbracketright: 0x300D,
  27422. cornerbracketrighthalfwidth: 0xFF63,
  27423. cornerbracketrightvertical: 0xFE42,
  27424. corporationsquare: 0x337F,
  27425. cosquare: 0x33C7,
  27426. coverkgsquare: 0x33C6,
  27427. cparen: 0x249E,
  27428. cruzeiro: 0x20A2,
  27429. cstretched: 0x0297,
  27430. curlyand: 0x22CF,
  27431. curlyor: 0x22CE,
  27432. currency: 0x00A4,
  27433. cyrBreve: 0xF6D1,
  27434. cyrFlex: 0xF6D2,
  27435. cyrbreve: 0xF6D4,
  27436. cyrflex: 0xF6D5,
  27437. d: 0x0064,
  27438. daarmenian: 0x0564,
  27439. dabengali: 0x09A6,
  27440. dadarabic: 0x0636,
  27441. dadeva: 0x0926,
  27442. dadfinalarabic: 0xFEBE,
  27443. dadinitialarabic: 0xFEBF,
  27444. dadmedialarabic: 0xFEC0,
  27445. dagesh: 0x05BC,
  27446. dageshhebrew: 0x05BC,
  27447. dagger: 0x2020,
  27448. daggerdbl: 0x2021,
  27449. dagujarati: 0x0AA6,
  27450. dagurmukhi: 0x0A26,
  27451. dahiragana: 0x3060,
  27452. dakatakana: 0x30C0,
  27453. dalarabic: 0x062F,
  27454. dalet: 0x05D3,
  27455. daletdagesh: 0xFB33,
  27456. daletdageshhebrew: 0xFB33,
  27457. dalethebrew: 0x05D3,
  27458. dalfinalarabic: 0xFEAA,
  27459. dammaarabic: 0x064F,
  27460. dammalowarabic: 0x064F,
  27461. dammatanaltonearabic: 0x064C,
  27462. dammatanarabic: 0x064C,
  27463. danda: 0x0964,
  27464. dargahebrew: 0x05A7,
  27465. dargalefthebrew: 0x05A7,
  27466. dasiapneumatacyrilliccmb: 0x0485,
  27467. dblGrave: 0xF6D3,
  27468. dblanglebracketleft: 0x300A,
  27469. dblanglebracketleftvertical: 0xFE3D,
  27470. dblanglebracketright: 0x300B,
  27471. dblanglebracketrightvertical: 0xFE3E,
  27472. dblarchinvertedbelowcmb: 0x032B,
  27473. dblarrowleft: 0x21D4,
  27474. dblarrowright: 0x21D2,
  27475. dbldanda: 0x0965,
  27476. dblgrave: 0xF6D6,
  27477. dblgravecmb: 0x030F,
  27478. dblintegral: 0x222C,
  27479. dbllowline: 0x2017,
  27480. dbllowlinecmb: 0x0333,
  27481. dbloverlinecmb: 0x033F,
  27482. dblprimemod: 0x02BA,
  27483. dblverticalbar: 0x2016,
  27484. dblverticallineabovecmb: 0x030E,
  27485. dbopomofo: 0x3109,
  27486. dbsquare: 0x33C8,
  27487. dcaron: 0x010F,
  27488. dcedilla: 0x1E11,
  27489. dcircle: 0x24D3,
  27490. dcircumflexbelow: 0x1E13,
  27491. dcroat: 0x0111,
  27492. ddabengali: 0x09A1,
  27493. ddadeva: 0x0921,
  27494. ddagujarati: 0x0AA1,
  27495. ddagurmukhi: 0x0A21,
  27496. ddalarabic: 0x0688,
  27497. ddalfinalarabic: 0xFB89,
  27498. dddhadeva: 0x095C,
  27499. ddhabengali: 0x09A2,
  27500. ddhadeva: 0x0922,
  27501. ddhagujarati: 0x0AA2,
  27502. ddhagurmukhi: 0x0A22,
  27503. ddotaccent: 0x1E0B,
  27504. ddotbelow: 0x1E0D,
  27505. decimalseparatorarabic: 0x066B,
  27506. decimalseparatorpersian: 0x066B,
  27507. decyrillic: 0x0434,
  27508. degree: 0x00B0,
  27509. dehihebrew: 0x05AD,
  27510. dehiragana: 0x3067,
  27511. deicoptic: 0x03EF,
  27512. dekatakana: 0x30C7,
  27513. deleteleft: 0x232B,
  27514. deleteright: 0x2326,
  27515. delta: 0x03B4,
  27516. deltaturned: 0x018D,
  27517. denominatorminusonenumeratorbengali: 0x09F8,
  27518. dezh: 0x02A4,
  27519. dhabengali: 0x09A7,
  27520. dhadeva: 0x0927,
  27521. dhagujarati: 0x0AA7,
  27522. dhagurmukhi: 0x0A27,
  27523. dhook: 0x0257,
  27524. dialytikatonos: 0x0385,
  27525. dialytikatonoscmb: 0x0344,
  27526. diamond: 0x2666,
  27527. diamondsuitwhite: 0x2662,
  27528. dieresis: 0x00A8,
  27529. dieresisacute: 0xF6D7,
  27530. dieresisbelowcmb: 0x0324,
  27531. dieresiscmb: 0x0308,
  27532. dieresisgrave: 0xF6D8,
  27533. dieresistonos: 0x0385,
  27534. dihiragana: 0x3062,
  27535. dikatakana: 0x30C2,
  27536. dittomark: 0x3003,
  27537. divide: 0x00F7,
  27538. divides: 0x2223,
  27539. divisionslash: 0x2215,
  27540. djecyrillic: 0x0452,
  27541. dkshade: 0x2593,
  27542. dlinebelow: 0x1E0F,
  27543. dlsquare: 0x3397,
  27544. dmacron: 0x0111,
  27545. dmonospace: 0xFF44,
  27546. dnblock: 0x2584,
  27547. dochadathai: 0x0E0E,
  27548. dodekthai: 0x0E14,
  27549. dohiragana: 0x3069,
  27550. dokatakana: 0x30C9,
  27551. dollar: 0x0024,
  27552. dollarinferior: 0xF6E3,
  27553. dollarmonospace: 0xFF04,
  27554. dollaroldstyle: 0xF724,
  27555. dollarsmall: 0xFE69,
  27556. dollarsuperior: 0xF6E4,
  27557. dong: 0x20AB,
  27558. dorusquare: 0x3326,
  27559. dotaccent: 0x02D9,
  27560. dotaccentcmb: 0x0307,
  27561. dotbelowcmb: 0x0323,
  27562. dotbelowcomb: 0x0323,
  27563. dotkatakana: 0x30FB,
  27564. dotlessi: 0x0131,
  27565. dotlessj: 0xF6BE,
  27566. dotlessjstrokehook: 0x0284,
  27567. dotmath: 0x22C5,
  27568. dottedcircle: 0x25CC,
  27569. doubleyodpatah: 0xFB1F,
  27570. doubleyodpatahhebrew: 0xFB1F,
  27571. downtackbelowcmb: 0x031E,
  27572. downtackmod: 0x02D5,
  27573. dparen: 0x249F,
  27574. dsuperior: 0xF6EB,
  27575. dtail: 0x0256,
  27576. dtopbar: 0x018C,
  27577. duhiragana: 0x3065,
  27578. dukatakana: 0x30C5,
  27579. dz: 0x01F3,
  27580. dzaltone: 0x02A3,
  27581. dzcaron: 0x01C6,
  27582. dzcurl: 0x02A5,
  27583. dzeabkhasiancyrillic: 0x04E1,
  27584. dzecyrillic: 0x0455,
  27585. dzhecyrillic: 0x045F,
  27586. e: 0x0065,
  27587. eacute: 0x00E9,
  27588. earth: 0x2641,
  27589. ebengali: 0x098F,
  27590. ebopomofo: 0x311C,
  27591. ebreve: 0x0115,
  27592. ecandradeva: 0x090D,
  27593. ecandragujarati: 0x0A8D,
  27594. ecandravowelsigndeva: 0x0945,
  27595. ecandravowelsigngujarati: 0x0AC5,
  27596. ecaron: 0x011B,
  27597. ecedillabreve: 0x1E1D,
  27598. echarmenian: 0x0565,
  27599. echyiwnarmenian: 0x0587,
  27600. ecircle: 0x24D4,
  27601. ecircumflex: 0x00EA,
  27602. ecircumflexacute: 0x1EBF,
  27603. ecircumflexbelow: 0x1E19,
  27604. ecircumflexdotbelow: 0x1EC7,
  27605. ecircumflexgrave: 0x1EC1,
  27606. ecircumflexhookabove: 0x1EC3,
  27607. ecircumflextilde: 0x1EC5,
  27608. ecyrillic: 0x0454,
  27609. edblgrave: 0x0205,
  27610. edeva: 0x090F,
  27611. edieresis: 0x00EB,
  27612. edot: 0x0117,
  27613. edotaccent: 0x0117,
  27614. edotbelow: 0x1EB9,
  27615. eegurmukhi: 0x0A0F,
  27616. eematragurmukhi: 0x0A47,
  27617. efcyrillic: 0x0444,
  27618. egrave: 0x00E8,
  27619. egujarati: 0x0A8F,
  27620. eharmenian: 0x0567,
  27621. ehbopomofo: 0x311D,
  27622. ehiragana: 0x3048,
  27623. ehookabove: 0x1EBB,
  27624. eibopomofo: 0x311F,
  27625. eight: 0x0038,
  27626. eightarabic: 0x0668,
  27627. eightbengali: 0x09EE,
  27628. eightcircle: 0x2467,
  27629. eightcircleinversesansserif: 0x2791,
  27630. eightdeva: 0x096E,
  27631. eighteencircle: 0x2471,
  27632. eighteenparen: 0x2485,
  27633. eighteenperiod: 0x2499,
  27634. eightgujarati: 0x0AEE,
  27635. eightgurmukhi: 0x0A6E,
  27636. eighthackarabic: 0x0668,
  27637. eighthangzhou: 0x3028,
  27638. eighthnotebeamed: 0x266B,
  27639. eightideographicparen: 0x3227,
  27640. eightinferior: 0x2088,
  27641. eightmonospace: 0xFF18,
  27642. eightoldstyle: 0xF738,
  27643. eightparen: 0x247B,
  27644. eightperiod: 0x248F,
  27645. eightpersian: 0x06F8,
  27646. eightroman: 0x2177,
  27647. eightsuperior: 0x2078,
  27648. eightthai: 0x0E58,
  27649. einvertedbreve: 0x0207,
  27650. eiotifiedcyrillic: 0x0465,
  27651. ekatakana: 0x30A8,
  27652. ekatakanahalfwidth: 0xFF74,
  27653. ekonkargurmukhi: 0x0A74,
  27654. ekorean: 0x3154,
  27655. elcyrillic: 0x043B,
  27656. element: 0x2208,
  27657. elevencircle: 0x246A,
  27658. elevenparen: 0x247E,
  27659. elevenperiod: 0x2492,
  27660. elevenroman: 0x217A,
  27661. ellipsis: 0x2026,
  27662. ellipsisvertical: 0x22EE,
  27663. emacron: 0x0113,
  27664. emacronacute: 0x1E17,
  27665. emacrongrave: 0x1E15,
  27666. emcyrillic: 0x043C,
  27667. emdash: 0x2014,
  27668. emdashvertical: 0xFE31,
  27669. emonospace: 0xFF45,
  27670. emphasismarkarmenian: 0x055B,
  27671. emptyset: 0x2205,
  27672. enbopomofo: 0x3123,
  27673. encyrillic: 0x043D,
  27674. endash: 0x2013,
  27675. endashvertical: 0xFE32,
  27676. endescendercyrillic: 0x04A3,
  27677. eng: 0x014B,
  27678. engbopomofo: 0x3125,
  27679. enghecyrillic: 0x04A5,
  27680. enhookcyrillic: 0x04C8,
  27681. enspace: 0x2002,
  27682. eogonek: 0x0119,
  27683. eokorean: 0x3153,
  27684. eopen: 0x025B,
  27685. eopenclosed: 0x029A,
  27686. eopenreversed: 0x025C,
  27687. eopenreversedclosed: 0x025E,
  27688. eopenreversedhook: 0x025D,
  27689. eparen: 0x24A0,
  27690. epsilon: 0x03B5,
  27691. epsilontonos: 0x03AD,
  27692. equal: 0x003D,
  27693. equalmonospace: 0xFF1D,
  27694. equalsmall: 0xFE66,
  27695. equalsuperior: 0x207C,
  27696. equivalence: 0x2261,
  27697. erbopomofo: 0x3126,
  27698. ercyrillic: 0x0440,
  27699. ereversed: 0x0258,
  27700. ereversedcyrillic: 0x044D,
  27701. escyrillic: 0x0441,
  27702. esdescendercyrillic: 0x04AB,
  27703. esh: 0x0283,
  27704. eshcurl: 0x0286,
  27705. eshortdeva: 0x090E,
  27706. eshortvowelsigndeva: 0x0946,
  27707. eshreversedloop: 0x01AA,
  27708. eshsquatreversed: 0x0285,
  27709. esmallhiragana: 0x3047,
  27710. esmallkatakana: 0x30A7,
  27711. esmallkatakanahalfwidth: 0xFF6A,
  27712. estimated: 0x212E,
  27713. esuperior: 0xF6EC,
  27714. eta: 0x03B7,
  27715. etarmenian: 0x0568,
  27716. etatonos: 0x03AE,
  27717. eth: 0x00F0,
  27718. etilde: 0x1EBD,
  27719. etildebelow: 0x1E1B,
  27720. etnahtafoukhhebrew: 0x0591,
  27721. etnahtafoukhlefthebrew: 0x0591,
  27722. etnahtahebrew: 0x0591,
  27723. etnahtalefthebrew: 0x0591,
  27724. eturned: 0x01DD,
  27725. eukorean: 0x3161,
  27726. euro: 0x20AC,
  27727. evowelsignbengali: 0x09C7,
  27728. evowelsigndeva: 0x0947,
  27729. evowelsigngujarati: 0x0AC7,
  27730. exclam: 0x0021,
  27731. exclamarmenian: 0x055C,
  27732. exclamdbl: 0x203C,
  27733. exclamdown: 0x00A1,
  27734. exclamdownsmall: 0xF7A1,
  27735. exclammonospace: 0xFF01,
  27736. exclamsmall: 0xF721,
  27737. existential: 0x2203,
  27738. ezh: 0x0292,
  27739. ezhcaron: 0x01EF,
  27740. ezhcurl: 0x0293,
  27741. ezhreversed: 0x01B9,
  27742. ezhtail: 0x01BA,
  27743. f: 0x0066,
  27744. fadeva: 0x095E,
  27745. fagurmukhi: 0x0A5E,
  27746. fahrenheit: 0x2109,
  27747. fathaarabic: 0x064E,
  27748. fathalowarabic: 0x064E,
  27749. fathatanarabic: 0x064B,
  27750. fbopomofo: 0x3108,
  27751. fcircle: 0x24D5,
  27752. fdotaccent: 0x1E1F,
  27753. feharabic: 0x0641,
  27754. feharmenian: 0x0586,
  27755. fehfinalarabic: 0xFED2,
  27756. fehinitialarabic: 0xFED3,
  27757. fehmedialarabic: 0xFED4,
  27758. feicoptic: 0x03E5,
  27759. female: 0x2640,
  27760. ff: 0xFB00,
  27761. ffi: 0xFB03,
  27762. ffl: 0xFB04,
  27763. fi: 0xFB01,
  27764. fifteencircle: 0x246E,
  27765. fifteenparen: 0x2482,
  27766. fifteenperiod: 0x2496,
  27767. figuredash: 0x2012,
  27768. filledbox: 0x25A0,
  27769. filledrect: 0x25AC,
  27770. finalkaf: 0x05DA,
  27771. finalkafdagesh: 0xFB3A,
  27772. finalkafdageshhebrew: 0xFB3A,
  27773. finalkafhebrew: 0x05DA,
  27774. finalmem: 0x05DD,
  27775. finalmemhebrew: 0x05DD,
  27776. finalnun: 0x05DF,
  27777. finalnunhebrew: 0x05DF,
  27778. finalpe: 0x05E3,
  27779. finalpehebrew: 0x05E3,
  27780. finaltsadi: 0x05E5,
  27781. finaltsadihebrew: 0x05E5,
  27782. firsttonechinese: 0x02C9,
  27783. fisheye: 0x25C9,
  27784. fitacyrillic: 0x0473,
  27785. five: 0x0035,
  27786. fivearabic: 0x0665,
  27787. fivebengali: 0x09EB,
  27788. fivecircle: 0x2464,
  27789. fivecircleinversesansserif: 0x278E,
  27790. fivedeva: 0x096B,
  27791. fiveeighths: 0x215D,
  27792. fivegujarati: 0x0AEB,
  27793. fivegurmukhi: 0x0A6B,
  27794. fivehackarabic: 0x0665,
  27795. fivehangzhou: 0x3025,
  27796. fiveideographicparen: 0x3224,
  27797. fiveinferior: 0x2085,
  27798. fivemonospace: 0xFF15,
  27799. fiveoldstyle: 0xF735,
  27800. fiveparen: 0x2478,
  27801. fiveperiod: 0x248C,
  27802. fivepersian: 0x06F5,
  27803. fiveroman: 0x2174,
  27804. fivesuperior: 0x2075,
  27805. fivethai: 0x0E55,
  27806. fl: 0xFB02,
  27807. florin: 0x0192,
  27808. fmonospace: 0xFF46,
  27809. fmsquare: 0x3399,
  27810. fofanthai: 0x0E1F,
  27811. fofathai: 0x0E1D,
  27812. fongmanthai: 0x0E4F,
  27813. forall: 0x2200,
  27814. four: 0x0034,
  27815. fourarabic: 0x0664,
  27816. fourbengali: 0x09EA,
  27817. fourcircle: 0x2463,
  27818. fourcircleinversesansserif: 0x278D,
  27819. fourdeva: 0x096A,
  27820. fourgujarati: 0x0AEA,
  27821. fourgurmukhi: 0x0A6A,
  27822. fourhackarabic: 0x0664,
  27823. fourhangzhou: 0x3024,
  27824. fourideographicparen: 0x3223,
  27825. fourinferior: 0x2084,
  27826. fourmonospace: 0xFF14,
  27827. fournumeratorbengali: 0x09F7,
  27828. fouroldstyle: 0xF734,
  27829. fourparen: 0x2477,
  27830. fourperiod: 0x248B,
  27831. fourpersian: 0x06F4,
  27832. fourroman: 0x2173,
  27833. foursuperior: 0x2074,
  27834. fourteencircle: 0x246D,
  27835. fourteenparen: 0x2481,
  27836. fourteenperiod: 0x2495,
  27837. fourthai: 0x0E54,
  27838. fourthtonechinese: 0x02CB,
  27839. fparen: 0x24A1,
  27840. fraction: 0x2044,
  27841. franc: 0x20A3,
  27842. g: 0x0067,
  27843. gabengali: 0x0997,
  27844. gacute: 0x01F5,
  27845. gadeva: 0x0917,
  27846. gafarabic: 0x06AF,
  27847. gaffinalarabic: 0xFB93,
  27848. gafinitialarabic: 0xFB94,
  27849. gafmedialarabic: 0xFB95,
  27850. gagujarati: 0x0A97,
  27851. gagurmukhi: 0x0A17,
  27852. gahiragana: 0x304C,
  27853. gakatakana: 0x30AC,
  27854. gamma: 0x03B3,
  27855. gammalatinsmall: 0x0263,
  27856. gammasuperior: 0x02E0,
  27857. gangiacoptic: 0x03EB,
  27858. gbopomofo: 0x310D,
  27859. gbreve: 0x011F,
  27860. gcaron: 0x01E7,
  27861. gcedilla: 0x0123,
  27862. gcircle: 0x24D6,
  27863. gcircumflex: 0x011D,
  27864. gcommaaccent: 0x0123,
  27865. gdot: 0x0121,
  27866. gdotaccent: 0x0121,
  27867. gecyrillic: 0x0433,
  27868. gehiragana: 0x3052,
  27869. gekatakana: 0x30B2,
  27870. geometricallyequal: 0x2251,
  27871. gereshaccenthebrew: 0x059C,
  27872. gereshhebrew: 0x05F3,
  27873. gereshmuqdamhebrew: 0x059D,
  27874. germandbls: 0x00DF,
  27875. gershayimaccenthebrew: 0x059E,
  27876. gershayimhebrew: 0x05F4,
  27877. getamark: 0x3013,
  27878. ghabengali: 0x0998,
  27879. ghadarmenian: 0x0572,
  27880. ghadeva: 0x0918,
  27881. ghagujarati: 0x0A98,
  27882. ghagurmukhi: 0x0A18,
  27883. ghainarabic: 0x063A,
  27884. ghainfinalarabic: 0xFECE,
  27885. ghaininitialarabic: 0xFECF,
  27886. ghainmedialarabic: 0xFED0,
  27887. ghemiddlehookcyrillic: 0x0495,
  27888. ghestrokecyrillic: 0x0493,
  27889. gheupturncyrillic: 0x0491,
  27890. ghhadeva: 0x095A,
  27891. ghhagurmukhi: 0x0A5A,
  27892. ghook: 0x0260,
  27893. ghzsquare: 0x3393,
  27894. gihiragana: 0x304E,
  27895. gikatakana: 0x30AE,
  27896. gimarmenian: 0x0563,
  27897. gimel: 0x05D2,
  27898. gimeldagesh: 0xFB32,
  27899. gimeldageshhebrew: 0xFB32,
  27900. gimelhebrew: 0x05D2,
  27901. gjecyrillic: 0x0453,
  27902. glottalinvertedstroke: 0x01BE,
  27903. glottalstop: 0x0294,
  27904. glottalstopinverted: 0x0296,
  27905. glottalstopmod: 0x02C0,
  27906. glottalstopreversed: 0x0295,
  27907. glottalstopreversedmod: 0x02C1,
  27908. glottalstopreversedsuperior: 0x02E4,
  27909. glottalstopstroke: 0x02A1,
  27910. glottalstopstrokereversed: 0x02A2,
  27911. gmacron: 0x1E21,
  27912. gmonospace: 0xFF47,
  27913. gohiragana: 0x3054,
  27914. gokatakana: 0x30B4,
  27915. gparen: 0x24A2,
  27916. gpasquare: 0x33AC,
  27917. gradient: 0x2207,
  27918. grave: 0x0060,
  27919. gravebelowcmb: 0x0316,
  27920. gravecmb: 0x0300,
  27921. gravecomb: 0x0300,
  27922. gravedeva: 0x0953,
  27923. gravelowmod: 0x02CE,
  27924. gravemonospace: 0xFF40,
  27925. gravetonecmb: 0x0340,
  27926. greater: 0x003E,
  27927. greaterequal: 0x2265,
  27928. greaterequalorless: 0x22DB,
  27929. greatermonospace: 0xFF1E,
  27930. greaterorequivalent: 0x2273,
  27931. greaterorless: 0x2277,
  27932. greateroverequal: 0x2267,
  27933. greatersmall: 0xFE65,
  27934. gscript: 0x0261,
  27935. gstroke: 0x01E5,
  27936. guhiragana: 0x3050,
  27937. guillemotleft: 0x00AB,
  27938. guillemotright: 0x00BB,
  27939. guilsinglleft: 0x2039,
  27940. guilsinglright: 0x203A,
  27941. gukatakana: 0x30B0,
  27942. guramusquare: 0x3318,
  27943. gysquare: 0x33C9,
  27944. h: 0x0068,
  27945. haabkhasiancyrillic: 0x04A9,
  27946. haaltonearabic: 0x06C1,
  27947. habengali: 0x09B9,
  27948. hadescendercyrillic: 0x04B3,
  27949. hadeva: 0x0939,
  27950. hagujarati: 0x0AB9,
  27951. hagurmukhi: 0x0A39,
  27952. haharabic: 0x062D,
  27953. hahfinalarabic: 0xFEA2,
  27954. hahinitialarabic: 0xFEA3,
  27955. hahiragana: 0x306F,
  27956. hahmedialarabic: 0xFEA4,
  27957. haitusquare: 0x332A,
  27958. hakatakana: 0x30CF,
  27959. hakatakanahalfwidth: 0xFF8A,
  27960. halantgurmukhi: 0x0A4D,
  27961. hamzaarabic: 0x0621,
  27962. hamzalowarabic: 0x0621,
  27963. hangulfiller: 0x3164,
  27964. hardsigncyrillic: 0x044A,
  27965. harpoonleftbarbup: 0x21BC,
  27966. harpoonrightbarbup: 0x21C0,
  27967. hasquare: 0x33CA,
  27968. hatafpatah: 0x05B2,
  27969. hatafpatah16: 0x05B2,
  27970. hatafpatah23: 0x05B2,
  27971. hatafpatah2f: 0x05B2,
  27972. hatafpatahhebrew: 0x05B2,
  27973. hatafpatahnarrowhebrew: 0x05B2,
  27974. hatafpatahquarterhebrew: 0x05B2,
  27975. hatafpatahwidehebrew: 0x05B2,
  27976. hatafqamats: 0x05B3,
  27977. hatafqamats1b: 0x05B3,
  27978. hatafqamats28: 0x05B3,
  27979. hatafqamats34: 0x05B3,
  27980. hatafqamatshebrew: 0x05B3,
  27981. hatafqamatsnarrowhebrew: 0x05B3,
  27982. hatafqamatsquarterhebrew: 0x05B3,
  27983. hatafqamatswidehebrew: 0x05B3,
  27984. hatafsegol: 0x05B1,
  27985. hatafsegol17: 0x05B1,
  27986. hatafsegol24: 0x05B1,
  27987. hatafsegol30: 0x05B1,
  27988. hatafsegolhebrew: 0x05B1,
  27989. hatafsegolnarrowhebrew: 0x05B1,
  27990. hatafsegolquarterhebrew: 0x05B1,
  27991. hatafsegolwidehebrew: 0x05B1,
  27992. hbar: 0x0127,
  27993. hbopomofo: 0x310F,
  27994. hbrevebelow: 0x1E2B,
  27995. hcedilla: 0x1E29,
  27996. hcircle: 0x24D7,
  27997. hcircumflex: 0x0125,
  27998. hdieresis: 0x1E27,
  27999. hdotaccent: 0x1E23,
  28000. hdotbelow: 0x1E25,
  28001. he: 0x05D4,
  28002. heart: 0x2665,
  28003. heartsuitblack: 0x2665,
  28004. heartsuitwhite: 0x2661,
  28005. hedagesh: 0xFB34,
  28006. hedageshhebrew: 0xFB34,
  28007. hehaltonearabic: 0x06C1,
  28008. heharabic: 0x0647,
  28009. hehebrew: 0x05D4,
  28010. hehfinalaltonearabic: 0xFBA7,
  28011. hehfinalalttwoarabic: 0xFEEA,
  28012. hehfinalarabic: 0xFEEA,
  28013. hehhamzaabovefinalarabic: 0xFBA5,
  28014. hehhamzaaboveisolatedarabic: 0xFBA4,
  28015. hehinitialaltonearabic: 0xFBA8,
  28016. hehinitialarabic: 0xFEEB,
  28017. hehiragana: 0x3078,
  28018. hehmedialaltonearabic: 0xFBA9,
  28019. hehmedialarabic: 0xFEEC,
  28020. heiseierasquare: 0x337B,
  28021. hekatakana: 0x30D8,
  28022. hekatakanahalfwidth: 0xFF8D,
  28023. hekutaarusquare: 0x3336,
  28024. henghook: 0x0267,
  28025. herutusquare: 0x3339,
  28026. het: 0x05D7,
  28027. hethebrew: 0x05D7,
  28028. hhook: 0x0266,
  28029. hhooksuperior: 0x02B1,
  28030. hieuhacirclekorean: 0x327B,
  28031. hieuhaparenkorean: 0x321B,
  28032. hieuhcirclekorean: 0x326D,
  28033. hieuhkorean: 0x314E,
  28034. hieuhparenkorean: 0x320D,
  28035. hihiragana: 0x3072,
  28036. hikatakana: 0x30D2,
  28037. hikatakanahalfwidth: 0xFF8B,
  28038. hiriq: 0x05B4,
  28039. hiriq14: 0x05B4,
  28040. hiriq21: 0x05B4,
  28041. hiriq2d: 0x05B4,
  28042. hiriqhebrew: 0x05B4,
  28043. hiriqnarrowhebrew: 0x05B4,
  28044. hiriqquarterhebrew: 0x05B4,
  28045. hiriqwidehebrew: 0x05B4,
  28046. hlinebelow: 0x1E96,
  28047. hmonospace: 0xFF48,
  28048. hoarmenian: 0x0570,
  28049. hohipthai: 0x0E2B,
  28050. hohiragana: 0x307B,
  28051. hokatakana: 0x30DB,
  28052. hokatakanahalfwidth: 0xFF8E,
  28053. holam: 0x05B9,
  28054. holam19: 0x05B9,
  28055. holam26: 0x05B9,
  28056. holam32: 0x05B9,
  28057. holamhebrew: 0x05B9,
  28058. holamnarrowhebrew: 0x05B9,
  28059. holamquarterhebrew: 0x05B9,
  28060. holamwidehebrew: 0x05B9,
  28061. honokhukthai: 0x0E2E,
  28062. hookabovecomb: 0x0309,
  28063. hookcmb: 0x0309,
  28064. hookpalatalizedbelowcmb: 0x0321,
  28065. hookretroflexbelowcmb: 0x0322,
  28066. hoonsquare: 0x3342,
  28067. horicoptic: 0x03E9,
  28068. horizontalbar: 0x2015,
  28069. horncmb: 0x031B,
  28070. hotsprings: 0x2668,
  28071. house: 0x2302,
  28072. hparen: 0x24A3,
  28073. hsuperior: 0x02B0,
  28074. hturned: 0x0265,
  28075. huhiragana: 0x3075,
  28076. huiitosquare: 0x3333,
  28077. hukatakana: 0x30D5,
  28078. hukatakanahalfwidth: 0xFF8C,
  28079. hungarumlaut: 0x02DD,
  28080. hungarumlautcmb: 0x030B,
  28081. hv: 0x0195,
  28082. hyphen: 0x002D,
  28083. hypheninferior: 0xF6E5,
  28084. hyphenmonospace: 0xFF0D,
  28085. hyphensmall: 0xFE63,
  28086. hyphensuperior: 0xF6E6,
  28087. hyphentwo: 0x2010,
  28088. i: 0x0069,
  28089. iacute: 0x00ED,
  28090. iacyrillic: 0x044F,
  28091. ibengali: 0x0987,
  28092. ibopomofo: 0x3127,
  28093. ibreve: 0x012D,
  28094. icaron: 0x01D0,
  28095. icircle: 0x24D8,
  28096. icircumflex: 0x00EE,
  28097. icyrillic: 0x0456,
  28098. idblgrave: 0x0209,
  28099. ideographearthcircle: 0x328F,
  28100. ideographfirecircle: 0x328B,
  28101. ideographicallianceparen: 0x323F,
  28102. ideographiccallparen: 0x323A,
  28103. ideographiccentrecircle: 0x32A5,
  28104. ideographicclose: 0x3006,
  28105. ideographiccomma: 0x3001,
  28106. ideographiccommaleft: 0xFF64,
  28107. ideographiccongratulationparen: 0x3237,
  28108. ideographiccorrectcircle: 0x32A3,
  28109. ideographicearthparen: 0x322F,
  28110. ideographicenterpriseparen: 0x323D,
  28111. ideographicexcellentcircle: 0x329D,
  28112. ideographicfestivalparen: 0x3240,
  28113. ideographicfinancialcircle: 0x3296,
  28114. ideographicfinancialparen: 0x3236,
  28115. ideographicfireparen: 0x322B,
  28116. ideographichaveparen: 0x3232,
  28117. ideographichighcircle: 0x32A4,
  28118. ideographiciterationmark: 0x3005,
  28119. ideographiclaborcircle: 0x3298,
  28120. ideographiclaborparen: 0x3238,
  28121. ideographicleftcircle: 0x32A7,
  28122. ideographiclowcircle: 0x32A6,
  28123. ideographicmedicinecircle: 0x32A9,
  28124. ideographicmetalparen: 0x322E,
  28125. ideographicmoonparen: 0x322A,
  28126. ideographicnameparen: 0x3234,
  28127. ideographicperiod: 0x3002,
  28128. ideographicprintcircle: 0x329E,
  28129. ideographicreachparen: 0x3243,
  28130. ideographicrepresentparen: 0x3239,
  28131. ideographicresourceparen: 0x323E,
  28132. ideographicrightcircle: 0x32A8,
  28133. ideographicsecretcircle: 0x3299,
  28134. ideographicselfparen: 0x3242,
  28135. ideographicsocietyparen: 0x3233,
  28136. ideographicspace: 0x3000,
  28137. ideographicspecialparen: 0x3235,
  28138. ideographicstockparen: 0x3231,
  28139. ideographicstudyparen: 0x323B,
  28140. ideographicsunparen: 0x3230,
  28141. ideographicsuperviseparen: 0x323C,
  28142. ideographicwaterparen: 0x322C,
  28143. ideographicwoodparen: 0x322D,
  28144. ideographiczero: 0x3007,
  28145. ideographmetalcircle: 0x328E,
  28146. ideographmooncircle: 0x328A,
  28147. ideographnamecircle: 0x3294,
  28148. ideographsuncircle: 0x3290,
  28149. ideographwatercircle: 0x328C,
  28150. ideographwoodcircle: 0x328D,
  28151. ideva: 0x0907,
  28152. idieresis: 0x00EF,
  28153. idieresisacute: 0x1E2F,
  28154. idieresiscyrillic: 0x04E5,
  28155. idotbelow: 0x1ECB,
  28156. iebrevecyrillic: 0x04D7,
  28157. iecyrillic: 0x0435,
  28158. ieungacirclekorean: 0x3275,
  28159. ieungaparenkorean: 0x3215,
  28160. ieungcirclekorean: 0x3267,
  28161. ieungkorean: 0x3147,
  28162. ieungparenkorean: 0x3207,
  28163. igrave: 0x00EC,
  28164. igujarati: 0x0A87,
  28165. igurmukhi: 0x0A07,
  28166. ihiragana: 0x3044,
  28167. ihookabove: 0x1EC9,
  28168. iibengali: 0x0988,
  28169. iicyrillic: 0x0438,
  28170. iideva: 0x0908,
  28171. iigujarati: 0x0A88,
  28172. iigurmukhi: 0x0A08,
  28173. iimatragurmukhi: 0x0A40,
  28174. iinvertedbreve: 0x020B,
  28175. iishortcyrillic: 0x0439,
  28176. iivowelsignbengali: 0x09C0,
  28177. iivowelsigndeva: 0x0940,
  28178. iivowelsigngujarati: 0x0AC0,
  28179. ij: 0x0133,
  28180. ikatakana: 0x30A4,
  28181. ikatakanahalfwidth: 0xFF72,
  28182. ikorean: 0x3163,
  28183. ilde: 0x02DC,
  28184. iluyhebrew: 0x05AC,
  28185. imacron: 0x012B,
  28186. imacroncyrillic: 0x04E3,
  28187. imageorapproximatelyequal: 0x2253,
  28188. imatragurmukhi: 0x0A3F,
  28189. imonospace: 0xFF49,
  28190. increment: 0x2206,
  28191. infinity: 0x221E,
  28192. iniarmenian: 0x056B,
  28193. integral: 0x222B,
  28194. integralbottom: 0x2321,
  28195. integralbt: 0x2321,
  28196. integralex: 0xF8F5,
  28197. integraltop: 0x2320,
  28198. integraltp: 0x2320,
  28199. intersection: 0x2229,
  28200. intisquare: 0x3305,
  28201. invbullet: 0x25D8,
  28202. invcircle: 0x25D9,
  28203. invsmileface: 0x263B,
  28204. iocyrillic: 0x0451,
  28205. iogonek: 0x012F,
  28206. iota: 0x03B9,
  28207. iotadieresis: 0x03CA,
  28208. iotadieresistonos: 0x0390,
  28209. iotalatin: 0x0269,
  28210. iotatonos: 0x03AF,
  28211. iparen: 0x24A4,
  28212. irigurmukhi: 0x0A72,
  28213. ismallhiragana: 0x3043,
  28214. ismallkatakana: 0x30A3,
  28215. ismallkatakanahalfwidth: 0xFF68,
  28216. issharbengali: 0x09FA,
  28217. istroke: 0x0268,
  28218. isuperior: 0xF6ED,
  28219. iterationhiragana: 0x309D,
  28220. iterationkatakana: 0x30FD,
  28221. itilde: 0x0129,
  28222. itildebelow: 0x1E2D,
  28223. iubopomofo: 0x3129,
  28224. iucyrillic: 0x044E,
  28225. ivowelsignbengali: 0x09BF,
  28226. ivowelsigndeva: 0x093F,
  28227. ivowelsigngujarati: 0x0ABF,
  28228. izhitsacyrillic: 0x0475,
  28229. izhitsadblgravecyrillic: 0x0477,
  28230. j: 0x006A,
  28231. jaarmenian: 0x0571,
  28232. jabengali: 0x099C,
  28233. jadeva: 0x091C,
  28234. jagujarati: 0x0A9C,
  28235. jagurmukhi: 0x0A1C,
  28236. jbopomofo: 0x3110,
  28237. jcaron: 0x01F0,
  28238. jcircle: 0x24D9,
  28239. jcircumflex: 0x0135,
  28240. jcrossedtail: 0x029D,
  28241. jdotlessstroke: 0x025F,
  28242. jecyrillic: 0x0458,
  28243. jeemarabic: 0x062C,
  28244. jeemfinalarabic: 0xFE9E,
  28245. jeeminitialarabic: 0xFE9F,
  28246. jeemmedialarabic: 0xFEA0,
  28247. jeharabic: 0x0698,
  28248. jehfinalarabic: 0xFB8B,
  28249. jhabengali: 0x099D,
  28250. jhadeva: 0x091D,
  28251. jhagujarati: 0x0A9D,
  28252. jhagurmukhi: 0x0A1D,
  28253. jheharmenian: 0x057B,
  28254. jis: 0x3004,
  28255. jmonospace: 0xFF4A,
  28256. jparen: 0x24A5,
  28257. jsuperior: 0x02B2,
  28258. k: 0x006B,
  28259. kabashkircyrillic: 0x04A1,
  28260. kabengali: 0x0995,
  28261. kacute: 0x1E31,
  28262. kacyrillic: 0x043A,
  28263. kadescendercyrillic: 0x049B,
  28264. kadeva: 0x0915,
  28265. kaf: 0x05DB,
  28266. kafarabic: 0x0643,
  28267. kafdagesh: 0xFB3B,
  28268. kafdageshhebrew: 0xFB3B,
  28269. kaffinalarabic: 0xFEDA,
  28270. kafhebrew: 0x05DB,
  28271. kafinitialarabic: 0xFEDB,
  28272. kafmedialarabic: 0xFEDC,
  28273. kafrafehebrew: 0xFB4D,
  28274. kagujarati: 0x0A95,
  28275. kagurmukhi: 0x0A15,
  28276. kahiragana: 0x304B,
  28277. kahookcyrillic: 0x04C4,
  28278. kakatakana: 0x30AB,
  28279. kakatakanahalfwidth: 0xFF76,
  28280. kappa: 0x03BA,
  28281. kappasymbolgreek: 0x03F0,
  28282. kapyeounmieumkorean: 0x3171,
  28283. kapyeounphieuphkorean: 0x3184,
  28284. kapyeounpieupkorean: 0x3178,
  28285. kapyeounssangpieupkorean: 0x3179,
  28286. karoriisquare: 0x330D,
  28287. kashidaautoarabic: 0x0640,
  28288. kashidaautonosidebearingarabic: 0x0640,
  28289. kasmallkatakana: 0x30F5,
  28290. kasquare: 0x3384,
  28291. kasraarabic: 0x0650,
  28292. kasratanarabic: 0x064D,
  28293. kastrokecyrillic: 0x049F,
  28294. katahiraprolongmarkhalfwidth: 0xFF70,
  28295. kaverticalstrokecyrillic: 0x049D,
  28296. kbopomofo: 0x310E,
  28297. kcalsquare: 0x3389,
  28298. kcaron: 0x01E9,
  28299. kcedilla: 0x0137,
  28300. kcircle: 0x24DA,
  28301. kcommaaccent: 0x0137,
  28302. kdotbelow: 0x1E33,
  28303. keharmenian: 0x0584,
  28304. kehiragana: 0x3051,
  28305. kekatakana: 0x30B1,
  28306. kekatakanahalfwidth: 0xFF79,
  28307. kenarmenian: 0x056F,
  28308. kesmallkatakana: 0x30F6,
  28309. kgreenlandic: 0x0138,
  28310. khabengali: 0x0996,
  28311. khacyrillic: 0x0445,
  28312. khadeva: 0x0916,
  28313. khagujarati: 0x0A96,
  28314. khagurmukhi: 0x0A16,
  28315. khaharabic: 0x062E,
  28316. khahfinalarabic: 0xFEA6,
  28317. khahinitialarabic: 0xFEA7,
  28318. khahmedialarabic: 0xFEA8,
  28319. kheicoptic: 0x03E7,
  28320. khhadeva: 0x0959,
  28321. khhagurmukhi: 0x0A59,
  28322. khieukhacirclekorean: 0x3278,
  28323. khieukhaparenkorean: 0x3218,
  28324. khieukhcirclekorean: 0x326A,
  28325. khieukhkorean: 0x314B,
  28326. khieukhparenkorean: 0x320A,
  28327. khokhaithai: 0x0E02,
  28328. khokhonthai: 0x0E05,
  28329. khokhuatthai: 0x0E03,
  28330. khokhwaithai: 0x0E04,
  28331. khomutthai: 0x0E5B,
  28332. khook: 0x0199,
  28333. khorakhangthai: 0x0E06,
  28334. khzsquare: 0x3391,
  28335. kihiragana: 0x304D,
  28336. kikatakana: 0x30AD,
  28337. kikatakanahalfwidth: 0xFF77,
  28338. kiroguramusquare: 0x3315,
  28339. kiromeetorusquare: 0x3316,
  28340. kirosquare: 0x3314,
  28341. kiyeokacirclekorean: 0x326E,
  28342. kiyeokaparenkorean: 0x320E,
  28343. kiyeokcirclekorean: 0x3260,
  28344. kiyeokkorean: 0x3131,
  28345. kiyeokparenkorean: 0x3200,
  28346. kiyeoksioskorean: 0x3133,
  28347. kjecyrillic: 0x045C,
  28348. klinebelow: 0x1E35,
  28349. klsquare: 0x3398,
  28350. kmcubedsquare: 0x33A6,
  28351. kmonospace: 0xFF4B,
  28352. kmsquaredsquare: 0x33A2,
  28353. kohiragana: 0x3053,
  28354. kohmsquare: 0x33C0,
  28355. kokaithai: 0x0E01,
  28356. kokatakana: 0x30B3,
  28357. kokatakanahalfwidth: 0xFF7A,
  28358. kooposquare: 0x331E,
  28359. koppacyrillic: 0x0481,
  28360. koreanstandardsymbol: 0x327F,
  28361. koroniscmb: 0x0343,
  28362. kparen: 0x24A6,
  28363. kpasquare: 0x33AA,
  28364. ksicyrillic: 0x046F,
  28365. ktsquare: 0x33CF,
  28366. kturned: 0x029E,
  28367. kuhiragana: 0x304F,
  28368. kukatakana: 0x30AF,
  28369. kukatakanahalfwidth: 0xFF78,
  28370. kvsquare: 0x33B8,
  28371. kwsquare: 0x33BE,
  28372. l: 0x006C,
  28373. labengali: 0x09B2,
  28374. lacute: 0x013A,
  28375. ladeva: 0x0932,
  28376. lagujarati: 0x0AB2,
  28377. lagurmukhi: 0x0A32,
  28378. lakkhangyaothai: 0x0E45,
  28379. lamaleffinalarabic: 0xFEFC,
  28380. lamalefhamzaabovefinalarabic: 0xFEF8,
  28381. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28382. lamalefhamzabelowfinalarabic: 0xFEFA,
  28383. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28384. lamalefisolatedarabic: 0xFEFB,
  28385. lamalefmaddaabovefinalarabic: 0xFEF6,
  28386. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28387. lamarabic: 0x0644,
  28388. lambda: 0x03BB,
  28389. lambdastroke: 0x019B,
  28390. lamed: 0x05DC,
  28391. lameddagesh: 0xFB3C,
  28392. lameddageshhebrew: 0xFB3C,
  28393. lamedhebrew: 0x05DC,
  28394. lamfinalarabic: 0xFEDE,
  28395. lamhahinitialarabic: 0xFCCA,
  28396. laminitialarabic: 0xFEDF,
  28397. lamjeeminitialarabic: 0xFCC9,
  28398. lamkhahinitialarabic: 0xFCCB,
  28399. lamlamhehisolatedarabic: 0xFDF2,
  28400. lammedialarabic: 0xFEE0,
  28401. lammeemhahinitialarabic: 0xFD88,
  28402. lammeeminitialarabic: 0xFCCC,
  28403. largecircle: 0x25EF,
  28404. lbar: 0x019A,
  28405. lbelt: 0x026C,
  28406. lbopomofo: 0x310C,
  28407. lcaron: 0x013E,
  28408. lcedilla: 0x013C,
  28409. lcircle: 0x24DB,
  28410. lcircumflexbelow: 0x1E3D,
  28411. lcommaaccent: 0x013C,
  28412. ldot: 0x0140,
  28413. ldotaccent: 0x0140,
  28414. ldotbelow: 0x1E37,
  28415. ldotbelowmacron: 0x1E39,
  28416. leftangleabovecmb: 0x031A,
  28417. lefttackbelowcmb: 0x0318,
  28418. less: 0x003C,
  28419. lessequal: 0x2264,
  28420. lessequalorgreater: 0x22DA,
  28421. lessmonospace: 0xFF1C,
  28422. lessorequivalent: 0x2272,
  28423. lessorgreater: 0x2276,
  28424. lessoverequal: 0x2266,
  28425. lesssmall: 0xFE64,
  28426. lezh: 0x026E,
  28427. lfblock: 0x258C,
  28428. lhookretroflex: 0x026D,
  28429. lira: 0x20A4,
  28430. liwnarmenian: 0x056C,
  28431. lj: 0x01C9,
  28432. ljecyrillic: 0x0459,
  28433. ll: 0xF6C0,
  28434. lladeva: 0x0933,
  28435. llagujarati: 0x0AB3,
  28436. llinebelow: 0x1E3B,
  28437. llladeva: 0x0934,
  28438. llvocalicbengali: 0x09E1,
  28439. llvocalicdeva: 0x0961,
  28440. llvocalicvowelsignbengali: 0x09E3,
  28441. llvocalicvowelsigndeva: 0x0963,
  28442. lmiddletilde: 0x026B,
  28443. lmonospace: 0xFF4C,
  28444. lmsquare: 0x33D0,
  28445. lochulathai: 0x0E2C,
  28446. logicaland: 0x2227,
  28447. logicalnot: 0x00AC,
  28448. logicalnotreversed: 0x2310,
  28449. logicalor: 0x2228,
  28450. lolingthai: 0x0E25,
  28451. longs: 0x017F,
  28452. lowlinecenterline: 0xFE4E,
  28453. lowlinecmb: 0x0332,
  28454. lowlinedashed: 0xFE4D,
  28455. lozenge: 0x25CA,
  28456. lparen: 0x24A7,
  28457. lslash: 0x0142,
  28458. lsquare: 0x2113,
  28459. lsuperior: 0xF6EE,
  28460. ltshade: 0x2591,
  28461. luthai: 0x0E26,
  28462. lvocalicbengali: 0x098C,
  28463. lvocalicdeva: 0x090C,
  28464. lvocalicvowelsignbengali: 0x09E2,
  28465. lvocalicvowelsigndeva: 0x0962,
  28466. lxsquare: 0x33D3,
  28467. m: 0x006D,
  28468. mabengali: 0x09AE,
  28469. macron: 0x00AF,
  28470. macronbelowcmb: 0x0331,
  28471. macroncmb: 0x0304,
  28472. macronlowmod: 0x02CD,
  28473. macronmonospace: 0xFFE3,
  28474. macute: 0x1E3F,
  28475. madeva: 0x092E,
  28476. magujarati: 0x0AAE,
  28477. magurmukhi: 0x0A2E,
  28478. mahapakhhebrew: 0x05A4,
  28479. mahapakhlefthebrew: 0x05A4,
  28480. mahiragana: 0x307E,
  28481. maichattawalowleftthai: 0xF895,
  28482. maichattawalowrightthai: 0xF894,
  28483. maichattawathai: 0x0E4B,
  28484. maichattawaupperleftthai: 0xF893,
  28485. maieklowleftthai: 0xF88C,
  28486. maieklowrightthai: 0xF88B,
  28487. maiekthai: 0x0E48,
  28488. maiekupperleftthai: 0xF88A,
  28489. maihanakatleftthai: 0xF884,
  28490. maihanakatthai: 0x0E31,
  28491. maitaikhuleftthai: 0xF889,
  28492. maitaikhuthai: 0x0E47,
  28493. maitholowleftthai: 0xF88F,
  28494. maitholowrightthai: 0xF88E,
  28495. maithothai: 0x0E49,
  28496. maithoupperleftthai: 0xF88D,
  28497. maitrilowleftthai: 0xF892,
  28498. maitrilowrightthai: 0xF891,
  28499. maitrithai: 0x0E4A,
  28500. maitriupperleftthai: 0xF890,
  28501. maiyamokthai: 0x0E46,
  28502. makatakana: 0x30DE,
  28503. makatakanahalfwidth: 0xFF8F,
  28504. male: 0x2642,
  28505. mansyonsquare: 0x3347,
  28506. maqafhebrew: 0x05BE,
  28507. mars: 0x2642,
  28508. masoracirclehebrew: 0x05AF,
  28509. masquare: 0x3383,
  28510. mbopomofo: 0x3107,
  28511. mbsquare: 0x33D4,
  28512. mcircle: 0x24DC,
  28513. mcubedsquare: 0x33A5,
  28514. mdotaccent: 0x1E41,
  28515. mdotbelow: 0x1E43,
  28516. meemarabic: 0x0645,
  28517. meemfinalarabic: 0xFEE2,
  28518. meeminitialarabic: 0xFEE3,
  28519. meemmedialarabic: 0xFEE4,
  28520. meemmeeminitialarabic: 0xFCD1,
  28521. meemmeemisolatedarabic: 0xFC48,
  28522. meetorusquare: 0x334D,
  28523. mehiragana: 0x3081,
  28524. meizierasquare: 0x337E,
  28525. mekatakana: 0x30E1,
  28526. mekatakanahalfwidth: 0xFF92,
  28527. mem: 0x05DE,
  28528. memdagesh: 0xFB3E,
  28529. memdageshhebrew: 0xFB3E,
  28530. memhebrew: 0x05DE,
  28531. menarmenian: 0x0574,
  28532. merkhahebrew: 0x05A5,
  28533. merkhakefulahebrew: 0x05A6,
  28534. merkhakefulalefthebrew: 0x05A6,
  28535. merkhalefthebrew: 0x05A5,
  28536. mhook: 0x0271,
  28537. mhzsquare: 0x3392,
  28538. middledotkatakanahalfwidth: 0xFF65,
  28539. middot: 0x00B7,
  28540. mieumacirclekorean: 0x3272,
  28541. mieumaparenkorean: 0x3212,
  28542. mieumcirclekorean: 0x3264,
  28543. mieumkorean: 0x3141,
  28544. mieumpansioskorean: 0x3170,
  28545. mieumparenkorean: 0x3204,
  28546. mieumpieupkorean: 0x316E,
  28547. mieumsioskorean: 0x316F,
  28548. mihiragana: 0x307F,
  28549. mikatakana: 0x30DF,
  28550. mikatakanahalfwidth: 0xFF90,
  28551. minus: 0x2212,
  28552. minusbelowcmb: 0x0320,
  28553. minuscircle: 0x2296,
  28554. minusmod: 0x02D7,
  28555. minusplus: 0x2213,
  28556. minute: 0x2032,
  28557. miribaarusquare: 0x334A,
  28558. mirisquare: 0x3349,
  28559. mlonglegturned: 0x0270,
  28560. mlsquare: 0x3396,
  28561. mmcubedsquare: 0x33A3,
  28562. mmonospace: 0xFF4D,
  28563. mmsquaredsquare: 0x339F,
  28564. mohiragana: 0x3082,
  28565. mohmsquare: 0x33C1,
  28566. mokatakana: 0x30E2,
  28567. mokatakanahalfwidth: 0xFF93,
  28568. molsquare: 0x33D6,
  28569. momathai: 0x0E21,
  28570. moverssquare: 0x33A7,
  28571. moverssquaredsquare: 0x33A8,
  28572. mparen: 0x24A8,
  28573. mpasquare: 0x33AB,
  28574. mssquare: 0x33B3,
  28575. msuperior: 0xF6EF,
  28576. mturned: 0x026F,
  28577. mu: 0x00B5,
  28578. mu1: 0x00B5,
  28579. muasquare: 0x3382,
  28580. muchgreater: 0x226B,
  28581. muchless: 0x226A,
  28582. mufsquare: 0x338C,
  28583. mugreek: 0x03BC,
  28584. mugsquare: 0x338D,
  28585. muhiragana: 0x3080,
  28586. mukatakana: 0x30E0,
  28587. mukatakanahalfwidth: 0xFF91,
  28588. mulsquare: 0x3395,
  28589. multiply: 0x00D7,
  28590. mumsquare: 0x339B,
  28591. munahhebrew: 0x05A3,
  28592. munahlefthebrew: 0x05A3,
  28593. musicalnote: 0x266A,
  28594. musicalnotedbl: 0x266B,
  28595. musicflatsign: 0x266D,
  28596. musicsharpsign: 0x266F,
  28597. mussquare: 0x33B2,
  28598. muvsquare: 0x33B6,
  28599. muwsquare: 0x33BC,
  28600. mvmegasquare: 0x33B9,
  28601. mvsquare: 0x33B7,
  28602. mwmegasquare: 0x33BF,
  28603. mwsquare: 0x33BD,
  28604. n: 0x006E,
  28605. nabengali: 0x09A8,
  28606. nabla: 0x2207,
  28607. nacute: 0x0144,
  28608. nadeva: 0x0928,
  28609. nagujarati: 0x0AA8,
  28610. nagurmukhi: 0x0A28,
  28611. nahiragana: 0x306A,
  28612. nakatakana: 0x30CA,
  28613. nakatakanahalfwidth: 0xFF85,
  28614. napostrophe: 0x0149,
  28615. nasquare: 0x3381,
  28616. nbopomofo: 0x310B,
  28617. nbspace: 0x00A0,
  28618. ncaron: 0x0148,
  28619. ncedilla: 0x0146,
  28620. ncircle: 0x24DD,
  28621. ncircumflexbelow: 0x1E4B,
  28622. ncommaaccent: 0x0146,
  28623. ndotaccent: 0x1E45,
  28624. ndotbelow: 0x1E47,
  28625. nehiragana: 0x306D,
  28626. nekatakana: 0x30CD,
  28627. nekatakanahalfwidth: 0xFF88,
  28628. newsheqelsign: 0x20AA,
  28629. nfsquare: 0x338B,
  28630. ngabengali: 0x0999,
  28631. ngadeva: 0x0919,
  28632. ngagujarati: 0x0A99,
  28633. ngagurmukhi: 0x0A19,
  28634. ngonguthai: 0x0E07,
  28635. nhiragana: 0x3093,
  28636. nhookleft: 0x0272,
  28637. nhookretroflex: 0x0273,
  28638. nieunacirclekorean: 0x326F,
  28639. nieunaparenkorean: 0x320F,
  28640. nieuncieuckorean: 0x3135,
  28641. nieuncirclekorean: 0x3261,
  28642. nieunhieuhkorean: 0x3136,
  28643. nieunkorean: 0x3134,
  28644. nieunpansioskorean: 0x3168,
  28645. nieunparenkorean: 0x3201,
  28646. nieunsioskorean: 0x3167,
  28647. nieuntikeutkorean: 0x3166,
  28648. nihiragana: 0x306B,
  28649. nikatakana: 0x30CB,
  28650. nikatakanahalfwidth: 0xFF86,
  28651. nikhahitleftthai: 0xF899,
  28652. nikhahitthai: 0x0E4D,
  28653. nine: 0x0039,
  28654. ninearabic: 0x0669,
  28655. ninebengali: 0x09EF,
  28656. ninecircle: 0x2468,
  28657. ninecircleinversesansserif: 0x2792,
  28658. ninedeva: 0x096F,
  28659. ninegujarati: 0x0AEF,
  28660. ninegurmukhi: 0x0A6F,
  28661. ninehackarabic: 0x0669,
  28662. ninehangzhou: 0x3029,
  28663. nineideographicparen: 0x3228,
  28664. nineinferior: 0x2089,
  28665. ninemonospace: 0xFF19,
  28666. nineoldstyle: 0xF739,
  28667. nineparen: 0x247C,
  28668. nineperiod: 0x2490,
  28669. ninepersian: 0x06F9,
  28670. nineroman: 0x2178,
  28671. ninesuperior: 0x2079,
  28672. nineteencircle: 0x2472,
  28673. nineteenparen: 0x2486,
  28674. nineteenperiod: 0x249A,
  28675. ninethai: 0x0E59,
  28676. nj: 0x01CC,
  28677. njecyrillic: 0x045A,
  28678. nkatakana: 0x30F3,
  28679. nkatakanahalfwidth: 0xFF9D,
  28680. nlegrightlong: 0x019E,
  28681. nlinebelow: 0x1E49,
  28682. nmonospace: 0xFF4E,
  28683. nmsquare: 0x339A,
  28684. nnabengali: 0x09A3,
  28685. nnadeva: 0x0923,
  28686. nnagujarati: 0x0AA3,
  28687. nnagurmukhi: 0x0A23,
  28688. nnnadeva: 0x0929,
  28689. nohiragana: 0x306E,
  28690. nokatakana: 0x30CE,
  28691. nokatakanahalfwidth: 0xFF89,
  28692. nonbreakingspace: 0x00A0,
  28693. nonenthai: 0x0E13,
  28694. nonuthai: 0x0E19,
  28695. noonarabic: 0x0646,
  28696. noonfinalarabic: 0xFEE6,
  28697. noonghunnaarabic: 0x06BA,
  28698. noonghunnafinalarabic: 0xFB9F,
  28699. nooninitialarabic: 0xFEE7,
  28700. noonjeeminitialarabic: 0xFCD2,
  28701. noonjeemisolatedarabic: 0xFC4B,
  28702. noonmedialarabic: 0xFEE8,
  28703. noonmeeminitialarabic: 0xFCD5,
  28704. noonmeemisolatedarabic: 0xFC4E,
  28705. noonnoonfinalarabic: 0xFC8D,
  28706. notcontains: 0x220C,
  28707. notelement: 0x2209,
  28708. notelementof: 0x2209,
  28709. notequal: 0x2260,
  28710. notgreater: 0x226F,
  28711. notgreaternorequal: 0x2271,
  28712. notgreaternorless: 0x2279,
  28713. notidentical: 0x2262,
  28714. notless: 0x226E,
  28715. notlessnorequal: 0x2270,
  28716. notparallel: 0x2226,
  28717. notprecedes: 0x2280,
  28718. notsubset: 0x2284,
  28719. notsucceeds: 0x2281,
  28720. notsuperset: 0x2285,
  28721. nowarmenian: 0x0576,
  28722. nparen: 0x24A9,
  28723. nssquare: 0x33B1,
  28724. nsuperior: 0x207F,
  28725. ntilde: 0x00F1,
  28726. nu: 0x03BD,
  28727. nuhiragana: 0x306C,
  28728. nukatakana: 0x30CC,
  28729. nukatakanahalfwidth: 0xFF87,
  28730. nuktabengali: 0x09BC,
  28731. nuktadeva: 0x093C,
  28732. nuktagujarati: 0x0ABC,
  28733. nuktagurmukhi: 0x0A3C,
  28734. numbersign: 0x0023,
  28735. numbersignmonospace: 0xFF03,
  28736. numbersignsmall: 0xFE5F,
  28737. numeralsigngreek: 0x0374,
  28738. numeralsignlowergreek: 0x0375,
  28739. numero: 0x2116,
  28740. nun: 0x05E0,
  28741. nundagesh: 0xFB40,
  28742. nundageshhebrew: 0xFB40,
  28743. nunhebrew: 0x05E0,
  28744. nvsquare: 0x33B5,
  28745. nwsquare: 0x33BB,
  28746. nyabengali: 0x099E,
  28747. nyadeva: 0x091E,
  28748. nyagujarati: 0x0A9E,
  28749. nyagurmukhi: 0x0A1E,
  28750. o: 0x006F,
  28751. oacute: 0x00F3,
  28752. oangthai: 0x0E2D,
  28753. obarred: 0x0275,
  28754. obarredcyrillic: 0x04E9,
  28755. obarreddieresiscyrillic: 0x04EB,
  28756. obengali: 0x0993,
  28757. obopomofo: 0x311B,
  28758. obreve: 0x014F,
  28759. ocandradeva: 0x0911,
  28760. ocandragujarati: 0x0A91,
  28761. ocandravowelsigndeva: 0x0949,
  28762. ocandravowelsigngujarati: 0x0AC9,
  28763. ocaron: 0x01D2,
  28764. ocircle: 0x24DE,
  28765. ocircumflex: 0x00F4,
  28766. ocircumflexacute: 0x1ED1,
  28767. ocircumflexdotbelow: 0x1ED9,
  28768. ocircumflexgrave: 0x1ED3,
  28769. ocircumflexhookabove: 0x1ED5,
  28770. ocircumflextilde: 0x1ED7,
  28771. ocyrillic: 0x043E,
  28772. odblacute: 0x0151,
  28773. odblgrave: 0x020D,
  28774. odeva: 0x0913,
  28775. odieresis: 0x00F6,
  28776. odieresiscyrillic: 0x04E7,
  28777. odotbelow: 0x1ECD,
  28778. oe: 0x0153,
  28779. oekorean: 0x315A,
  28780. ogonek: 0x02DB,
  28781. ogonekcmb: 0x0328,
  28782. ograve: 0x00F2,
  28783. ogujarati: 0x0A93,
  28784. oharmenian: 0x0585,
  28785. ohiragana: 0x304A,
  28786. ohookabove: 0x1ECF,
  28787. ohorn: 0x01A1,
  28788. ohornacute: 0x1EDB,
  28789. ohorndotbelow: 0x1EE3,
  28790. ohorngrave: 0x1EDD,
  28791. ohornhookabove: 0x1EDF,
  28792. ohorntilde: 0x1EE1,
  28793. ohungarumlaut: 0x0151,
  28794. oi: 0x01A3,
  28795. oinvertedbreve: 0x020F,
  28796. okatakana: 0x30AA,
  28797. okatakanahalfwidth: 0xFF75,
  28798. okorean: 0x3157,
  28799. olehebrew: 0x05AB,
  28800. omacron: 0x014D,
  28801. omacronacute: 0x1E53,
  28802. omacrongrave: 0x1E51,
  28803. omdeva: 0x0950,
  28804. omega: 0x03C9,
  28805. omega1: 0x03D6,
  28806. omegacyrillic: 0x0461,
  28807. omegalatinclosed: 0x0277,
  28808. omegaroundcyrillic: 0x047B,
  28809. omegatitlocyrillic: 0x047D,
  28810. omegatonos: 0x03CE,
  28811. omgujarati: 0x0AD0,
  28812. omicron: 0x03BF,
  28813. omicrontonos: 0x03CC,
  28814. omonospace: 0xFF4F,
  28815. one: 0x0031,
  28816. onearabic: 0x0661,
  28817. onebengali: 0x09E7,
  28818. onecircle: 0x2460,
  28819. onecircleinversesansserif: 0x278A,
  28820. onedeva: 0x0967,
  28821. onedotenleader: 0x2024,
  28822. oneeighth: 0x215B,
  28823. onefitted: 0xF6DC,
  28824. onegujarati: 0x0AE7,
  28825. onegurmukhi: 0x0A67,
  28826. onehackarabic: 0x0661,
  28827. onehalf: 0x00BD,
  28828. onehangzhou: 0x3021,
  28829. oneideographicparen: 0x3220,
  28830. oneinferior: 0x2081,
  28831. onemonospace: 0xFF11,
  28832. onenumeratorbengali: 0x09F4,
  28833. oneoldstyle: 0xF731,
  28834. oneparen: 0x2474,
  28835. oneperiod: 0x2488,
  28836. onepersian: 0x06F1,
  28837. onequarter: 0x00BC,
  28838. oneroman: 0x2170,
  28839. onesuperior: 0x00B9,
  28840. onethai: 0x0E51,
  28841. onethird: 0x2153,
  28842. oogonek: 0x01EB,
  28843. oogonekmacron: 0x01ED,
  28844. oogurmukhi: 0x0A13,
  28845. oomatragurmukhi: 0x0A4B,
  28846. oopen: 0x0254,
  28847. oparen: 0x24AA,
  28848. openbullet: 0x25E6,
  28849. option: 0x2325,
  28850. ordfeminine: 0x00AA,
  28851. ordmasculine: 0x00BA,
  28852. orthogonal: 0x221F,
  28853. oshortdeva: 0x0912,
  28854. oshortvowelsigndeva: 0x094A,
  28855. oslash: 0x00F8,
  28856. oslashacute: 0x01FF,
  28857. osmallhiragana: 0x3049,
  28858. osmallkatakana: 0x30A9,
  28859. osmallkatakanahalfwidth: 0xFF6B,
  28860. ostrokeacute: 0x01FF,
  28861. osuperior: 0xF6F0,
  28862. otcyrillic: 0x047F,
  28863. otilde: 0x00F5,
  28864. otildeacute: 0x1E4D,
  28865. otildedieresis: 0x1E4F,
  28866. oubopomofo: 0x3121,
  28867. overline: 0x203E,
  28868. overlinecenterline: 0xFE4A,
  28869. overlinecmb: 0x0305,
  28870. overlinedashed: 0xFE49,
  28871. overlinedblwavy: 0xFE4C,
  28872. overlinewavy: 0xFE4B,
  28873. overscore: 0x00AF,
  28874. ovowelsignbengali: 0x09CB,
  28875. ovowelsigndeva: 0x094B,
  28876. ovowelsigngujarati: 0x0ACB,
  28877. p: 0x0070,
  28878. paampssquare: 0x3380,
  28879. paasentosquare: 0x332B,
  28880. pabengali: 0x09AA,
  28881. pacute: 0x1E55,
  28882. padeva: 0x092A,
  28883. pagedown: 0x21DF,
  28884. pageup: 0x21DE,
  28885. pagujarati: 0x0AAA,
  28886. pagurmukhi: 0x0A2A,
  28887. pahiragana: 0x3071,
  28888. paiyannoithai: 0x0E2F,
  28889. pakatakana: 0x30D1,
  28890. palatalizationcyrilliccmb: 0x0484,
  28891. palochkacyrillic: 0x04C0,
  28892. pansioskorean: 0x317F,
  28893. paragraph: 0x00B6,
  28894. parallel: 0x2225,
  28895. parenleft: 0x0028,
  28896. parenleftaltonearabic: 0xFD3E,
  28897. parenleftbt: 0xF8ED,
  28898. parenleftex: 0xF8EC,
  28899. parenleftinferior: 0x208D,
  28900. parenleftmonospace: 0xFF08,
  28901. parenleftsmall: 0xFE59,
  28902. parenleftsuperior: 0x207D,
  28903. parenlefttp: 0xF8EB,
  28904. parenleftvertical: 0xFE35,
  28905. parenright: 0x0029,
  28906. parenrightaltonearabic: 0xFD3F,
  28907. parenrightbt: 0xF8F8,
  28908. parenrightex: 0xF8F7,
  28909. parenrightinferior: 0x208E,
  28910. parenrightmonospace: 0xFF09,
  28911. parenrightsmall: 0xFE5A,
  28912. parenrightsuperior: 0x207E,
  28913. parenrighttp: 0xF8F6,
  28914. parenrightvertical: 0xFE36,
  28915. partialdiff: 0x2202,
  28916. paseqhebrew: 0x05C0,
  28917. pashtahebrew: 0x0599,
  28918. pasquare: 0x33A9,
  28919. patah: 0x05B7,
  28920. patah11: 0x05B7,
  28921. patah1d: 0x05B7,
  28922. patah2a: 0x05B7,
  28923. patahhebrew: 0x05B7,
  28924. patahnarrowhebrew: 0x05B7,
  28925. patahquarterhebrew: 0x05B7,
  28926. patahwidehebrew: 0x05B7,
  28927. pazerhebrew: 0x05A1,
  28928. pbopomofo: 0x3106,
  28929. pcircle: 0x24DF,
  28930. pdotaccent: 0x1E57,
  28931. pe: 0x05E4,
  28932. pecyrillic: 0x043F,
  28933. pedagesh: 0xFB44,
  28934. pedageshhebrew: 0xFB44,
  28935. peezisquare: 0x333B,
  28936. pefinaldageshhebrew: 0xFB43,
  28937. peharabic: 0x067E,
  28938. peharmenian: 0x057A,
  28939. pehebrew: 0x05E4,
  28940. pehfinalarabic: 0xFB57,
  28941. pehinitialarabic: 0xFB58,
  28942. pehiragana: 0x307A,
  28943. pehmedialarabic: 0xFB59,
  28944. pekatakana: 0x30DA,
  28945. pemiddlehookcyrillic: 0x04A7,
  28946. perafehebrew: 0xFB4E,
  28947. percent: 0x0025,
  28948. percentarabic: 0x066A,
  28949. percentmonospace: 0xFF05,
  28950. percentsmall: 0xFE6A,
  28951. period: 0x002E,
  28952. periodarmenian: 0x0589,
  28953. periodcentered: 0x00B7,
  28954. periodhalfwidth: 0xFF61,
  28955. periodinferior: 0xF6E7,
  28956. periodmonospace: 0xFF0E,
  28957. periodsmall: 0xFE52,
  28958. periodsuperior: 0xF6E8,
  28959. perispomenigreekcmb: 0x0342,
  28960. perpendicular: 0x22A5,
  28961. perthousand: 0x2030,
  28962. peseta: 0x20A7,
  28963. pfsquare: 0x338A,
  28964. phabengali: 0x09AB,
  28965. phadeva: 0x092B,
  28966. phagujarati: 0x0AAB,
  28967. phagurmukhi: 0x0A2B,
  28968. phi: 0x03C6,
  28969. phi1: 0x03D5,
  28970. phieuphacirclekorean: 0x327A,
  28971. phieuphaparenkorean: 0x321A,
  28972. phieuphcirclekorean: 0x326C,
  28973. phieuphkorean: 0x314D,
  28974. phieuphparenkorean: 0x320C,
  28975. philatin: 0x0278,
  28976. phinthuthai: 0x0E3A,
  28977. phisymbolgreek: 0x03D5,
  28978. phook: 0x01A5,
  28979. phophanthai: 0x0E1E,
  28980. phophungthai: 0x0E1C,
  28981. phosamphaothai: 0x0E20,
  28982. pi: 0x03C0,
  28983. pieupacirclekorean: 0x3273,
  28984. pieupaparenkorean: 0x3213,
  28985. pieupcieuckorean: 0x3176,
  28986. pieupcirclekorean: 0x3265,
  28987. pieupkiyeokkorean: 0x3172,
  28988. pieupkorean: 0x3142,
  28989. pieupparenkorean: 0x3205,
  28990. pieupsioskiyeokkorean: 0x3174,
  28991. pieupsioskorean: 0x3144,
  28992. pieupsiostikeutkorean: 0x3175,
  28993. pieupthieuthkorean: 0x3177,
  28994. pieuptikeutkorean: 0x3173,
  28995. pihiragana: 0x3074,
  28996. pikatakana: 0x30D4,
  28997. pisymbolgreek: 0x03D6,
  28998. piwrarmenian: 0x0583,
  28999. plus: 0x002B,
  29000. plusbelowcmb: 0x031F,
  29001. pluscircle: 0x2295,
  29002. plusminus: 0x00B1,
  29003. plusmod: 0x02D6,
  29004. plusmonospace: 0xFF0B,
  29005. plussmall: 0xFE62,
  29006. plussuperior: 0x207A,
  29007. pmonospace: 0xFF50,
  29008. pmsquare: 0x33D8,
  29009. pohiragana: 0x307D,
  29010. pointingindexdownwhite: 0x261F,
  29011. pointingindexleftwhite: 0x261C,
  29012. pointingindexrightwhite: 0x261E,
  29013. pointingindexupwhite: 0x261D,
  29014. pokatakana: 0x30DD,
  29015. poplathai: 0x0E1B,
  29016. postalmark: 0x3012,
  29017. postalmarkface: 0x3020,
  29018. pparen: 0x24AB,
  29019. precedes: 0x227A,
  29020. prescription: 0x211E,
  29021. primemod: 0x02B9,
  29022. primereversed: 0x2035,
  29023. product: 0x220F,
  29024. projective: 0x2305,
  29025. prolongedkana: 0x30FC,
  29026. propellor: 0x2318,
  29027. propersubset: 0x2282,
  29028. propersuperset: 0x2283,
  29029. proportion: 0x2237,
  29030. proportional: 0x221D,
  29031. psi: 0x03C8,
  29032. psicyrillic: 0x0471,
  29033. psilipneumatacyrilliccmb: 0x0486,
  29034. pssquare: 0x33B0,
  29035. puhiragana: 0x3077,
  29036. pukatakana: 0x30D7,
  29037. pvsquare: 0x33B4,
  29038. pwsquare: 0x33BA,
  29039. q: 0x0071,
  29040. qadeva: 0x0958,
  29041. qadmahebrew: 0x05A8,
  29042. qafarabic: 0x0642,
  29043. qaffinalarabic: 0xFED6,
  29044. qafinitialarabic: 0xFED7,
  29045. qafmedialarabic: 0xFED8,
  29046. qamats: 0x05B8,
  29047. qamats10: 0x05B8,
  29048. qamats1a: 0x05B8,
  29049. qamats1c: 0x05B8,
  29050. qamats27: 0x05B8,
  29051. qamats29: 0x05B8,
  29052. qamats33: 0x05B8,
  29053. qamatsde: 0x05B8,
  29054. qamatshebrew: 0x05B8,
  29055. qamatsnarrowhebrew: 0x05B8,
  29056. qamatsqatanhebrew: 0x05B8,
  29057. qamatsqatannarrowhebrew: 0x05B8,
  29058. qamatsqatanquarterhebrew: 0x05B8,
  29059. qamatsqatanwidehebrew: 0x05B8,
  29060. qamatsquarterhebrew: 0x05B8,
  29061. qamatswidehebrew: 0x05B8,
  29062. qarneyparahebrew: 0x059F,
  29063. qbopomofo: 0x3111,
  29064. qcircle: 0x24E0,
  29065. qhook: 0x02A0,
  29066. qmonospace: 0xFF51,
  29067. qof: 0x05E7,
  29068. qofdagesh: 0xFB47,
  29069. qofdageshhebrew: 0xFB47,
  29070. qofhebrew: 0x05E7,
  29071. qparen: 0x24AC,
  29072. quarternote: 0x2669,
  29073. qubuts: 0x05BB,
  29074. qubuts18: 0x05BB,
  29075. qubuts25: 0x05BB,
  29076. qubuts31: 0x05BB,
  29077. qubutshebrew: 0x05BB,
  29078. qubutsnarrowhebrew: 0x05BB,
  29079. qubutsquarterhebrew: 0x05BB,
  29080. qubutswidehebrew: 0x05BB,
  29081. question: 0x003F,
  29082. questionarabic: 0x061F,
  29083. questionarmenian: 0x055E,
  29084. questiondown: 0x00BF,
  29085. questiondownsmall: 0xF7BF,
  29086. questiongreek: 0x037E,
  29087. questionmonospace: 0xFF1F,
  29088. questionsmall: 0xF73F,
  29089. quotedbl: 0x0022,
  29090. quotedblbase: 0x201E,
  29091. quotedblleft: 0x201C,
  29092. quotedblmonospace: 0xFF02,
  29093. quotedblprime: 0x301E,
  29094. quotedblprimereversed: 0x301D,
  29095. quotedblright: 0x201D,
  29096. quoteleft: 0x2018,
  29097. quoteleftreversed: 0x201B,
  29098. quotereversed: 0x201B,
  29099. quoteright: 0x2019,
  29100. quoterightn: 0x0149,
  29101. quotesinglbase: 0x201A,
  29102. quotesingle: 0x0027,
  29103. quotesinglemonospace: 0xFF07,
  29104. r: 0x0072,
  29105. raarmenian: 0x057C,
  29106. rabengali: 0x09B0,
  29107. racute: 0x0155,
  29108. radeva: 0x0930,
  29109. radical: 0x221A,
  29110. radicalex: 0xF8E5,
  29111. radoverssquare: 0x33AE,
  29112. radoverssquaredsquare: 0x33AF,
  29113. radsquare: 0x33AD,
  29114. rafe: 0x05BF,
  29115. rafehebrew: 0x05BF,
  29116. ragujarati: 0x0AB0,
  29117. ragurmukhi: 0x0A30,
  29118. rahiragana: 0x3089,
  29119. rakatakana: 0x30E9,
  29120. rakatakanahalfwidth: 0xFF97,
  29121. ralowerdiagonalbengali: 0x09F1,
  29122. ramiddlediagonalbengali: 0x09F0,
  29123. ramshorn: 0x0264,
  29124. ratio: 0x2236,
  29125. rbopomofo: 0x3116,
  29126. rcaron: 0x0159,
  29127. rcedilla: 0x0157,
  29128. rcircle: 0x24E1,
  29129. rcommaaccent: 0x0157,
  29130. rdblgrave: 0x0211,
  29131. rdotaccent: 0x1E59,
  29132. rdotbelow: 0x1E5B,
  29133. rdotbelowmacron: 0x1E5D,
  29134. referencemark: 0x203B,
  29135. reflexsubset: 0x2286,
  29136. reflexsuperset: 0x2287,
  29137. registered: 0x00AE,
  29138. registersans: 0xF8E8,
  29139. registerserif: 0xF6DA,
  29140. reharabic: 0x0631,
  29141. reharmenian: 0x0580,
  29142. rehfinalarabic: 0xFEAE,
  29143. rehiragana: 0x308C,
  29144. rekatakana: 0x30EC,
  29145. rekatakanahalfwidth: 0xFF9A,
  29146. resh: 0x05E8,
  29147. reshdageshhebrew: 0xFB48,
  29148. reshhebrew: 0x05E8,
  29149. reversedtilde: 0x223D,
  29150. reviahebrew: 0x0597,
  29151. reviamugrashhebrew: 0x0597,
  29152. revlogicalnot: 0x2310,
  29153. rfishhook: 0x027E,
  29154. rfishhookreversed: 0x027F,
  29155. rhabengali: 0x09DD,
  29156. rhadeva: 0x095D,
  29157. rho: 0x03C1,
  29158. rhook: 0x027D,
  29159. rhookturned: 0x027B,
  29160. rhookturnedsuperior: 0x02B5,
  29161. rhosymbolgreek: 0x03F1,
  29162. rhotichookmod: 0x02DE,
  29163. rieulacirclekorean: 0x3271,
  29164. rieulaparenkorean: 0x3211,
  29165. rieulcirclekorean: 0x3263,
  29166. rieulhieuhkorean: 0x3140,
  29167. rieulkiyeokkorean: 0x313A,
  29168. rieulkiyeoksioskorean: 0x3169,
  29169. rieulkorean: 0x3139,
  29170. rieulmieumkorean: 0x313B,
  29171. rieulpansioskorean: 0x316C,
  29172. rieulparenkorean: 0x3203,
  29173. rieulphieuphkorean: 0x313F,
  29174. rieulpieupkorean: 0x313C,
  29175. rieulpieupsioskorean: 0x316B,
  29176. rieulsioskorean: 0x313D,
  29177. rieulthieuthkorean: 0x313E,
  29178. rieultikeutkorean: 0x316A,
  29179. rieulyeorinhieuhkorean: 0x316D,
  29180. rightangle: 0x221F,
  29181. righttackbelowcmb: 0x0319,
  29182. righttriangle: 0x22BF,
  29183. rihiragana: 0x308A,
  29184. rikatakana: 0x30EA,
  29185. rikatakanahalfwidth: 0xFF98,
  29186. ring: 0x02DA,
  29187. ringbelowcmb: 0x0325,
  29188. ringcmb: 0x030A,
  29189. ringhalfleft: 0x02BF,
  29190. ringhalfleftarmenian: 0x0559,
  29191. ringhalfleftbelowcmb: 0x031C,
  29192. ringhalfleftcentered: 0x02D3,
  29193. ringhalfright: 0x02BE,
  29194. ringhalfrightbelowcmb: 0x0339,
  29195. ringhalfrightcentered: 0x02D2,
  29196. rinvertedbreve: 0x0213,
  29197. rittorusquare: 0x3351,
  29198. rlinebelow: 0x1E5F,
  29199. rlongleg: 0x027C,
  29200. rlonglegturned: 0x027A,
  29201. rmonospace: 0xFF52,
  29202. rohiragana: 0x308D,
  29203. rokatakana: 0x30ED,
  29204. rokatakanahalfwidth: 0xFF9B,
  29205. roruathai: 0x0E23,
  29206. rparen: 0x24AD,
  29207. rrabengali: 0x09DC,
  29208. rradeva: 0x0931,
  29209. rragurmukhi: 0x0A5C,
  29210. rreharabic: 0x0691,
  29211. rrehfinalarabic: 0xFB8D,
  29212. rrvocalicbengali: 0x09E0,
  29213. rrvocalicdeva: 0x0960,
  29214. rrvocalicgujarati: 0x0AE0,
  29215. rrvocalicvowelsignbengali: 0x09C4,
  29216. rrvocalicvowelsigndeva: 0x0944,
  29217. rrvocalicvowelsigngujarati: 0x0AC4,
  29218. rsuperior: 0xF6F1,
  29219. rtblock: 0x2590,
  29220. rturned: 0x0279,
  29221. rturnedsuperior: 0x02B4,
  29222. ruhiragana: 0x308B,
  29223. rukatakana: 0x30EB,
  29224. rukatakanahalfwidth: 0xFF99,
  29225. rupeemarkbengali: 0x09F2,
  29226. rupeesignbengali: 0x09F3,
  29227. rupiah: 0xF6DD,
  29228. ruthai: 0x0E24,
  29229. rvocalicbengali: 0x098B,
  29230. rvocalicdeva: 0x090B,
  29231. rvocalicgujarati: 0x0A8B,
  29232. rvocalicvowelsignbengali: 0x09C3,
  29233. rvocalicvowelsigndeva: 0x0943,
  29234. rvocalicvowelsigngujarati: 0x0AC3,
  29235. s: 0x0073,
  29236. sabengali: 0x09B8,
  29237. sacute: 0x015B,
  29238. sacutedotaccent: 0x1E65,
  29239. sadarabic: 0x0635,
  29240. sadeva: 0x0938,
  29241. sadfinalarabic: 0xFEBA,
  29242. sadinitialarabic: 0xFEBB,
  29243. sadmedialarabic: 0xFEBC,
  29244. sagujarati: 0x0AB8,
  29245. sagurmukhi: 0x0A38,
  29246. sahiragana: 0x3055,
  29247. sakatakana: 0x30B5,
  29248. sakatakanahalfwidth: 0xFF7B,
  29249. sallallahoualayhewasallamarabic: 0xFDFA,
  29250. samekh: 0x05E1,
  29251. samekhdagesh: 0xFB41,
  29252. samekhdageshhebrew: 0xFB41,
  29253. samekhhebrew: 0x05E1,
  29254. saraaathai: 0x0E32,
  29255. saraaethai: 0x0E41,
  29256. saraaimaimalaithai: 0x0E44,
  29257. saraaimaimuanthai: 0x0E43,
  29258. saraamthai: 0x0E33,
  29259. saraathai: 0x0E30,
  29260. saraethai: 0x0E40,
  29261. saraiileftthai: 0xF886,
  29262. saraiithai: 0x0E35,
  29263. saraileftthai: 0xF885,
  29264. saraithai: 0x0E34,
  29265. saraothai: 0x0E42,
  29266. saraueeleftthai: 0xF888,
  29267. saraueethai: 0x0E37,
  29268. saraueleftthai: 0xF887,
  29269. sarauethai: 0x0E36,
  29270. sarauthai: 0x0E38,
  29271. sarauuthai: 0x0E39,
  29272. sbopomofo: 0x3119,
  29273. scaron: 0x0161,
  29274. scarondotaccent: 0x1E67,
  29275. scedilla: 0x015F,
  29276. schwa: 0x0259,
  29277. schwacyrillic: 0x04D9,
  29278. schwadieresiscyrillic: 0x04DB,
  29279. schwahook: 0x025A,
  29280. scircle: 0x24E2,
  29281. scircumflex: 0x015D,
  29282. scommaaccent: 0x0219,
  29283. sdotaccent: 0x1E61,
  29284. sdotbelow: 0x1E63,
  29285. sdotbelowdotaccent: 0x1E69,
  29286. seagullbelowcmb: 0x033C,
  29287. second: 0x2033,
  29288. secondtonechinese: 0x02CA,
  29289. section: 0x00A7,
  29290. seenarabic: 0x0633,
  29291. seenfinalarabic: 0xFEB2,
  29292. seeninitialarabic: 0xFEB3,
  29293. seenmedialarabic: 0xFEB4,
  29294. segol: 0x05B6,
  29295. segol13: 0x05B6,
  29296. segol1f: 0x05B6,
  29297. segol2c: 0x05B6,
  29298. segolhebrew: 0x05B6,
  29299. segolnarrowhebrew: 0x05B6,
  29300. segolquarterhebrew: 0x05B6,
  29301. segoltahebrew: 0x0592,
  29302. segolwidehebrew: 0x05B6,
  29303. seharmenian: 0x057D,
  29304. sehiragana: 0x305B,
  29305. sekatakana: 0x30BB,
  29306. sekatakanahalfwidth: 0xFF7E,
  29307. semicolon: 0x003B,
  29308. semicolonarabic: 0x061B,
  29309. semicolonmonospace: 0xFF1B,
  29310. semicolonsmall: 0xFE54,
  29311. semivoicedmarkkana: 0x309C,
  29312. semivoicedmarkkanahalfwidth: 0xFF9F,
  29313. sentisquare: 0x3322,
  29314. sentosquare: 0x3323,
  29315. seven: 0x0037,
  29316. sevenarabic: 0x0667,
  29317. sevenbengali: 0x09ED,
  29318. sevencircle: 0x2466,
  29319. sevencircleinversesansserif: 0x2790,
  29320. sevendeva: 0x096D,
  29321. seveneighths: 0x215E,
  29322. sevengujarati: 0x0AED,
  29323. sevengurmukhi: 0x0A6D,
  29324. sevenhackarabic: 0x0667,
  29325. sevenhangzhou: 0x3027,
  29326. sevenideographicparen: 0x3226,
  29327. seveninferior: 0x2087,
  29328. sevenmonospace: 0xFF17,
  29329. sevenoldstyle: 0xF737,
  29330. sevenparen: 0x247A,
  29331. sevenperiod: 0x248E,
  29332. sevenpersian: 0x06F7,
  29333. sevenroman: 0x2176,
  29334. sevensuperior: 0x2077,
  29335. seventeencircle: 0x2470,
  29336. seventeenparen: 0x2484,
  29337. seventeenperiod: 0x2498,
  29338. seventhai: 0x0E57,
  29339. sfthyphen: 0x00AD,
  29340. shaarmenian: 0x0577,
  29341. shabengali: 0x09B6,
  29342. shacyrillic: 0x0448,
  29343. shaddaarabic: 0x0651,
  29344. shaddadammaarabic: 0xFC61,
  29345. shaddadammatanarabic: 0xFC5E,
  29346. shaddafathaarabic: 0xFC60,
  29347. shaddakasraarabic: 0xFC62,
  29348. shaddakasratanarabic: 0xFC5F,
  29349. shade: 0x2592,
  29350. shadedark: 0x2593,
  29351. shadelight: 0x2591,
  29352. shademedium: 0x2592,
  29353. shadeva: 0x0936,
  29354. shagujarati: 0x0AB6,
  29355. shagurmukhi: 0x0A36,
  29356. shalshelethebrew: 0x0593,
  29357. shbopomofo: 0x3115,
  29358. shchacyrillic: 0x0449,
  29359. sheenarabic: 0x0634,
  29360. sheenfinalarabic: 0xFEB6,
  29361. sheeninitialarabic: 0xFEB7,
  29362. sheenmedialarabic: 0xFEB8,
  29363. sheicoptic: 0x03E3,
  29364. sheqel: 0x20AA,
  29365. sheqelhebrew: 0x20AA,
  29366. sheva: 0x05B0,
  29367. sheva115: 0x05B0,
  29368. sheva15: 0x05B0,
  29369. sheva22: 0x05B0,
  29370. sheva2e: 0x05B0,
  29371. shevahebrew: 0x05B0,
  29372. shevanarrowhebrew: 0x05B0,
  29373. shevaquarterhebrew: 0x05B0,
  29374. shevawidehebrew: 0x05B0,
  29375. shhacyrillic: 0x04BB,
  29376. shimacoptic: 0x03ED,
  29377. shin: 0x05E9,
  29378. shindagesh: 0xFB49,
  29379. shindageshhebrew: 0xFB49,
  29380. shindageshshindot: 0xFB2C,
  29381. shindageshshindothebrew: 0xFB2C,
  29382. shindageshsindot: 0xFB2D,
  29383. shindageshsindothebrew: 0xFB2D,
  29384. shindothebrew: 0x05C1,
  29385. shinhebrew: 0x05E9,
  29386. shinshindot: 0xFB2A,
  29387. shinshindothebrew: 0xFB2A,
  29388. shinsindot: 0xFB2B,
  29389. shinsindothebrew: 0xFB2B,
  29390. shook: 0x0282,
  29391. sigma: 0x03C3,
  29392. sigma1: 0x03C2,
  29393. sigmafinal: 0x03C2,
  29394. sigmalunatesymbolgreek: 0x03F2,
  29395. sihiragana: 0x3057,
  29396. sikatakana: 0x30B7,
  29397. sikatakanahalfwidth: 0xFF7C,
  29398. siluqhebrew: 0x05BD,
  29399. siluqlefthebrew: 0x05BD,
  29400. similar: 0x223C,
  29401. sindothebrew: 0x05C2,
  29402. siosacirclekorean: 0x3274,
  29403. siosaparenkorean: 0x3214,
  29404. sioscieuckorean: 0x317E,
  29405. sioscirclekorean: 0x3266,
  29406. sioskiyeokkorean: 0x317A,
  29407. sioskorean: 0x3145,
  29408. siosnieunkorean: 0x317B,
  29409. siosparenkorean: 0x3206,
  29410. siospieupkorean: 0x317D,
  29411. siostikeutkorean: 0x317C,
  29412. six: 0x0036,
  29413. sixarabic: 0x0666,
  29414. sixbengali: 0x09EC,
  29415. sixcircle: 0x2465,
  29416. sixcircleinversesansserif: 0x278F,
  29417. sixdeva: 0x096C,
  29418. sixgujarati: 0x0AEC,
  29419. sixgurmukhi: 0x0A6C,
  29420. sixhackarabic: 0x0666,
  29421. sixhangzhou: 0x3026,
  29422. sixideographicparen: 0x3225,
  29423. sixinferior: 0x2086,
  29424. sixmonospace: 0xFF16,
  29425. sixoldstyle: 0xF736,
  29426. sixparen: 0x2479,
  29427. sixperiod: 0x248D,
  29428. sixpersian: 0x06F6,
  29429. sixroman: 0x2175,
  29430. sixsuperior: 0x2076,
  29431. sixteencircle: 0x246F,
  29432. sixteencurrencydenominatorbengali: 0x09F9,
  29433. sixteenparen: 0x2483,
  29434. sixteenperiod: 0x2497,
  29435. sixthai: 0x0E56,
  29436. slash: 0x002F,
  29437. slashmonospace: 0xFF0F,
  29438. slong: 0x017F,
  29439. slongdotaccent: 0x1E9B,
  29440. smileface: 0x263A,
  29441. smonospace: 0xFF53,
  29442. sofpasuqhebrew: 0x05C3,
  29443. softhyphen: 0x00AD,
  29444. softsigncyrillic: 0x044C,
  29445. sohiragana: 0x305D,
  29446. sokatakana: 0x30BD,
  29447. sokatakanahalfwidth: 0xFF7F,
  29448. soliduslongoverlaycmb: 0x0338,
  29449. solidusshortoverlaycmb: 0x0337,
  29450. sorusithai: 0x0E29,
  29451. sosalathai: 0x0E28,
  29452. sosothai: 0x0E0B,
  29453. sosuathai: 0x0E2A,
  29454. space: 0x0020,
  29455. spacehackarabic: 0x0020,
  29456. spade: 0x2660,
  29457. spadesuitblack: 0x2660,
  29458. spadesuitwhite: 0x2664,
  29459. sparen: 0x24AE,
  29460. squarebelowcmb: 0x033B,
  29461. squarecc: 0x33C4,
  29462. squarecm: 0x339D,
  29463. squarediagonalcrosshatchfill: 0x25A9,
  29464. squarehorizontalfill: 0x25A4,
  29465. squarekg: 0x338F,
  29466. squarekm: 0x339E,
  29467. squarekmcapital: 0x33CE,
  29468. squareln: 0x33D1,
  29469. squarelog: 0x33D2,
  29470. squaremg: 0x338E,
  29471. squaremil: 0x33D5,
  29472. squaremm: 0x339C,
  29473. squaremsquared: 0x33A1,
  29474. squareorthogonalcrosshatchfill: 0x25A6,
  29475. squareupperlefttolowerrightfill: 0x25A7,
  29476. squareupperrighttolowerleftfill: 0x25A8,
  29477. squareverticalfill: 0x25A5,
  29478. squarewhitewithsmallblack: 0x25A3,
  29479. srsquare: 0x33DB,
  29480. ssabengali: 0x09B7,
  29481. ssadeva: 0x0937,
  29482. ssagujarati: 0x0AB7,
  29483. ssangcieuckorean: 0x3149,
  29484. ssanghieuhkorean: 0x3185,
  29485. ssangieungkorean: 0x3180,
  29486. ssangkiyeokkorean: 0x3132,
  29487. ssangnieunkorean: 0x3165,
  29488. ssangpieupkorean: 0x3143,
  29489. ssangsioskorean: 0x3146,
  29490. ssangtikeutkorean: 0x3138,
  29491. ssuperior: 0xF6F2,
  29492. sterling: 0x00A3,
  29493. sterlingmonospace: 0xFFE1,
  29494. strokelongoverlaycmb: 0x0336,
  29495. strokeshortoverlaycmb: 0x0335,
  29496. subset: 0x2282,
  29497. subsetnotequal: 0x228A,
  29498. subsetorequal: 0x2286,
  29499. succeeds: 0x227B,
  29500. suchthat: 0x220B,
  29501. suhiragana: 0x3059,
  29502. sukatakana: 0x30B9,
  29503. sukatakanahalfwidth: 0xFF7D,
  29504. sukunarabic: 0x0652,
  29505. summation: 0x2211,
  29506. sun: 0x263C,
  29507. superset: 0x2283,
  29508. supersetnotequal: 0x228B,
  29509. supersetorequal: 0x2287,
  29510. svsquare: 0x33DC,
  29511. syouwaerasquare: 0x337C,
  29512. t: 0x0074,
  29513. tabengali: 0x09A4,
  29514. tackdown: 0x22A4,
  29515. tackleft: 0x22A3,
  29516. tadeva: 0x0924,
  29517. tagujarati: 0x0AA4,
  29518. tagurmukhi: 0x0A24,
  29519. taharabic: 0x0637,
  29520. tahfinalarabic: 0xFEC2,
  29521. tahinitialarabic: 0xFEC3,
  29522. tahiragana: 0x305F,
  29523. tahmedialarabic: 0xFEC4,
  29524. taisyouerasquare: 0x337D,
  29525. takatakana: 0x30BF,
  29526. takatakanahalfwidth: 0xFF80,
  29527. tatweelarabic: 0x0640,
  29528. tau: 0x03C4,
  29529. tav: 0x05EA,
  29530. tavdages: 0xFB4A,
  29531. tavdagesh: 0xFB4A,
  29532. tavdageshhebrew: 0xFB4A,
  29533. tavhebrew: 0x05EA,
  29534. tbar: 0x0167,
  29535. tbopomofo: 0x310A,
  29536. tcaron: 0x0165,
  29537. tccurl: 0x02A8,
  29538. tcedilla: 0x0163,
  29539. tcheharabic: 0x0686,
  29540. tchehfinalarabic: 0xFB7B,
  29541. tchehinitialarabic: 0xFB7C,
  29542. tchehmedialarabic: 0xFB7D,
  29543. tcircle: 0x24E3,
  29544. tcircumflexbelow: 0x1E71,
  29545. tcommaaccent: 0x0163,
  29546. tdieresis: 0x1E97,
  29547. tdotaccent: 0x1E6B,
  29548. tdotbelow: 0x1E6D,
  29549. tecyrillic: 0x0442,
  29550. tedescendercyrillic: 0x04AD,
  29551. teharabic: 0x062A,
  29552. tehfinalarabic: 0xFE96,
  29553. tehhahinitialarabic: 0xFCA2,
  29554. tehhahisolatedarabic: 0xFC0C,
  29555. tehinitialarabic: 0xFE97,
  29556. tehiragana: 0x3066,
  29557. tehjeeminitialarabic: 0xFCA1,
  29558. tehjeemisolatedarabic: 0xFC0B,
  29559. tehmarbutaarabic: 0x0629,
  29560. tehmarbutafinalarabic: 0xFE94,
  29561. tehmedialarabic: 0xFE98,
  29562. tehmeeminitialarabic: 0xFCA4,
  29563. tehmeemisolatedarabic: 0xFC0E,
  29564. tehnoonfinalarabic: 0xFC73,
  29565. tekatakana: 0x30C6,
  29566. tekatakanahalfwidth: 0xFF83,
  29567. telephone: 0x2121,
  29568. telephoneblack: 0x260E,
  29569. telishagedolahebrew: 0x05A0,
  29570. telishaqetanahebrew: 0x05A9,
  29571. tencircle: 0x2469,
  29572. tenideographicparen: 0x3229,
  29573. tenparen: 0x247D,
  29574. tenperiod: 0x2491,
  29575. tenroman: 0x2179,
  29576. tesh: 0x02A7,
  29577. tet: 0x05D8,
  29578. tetdagesh: 0xFB38,
  29579. tetdageshhebrew: 0xFB38,
  29580. tethebrew: 0x05D8,
  29581. tetsecyrillic: 0x04B5,
  29582. tevirhebrew: 0x059B,
  29583. tevirlefthebrew: 0x059B,
  29584. thabengali: 0x09A5,
  29585. thadeva: 0x0925,
  29586. thagujarati: 0x0AA5,
  29587. thagurmukhi: 0x0A25,
  29588. thalarabic: 0x0630,
  29589. thalfinalarabic: 0xFEAC,
  29590. thanthakhatlowleftthai: 0xF898,
  29591. thanthakhatlowrightthai: 0xF897,
  29592. thanthakhatthai: 0x0E4C,
  29593. thanthakhatupperleftthai: 0xF896,
  29594. theharabic: 0x062B,
  29595. thehfinalarabic: 0xFE9A,
  29596. thehinitialarabic: 0xFE9B,
  29597. thehmedialarabic: 0xFE9C,
  29598. thereexists: 0x2203,
  29599. therefore: 0x2234,
  29600. theta: 0x03B8,
  29601. theta1: 0x03D1,
  29602. thetasymbolgreek: 0x03D1,
  29603. thieuthacirclekorean: 0x3279,
  29604. thieuthaparenkorean: 0x3219,
  29605. thieuthcirclekorean: 0x326B,
  29606. thieuthkorean: 0x314C,
  29607. thieuthparenkorean: 0x320B,
  29608. thirteencircle: 0x246C,
  29609. thirteenparen: 0x2480,
  29610. thirteenperiod: 0x2494,
  29611. thonangmonthothai: 0x0E11,
  29612. thook: 0x01AD,
  29613. thophuthaothai: 0x0E12,
  29614. thorn: 0x00FE,
  29615. thothahanthai: 0x0E17,
  29616. thothanthai: 0x0E10,
  29617. thothongthai: 0x0E18,
  29618. thothungthai: 0x0E16,
  29619. thousandcyrillic: 0x0482,
  29620. thousandsseparatorarabic: 0x066C,
  29621. thousandsseparatorpersian: 0x066C,
  29622. three: 0x0033,
  29623. threearabic: 0x0663,
  29624. threebengali: 0x09E9,
  29625. threecircle: 0x2462,
  29626. threecircleinversesansserif: 0x278C,
  29627. threedeva: 0x0969,
  29628. threeeighths: 0x215C,
  29629. threegujarati: 0x0AE9,
  29630. threegurmukhi: 0x0A69,
  29631. threehackarabic: 0x0663,
  29632. threehangzhou: 0x3023,
  29633. threeideographicparen: 0x3222,
  29634. threeinferior: 0x2083,
  29635. threemonospace: 0xFF13,
  29636. threenumeratorbengali: 0x09F6,
  29637. threeoldstyle: 0xF733,
  29638. threeparen: 0x2476,
  29639. threeperiod: 0x248A,
  29640. threepersian: 0x06F3,
  29641. threequarters: 0x00BE,
  29642. threequartersemdash: 0xF6DE,
  29643. threeroman: 0x2172,
  29644. threesuperior: 0x00B3,
  29645. threethai: 0x0E53,
  29646. thzsquare: 0x3394,
  29647. tihiragana: 0x3061,
  29648. tikatakana: 0x30C1,
  29649. tikatakanahalfwidth: 0xFF81,
  29650. tikeutacirclekorean: 0x3270,
  29651. tikeutaparenkorean: 0x3210,
  29652. tikeutcirclekorean: 0x3262,
  29653. tikeutkorean: 0x3137,
  29654. tikeutparenkorean: 0x3202,
  29655. tilde: 0x02DC,
  29656. tildebelowcmb: 0x0330,
  29657. tildecmb: 0x0303,
  29658. tildecomb: 0x0303,
  29659. tildedoublecmb: 0x0360,
  29660. tildeoperator: 0x223C,
  29661. tildeoverlaycmb: 0x0334,
  29662. tildeverticalcmb: 0x033E,
  29663. timescircle: 0x2297,
  29664. tipehahebrew: 0x0596,
  29665. tipehalefthebrew: 0x0596,
  29666. tippigurmukhi: 0x0A70,
  29667. titlocyrilliccmb: 0x0483,
  29668. tiwnarmenian: 0x057F,
  29669. tlinebelow: 0x1E6F,
  29670. tmonospace: 0xFF54,
  29671. toarmenian: 0x0569,
  29672. tohiragana: 0x3068,
  29673. tokatakana: 0x30C8,
  29674. tokatakanahalfwidth: 0xFF84,
  29675. tonebarextrahighmod: 0x02E5,
  29676. tonebarextralowmod: 0x02E9,
  29677. tonebarhighmod: 0x02E6,
  29678. tonebarlowmod: 0x02E8,
  29679. tonebarmidmod: 0x02E7,
  29680. tonefive: 0x01BD,
  29681. tonesix: 0x0185,
  29682. tonetwo: 0x01A8,
  29683. tonos: 0x0384,
  29684. tonsquare: 0x3327,
  29685. topatakthai: 0x0E0F,
  29686. tortoiseshellbracketleft: 0x3014,
  29687. tortoiseshellbracketleftsmall: 0xFE5D,
  29688. tortoiseshellbracketleftvertical: 0xFE39,
  29689. tortoiseshellbracketright: 0x3015,
  29690. tortoiseshellbracketrightsmall: 0xFE5E,
  29691. tortoiseshellbracketrightvertical: 0xFE3A,
  29692. totaothai: 0x0E15,
  29693. tpalatalhook: 0x01AB,
  29694. tparen: 0x24AF,
  29695. trademark: 0x2122,
  29696. trademarksans: 0xF8EA,
  29697. trademarkserif: 0xF6DB,
  29698. tretroflexhook: 0x0288,
  29699. triagdn: 0x25BC,
  29700. triaglf: 0x25C4,
  29701. triagrt: 0x25BA,
  29702. triagup: 0x25B2,
  29703. ts: 0x02A6,
  29704. tsadi: 0x05E6,
  29705. tsadidagesh: 0xFB46,
  29706. tsadidageshhebrew: 0xFB46,
  29707. tsadihebrew: 0x05E6,
  29708. tsecyrillic: 0x0446,
  29709. tsere: 0x05B5,
  29710. tsere12: 0x05B5,
  29711. tsere1e: 0x05B5,
  29712. tsere2b: 0x05B5,
  29713. tserehebrew: 0x05B5,
  29714. tserenarrowhebrew: 0x05B5,
  29715. tserequarterhebrew: 0x05B5,
  29716. tserewidehebrew: 0x05B5,
  29717. tshecyrillic: 0x045B,
  29718. tsuperior: 0xF6F3,
  29719. ttabengali: 0x099F,
  29720. ttadeva: 0x091F,
  29721. ttagujarati: 0x0A9F,
  29722. ttagurmukhi: 0x0A1F,
  29723. tteharabic: 0x0679,
  29724. ttehfinalarabic: 0xFB67,
  29725. ttehinitialarabic: 0xFB68,
  29726. ttehmedialarabic: 0xFB69,
  29727. tthabengali: 0x09A0,
  29728. tthadeva: 0x0920,
  29729. tthagujarati: 0x0AA0,
  29730. tthagurmukhi: 0x0A20,
  29731. tturned: 0x0287,
  29732. tuhiragana: 0x3064,
  29733. tukatakana: 0x30C4,
  29734. tukatakanahalfwidth: 0xFF82,
  29735. tusmallhiragana: 0x3063,
  29736. tusmallkatakana: 0x30C3,
  29737. tusmallkatakanahalfwidth: 0xFF6F,
  29738. twelvecircle: 0x246B,
  29739. twelveparen: 0x247F,
  29740. twelveperiod: 0x2493,
  29741. twelveroman: 0x217B,
  29742. twentycircle: 0x2473,
  29743. twentyhangzhou: 0x5344,
  29744. twentyparen: 0x2487,
  29745. twentyperiod: 0x249B,
  29746. two: 0x0032,
  29747. twoarabic: 0x0662,
  29748. twobengali: 0x09E8,
  29749. twocircle: 0x2461,
  29750. twocircleinversesansserif: 0x278B,
  29751. twodeva: 0x0968,
  29752. twodotenleader: 0x2025,
  29753. twodotleader: 0x2025,
  29754. twodotleadervertical: 0xFE30,
  29755. twogujarati: 0x0AE8,
  29756. twogurmukhi: 0x0A68,
  29757. twohackarabic: 0x0662,
  29758. twohangzhou: 0x3022,
  29759. twoideographicparen: 0x3221,
  29760. twoinferior: 0x2082,
  29761. twomonospace: 0xFF12,
  29762. twonumeratorbengali: 0x09F5,
  29763. twooldstyle: 0xF732,
  29764. twoparen: 0x2475,
  29765. twoperiod: 0x2489,
  29766. twopersian: 0x06F2,
  29767. tworoman: 0x2171,
  29768. twostroke: 0x01BB,
  29769. twosuperior: 0x00B2,
  29770. twothai: 0x0E52,
  29771. twothirds: 0x2154,
  29772. u: 0x0075,
  29773. uacute: 0x00FA,
  29774. ubar: 0x0289,
  29775. ubengali: 0x0989,
  29776. ubopomofo: 0x3128,
  29777. ubreve: 0x016D,
  29778. ucaron: 0x01D4,
  29779. ucircle: 0x24E4,
  29780. ucircumflex: 0x00FB,
  29781. ucircumflexbelow: 0x1E77,
  29782. ucyrillic: 0x0443,
  29783. udattadeva: 0x0951,
  29784. udblacute: 0x0171,
  29785. udblgrave: 0x0215,
  29786. udeva: 0x0909,
  29787. udieresis: 0x00FC,
  29788. udieresisacute: 0x01D8,
  29789. udieresisbelow: 0x1E73,
  29790. udieresiscaron: 0x01DA,
  29791. udieresiscyrillic: 0x04F1,
  29792. udieresisgrave: 0x01DC,
  29793. udieresismacron: 0x01D6,
  29794. udotbelow: 0x1EE5,
  29795. ugrave: 0x00F9,
  29796. ugujarati: 0x0A89,
  29797. ugurmukhi: 0x0A09,
  29798. uhiragana: 0x3046,
  29799. uhookabove: 0x1EE7,
  29800. uhorn: 0x01B0,
  29801. uhornacute: 0x1EE9,
  29802. uhorndotbelow: 0x1EF1,
  29803. uhorngrave: 0x1EEB,
  29804. uhornhookabove: 0x1EED,
  29805. uhorntilde: 0x1EEF,
  29806. uhungarumlaut: 0x0171,
  29807. uhungarumlautcyrillic: 0x04F3,
  29808. uinvertedbreve: 0x0217,
  29809. ukatakana: 0x30A6,
  29810. ukatakanahalfwidth: 0xFF73,
  29811. ukcyrillic: 0x0479,
  29812. ukorean: 0x315C,
  29813. umacron: 0x016B,
  29814. umacroncyrillic: 0x04EF,
  29815. umacrondieresis: 0x1E7B,
  29816. umatragurmukhi: 0x0A41,
  29817. umonospace: 0xFF55,
  29818. underscore: 0x005F,
  29819. underscoredbl: 0x2017,
  29820. underscoremonospace: 0xFF3F,
  29821. underscorevertical: 0xFE33,
  29822. underscorewavy: 0xFE4F,
  29823. union: 0x222A,
  29824. universal: 0x2200,
  29825. uogonek: 0x0173,
  29826. uparen: 0x24B0,
  29827. upblock: 0x2580,
  29828. upperdothebrew: 0x05C4,
  29829. upsilon: 0x03C5,
  29830. upsilondieresis: 0x03CB,
  29831. upsilondieresistonos: 0x03B0,
  29832. upsilonlatin: 0x028A,
  29833. upsilontonos: 0x03CD,
  29834. uptackbelowcmb: 0x031D,
  29835. uptackmod: 0x02D4,
  29836. uragurmukhi: 0x0A73,
  29837. uring: 0x016F,
  29838. ushortcyrillic: 0x045E,
  29839. usmallhiragana: 0x3045,
  29840. usmallkatakana: 0x30A5,
  29841. usmallkatakanahalfwidth: 0xFF69,
  29842. ustraightcyrillic: 0x04AF,
  29843. ustraightstrokecyrillic: 0x04B1,
  29844. utilde: 0x0169,
  29845. utildeacute: 0x1E79,
  29846. utildebelow: 0x1E75,
  29847. uubengali: 0x098A,
  29848. uudeva: 0x090A,
  29849. uugujarati: 0x0A8A,
  29850. uugurmukhi: 0x0A0A,
  29851. uumatragurmukhi: 0x0A42,
  29852. uuvowelsignbengali: 0x09C2,
  29853. uuvowelsigndeva: 0x0942,
  29854. uuvowelsigngujarati: 0x0AC2,
  29855. uvowelsignbengali: 0x09C1,
  29856. uvowelsigndeva: 0x0941,
  29857. uvowelsigngujarati: 0x0AC1,
  29858. v: 0x0076,
  29859. vadeva: 0x0935,
  29860. vagujarati: 0x0AB5,
  29861. vagurmukhi: 0x0A35,
  29862. vakatakana: 0x30F7,
  29863. vav: 0x05D5,
  29864. vavdagesh: 0xFB35,
  29865. vavdagesh65: 0xFB35,
  29866. vavdageshhebrew: 0xFB35,
  29867. vavhebrew: 0x05D5,
  29868. vavholam: 0xFB4B,
  29869. vavholamhebrew: 0xFB4B,
  29870. vavvavhebrew: 0x05F0,
  29871. vavyodhebrew: 0x05F1,
  29872. vcircle: 0x24E5,
  29873. vdotbelow: 0x1E7F,
  29874. vecyrillic: 0x0432,
  29875. veharabic: 0x06A4,
  29876. vehfinalarabic: 0xFB6B,
  29877. vehinitialarabic: 0xFB6C,
  29878. vehmedialarabic: 0xFB6D,
  29879. vekatakana: 0x30F9,
  29880. venus: 0x2640,
  29881. verticalbar: 0x007C,
  29882. verticallineabovecmb: 0x030D,
  29883. verticallinebelowcmb: 0x0329,
  29884. verticallinelowmod: 0x02CC,
  29885. verticallinemod: 0x02C8,
  29886. vewarmenian: 0x057E,
  29887. vhook: 0x028B,
  29888. vikatakana: 0x30F8,
  29889. viramabengali: 0x09CD,
  29890. viramadeva: 0x094D,
  29891. viramagujarati: 0x0ACD,
  29892. visargabengali: 0x0983,
  29893. visargadeva: 0x0903,
  29894. visargagujarati: 0x0A83,
  29895. vmonospace: 0xFF56,
  29896. voarmenian: 0x0578,
  29897. voicediterationhiragana: 0x309E,
  29898. voicediterationkatakana: 0x30FE,
  29899. voicedmarkkana: 0x309B,
  29900. voicedmarkkanahalfwidth: 0xFF9E,
  29901. vokatakana: 0x30FA,
  29902. vparen: 0x24B1,
  29903. vtilde: 0x1E7D,
  29904. vturned: 0x028C,
  29905. vuhiragana: 0x3094,
  29906. vukatakana: 0x30F4,
  29907. w: 0x0077,
  29908. wacute: 0x1E83,
  29909. waekorean: 0x3159,
  29910. wahiragana: 0x308F,
  29911. wakatakana: 0x30EF,
  29912. wakatakanahalfwidth: 0xFF9C,
  29913. wakorean: 0x3158,
  29914. wasmallhiragana: 0x308E,
  29915. wasmallkatakana: 0x30EE,
  29916. wattosquare: 0x3357,
  29917. wavedash: 0x301C,
  29918. wavyunderscorevertical: 0xFE34,
  29919. wawarabic: 0x0648,
  29920. wawfinalarabic: 0xFEEE,
  29921. wawhamzaabovearabic: 0x0624,
  29922. wawhamzaabovefinalarabic: 0xFE86,
  29923. wbsquare: 0x33DD,
  29924. wcircle: 0x24E6,
  29925. wcircumflex: 0x0175,
  29926. wdieresis: 0x1E85,
  29927. wdotaccent: 0x1E87,
  29928. wdotbelow: 0x1E89,
  29929. wehiragana: 0x3091,
  29930. weierstrass: 0x2118,
  29931. wekatakana: 0x30F1,
  29932. wekorean: 0x315E,
  29933. weokorean: 0x315D,
  29934. wgrave: 0x1E81,
  29935. whitebullet: 0x25E6,
  29936. whitecircle: 0x25CB,
  29937. whitecircleinverse: 0x25D9,
  29938. whitecornerbracketleft: 0x300E,
  29939. whitecornerbracketleftvertical: 0xFE43,
  29940. whitecornerbracketright: 0x300F,
  29941. whitecornerbracketrightvertical: 0xFE44,
  29942. whitediamond: 0x25C7,
  29943. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29944. whitedownpointingsmalltriangle: 0x25BF,
  29945. whitedownpointingtriangle: 0x25BD,
  29946. whiteleftpointingsmalltriangle: 0x25C3,
  29947. whiteleftpointingtriangle: 0x25C1,
  29948. whitelenticularbracketleft: 0x3016,
  29949. whitelenticularbracketright: 0x3017,
  29950. whiterightpointingsmalltriangle: 0x25B9,
  29951. whiterightpointingtriangle: 0x25B7,
  29952. whitesmallsquare: 0x25AB,
  29953. whitesmilingface: 0x263A,
  29954. whitesquare: 0x25A1,
  29955. whitestar: 0x2606,
  29956. whitetelephone: 0x260F,
  29957. whitetortoiseshellbracketleft: 0x3018,
  29958. whitetortoiseshellbracketright: 0x3019,
  29959. whiteuppointingsmalltriangle: 0x25B5,
  29960. whiteuppointingtriangle: 0x25B3,
  29961. wihiragana: 0x3090,
  29962. wikatakana: 0x30F0,
  29963. wikorean: 0x315F,
  29964. wmonospace: 0xFF57,
  29965. wohiragana: 0x3092,
  29966. wokatakana: 0x30F2,
  29967. wokatakanahalfwidth: 0xFF66,
  29968. won: 0x20A9,
  29969. wonmonospace: 0xFFE6,
  29970. wowaenthai: 0x0E27,
  29971. wparen: 0x24B2,
  29972. wring: 0x1E98,
  29973. wsuperior: 0x02B7,
  29974. wturned: 0x028D,
  29975. wynn: 0x01BF,
  29976. x: 0x0078,
  29977. xabovecmb: 0x033D,
  29978. xbopomofo: 0x3112,
  29979. xcircle: 0x24E7,
  29980. xdieresis: 0x1E8D,
  29981. xdotaccent: 0x1E8B,
  29982. xeharmenian: 0x056D,
  29983. xi: 0x03BE,
  29984. xmonospace: 0xFF58,
  29985. xparen: 0x24B3,
  29986. xsuperior: 0x02E3,
  29987. y: 0x0079,
  29988. yaadosquare: 0x334E,
  29989. yabengali: 0x09AF,
  29990. yacute: 0x00FD,
  29991. yadeva: 0x092F,
  29992. yaekorean: 0x3152,
  29993. yagujarati: 0x0AAF,
  29994. yagurmukhi: 0x0A2F,
  29995. yahiragana: 0x3084,
  29996. yakatakana: 0x30E4,
  29997. yakatakanahalfwidth: 0xFF94,
  29998. yakorean: 0x3151,
  29999. yamakkanthai: 0x0E4E,
  30000. yasmallhiragana: 0x3083,
  30001. yasmallkatakana: 0x30E3,
  30002. yasmallkatakanahalfwidth: 0xFF6C,
  30003. yatcyrillic: 0x0463,
  30004. ycircle: 0x24E8,
  30005. ycircumflex: 0x0177,
  30006. ydieresis: 0x00FF,
  30007. ydotaccent: 0x1E8F,
  30008. ydotbelow: 0x1EF5,
  30009. yeharabic: 0x064A,
  30010. yehbarreearabic: 0x06D2,
  30011. yehbarreefinalarabic: 0xFBAF,
  30012. yehfinalarabic: 0xFEF2,
  30013. yehhamzaabovearabic: 0x0626,
  30014. yehhamzaabovefinalarabic: 0xFE8A,
  30015. yehhamzaaboveinitialarabic: 0xFE8B,
  30016. yehhamzaabovemedialarabic: 0xFE8C,
  30017. yehinitialarabic: 0xFEF3,
  30018. yehmedialarabic: 0xFEF4,
  30019. yehmeeminitialarabic: 0xFCDD,
  30020. yehmeemisolatedarabic: 0xFC58,
  30021. yehnoonfinalarabic: 0xFC94,
  30022. yehthreedotsbelowarabic: 0x06D1,
  30023. yekorean: 0x3156,
  30024. yen: 0x00A5,
  30025. yenmonospace: 0xFFE5,
  30026. yeokorean: 0x3155,
  30027. yeorinhieuhkorean: 0x3186,
  30028. yerahbenyomohebrew: 0x05AA,
  30029. yerahbenyomolefthebrew: 0x05AA,
  30030. yericyrillic: 0x044B,
  30031. yerudieresiscyrillic: 0x04F9,
  30032. yesieungkorean: 0x3181,
  30033. yesieungpansioskorean: 0x3183,
  30034. yesieungsioskorean: 0x3182,
  30035. yetivhebrew: 0x059A,
  30036. ygrave: 0x1EF3,
  30037. yhook: 0x01B4,
  30038. yhookabove: 0x1EF7,
  30039. yiarmenian: 0x0575,
  30040. yicyrillic: 0x0457,
  30041. yikorean: 0x3162,
  30042. yinyang: 0x262F,
  30043. yiwnarmenian: 0x0582,
  30044. ymonospace: 0xFF59,
  30045. yod: 0x05D9,
  30046. yoddagesh: 0xFB39,
  30047. yoddageshhebrew: 0xFB39,
  30048. yodhebrew: 0x05D9,
  30049. yodyodhebrew: 0x05F2,
  30050. yodyodpatahhebrew: 0xFB1F,
  30051. yohiragana: 0x3088,
  30052. yoikorean: 0x3189,
  30053. yokatakana: 0x30E8,
  30054. yokatakanahalfwidth: 0xFF96,
  30055. yokorean: 0x315B,
  30056. yosmallhiragana: 0x3087,
  30057. yosmallkatakana: 0x30E7,
  30058. yosmallkatakanahalfwidth: 0xFF6E,
  30059. yotgreek: 0x03F3,
  30060. yoyaekorean: 0x3188,
  30061. yoyakorean: 0x3187,
  30062. yoyakthai: 0x0E22,
  30063. yoyingthai: 0x0E0D,
  30064. yparen: 0x24B4,
  30065. ypogegrammeni: 0x037A,
  30066. ypogegrammenigreekcmb: 0x0345,
  30067. yr: 0x01A6,
  30068. yring: 0x1E99,
  30069. ysuperior: 0x02B8,
  30070. ytilde: 0x1EF9,
  30071. yturned: 0x028E,
  30072. yuhiragana: 0x3086,
  30073. yuikorean: 0x318C,
  30074. yukatakana: 0x30E6,
  30075. yukatakanahalfwidth: 0xFF95,
  30076. yukorean: 0x3160,
  30077. yusbigcyrillic: 0x046B,
  30078. yusbigiotifiedcyrillic: 0x046D,
  30079. yuslittlecyrillic: 0x0467,
  30080. yuslittleiotifiedcyrillic: 0x0469,
  30081. yusmallhiragana: 0x3085,
  30082. yusmallkatakana: 0x30E5,
  30083. yusmallkatakanahalfwidth: 0xFF6D,
  30084. yuyekorean: 0x318B,
  30085. yuyeokorean: 0x318A,
  30086. yyabengali: 0x09DF,
  30087. yyadeva: 0x095F,
  30088. z: 0x007A,
  30089. zaarmenian: 0x0566,
  30090. zacute: 0x017A,
  30091. zadeva: 0x095B,
  30092. zagurmukhi: 0x0A5B,
  30093. zaharabic: 0x0638,
  30094. zahfinalarabic: 0xFEC6,
  30095. zahinitialarabic: 0xFEC7,
  30096. zahiragana: 0x3056,
  30097. zahmedialarabic: 0xFEC8,
  30098. zainarabic: 0x0632,
  30099. zainfinalarabic: 0xFEB0,
  30100. zakatakana: 0x30B6,
  30101. zaqefgadolhebrew: 0x0595,
  30102. zaqefqatanhebrew: 0x0594,
  30103. zarqahebrew: 0x0598,
  30104. zayin: 0x05D6,
  30105. zayindagesh: 0xFB36,
  30106. zayindageshhebrew: 0xFB36,
  30107. zayinhebrew: 0x05D6,
  30108. zbopomofo: 0x3117,
  30109. zcaron: 0x017E,
  30110. zcircle: 0x24E9,
  30111. zcircumflex: 0x1E91,
  30112. zcurl: 0x0291,
  30113. zdot: 0x017C,
  30114. zdotaccent: 0x017C,
  30115. zdotbelow: 0x1E93,
  30116. zecyrillic: 0x0437,
  30117. zedescendercyrillic: 0x0499,
  30118. zedieresiscyrillic: 0x04DF,
  30119. zehiragana: 0x305C,
  30120. zekatakana: 0x30BC,
  30121. zero: 0x0030,
  30122. zeroarabic: 0x0660,
  30123. zerobengali: 0x09E6,
  30124. zerodeva: 0x0966,
  30125. zerogujarati: 0x0AE6,
  30126. zerogurmukhi: 0x0A66,
  30127. zerohackarabic: 0x0660,
  30128. zeroinferior: 0x2080,
  30129. zeromonospace: 0xFF10,
  30130. zerooldstyle: 0xF730,
  30131. zeropersian: 0x06F0,
  30132. zerosuperior: 0x2070,
  30133. zerothai: 0x0E50,
  30134. zerowidthjoiner: 0xFEFF,
  30135. zerowidthnonjoiner: 0x200C,
  30136. zerowidthspace: 0x200B,
  30137. zeta: 0x03B6,
  30138. zhbopomofo: 0x3113,
  30139. zhearmenian: 0x056A,
  30140. zhebrevecyrillic: 0x04C2,
  30141. zhecyrillic: 0x0436,
  30142. zhedescendercyrillic: 0x0497,
  30143. zhedieresiscyrillic: 0x04DD,
  30144. zihiragana: 0x3058,
  30145. zikatakana: 0x30B8,
  30146. zinorhebrew: 0x05AE,
  30147. zlinebelow: 0x1E95,
  30148. zmonospace: 0xFF5A,
  30149. zohiragana: 0x305E,
  30150. zokatakana: 0x30BE,
  30151. zparen: 0x24B5,
  30152. zretroflexhook: 0x0290,
  30153. zstroke: 0x01B6,
  30154. zuhiragana: 0x305A,
  30155. zukatakana: 0x30BA,
  30156. '.notdef': 0x0000
  30157. };
  30158. var DingbatsGlyphsUnicode = {
  30159. space: 0x0020,
  30160. a1: 0x2701,
  30161. a2: 0x2702,
  30162. a202: 0x2703,
  30163. a3: 0x2704,
  30164. a4: 0x260E,
  30165. a5: 0x2706,
  30166. a119: 0x2707,
  30167. a118: 0x2708,
  30168. a117: 0x2709,
  30169. a11: 0x261B,
  30170. a12: 0x261E,
  30171. a13: 0x270C,
  30172. a14: 0x270D,
  30173. a15: 0x270E,
  30174. a16: 0x270F,
  30175. a105: 0x2710,
  30176. a17: 0x2711,
  30177. a18: 0x2712,
  30178. a19: 0x2713,
  30179. a20: 0x2714,
  30180. a21: 0x2715,
  30181. a22: 0x2716,
  30182. a23: 0x2717,
  30183. a24: 0x2718,
  30184. a25: 0x2719,
  30185. a26: 0x271A,
  30186. a27: 0x271B,
  30187. a28: 0x271C,
  30188. a6: 0x271D,
  30189. a7: 0x271E,
  30190. a8: 0x271F,
  30191. a9: 0x2720,
  30192. a10: 0x2721,
  30193. a29: 0x2722,
  30194. a30: 0x2723,
  30195. a31: 0x2724,
  30196. a32: 0x2725,
  30197. a33: 0x2726,
  30198. a34: 0x2727,
  30199. a35: 0x2605,
  30200. a36: 0x2729,
  30201. a37: 0x272A,
  30202. a38: 0x272B,
  30203. a39: 0x272C,
  30204. a40: 0x272D,
  30205. a41: 0x272E,
  30206. a42: 0x272F,
  30207. a43: 0x2730,
  30208. a44: 0x2731,
  30209. a45: 0x2732,
  30210. a46: 0x2733,
  30211. a47: 0x2734,
  30212. a48: 0x2735,
  30213. a49: 0x2736,
  30214. a50: 0x2737,
  30215. a51: 0x2738,
  30216. a52: 0x2739,
  30217. a53: 0x273A,
  30218. a54: 0x273B,
  30219. a55: 0x273C,
  30220. a56: 0x273D,
  30221. a57: 0x273E,
  30222. a58: 0x273F,
  30223. a59: 0x2740,
  30224. a60: 0x2741,
  30225. a61: 0x2742,
  30226. a62: 0x2743,
  30227. a63: 0x2744,
  30228. a64: 0x2745,
  30229. a65: 0x2746,
  30230. a66: 0x2747,
  30231. a67: 0x2748,
  30232. a68: 0x2749,
  30233. a69: 0x274A,
  30234. a70: 0x274B,
  30235. a71: 0x25CF,
  30236. a72: 0x274D,
  30237. a73: 0x25A0,
  30238. a74: 0x274F,
  30239. a203: 0x2750,
  30240. a75: 0x2751,
  30241. a204: 0x2752,
  30242. a76: 0x25B2,
  30243. a77: 0x25BC,
  30244. a78: 0x25C6,
  30245. a79: 0x2756,
  30246. a81: 0x25D7,
  30247. a82: 0x2758,
  30248. a83: 0x2759,
  30249. a84: 0x275A,
  30250. a97: 0x275B,
  30251. a98: 0x275C,
  30252. a99: 0x275D,
  30253. a100: 0x275E,
  30254. a101: 0x2761,
  30255. a102: 0x2762,
  30256. a103: 0x2763,
  30257. a104: 0x2764,
  30258. a106: 0x2765,
  30259. a107: 0x2766,
  30260. a108: 0x2767,
  30261. a112: 0x2663,
  30262. a111: 0x2666,
  30263. a110: 0x2665,
  30264. a109: 0x2660,
  30265. a120: 0x2460,
  30266. a121: 0x2461,
  30267. a122: 0x2462,
  30268. a123: 0x2463,
  30269. a124: 0x2464,
  30270. a125: 0x2465,
  30271. a126: 0x2466,
  30272. a127: 0x2467,
  30273. a128: 0x2468,
  30274. a129: 0x2469,
  30275. a130: 0x2776,
  30276. a131: 0x2777,
  30277. a132: 0x2778,
  30278. a133: 0x2779,
  30279. a134: 0x277A,
  30280. a135: 0x277B,
  30281. a136: 0x277C,
  30282. a137: 0x277D,
  30283. a138: 0x277E,
  30284. a139: 0x277F,
  30285. a140: 0x2780,
  30286. a141: 0x2781,
  30287. a142: 0x2782,
  30288. a143: 0x2783,
  30289. a144: 0x2784,
  30290. a145: 0x2785,
  30291. a146: 0x2786,
  30292. a147: 0x2787,
  30293. a148: 0x2788,
  30294. a149: 0x2789,
  30295. a150: 0x278A,
  30296. a151: 0x278B,
  30297. a152: 0x278C,
  30298. a153: 0x278D,
  30299. a154: 0x278E,
  30300. a155: 0x278F,
  30301. a156: 0x2790,
  30302. a157: 0x2791,
  30303. a158: 0x2792,
  30304. a159: 0x2793,
  30305. a160: 0x2794,
  30306. a161: 0x2192,
  30307. a163: 0x2194,
  30308. a164: 0x2195,
  30309. a196: 0x2798,
  30310. a165: 0x2799,
  30311. a192: 0x279A,
  30312. a166: 0x279B,
  30313. a167: 0x279C,
  30314. a168: 0x279D,
  30315. a169: 0x279E,
  30316. a170: 0x279F,
  30317. a171: 0x27A0,
  30318. a172: 0x27A1,
  30319. a173: 0x27A2,
  30320. a162: 0x27A3,
  30321. a174: 0x27A4,
  30322. a175: 0x27A5,
  30323. a176: 0x27A6,
  30324. a177: 0x27A7,
  30325. a178: 0x27A8,
  30326. a179: 0x27A9,
  30327. a193: 0x27AA,
  30328. a180: 0x27AB,
  30329. a199: 0x27AC,
  30330. a181: 0x27AD,
  30331. a200: 0x27AE,
  30332. a182: 0x27AF,
  30333. a201: 0x27B1,
  30334. a183: 0x27B2,
  30335. a184: 0x27B3,
  30336. a197: 0x27B4,
  30337. a185: 0x27B5,
  30338. a194: 0x27B6,
  30339. a198: 0x27B7,
  30340. a186: 0x27B8,
  30341. a195: 0x27B9,
  30342. a187: 0x27BA,
  30343. a188: 0x27BB,
  30344. a189: 0x27BC,
  30345. a190: 0x27BD,
  30346. a191: 0x27BE,
  30347. a89: 0x2768, // 0xF8D7
  30348. a90: 0x2769, // 0xF8D8
  30349. a93: 0x276A, // 0xF8D9
  30350. a94: 0x276B, // 0xF8DA
  30351. a91: 0x276C, // 0xF8DB
  30352. a92: 0x276D, // 0xF8DC
  30353. a205: 0x276E, // 0xF8DD
  30354. a85: 0x276F, // 0xF8DE
  30355. a206: 0x2770, // 0xF8DF
  30356. a86: 0x2771, // 0xF8E0
  30357. a87: 0x2772, // 0xF8E1
  30358. a88: 0x2773, // 0xF8E2
  30359. a95: 0x2774, // 0xF8E3
  30360. a96: 0x2775, // 0xF8E4
  30361. '.notdef': 0x0000
  30362. };
  30363. var PDFImage = (function PDFImageClosure() {
  30364. /**
  30365. * Decode the image in the main thread if it supported. Resovles the promise
  30366. * when the image data is ready.
  30367. */
  30368. function handleImageData(handler, xref, res, image) {
  30369. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30370. // For natively supported jpegs send them to the main thread for decoding.
  30371. var dict = image.dict;
  30372. var colorSpace = dict.get('ColorSpace', 'CS');
  30373. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30374. var numComps = colorSpace.numComps;
  30375. var decodePromise = handler.sendWithPromise('JpegDecode',
  30376. [image.getIR(), numComps]);
  30377. return decodePromise.then(function (message) {
  30378. var data = message.data;
  30379. return new Stream(data, 0, data.length, image.dict);
  30380. });
  30381. } else {
  30382. return Promise.resolve(image);
  30383. }
  30384. }
  30385. /**
  30386. * Decode and clamp a value. The formula is different from the spec because we
  30387. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30388. */
  30389. function decodeAndClamp(value, addend, coefficient, max) {
  30390. value = addend + value * coefficient;
  30391. // Clamp the value to the range
  30392. return (value < 0 ? 0 : (value > max ? max : value));
  30393. }
  30394. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30395. this.image = image;
  30396. var dict = image.dict;
  30397. if (dict.has('Filter')) {
  30398. var filter = dict.get('Filter').name;
  30399. if (filter === 'JPXDecode') {
  30400. var jpxImage = new JpxImage();
  30401. jpxImage.parseImageProperties(image.stream);
  30402. image.stream.reset();
  30403. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30404. image.numComps = jpxImage.componentsCount;
  30405. } else if (filter === 'JBIG2Decode') {
  30406. image.bitsPerComponent = 1;
  30407. image.numComps = 1;
  30408. }
  30409. }
  30410. // TODO cache rendered images?
  30411. this.width = dict.get('Width', 'W');
  30412. this.height = dict.get('Height', 'H');
  30413. if (this.width < 1 || this.height < 1) {
  30414. error('Invalid image width: ' + this.width + ' or height: ' +
  30415. this.height);
  30416. }
  30417. this.interpolate = dict.get('Interpolate', 'I') || false;
  30418. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30419. this.matte = dict.get('Matte') || false;
  30420. var bitsPerComponent = image.bitsPerComponent;
  30421. if (!bitsPerComponent) {
  30422. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30423. if (!bitsPerComponent) {
  30424. if (this.imageMask) {
  30425. bitsPerComponent = 1;
  30426. } else {
  30427. error('Bits per component missing in image: ' + this.imageMask);
  30428. }
  30429. }
  30430. }
  30431. this.bpc = bitsPerComponent;
  30432. if (!this.imageMask) {
  30433. var colorSpace = dict.get('ColorSpace', 'CS');
  30434. if (!colorSpace) {
  30435. info('JPX images (which do not require color spaces)');
  30436. switch (image.numComps) {
  30437. case 1:
  30438. colorSpace = Name.get('DeviceGray');
  30439. break;
  30440. case 3:
  30441. colorSpace = Name.get('DeviceRGB');
  30442. break;
  30443. case 4:
  30444. colorSpace = Name.get('DeviceCMYK');
  30445. break;
  30446. default:
  30447. error('JPX images with ' + this.numComps +
  30448. ' color components not supported.');
  30449. }
  30450. }
  30451. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30452. this.numComps = this.colorSpace.numComps;
  30453. }
  30454. this.decode = dict.get('Decode', 'D');
  30455. this.needsDecode = false;
  30456. if (this.decode &&
  30457. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30458. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30459. this.needsDecode = true;
  30460. // Do some preprocessing to avoid more math.
  30461. var max = (1 << bitsPerComponent) - 1;
  30462. this.decodeCoefficients = [];
  30463. this.decodeAddends = [];
  30464. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30465. var dmin = this.decode[i];
  30466. var dmax = this.decode[i + 1];
  30467. this.decodeCoefficients[j] = dmax - dmin;
  30468. this.decodeAddends[j] = max * dmin;
  30469. }
  30470. }
  30471. if (smask) {
  30472. this.smask = new PDFImage(xref, res, smask, false);
  30473. } else if (mask) {
  30474. if (isStream(mask)) {
  30475. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30476. } else {
  30477. // Color key mask (just an array).
  30478. this.mask = mask;
  30479. }
  30480. }
  30481. }
  30482. /**
  30483. * Handles processing of image data and returns the Promise that is resolved
  30484. * with a PDFImage when the image is ready to be used.
  30485. */
  30486. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30487. res, image, inline) {
  30488. var imagePromise = handleImageData(handler, xref, res, image);
  30489. var smaskPromise;
  30490. var maskPromise;
  30491. var smask = image.dict.get('SMask');
  30492. var mask = image.dict.get('Mask');
  30493. if (smask) {
  30494. smaskPromise = handleImageData(handler, xref, res, smask);
  30495. maskPromise = Promise.resolve(null);
  30496. } else {
  30497. smaskPromise = Promise.resolve(null);
  30498. if (mask) {
  30499. if (isStream(mask)) {
  30500. maskPromise = handleImageData(handler, xref, res, mask);
  30501. } else if (isArray(mask)) {
  30502. maskPromise = Promise.resolve(mask);
  30503. } else {
  30504. warn('Unsupported mask format.');
  30505. maskPromise = Promise.resolve(null);
  30506. }
  30507. } else {
  30508. maskPromise = Promise.resolve(null);
  30509. }
  30510. }
  30511. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30512. function(results) {
  30513. var imageData = results[0];
  30514. var smaskData = results[1];
  30515. var maskData = results[2];
  30516. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30517. });
  30518. };
  30519. /**
  30520. * Resize an image using the nearest neighbor algorithm. Currently only
  30521. * supports one and three component images.
  30522. * @param {TypedArray} pixels The original image with one component.
  30523. * @param {Number} bpc Number of bits per component.
  30524. * @param {Number} components Number of color components, 1 or 3 is supported.
  30525. * @param {Number} w1 Original width.
  30526. * @param {Number} h1 Original height.
  30527. * @param {Number} w2 New width.
  30528. * @param {Number} h2 New height.
  30529. * @param {TypedArray} dest (Optional) The destination buffer.
  30530. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30531. * @return {TypedArray} Resized image data.
  30532. */
  30533. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30534. w1, h1, w2, h2, dest, alpha01) {
  30535. if (components !== 1 && components !== 3) {
  30536. error('Unsupported component count for resizing.');
  30537. }
  30538. var length = w2 * h2 * components;
  30539. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30540. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30541. var xRatio = w1 / w2;
  30542. var yRatio = h1 / h2;
  30543. var i, j, py, newIndex = 0, oldIndex;
  30544. var xScaled = new Uint16Array(w2);
  30545. var w1Scanline = w1 * components;
  30546. if (alpha01 !== 1) {
  30547. alpha01 = 0;
  30548. }
  30549. for (j = 0; j < w2; j++) {
  30550. xScaled[j] = Math.floor(j * xRatio) * components;
  30551. }
  30552. if (components === 1) {
  30553. for (i = 0; i < h2; i++) {
  30554. py = Math.floor(i * yRatio) * w1Scanline;
  30555. for (j = 0; j < w2; j++) {
  30556. oldIndex = py + xScaled[j];
  30557. temp[newIndex++] = pixels[oldIndex];
  30558. }
  30559. }
  30560. } else if (components === 3) {
  30561. for (i = 0; i < h2; i++) {
  30562. py = Math.floor(i * yRatio) * w1Scanline;
  30563. for (j = 0; j < w2; j++) {
  30564. oldIndex = py + xScaled[j];
  30565. temp[newIndex++] = pixels[oldIndex++];
  30566. temp[newIndex++] = pixels[oldIndex++];
  30567. temp[newIndex++] = pixels[oldIndex++];
  30568. newIndex += alpha01;
  30569. }
  30570. }
  30571. }
  30572. return temp;
  30573. };
  30574. PDFImage.createMask =
  30575. function PDFImage_createMask(imgArray, width, height,
  30576. imageIsFromDecodeStream, inverseDecode) {
  30577. // |imgArray| might not contain full data for every pixel of the mask, so
  30578. // we need to distinguish between |computedLength| and |actualLength|.
  30579. // In particular, if inverseDecode is true, then the array we return must
  30580. // have a length of |computedLength|.
  30581. var computedLength = ((width + 7) >> 3) * height;
  30582. var actualLength = imgArray.byteLength;
  30583. var haveFullData = computedLength === actualLength;
  30584. var data, i;
  30585. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30586. // imgArray came from a DecodeStream and its data is in an appropriate
  30587. // form, so we can just transfer it.
  30588. data = imgArray;
  30589. } else if (!inverseDecode) {
  30590. data = new Uint8Array(actualLength);
  30591. data.set(imgArray);
  30592. } else {
  30593. data = new Uint8Array(computedLength);
  30594. data.set(imgArray);
  30595. for (i = actualLength; i < computedLength; i++) {
  30596. data[i] = 0xff;
  30597. }
  30598. }
  30599. // If necessary, invert the original mask data (but not any extra we might
  30600. // have added above). It's safe to modify the array -- whether it's the
  30601. // original or a copy, we're about to transfer it anyway, so nothing else
  30602. // in this thread can be relying on its contents.
  30603. if (inverseDecode) {
  30604. for (i = 0; i < actualLength; i++) {
  30605. data[i] = ~data[i];
  30606. }
  30607. }
  30608. return {data: data, width: width, height: height};
  30609. };
  30610. PDFImage.prototype = {
  30611. get drawWidth() {
  30612. return Math.max(this.width,
  30613. this.smask && this.smask.width || 0,
  30614. this.mask && this.mask.width || 0);
  30615. },
  30616. get drawHeight() {
  30617. return Math.max(this.height,
  30618. this.smask && this.smask.height || 0,
  30619. this.mask && this.mask.height || 0);
  30620. },
  30621. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30622. var bpc = this.bpc;
  30623. var numComps = this.numComps;
  30624. var decodeAddends = this.decodeAddends;
  30625. var decodeCoefficients = this.decodeCoefficients;
  30626. var max = (1 << bpc) - 1;
  30627. var i, ii;
  30628. if (bpc === 1) {
  30629. // If the buffer needed decode that means it just needs to be inverted.
  30630. for (i = 0, ii = buffer.length; i < ii; i++) {
  30631. buffer[i] = +!(buffer[i]);
  30632. }
  30633. return;
  30634. }
  30635. var index = 0;
  30636. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30637. for (var j = 0; j < numComps; j++) {
  30638. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30639. decodeCoefficients[j], max);
  30640. index++;
  30641. }
  30642. }
  30643. },
  30644. getComponents: function PDFImage_getComponents(buffer) {
  30645. var bpc = this.bpc;
  30646. // This image doesn't require any extra work.
  30647. if (bpc === 8) {
  30648. return buffer;
  30649. }
  30650. var width = this.width;
  30651. var height = this.height;
  30652. var numComps = this.numComps;
  30653. var length = width * height * numComps;
  30654. var bufferPos = 0;
  30655. var output = (bpc <= 8 ? new Uint8Array(length) :
  30656. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30657. var rowComps = width * numComps;
  30658. var max = (1 << bpc) - 1;
  30659. var i = 0, ii, buf;
  30660. if (bpc === 1) {
  30661. // Optimization for reading 1 bpc images.
  30662. var mask, loop1End, loop2End;
  30663. for (var j = 0; j < height; j++) {
  30664. loop1End = i + (rowComps & ~7);
  30665. loop2End = i + rowComps;
  30666. // unroll loop for all full bytes
  30667. while (i < loop1End) {
  30668. buf = buffer[bufferPos++];
  30669. output[i] = (buf >> 7) & 1;
  30670. output[i + 1] = (buf >> 6) & 1;
  30671. output[i + 2] = (buf >> 5) & 1;
  30672. output[i + 3] = (buf >> 4) & 1;
  30673. output[i + 4] = (buf >> 3) & 1;
  30674. output[i + 5] = (buf >> 2) & 1;
  30675. output[i + 6] = (buf >> 1) & 1;
  30676. output[i + 7] = buf & 1;
  30677. i += 8;
  30678. }
  30679. // handle remaing bits
  30680. if (i < loop2End) {
  30681. buf = buffer[bufferPos++];
  30682. mask = 128;
  30683. while (i < loop2End) {
  30684. output[i++] = +!!(buf & mask);
  30685. mask >>= 1;
  30686. }
  30687. }
  30688. }
  30689. } else {
  30690. // The general case that handles all other bpc values.
  30691. var bits = 0;
  30692. buf = 0;
  30693. for (i = 0, ii = length; i < ii; ++i) {
  30694. if (i % rowComps === 0) {
  30695. buf = 0;
  30696. bits = 0;
  30697. }
  30698. while (bits < bpc) {
  30699. buf = (buf << 8) | buffer[bufferPos++];
  30700. bits += 8;
  30701. }
  30702. var remainingBits = bits - bpc;
  30703. var value = buf >> remainingBits;
  30704. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30705. buf = buf & ((1 << remainingBits) - 1);
  30706. bits = remainingBits;
  30707. }
  30708. }
  30709. return output;
  30710. },
  30711. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30712. actualHeight, image) {
  30713. var smask = this.smask;
  30714. var mask = this.mask;
  30715. var alphaBuf, sw, sh, i, ii, j;
  30716. if (smask) {
  30717. sw = smask.width;
  30718. sh = smask.height;
  30719. alphaBuf = new Uint8Array(sw * sh);
  30720. smask.fillGrayBuffer(alphaBuf);
  30721. if (sw !== width || sh !== height) {
  30722. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30723. height);
  30724. }
  30725. } else if (mask) {
  30726. if (mask instanceof PDFImage) {
  30727. sw = mask.width;
  30728. sh = mask.height;
  30729. alphaBuf = new Uint8Array(sw * sh);
  30730. mask.numComps = 1;
  30731. mask.fillGrayBuffer(alphaBuf);
  30732. // Need to invert values in rgbaBuf
  30733. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30734. alphaBuf[i] = 255 - alphaBuf[i];
  30735. }
  30736. if (sw !== width || sh !== height) {
  30737. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30738. height);
  30739. }
  30740. } else if (isArray(mask)) {
  30741. // Color key mask: if any of the compontents are outside the range
  30742. // then they should be painted.
  30743. alphaBuf = new Uint8Array(width * height);
  30744. var numComps = this.numComps;
  30745. for (i = 0, ii = width * height; i < ii; ++i) {
  30746. var opacity = 0;
  30747. var imageOffset = i * numComps;
  30748. for (j = 0; j < numComps; ++j) {
  30749. var color = image[imageOffset + j];
  30750. var maskOffset = j * 2;
  30751. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30752. opacity = 255;
  30753. break;
  30754. }
  30755. }
  30756. alphaBuf[i] = opacity;
  30757. }
  30758. } else {
  30759. error('Unknown mask format.');
  30760. }
  30761. }
  30762. if (alphaBuf) {
  30763. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30764. rgbaBuf[j] = alphaBuf[i];
  30765. }
  30766. } else {
  30767. // No mask.
  30768. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30769. rgbaBuf[j] = 255;
  30770. }
  30771. }
  30772. },
  30773. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30774. var matte = this.smask && this.smask.matte;
  30775. if (!matte) {
  30776. return;
  30777. }
  30778. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30779. var matteR = matteRgb[0];
  30780. var matteG = matteRgb[1];
  30781. var matteB = matteRgb[2];
  30782. var length = width * height * 4;
  30783. var r, g, b;
  30784. for (var i = 0; i < length; i += 4) {
  30785. var alpha = buffer[i + 3];
  30786. if (alpha === 0) {
  30787. // according formula we have to get Infinity in all components
  30788. // making it white (typical paper color) should be okay
  30789. buffer[i] = 255;
  30790. buffer[i + 1] = 255;
  30791. buffer[i + 2] = 255;
  30792. continue;
  30793. }
  30794. var k = 255 / alpha;
  30795. r = (buffer[i] - matteR) * k + matteR;
  30796. g = (buffer[i + 1] - matteG) * k + matteG;
  30797. b = (buffer[i + 2] - matteB) * k + matteB;
  30798. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30799. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30800. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30801. }
  30802. },
  30803. createImageData: function PDFImage_createImageData(forceRGBA) {
  30804. var drawWidth = this.drawWidth;
  30805. var drawHeight = this.drawHeight;
  30806. var imgData = { // other fields are filled in below
  30807. width: drawWidth,
  30808. height: drawHeight
  30809. };
  30810. var numComps = this.numComps;
  30811. var originalWidth = this.width;
  30812. var originalHeight = this.height;
  30813. var bpc = this.bpc;
  30814. // Rows start at byte boundary.
  30815. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30816. var imgArray;
  30817. if (!forceRGBA) {
  30818. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30819. // without any complications, we pass a same-sized copy to the main
  30820. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30821. // of memory for many scanned documents. It's also much faster.
  30822. //
  30823. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30824. // complications, we avoid expanding by 1.333x to RGBA form.
  30825. var kind;
  30826. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30827. kind = ImageKind.GRAYSCALE_1BPP;
  30828. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30829. !this.needsDecode) {
  30830. kind = ImageKind.RGB_24BPP;
  30831. }
  30832. if (kind && !this.smask && !this.mask &&
  30833. drawWidth === originalWidth && drawHeight === originalHeight) {
  30834. imgData.kind = kind;
  30835. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30836. // If imgArray came from a DecodeStream, we're safe to transfer it
  30837. // (and thus neuter it) because it will constitute the entire
  30838. // DecodeStream's data. But if it came from a Stream, we need to
  30839. // copy it because it'll only be a portion of the Stream's data, and
  30840. // the rest will be read later on.
  30841. if (this.image instanceof DecodeStream) {
  30842. imgData.data = imgArray;
  30843. } else {
  30844. var newArray = new Uint8Array(imgArray.length);
  30845. newArray.set(imgArray);
  30846. imgData.data = newArray;
  30847. }
  30848. if (this.needsDecode) {
  30849. // Invert the buffer (which must be grayscale if we reached here).
  30850. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30851. var buffer = imgData.data;
  30852. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30853. buffer[i] ^= 0xff;
  30854. }
  30855. }
  30856. return imgData;
  30857. }
  30858. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30859. imgData.kind = ImageKind.RGB_24BPP;
  30860. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30861. drawWidth, drawHeight, true);
  30862. return imgData;
  30863. }
  30864. }
  30865. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30866. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30867. var actualHeight = 0 | (imgArray.length / rowBytes *
  30868. drawHeight / originalHeight);
  30869. var comps = this.getComponents(imgArray);
  30870. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30871. // more compact RGB_24BPP form if allowable.
  30872. var alpha01, maybeUndoPreblend;
  30873. if (!forceRGBA && !this.smask && !this.mask) {
  30874. imgData.kind = ImageKind.RGB_24BPP;
  30875. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30876. alpha01 = 0;
  30877. maybeUndoPreblend = false;
  30878. } else {
  30879. imgData.kind = ImageKind.RGBA_32BPP;
  30880. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30881. alpha01 = 1;
  30882. maybeUndoPreblend = true;
  30883. // Color key masking (opacity) must be performed before decoding.
  30884. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30885. comps);
  30886. }
  30887. if (this.needsDecode) {
  30888. this.decodeBuffer(comps);
  30889. }
  30890. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30891. drawWidth, drawHeight, actualHeight, bpc, comps,
  30892. alpha01);
  30893. if (maybeUndoPreblend) {
  30894. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30895. }
  30896. return imgData;
  30897. },
  30898. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30899. var numComps = this.numComps;
  30900. if (numComps !== 1) {
  30901. error('Reading gray scale from a color image: ' + numComps);
  30902. }
  30903. var width = this.width;
  30904. var height = this.height;
  30905. var bpc = this.bpc;
  30906. // rows start at byte boundary
  30907. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30908. var imgArray = this.getImageBytes(height * rowBytes);
  30909. var comps = this.getComponents(imgArray);
  30910. var i, length;
  30911. if (bpc === 1) {
  30912. // inline decoding (= inversion) for 1 bpc images
  30913. length = width * height;
  30914. if (this.needsDecode) {
  30915. // invert and scale to {0, 255}
  30916. for (i = 0; i < length; ++i) {
  30917. buffer[i] = (comps[i] - 1) & 255;
  30918. }
  30919. } else {
  30920. // scale to {0, 255}
  30921. for (i = 0; i < length; ++i) {
  30922. buffer[i] = (-comps[i]) & 255;
  30923. }
  30924. }
  30925. return;
  30926. }
  30927. if (this.needsDecode) {
  30928. this.decodeBuffer(comps);
  30929. }
  30930. length = width * height;
  30931. // we aren't using a colorspace so we need to scale the value
  30932. var scale = 255 / ((1 << bpc) - 1);
  30933. for (i = 0; i < length; ++i) {
  30934. buffer[i] = (scale * comps[i]) | 0;
  30935. }
  30936. },
  30937. getImageBytes: function PDFImage_getImageBytes(length,
  30938. drawWidth, drawHeight,
  30939. forceRGB) {
  30940. this.image.reset();
  30941. this.image.drawWidth = drawWidth || this.width;
  30942. this.image.drawHeight = drawHeight || this.height;
  30943. this.image.forceRGB = !!forceRGB;
  30944. return this.image.getBytes(length);
  30945. }
  30946. };
  30947. return PDFImage;
  30948. })();
  30949. // The Metrics object contains glyph widths (in glyph space units).
  30950. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30951. // space unit corresponds to 1/1000th of text space unit.
  30952. var Metrics = {
  30953. 'Courier': 600,
  30954. 'Courier-Bold': 600,
  30955. 'Courier-BoldOblique': 600,
  30956. 'Courier-Oblique': 600,
  30957. 'Helvetica' : {
  30958. 'space': 278,
  30959. 'exclam': 278,
  30960. 'quotedbl': 355,
  30961. 'numbersign': 556,
  30962. 'dollar': 556,
  30963. 'percent': 889,
  30964. 'ampersand': 667,
  30965. 'quoteright': 222,
  30966. 'parenleft': 333,
  30967. 'parenright': 333,
  30968. 'asterisk': 389,
  30969. 'plus': 584,
  30970. 'comma': 278,
  30971. 'hyphen': 333,
  30972. 'period': 278,
  30973. 'slash': 278,
  30974. 'zero': 556,
  30975. 'one': 556,
  30976. 'two': 556,
  30977. 'three': 556,
  30978. 'four': 556,
  30979. 'five': 556,
  30980. 'six': 556,
  30981. 'seven': 556,
  30982. 'eight': 556,
  30983. 'nine': 556,
  30984. 'colon': 278,
  30985. 'semicolon': 278,
  30986. 'less': 584,
  30987. 'equal': 584,
  30988. 'greater': 584,
  30989. 'question': 556,
  30990. 'at': 1015,
  30991. 'A': 667,
  30992. 'B': 667,
  30993. 'C': 722,
  30994. 'D': 722,
  30995. 'E': 667,
  30996. 'F': 611,
  30997. 'G': 778,
  30998. 'H': 722,
  30999. 'I': 278,
  31000. 'J': 500,
  31001. 'K': 667,
  31002. 'L': 556,
  31003. 'M': 833,
  31004. 'N': 722,
  31005. 'O': 778,
  31006. 'P': 667,
  31007. 'Q': 778,
  31008. 'R': 722,
  31009. 'S': 667,
  31010. 'T': 611,
  31011. 'U': 722,
  31012. 'V': 667,
  31013. 'W': 944,
  31014. 'X': 667,
  31015. 'Y': 667,
  31016. 'Z': 611,
  31017. 'bracketleft': 278,
  31018. 'backslash': 278,
  31019. 'bracketright': 278,
  31020. 'asciicircum': 469,
  31021. 'underscore': 556,
  31022. 'quoteleft': 222,
  31023. 'a': 556,
  31024. 'b': 556,
  31025. 'c': 500,
  31026. 'd': 556,
  31027. 'e': 556,
  31028. 'f': 278,
  31029. 'g': 556,
  31030. 'h': 556,
  31031. 'i': 222,
  31032. 'j': 222,
  31033. 'k': 500,
  31034. 'l': 222,
  31035. 'm': 833,
  31036. 'n': 556,
  31037. 'o': 556,
  31038. 'p': 556,
  31039. 'q': 556,
  31040. 'r': 333,
  31041. 's': 500,
  31042. 't': 278,
  31043. 'u': 556,
  31044. 'v': 500,
  31045. 'w': 722,
  31046. 'x': 500,
  31047. 'y': 500,
  31048. 'z': 500,
  31049. 'braceleft': 334,
  31050. 'bar': 260,
  31051. 'braceright': 334,
  31052. 'asciitilde': 584,
  31053. 'exclamdown': 333,
  31054. 'cent': 556,
  31055. 'sterling': 556,
  31056. 'fraction': 167,
  31057. 'yen': 556,
  31058. 'florin': 556,
  31059. 'section': 556,
  31060. 'currency': 556,
  31061. 'quotesingle': 191,
  31062. 'quotedblleft': 333,
  31063. 'guillemotleft': 556,
  31064. 'guilsinglleft': 333,
  31065. 'guilsinglright': 333,
  31066. 'fi': 500,
  31067. 'fl': 500,
  31068. 'endash': 556,
  31069. 'dagger': 556,
  31070. 'daggerdbl': 556,
  31071. 'periodcentered': 278,
  31072. 'paragraph': 537,
  31073. 'bullet': 350,
  31074. 'quotesinglbase': 222,
  31075. 'quotedblbase': 333,
  31076. 'quotedblright': 333,
  31077. 'guillemotright': 556,
  31078. 'ellipsis': 1000,
  31079. 'perthousand': 1000,
  31080. 'questiondown': 611,
  31081. 'grave': 333,
  31082. 'acute': 333,
  31083. 'circumflex': 333,
  31084. 'tilde': 333,
  31085. 'macron': 333,
  31086. 'breve': 333,
  31087. 'dotaccent': 333,
  31088. 'dieresis': 333,
  31089. 'ring': 333,
  31090. 'cedilla': 333,
  31091. 'hungarumlaut': 333,
  31092. 'ogonek': 333,
  31093. 'caron': 333,
  31094. 'emdash': 1000,
  31095. 'AE': 1000,
  31096. 'ordfeminine': 370,
  31097. 'Lslash': 556,
  31098. 'Oslash': 778,
  31099. 'OE': 1000,
  31100. 'ordmasculine': 365,
  31101. 'ae': 889,
  31102. 'dotlessi': 278,
  31103. 'lslash': 222,
  31104. 'oslash': 611,
  31105. 'oe': 944,
  31106. 'germandbls': 611,
  31107. 'Idieresis': 278,
  31108. 'eacute': 556,
  31109. 'abreve': 556,
  31110. 'uhungarumlaut': 556,
  31111. 'ecaron': 556,
  31112. 'Ydieresis': 667,
  31113. 'divide': 584,
  31114. 'Yacute': 667,
  31115. 'Acircumflex': 667,
  31116. 'aacute': 556,
  31117. 'Ucircumflex': 722,
  31118. 'yacute': 500,
  31119. 'scommaaccent': 500,
  31120. 'ecircumflex': 556,
  31121. 'Uring': 722,
  31122. 'Udieresis': 722,
  31123. 'aogonek': 556,
  31124. 'Uacute': 722,
  31125. 'uogonek': 556,
  31126. 'Edieresis': 667,
  31127. 'Dcroat': 722,
  31128. 'commaaccent': 250,
  31129. 'copyright': 737,
  31130. 'Emacron': 667,
  31131. 'ccaron': 500,
  31132. 'aring': 556,
  31133. 'Ncommaaccent': 722,
  31134. 'lacute': 222,
  31135. 'agrave': 556,
  31136. 'Tcommaaccent': 611,
  31137. 'Cacute': 722,
  31138. 'atilde': 556,
  31139. 'Edotaccent': 667,
  31140. 'scaron': 500,
  31141. 'scedilla': 500,
  31142. 'iacute': 278,
  31143. 'lozenge': 471,
  31144. 'Rcaron': 722,
  31145. 'Gcommaaccent': 778,
  31146. 'ucircumflex': 556,
  31147. 'acircumflex': 556,
  31148. 'Amacron': 667,
  31149. 'rcaron': 333,
  31150. 'ccedilla': 500,
  31151. 'Zdotaccent': 611,
  31152. 'Thorn': 667,
  31153. 'Omacron': 778,
  31154. 'Racute': 722,
  31155. 'Sacute': 667,
  31156. 'dcaron': 643,
  31157. 'Umacron': 722,
  31158. 'uring': 556,
  31159. 'threesuperior': 333,
  31160. 'Ograve': 778,
  31161. 'Agrave': 667,
  31162. 'Abreve': 667,
  31163. 'multiply': 584,
  31164. 'uacute': 556,
  31165. 'Tcaron': 611,
  31166. 'partialdiff': 476,
  31167. 'ydieresis': 500,
  31168. 'Nacute': 722,
  31169. 'icircumflex': 278,
  31170. 'Ecircumflex': 667,
  31171. 'adieresis': 556,
  31172. 'edieresis': 556,
  31173. 'cacute': 500,
  31174. 'nacute': 556,
  31175. 'umacron': 556,
  31176. 'Ncaron': 722,
  31177. 'Iacute': 278,
  31178. 'plusminus': 584,
  31179. 'brokenbar': 260,
  31180. 'registered': 737,
  31181. 'Gbreve': 778,
  31182. 'Idotaccent': 278,
  31183. 'summation': 600,
  31184. 'Egrave': 667,
  31185. 'racute': 333,
  31186. 'omacron': 556,
  31187. 'Zacute': 611,
  31188. 'Zcaron': 611,
  31189. 'greaterequal': 549,
  31190. 'Eth': 722,
  31191. 'Ccedilla': 722,
  31192. 'lcommaaccent': 222,
  31193. 'tcaron': 317,
  31194. 'eogonek': 556,
  31195. 'Uogonek': 722,
  31196. 'Aacute': 667,
  31197. 'Adieresis': 667,
  31198. 'egrave': 556,
  31199. 'zacute': 500,
  31200. 'iogonek': 222,
  31201. 'Oacute': 778,
  31202. 'oacute': 556,
  31203. 'amacron': 556,
  31204. 'sacute': 500,
  31205. 'idieresis': 278,
  31206. 'Ocircumflex': 778,
  31207. 'Ugrave': 722,
  31208. 'Delta': 612,
  31209. 'thorn': 556,
  31210. 'twosuperior': 333,
  31211. 'Odieresis': 778,
  31212. 'mu': 556,
  31213. 'igrave': 278,
  31214. 'ohungarumlaut': 556,
  31215. 'Eogonek': 667,
  31216. 'dcroat': 556,
  31217. 'threequarters': 834,
  31218. 'Scedilla': 667,
  31219. 'lcaron': 299,
  31220. 'Kcommaaccent': 667,
  31221. 'Lacute': 556,
  31222. 'trademark': 1000,
  31223. 'edotaccent': 556,
  31224. 'Igrave': 278,
  31225. 'Imacron': 278,
  31226. 'Lcaron': 556,
  31227. 'onehalf': 834,
  31228. 'lessequal': 549,
  31229. 'ocircumflex': 556,
  31230. 'ntilde': 556,
  31231. 'Uhungarumlaut': 722,
  31232. 'Eacute': 667,
  31233. 'emacron': 556,
  31234. 'gbreve': 556,
  31235. 'onequarter': 834,
  31236. 'Scaron': 667,
  31237. 'Scommaaccent': 667,
  31238. 'Ohungarumlaut': 778,
  31239. 'degree': 400,
  31240. 'ograve': 556,
  31241. 'Ccaron': 722,
  31242. 'ugrave': 556,
  31243. 'radical': 453,
  31244. 'Dcaron': 722,
  31245. 'rcommaaccent': 333,
  31246. 'Ntilde': 722,
  31247. 'otilde': 556,
  31248. 'Rcommaaccent': 722,
  31249. 'Lcommaaccent': 556,
  31250. 'Atilde': 667,
  31251. 'Aogonek': 667,
  31252. 'Aring': 667,
  31253. 'Otilde': 778,
  31254. 'zdotaccent': 500,
  31255. 'Ecaron': 667,
  31256. 'Iogonek': 278,
  31257. 'kcommaaccent': 500,
  31258. 'minus': 584,
  31259. 'Icircumflex': 278,
  31260. 'ncaron': 556,
  31261. 'tcommaaccent': 278,
  31262. 'logicalnot': 584,
  31263. 'odieresis': 556,
  31264. 'udieresis': 556,
  31265. 'notequal': 549,
  31266. 'gcommaaccent': 556,
  31267. 'eth': 556,
  31268. 'zcaron': 500,
  31269. 'ncommaaccent': 556,
  31270. 'onesuperior': 333,
  31271. 'imacron': 278,
  31272. 'Euro': 556
  31273. },
  31274. 'Helvetica-Bold': {
  31275. 'space': 278,
  31276. 'exclam': 333,
  31277. 'quotedbl': 474,
  31278. 'numbersign': 556,
  31279. 'dollar': 556,
  31280. 'percent': 889,
  31281. 'ampersand': 722,
  31282. 'quoteright': 278,
  31283. 'parenleft': 333,
  31284. 'parenright': 333,
  31285. 'asterisk': 389,
  31286. 'plus': 584,
  31287. 'comma': 278,
  31288. 'hyphen': 333,
  31289. 'period': 278,
  31290. 'slash': 278,
  31291. 'zero': 556,
  31292. 'one': 556,
  31293. 'two': 556,
  31294. 'three': 556,
  31295. 'four': 556,
  31296. 'five': 556,
  31297. 'six': 556,
  31298. 'seven': 556,
  31299. 'eight': 556,
  31300. 'nine': 556,
  31301. 'colon': 333,
  31302. 'semicolon': 333,
  31303. 'less': 584,
  31304. 'equal': 584,
  31305. 'greater': 584,
  31306. 'question': 611,
  31307. 'at': 975,
  31308. 'A': 722,
  31309. 'B': 722,
  31310. 'C': 722,
  31311. 'D': 722,
  31312. 'E': 667,
  31313. 'F': 611,
  31314. 'G': 778,
  31315. 'H': 722,
  31316. 'I': 278,
  31317. 'J': 556,
  31318. 'K': 722,
  31319. 'L': 611,
  31320. 'M': 833,
  31321. 'N': 722,
  31322. 'O': 778,
  31323. 'P': 667,
  31324. 'Q': 778,
  31325. 'R': 722,
  31326. 'S': 667,
  31327. 'T': 611,
  31328. 'U': 722,
  31329. 'V': 667,
  31330. 'W': 944,
  31331. 'X': 667,
  31332. 'Y': 667,
  31333. 'Z': 611,
  31334. 'bracketleft': 333,
  31335. 'backslash': 278,
  31336. 'bracketright': 333,
  31337. 'asciicircum': 584,
  31338. 'underscore': 556,
  31339. 'quoteleft': 278,
  31340. 'a': 556,
  31341. 'b': 611,
  31342. 'c': 556,
  31343. 'd': 611,
  31344. 'e': 556,
  31345. 'f': 333,
  31346. 'g': 611,
  31347. 'h': 611,
  31348. 'i': 278,
  31349. 'j': 278,
  31350. 'k': 556,
  31351. 'l': 278,
  31352. 'm': 889,
  31353. 'n': 611,
  31354. 'o': 611,
  31355. 'p': 611,
  31356. 'q': 611,
  31357. 'r': 389,
  31358. 's': 556,
  31359. 't': 333,
  31360. 'u': 611,
  31361. 'v': 556,
  31362. 'w': 778,
  31363. 'x': 556,
  31364. 'y': 556,
  31365. 'z': 500,
  31366. 'braceleft': 389,
  31367. 'bar': 280,
  31368. 'braceright': 389,
  31369. 'asciitilde': 584,
  31370. 'exclamdown': 333,
  31371. 'cent': 556,
  31372. 'sterling': 556,
  31373. 'fraction': 167,
  31374. 'yen': 556,
  31375. 'florin': 556,
  31376. 'section': 556,
  31377. 'currency': 556,
  31378. 'quotesingle': 238,
  31379. 'quotedblleft': 500,
  31380. 'guillemotleft': 556,
  31381. 'guilsinglleft': 333,
  31382. 'guilsinglright': 333,
  31383. 'fi': 611,
  31384. 'fl': 611,
  31385. 'endash': 556,
  31386. 'dagger': 556,
  31387. 'daggerdbl': 556,
  31388. 'periodcentered': 278,
  31389. 'paragraph': 556,
  31390. 'bullet': 350,
  31391. 'quotesinglbase': 278,
  31392. 'quotedblbase': 500,
  31393. 'quotedblright': 500,
  31394. 'guillemotright': 556,
  31395. 'ellipsis': 1000,
  31396. 'perthousand': 1000,
  31397. 'questiondown': 611,
  31398. 'grave': 333,
  31399. 'acute': 333,
  31400. 'circumflex': 333,
  31401. 'tilde': 333,
  31402. 'macron': 333,
  31403. 'breve': 333,
  31404. 'dotaccent': 333,
  31405. 'dieresis': 333,
  31406. 'ring': 333,
  31407. 'cedilla': 333,
  31408. 'hungarumlaut': 333,
  31409. 'ogonek': 333,
  31410. 'caron': 333,
  31411. 'emdash': 1000,
  31412. 'AE': 1000,
  31413. 'ordfeminine': 370,
  31414. 'Lslash': 611,
  31415. 'Oslash': 778,
  31416. 'OE': 1000,
  31417. 'ordmasculine': 365,
  31418. 'ae': 889,
  31419. 'dotlessi': 278,
  31420. 'lslash': 278,
  31421. 'oslash': 611,
  31422. 'oe': 944,
  31423. 'germandbls': 611,
  31424. 'Idieresis': 278,
  31425. 'eacute': 556,
  31426. 'abreve': 556,
  31427. 'uhungarumlaut': 611,
  31428. 'ecaron': 556,
  31429. 'Ydieresis': 667,
  31430. 'divide': 584,
  31431. 'Yacute': 667,
  31432. 'Acircumflex': 722,
  31433. 'aacute': 556,
  31434. 'Ucircumflex': 722,
  31435. 'yacute': 556,
  31436. 'scommaaccent': 556,
  31437. 'ecircumflex': 556,
  31438. 'Uring': 722,
  31439. 'Udieresis': 722,
  31440. 'aogonek': 556,
  31441. 'Uacute': 722,
  31442. 'uogonek': 611,
  31443. 'Edieresis': 667,
  31444. 'Dcroat': 722,
  31445. 'commaaccent': 250,
  31446. 'copyright': 737,
  31447. 'Emacron': 667,
  31448. 'ccaron': 556,
  31449. 'aring': 556,
  31450. 'Ncommaaccent': 722,
  31451. 'lacute': 278,
  31452. 'agrave': 556,
  31453. 'Tcommaaccent': 611,
  31454. 'Cacute': 722,
  31455. 'atilde': 556,
  31456. 'Edotaccent': 667,
  31457. 'scaron': 556,
  31458. 'scedilla': 556,
  31459. 'iacute': 278,
  31460. 'lozenge': 494,
  31461. 'Rcaron': 722,
  31462. 'Gcommaaccent': 778,
  31463. 'ucircumflex': 611,
  31464. 'acircumflex': 556,
  31465. 'Amacron': 722,
  31466. 'rcaron': 389,
  31467. 'ccedilla': 556,
  31468. 'Zdotaccent': 611,
  31469. 'Thorn': 667,
  31470. 'Omacron': 778,
  31471. 'Racute': 722,
  31472. 'Sacute': 667,
  31473. 'dcaron': 743,
  31474. 'Umacron': 722,
  31475. 'uring': 611,
  31476. 'threesuperior': 333,
  31477. 'Ograve': 778,
  31478. 'Agrave': 722,
  31479. 'Abreve': 722,
  31480. 'multiply': 584,
  31481. 'uacute': 611,
  31482. 'Tcaron': 611,
  31483. 'partialdiff': 494,
  31484. 'ydieresis': 556,
  31485. 'Nacute': 722,
  31486. 'icircumflex': 278,
  31487. 'Ecircumflex': 667,
  31488. 'adieresis': 556,
  31489. 'edieresis': 556,
  31490. 'cacute': 556,
  31491. 'nacute': 611,
  31492. 'umacron': 611,
  31493. 'Ncaron': 722,
  31494. 'Iacute': 278,
  31495. 'plusminus': 584,
  31496. 'brokenbar': 280,
  31497. 'registered': 737,
  31498. 'Gbreve': 778,
  31499. 'Idotaccent': 278,
  31500. 'summation': 600,
  31501. 'Egrave': 667,
  31502. 'racute': 389,
  31503. 'omacron': 611,
  31504. 'Zacute': 611,
  31505. 'Zcaron': 611,
  31506. 'greaterequal': 549,
  31507. 'Eth': 722,
  31508. 'Ccedilla': 722,
  31509. 'lcommaaccent': 278,
  31510. 'tcaron': 389,
  31511. 'eogonek': 556,
  31512. 'Uogonek': 722,
  31513. 'Aacute': 722,
  31514. 'Adieresis': 722,
  31515. 'egrave': 556,
  31516. 'zacute': 500,
  31517. 'iogonek': 278,
  31518. 'Oacute': 778,
  31519. 'oacute': 611,
  31520. 'amacron': 556,
  31521. 'sacute': 556,
  31522. 'idieresis': 278,
  31523. 'Ocircumflex': 778,
  31524. 'Ugrave': 722,
  31525. 'Delta': 612,
  31526. 'thorn': 611,
  31527. 'twosuperior': 333,
  31528. 'Odieresis': 778,
  31529. 'mu': 611,
  31530. 'igrave': 278,
  31531. 'ohungarumlaut': 611,
  31532. 'Eogonek': 667,
  31533. 'dcroat': 611,
  31534. 'threequarters': 834,
  31535. 'Scedilla': 667,
  31536. 'lcaron': 400,
  31537. 'Kcommaaccent': 722,
  31538. 'Lacute': 611,
  31539. 'trademark': 1000,
  31540. 'edotaccent': 556,
  31541. 'Igrave': 278,
  31542. 'Imacron': 278,
  31543. 'Lcaron': 611,
  31544. 'onehalf': 834,
  31545. 'lessequal': 549,
  31546. 'ocircumflex': 611,
  31547. 'ntilde': 611,
  31548. 'Uhungarumlaut': 722,
  31549. 'Eacute': 667,
  31550. 'emacron': 556,
  31551. 'gbreve': 611,
  31552. 'onequarter': 834,
  31553. 'Scaron': 667,
  31554. 'Scommaaccent': 667,
  31555. 'Ohungarumlaut': 778,
  31556. 'degree': 400,
  31557. 'ograve': 611,
  31558. 'Ccaron': 722,
  31559. 'ugrave': 611,
  31560. 'radical': 549,
  31561. 'Dcaron': 722,
  31562. 'rcommaaccent': 389,
  31563. 'Ntilde': 722,
  31564. 'otilde': 611,
  31565. 'Rcommaaccent': 722,
  31566. 'Lcommaaccent': 611,
  31567. 'Atilde': 722,
  31568. 'Aogonek': 722,
  31569. 'Aring': 722,
  31570. 'Otilde': 778,
  31571. 'zdotaccent': 500,
  31572. 'Ecaron': 667,
  31573. 'Iogonek': 278,
  31574. 'kcommaaccent': 556,
  31575. 'minus': 584,
  31576. 'Icircumflex': 278,
  31577. 'ncaron': 611,
  31578. 'tcommaaccent': 333,
  31579. 'logicalnot': 584,
  31580. 'odieresis': 611,
  31581. 'udieresis': 611,
  31582. 'notequal': 549,
  31583. 'gcommaaccent': 611,
  31584. 'eth': 611,
  31585. 'zcaron': 500,
  31586. 'ncommaaccent': 611,
  31587. 'onesuperior': 333,
  31588. 'imacron': 278,
  31589. 'Euro': 556
  31590. },
  31591. 'Helvetica-BoldOblique': {
  31592. 'space': 278,
  31593. 'exclam': 333,
  31594. 'quotedbl': 474,
  31595. 'numbersign': 556,
  31596. 'dollar': 556,
  31597. 'percent': 889,
  31598. 'ampersand': 722,
  31599. 'quoteright': 278,
  31600. 'parenleft': 333,
  31601. 'parenright': 333,
  31602. 'asterisk': 389,
  31603. 'plus': 584,
  31604. 'comma': 278,
  31605. 'hyphen': 333,
  31606. 'period': 278,
  31607. 'slash': 278,
  31608. 'zero': 556,
  31609. 'one': 556,
  31610. 'two': 556,
  31611. 'three': 556,
  31612. 'four': 556,
  31613. 'five': 556,
  31614. 'six': 556,
  31615. 'seven': 556,
  31616. 'eight': 556,
  31617. 'nine': 556,
  31618. 'colon': 333,
  31619. 'semicolon': 333,
  31620. 'less': 584,
  31621. 'equal': 584,
  31622. 'greater': 584,
  31623. 'question': 611,
  31624. 'at': 975,
  31625. 'A': 722,
  31626. 'B': 722,
  31627. 'C': 722,
  31628. 'D': 722,
  31629. 'E': 667,
  31630. 'F': 611,
  31631. 'G': 778,
  31632. 'H': 722,
  31633. 'I': 278,
  31634. 'J': 556,
  31635. 'K': 722,
  31636. 'L': 611,
  31637. 'M': 833,
  31638. 'N': 722,
  31639. 'O': 778,
  31640. 'P': 667,
  31641. 'Q': 778,
  31642. 'R': 722,
  31643. 'S': 667,
  31644. 'T': 611,
  31645. 'U': 722,
  31646. 'V': 667,
  31647. 'W': 944,
  31648. 'X': 667,
  31649. 'Y': 667,
  31650. 'Z': 611,
  31651. 'bracketleft': 333,
  31652. 'backslash': 278,
  31653. 'bracketright': 333,
  31654. 'asciicircum': 584,
  31655. 'underscore': 556,
  31656. 'quoteleft': 278,
  31657. 'a': 556,
  31658. 'b': 611,
  31659. 'c': 556,
  31660. 'd': 611,
  31661. 'e': 556,
  31662. 'f': 333,
  31663. 'g': 611,
  31664. 'h': 611,
  31665. 'i': 278,
  31666. 'j': 278,
  31667. 'k': 556,
  31668. 'l': 278,
  31669. 'm': 889,
  31670. 'n': 611,
  31671. 'o': 611,
  31672. 'p': 611,
  31673. 'q': 611,
  31674. 'r': 389,
  31675. 's': 556,
  31676. 't': 333,
  31677. 'u': 611,
  31678. 'v': 556,
  31679. 'w': 778,
  31680. 'x': 556,
  31681. 'y': 556,
  31682. 'z': 500,
  31683. 'braceleft': 389,
  31684. 'bar': 280,
  31685. 'braceright': 389,
  31686. 'asciitilde': 584,
  31687. 'exclamdown': 333,
  31688. 'cent': 556,
  31689. 'sterling': 556,
  31690. 'fraction': 167,
  31691. 'yen': 556,
  31692. 'florin': 556,
  31693. 'section': 556,
  31694. 'currency': 556,
  31695. 'quotesingle': 238,
  31696. 'quotedblleft': 500,
  31697. 'guillemotleft': 556,
  31698. 'guilsinglleft': 333,
  31699. 'guilsinglright': 333,
  31700. 'fi': 611,
  31701. 'fl': 611,
  31702. 'endash': 556,
  31703. 'dagger': 556,
  31704. 'daggerdbl': 556,
  31705. 'periodcentered': 278,
  31706. 'paragraph': 556,
  31707. 'bullet': 350,
  31708. 'quotesinglbase': 278,
  31709. 'quotedblbase': 500,
  31710. 'quotedblright': 500,
  31711. 'guillemotright': 556,
  31712. 'ellipsis': 1000,
  31713. 'perthousand': 1000,
  31714. 'questiondown': 611,
  31715. 'grave': 333,
  31716. 'acute': 333,
  31717. 'circumflex': 333,
  31718. 'tilde': 333,
  31719. 'macron': 333,
  31720. 'breve': 333,
  31721. 'dotaccent': 333,
  31722. 'dieresis': 333,
  31723. 'ring': 333,
  31724. 'cedilla': 333,
  31725. 'hungarumlaut': 333,
  31726. 'ogonek': 333,
  31727. 'caron': 333,
  31728. 'emdash': 1000,
  31729. 'AE': 1000,
  31730. 'ordfeminine': 370,
  31731. 'Lslash': 611,
  31732. 'Oslash': 778,
  31733. 'OE': 1000,
  31734. 'ordmasculine': 365,
  31735. 'ae': 889,
  31736. 'dotlessi': 278,
  31737. 'lslash': 278,
  31738. 'oslash': 611,
  31739. 'oe': 944,
  31740. 'germandbls': 611,
  31741. 'Idieresis': 278,
  31742. 'eacute': 556,
  31743. 'abreve': 556,
  31744. 'uhungarumlaut': 611,
  31745. 'ecaron': 556,
  31746. 'Ydieresis': 667,
  31747. 'divide': 584,
  31748. 'Yacute': 667,
  31749. 'Acircumflex': 722,
  31750. 'aacute': 556,
  31751. 'Ucircumflex': 722,
  31752. 'yacute': 556,
  31753. 'scommaaccent': 556,
  31754. 'ecircumflex': 556,
  31755. 'Uring': 722,
  31756. 'Udieresis': 722,
  31757. 'aogonek': 556,
  31758. 'Uacute': 722,
  31759. 'uogonek': 611,
  31760. 'Edieresis': 667,
  31761. 'Dcroat': 722,
  31762. 'commaaccent': 250,
  31763. 'copyright': 737,
  31764. 'Emacron': 667,
  31765. 'ccaron': 556,
  31766. 'aring': 556,
  31767. 'Ncommaaccent': 722,
  31768. 'lacute': 278,
  31769. 'agrave': 556,
  31770. 'Tcommaaccent': 611,
  31771. 'Cacute': 722,
  31772. 'atilde': 556,
  31773. 'Edotaccent': 667,
  31774. 'scaron': 556,
  31775. 'scedilla': 556,
  31776. 'iacute': 278,
  31777. 'lozenge': 494,
  31778. 'Rcaron': 722,
  31779. 'Gcommaaccent': 778,
  31780. 'ucircumflex': 611,
  31781. 'acircumflex': 556,
  31782. 'Amacron': 722,
  31783. 'rcaron': 389,
  31784. 'ccedilla': 556,
  31785. 'Zdotaccent': 611,
  31786. 'Thorn': 667,
  31787. 'Omacron': 778,
  31788. 'Racute': 722,
  31789. 'Sacute': 667,
  31790. 'dcaron': 743,
  31791. 'Umacron': 722,
  31792. 'uring': 611,
  31793. 'threesuperior': 333,
  31794. 'Ograve': 778,
  31795. 'Agrave': 722,
  31796. 'Abreve': 722,
  31797. 'multiply': 584,
  31798. 'uacute': 611,
  31799. 'Tcaron': 611,
  31800. 'partialdiff': 494,
  31801. 'ydieresis': 556,
  31802. 'Nacute': 722,
  31803. 'icircumflex': 278,
  31804. 'Ecircumflex': 667,
  31805. 'adieresis': 556,
  31806. 'edieresis': 556,
  31807. 'cacute': 556,
  31808. 'nacute': 611,
  31809. 'umacron': 611,
  31810. 'Ncaron': 722,
  31811. 'Iacute': 278,
  31812. 'plusminus': 584,
  31813. 'brokenbar': 280,
  31814. 'registered': 737,
  31815. 'Gbreve': 778,
  31816. 'Idotaccent': 278,
  31817. 'summation': 600,
  31818. 'Egrave': 667,
  31819. 'racute': 389,
  31820. 'omacron': 611,
  31821. 'Zacute': 611,
  31822. 'Zcaron': 611,
  31823. 'greaterequal': 549,
  31824. 'Eth': 722,
  31825. 'Ccedilla': 722,
  31826. 'lcommaaccent': 278,
  31827. 'tcaron': 389,
  31828. 'eogonek': 556,
  31829. 'Uogonek': 722,
  31830. 'Aacute': 722,
  31831. 'Adieresis': 722,
  31832. 'egrave': 556,
  31833. 'zacute': 500,
  31834. 'iogonek': 278,
  31835. 'Oacute': 778,
  31836. 'oacute': 611,
  31837. 'amacron': 556,
  31838. 'sacute': 556,
  31839. 'idieresis': 278,
  31840. 'Ocircumflex': 778,
  31841. 'Ugrave': 722,
  31842. 'Delta': 612,
  31843. 'thorn': 611,
  31844. 'twosuperior': 333,
  31845. 'Odieresis': 778,
  31846. 'mu': 611,
  31847. 'igrave': 278,
  31848. 'ohungarumlaut': 611,
  31849. 'Eogonek': 667,
  31850. 'dcroat': 611,
  31851. 'threequarters': 834,
  31852. 'Scedilla': 667,
  31853. 'lcaron': 400,
  31854. 'Kcommaaccent': 722,
  31855. 'Lacute': 611,
  31856. 'trademark': 1000,
  31857. 'edotaccent': 556,
  31858. 'Igrave': 278,
  31859. 'Imacron': 278,
  31860. 'Lcaron': 611,
  31861. 'onehalf': 834,
  31862. 'lessequal': 549,
  31863. 'ocircumflex': 611,
  31864. 'ntilde': 611,
  31865. 'Uhungarumlaut': 722,
  31866. 'Eacute': 667,
  31867. 'emacron': 556,
  31868. 'gbreve': 611,
  31869. 'onequarter': 834,
  31870. 'Scaron': 667,
  31871. 'Scommaaccent': 667,
  31872. 'Ohungarumlaut': 778,
  31873. 'degree': 400,
  31874. 'ograve': 611,
  31875. 'Ccaron': 722,
  31876. 'ugrave': 611,
  31877. 'radical': 549,
  31878. 'Dcaron': 722,
  31879. 'rcommaaccent': 389,
  31880. 'Ntilde': 722,
  31881. 'otilde': 611,
  31882. 'Rcommaaccent': 722,
  31883. 'Lcommaaccent': 611,
  31884. 'Atilde': 722,
  31885. 'Aogonek': 722,
  31886. 'Aring': 722,
  31887. 'Otilde': 778,
  31888. 'zdotaccent': 500,
  31889. 'Ecaron': 667,
  31890. 'Iogonek': 278,
  31891. 'kcommaaccent': 556,
  31892. 'minus': 584,
  31893. 'Icircumflex': 278,
  31894. 'ncaron': 611,
  31895. 'tcommaaccent': 333,
  31896. 'logicalnot': 584,
  31897. 'odieresis': 611,
  31898. 'udieresis': 611,
  31899. 'notequal': 549,
  31900. 'gcommaaccent': 611,
  31901. 'eth': 611,
  31902. 'zcaron': 500,
  31903. 'ncommaaccent': 611,
  31904. 'onesuperior': 333,
  31905. 'imacron': 278,
  31906. 'Euro': 556
  31907. },
  31908. 'Helvetica-Oblique' : {
  31909. 'space': 278,
  31910. 'exclam': 278,
  31911. 'quotedbl': 355,
  31912. 'numbersign': 556,
  31913. 'dollar': 556,
  31914. 'percent': 889,
  31915. 'ampersand': 667,
  31916. 'quoteright': 222,
  31917. 'parenleft': 333,
  31918. 'parenright': 333,
  31919. 'asterisk': 389,
  31920. 'plus': 584,
  31921. 'comma': 278,
  31922. 'hyphen': 333,
  31923. 'period': 278,
  31924. 'slash': 278,
  31925. 'zero': 556,
  31926. 'one': 556,
  31927. 'two': 556,
  31928. 'three': 556,
  31929. 'four': 556,
  31930. 'five': 556,
  31931. 'six': 556,
  31932. 'seven': 556,
  31933. 'eight': 556,
  31934. 'nine': 556,
  31935. 'colon': 278,
  31936. 'semicolon': 278,
  31937. 'less': 584,
  31938. 'equal': 584,
  31939. 'greater': 584,
  31940. 'question': 556,
  31941. 'at': 1015,
  31942. 'A': 667,
  31943. 'B': 667,
  31944. 'C': 722,
  31945. 'D': 722,
  31946. 'E': 667,
  31947. 'F': 611,
  31948. 'G': 778,
  31949. 'H': 722,
  31950. 'I': 278,
  31951. 'J': 500,
  31952. 'K': 667,
  31953. 'L': 556,
  31954. 'M': 833,
  31955. 'N': 722,
  31956. 'O': 778,
  31957. 'P': 667,
  31958. 'Q': 778,
  31959. 'R': 722,
  31960. 'S': 667,
  31961. 'T': 611,
  31962. 'U': 722,
  31963. 'V': 667,
  31964. 'W': 944,
  31965. 'X': 667,
  31966. 'Y': 667,
  31967. 'Z': 611,
  31968. 'bracketleft': 278,
  31969. 'backslash': 278,
  31970. 'bracketright': 278,
  31971. 'asciicircum': 469,
  31972. 'underscore': 556,
  31973. 'quoteleft': 222,
  31974. 'a': 556,
  31975. 'b': 556,
  31976. 'c': 500,
  31977. 'd': 556,
  31978. 'e': 556,
  31979. 'f': 278,
  31980. 'g': 556,
  31981. 'h': 556,
  31982. 'i': 222,
  31983. 'j': 222,
  31984. 'k': 500,
  31985. 'l': 222,
  31986. 'm': 833,
  31987. 'n': 556,
  31988. 'o': 556,
  31989. 'p': 556,
  31990. 'q': 556,
  31991. 'r': 333,
  31992. 's': 500,
  31993. 't': 278,
  31994. 'u': 556,
  31995. 'v': 500,
  31996. 'w': 722,
  31997. 'x': 500,
  31998. 'y': 500,
  31999. 'z': 500,
  32000. 'braceleft': 334,
  32001. 'bar': 260,
  32002. 'braceright': 334,
  32003. 'asciitilde': 584,
  32004. 'exclamdown': 333,
  32005. 'cent': 556,
  32006. 'sterling': 556,
  32007. 'fraction': 167,
  32008. 'yen': 556,
  32009. 'florin': 556,
  32010. 'section': 556,
  32011. 'currency': 556,
  32012. 'quotesingle': 191,
  32013. 'quotedblleft': 333,
  32014. 'guillemotleft': 556,
  32015. 'guilsinglleft': 333,
  32016. 'guilsinglright': 333,
  32017. 'fi': 500,
  32018. 'fl': 500,
  32019. 'endash': 556,
  32020. 'dagger': 556,
  32021. 'daggerdbl': 556,
  32022. 'periodcentered': 278,
  32023. 'paragraph': 537,
  32024. 'bullet': 350,
  32025. 'quotesinglbase': 222,
  32026. 'quotedblbase': 333,
  32027. 'quotedblright': 333,
  32028. 'guillemotright': 556,
  32029. 'ellipsis': 1000,
  32030. 'perthousand': 1000,
  32031. 'questiondown': 611,
  32032. 'grave': 333,
  32033. 'acute': 333,
  32034. 'circumflex': 333,
  32035. 'tilde': 333,
  32036. 'macron': 333,
  32037. 'breve': 333,
  32038. 'dotaccent': 333,
  32039. 'dieresis': 333,
  32040. 'ring': 333,
  32041. 'cedilla': 333,
  32042. 'hungarumlaut': 333,
  32043. 'ogonek': 333,
  32044. 'caron': 333,
  32045. 'emdash': 1000,
  32046. 'AE': 1000,
  32047. 'ordfeminine': 370,
  32048. 'Lslash': 556,
  32049. 'Oslash': 778,
  32050. 'OE': 1000,
  32051. 'ordmasculine': 365,
  32052. 'ae': 889,
  32053. 'dotlessi': 278,
  32054. 'lslash': 222,
  32055. 'oslash': 611,
  32056. 'oe': 944,
  32057. 'germandbls': 611,
  32058. 'Idieresis': 278,
  32059. 'eacute': 556,
  32060. 'abreve': 556,
  32061. 'uhungarumlaut': 556,
  32062. 'ecaron': 556,
  32063. 'Ydieresis': 667,
  32064. 'divide': 584,
  32065. 'Yacute': 667,
  32066. 'Acircumflex': 667,
  32067. 'aacute': 556,
  32068. 'Ucircumflex': 722,
  32069. 'yacute': 500,
  32070. 'scommaaccent': 500,
  32071. 'ecircumflex': 556,
  32072. 'Uring': 722,
  32073. 'Udieresis': 722,
  32074. 'aogonek': 556,
  32075. 'Uacute': 722,
  32076. 'uogonek': 556,
  32077. 'Edieresis': 667,
  32078. 'Dcroat': 722,
  32079. 'commaaccent': 250,
  32080. 'copyright': 737,
  32081. 'Emacron': 667,
  32082. 'ccaron': 500,
  32083. 'aring': 556,
  32084. 'Ncommaaccent': 722,
  32085. 'lacute': 222,
  32086. 'agrave': 556,
  32087. 'Tcommaaccent': 611,
  32088. 'Cacute': 722,
  32089. 'atilde': 556,
  32090. 'Edotaccent': 667,
  32091. 'scaron': 500,
  32092. 'scedilla': 500,
  32093. 'iacute': 278,
  32094. 'lozenge': 471,
  32095. 'Rcaron': 722,
  32096. 'Gcommaaccent': 778,
  32097. 'ucircumflex': 556,
  32098. 'acircumflex': 556,
  32099. 'Amacron': 667,
  32100. 'rcaron': 333,
  32101. 'ccedilla': 500,
  32102. 'Zdotaccent': 611,
  32103. 'Thorn': 667,
  32104. 'Omacron': 778,
  32105. 'Racute': 722,
  32106. 'Sacute': 667,
  32107. 'dcaron': 643,
  32108. 'Umacron': 722,
  32109. 'uring': 556,
  32110. 'threesuperior': 333,
  32111. 'Ograve': 778,
  32112. 'Agrave': 667,
  32113. 'Abreve': 667,
  32114. 'multiply': 584,
  32115. 'uacute': 556,
  32116. 'Tcaron': 611,
  32117. 'partialdiff': 476,
  32118. 'ydieresis': 500,
  32119. 'Nacute': 722,
  32120. 'icircumflex': 278,
  32121. 'Ecircumflex': 667,
  32122. 'adieresis': 556,
  32123. 'edieresis': 556,
  32124. 'cacute': 500,
  32125. 'nacute': 556,
  32126. 'umacron': 556,
  32127. 'Ncaron': 722,
  32128. 'Iacute': 278,
  32129. 'plusminus': 584,
  32130. 'brokenbar': 260,
  32131. 'registered': 737,
  32132. 'Gbreve': 778,
  32133. 'Idotaccent': 278,
  32134. 'summation': 600,
  32135. 'Egrave': 667,
  32136. 'racute': 333,
  32137. 'omacron': 556,
  32138. 'Zacute': 611,
  32139. 'Zcaron': 611,
  32140. 'greaterequal': 549,
  32141. 'Eth': 722,
  32142. 'Ccedilla': 722,
  32143. 'lcommaaccent': 222,
  32144. 'tcaron': 317,
  32145. 'eogonek': 556,
  32146. 'Uogonek': 722,
  32147. 'Aacute': 667,
  32148. 'Adieresis': 667,
  32149. 'egrave': 556,
  32150. 'zacute': 500,
  32151. 'iogonek': 222,
  32152. 'Oacute': 778,
  32153. 'oacute': 556,
  32154. 'amacron': 556,
  32155. 'sacute': 500,
  32156. 'idieresis': 278,
  32157. 'Ocircumflex': 778,
  32158. 'Ugrave': 722,
  32159. 'Delta': 612,
  32160. 'thorn': 556,
  32161. 'twosuperior': 333,
  32162. 'Odieresis': 778,
  32163. 'mu': 556,
  32164. 'igrave': 278,
  32165. 'ohungarumlaut': 556,
  32166. 'Eogonek': 667,
  32167. 'dcroat': 556,
  32168. 'threequarters': 834,
  32169. 'Scedilla': 667,
  32170. 'lcaron': 299,
  32171. 'Kcommaaccent': 667,
  32172. 'Lacute': 556,
  32173. 'trademark': 1000,
  32174. 'edotaccent': 556,
  32175. 'Igrave': 278,
  32176. 'Imacron': 278,
  32177. 'Lcaron': 556,
  32178. 'onehalf': 834,
  32179. 'lessequal': 549,
  32180. 'ocircumflex': 556,
  32181. 'ntilde': 556,
  32182. 'Uhungarumlaut': 722,
  32183. 'Eacute': 667,
  32184. 'emacron': 556,
  32185. 'gbreve': 556,
  32186. 'onequarter': 834,
  32187. 'Scaron': 667,
  32188. 'Scommaaccent': 667,
  32189. 'Ohungarumlaut': 778,
  32190. 'degree': 400,
  32191. 'ograve': 556,
  32192. 'Ccaron': 722,
  32193. 'ugrave': 556,
  32194. 'radical': 453,
  32195. 'Dcaron': 722,
  32196. 'rcommaaccent': 333,
  32197. 'Ntilde': 722,
  32198. 'otilde': 556,
  32199. 'Rcommaaccent': 722,
  32200. 'Lcommaaccent': 556,
  32201. 'Atilde': 667,
  32202. 'Aogonek': 667,
  32203. 'Aring': 667,
  32204. 'Otilde': 778,
  32205. 'zdotaccent': 500,
  32206. 'Ecaron': 667,
  32207. 'Iogonek': 278,
  32208. 'kcommaaccent': 500,
  32209. 'minus': 584,
  32210. 'Icircumflex': 278,
  32211. 'ncaron': 556,
  32212. 'tcommaaccent': 278,
  32213. 'logicalnot': 584,
  32214. 'odieresis': 556,
  32215. 'udieresis': 556,
  32216. 'notequal': 549,
  32217. 'gcommaaccent': 556,
  32218. 'eth': 556,
  32219. 'zcaron': 500,
  32220. 'ncommaaccent': 556,
  32221. 'onesuperior': 333,
  32222. 'imacron': 278,
  32223. 'Euro': 556
  32224. },
  32225. 'Symbol': {
  32226. 'space': 250,
  32227. 'exclam': 333,
  32228. 'universal': 713,
  32229. 'numbersign': 500,
  32230. 'existential': 549,
  32231. 'percent': 833,
  32232. 'ampersand': 778,
  32233. 'suchthat': 439,
  32234. 'parenleft': 333,
  32235. 'parenright': 333,
  32236. 'asteriskmath': 500,
  32237. 'plus': 549,
  32238. 'comma': 250,
  32239. 'minus': 549,
  32240. 'period': 250,
  32241. 'slash': 278,
  32242. 'zero': 500,
  32243. 'one': 500,
  32244. 'two': 500,
  32245. 'three': 500,
  32246. 'four': 500,
  32247. 'five': 500,
  32248. 'six': 500,
  32249. 'seven': 500,
  32250. 'eight': 500,
  32251. 'nine': 500,
  32252. 'colon': 278,
  32253. 'semicolon': 278,
  32254. 'less': 549,
  32255. 'equal': 549,
  32256. 'greater': 549,
  32257. 'question': 444,
  32258. 'congruent': 549,
  32259. 'Alpha': 722,
  32260. 'Beta': 667,
  32261. 'Chi': 722,
  32262. 'Delta': 612,
  32263. 'Epsilon': 611,
  32264. 'Phi': 763,
  32265. 'Gamma': 603,
  32266. 'Eta': 722,
  32267. 'Iota': 333,
  32268. 'theta1': 631,
  32269. 'Kappa': 722,
  32270. 'Lambda': 686,
  32271. 'Mu': 889,
  32272. 'Nu': 722,
  32273. 'Omicron': 722,
  32274. 'Pi': 768,
  32275. 'Theta': 741,
  32276. 'Rho': 556,
  32277. 'Sigma': 592,
  32278. 'Tau': 611,
  32279. 'Upsilon': 690,
  32280. 'sigma1': 439,
  32281. 'Omega': 768,
  32282. 'Xi': 645,
  32283. 'Psi': 795,
  32284. 'Zeta': 611,
  32285. 'bracketleft': 333,
  32286. 'therefore': 863,
  32287. 'bracketright': 333,
  32288. 'perpendicular': 658,
  32289. 'underscore': 500,
  32290. 'radicalex': 500,
  32291. 'alpha': 631,
  32292. 'beta': 549,
  32293. 'chi': 549,
  32294. 'delta': 494,
  32295. 'epsilon': 439,
  32296. 'phi': 521,
  32297. 'gamma': 411,
  32298. 'eta': 603,
  32299. 'iota': 329,
  32300. 'phi1': 603,
  32301. 'kappa': 549,
  32302. 'lambda': 549,
  32303. 'mu': 576,
  32304. 'nu': 521,
  32305. 'omicron': 549,
  32306. 'pi': 549,
  32307. 'theta': 521,
  32308. 'rho': 549,
  32309. 'sigma': 603,
  32310. 'tau': 439,
  32311. 'upsilon': 576,
  32312. 'omega1': 713,
  32313. 'omega': 686,
  32314. 'xi': 493,
  32315. 'psi': 686,
  32316. 'zeta': 494,
  32317. 'braceleft': 480,
  32318. 'bar': 200,
  32319. 'braceright': 480,
  32320. 'similar': 549,
  32321. 'Euro': 750,
  32322. 'Upsilon1': 620,
  32323. 'minute': 247,
  32324. 'lessequal': 549,
  32325. 'fraction': 167,
  32326. 'infinity': 713,
  32327. 'florin': 500,
  32328. 'club': 753,
  32329. 'diamond': 753,
  32330. 'heart': 753,
  32331. 'spade': 753,
  32332. 'arrowboth': 1042,
  32333. 'arrowleft': 987,
  32334. 'arrowup': 603,
  32335. 'arrowright': 987,
  32336. 'arrowdown': 603,
  32337. 'degree': 400,
  32338. 'plusminus': 549,
  32339. 'second': 411,
  32340. 'greaterequal': 549,
  32341. 'multiply': 549,
  32342. 'proportional': 713,
  32343. 'partialdiff': 494,
  32344. 'bullet': 460,
  32345. 'divide': 549,
  32346. 'notequal': 549,
  32347. 'equivalence': 549,
  32348. 'approxequal': 549,
  32349. 'ellipsis': 1000,
  32350. 'arrowvertex': 603,
  32351. 'arrowhorizex': 1000,
  32352. 'carriagereturn': 658,
  32353. 'aleph': 823,
  32354. 'Ifraktur': 686,
  32355. 'Rfraktur': 795,
  32356. 'weierstrass': 987,
  32357. 'circlemultiply': 768,
  32358. 'circleplus': 768,
  32359. 'emptyset': 823,
  32360. 'intersection': 768,
  32361. 'union': 768,
  32362. 'propersuperset': 713,
  32363. 'reflexsuperset': 713,
  32364. 'notsubset': 713,
  32365. 'propersubset': 713,
  32366. 'reflexsubset': 713,
  32367. 'element': 713,
  32368. 'notelement': 713,
  32369. 'angle': 768,
  32370. 'gradient': 713,
  32371. 'registerserif': 790,
  32372. 'copyrightserif': 790,
  32373. 'trademarkserif': 890,
  32374. 'product': 823,
  32375. 'radical': 549,
  32376. 'dotmath': 250,
  32377. 'logicalnot': 713,
  32378. 'logicaland': 603,
  32379. 'logicalor': 603,
  32380. 'arrowdblboth': 1042,
  32381. 'arrowdblleft': 987,
  32382. 'arrowdblup': 603,
  32383. 'arrowdblright': 987,
  32384. 'arrowdbldown': 603,
  32385. 'lozenge': 494,
  32386. 'angleleft': 329,
  32387. 'registersans': 790,
  32388. 'copyrightsans': 790,
  32389. 'trademarksans': 786,
  32390. 'summation': 713,
  32391. 'parenlefttp': 384,
  32392. 'parenleftex': 384,
  32393. 'parenleftbt': 384,
  32394. 'bracketlefttp': 384,
  32395. 'bracketleftex': 384,
  32396. 'bracketleftbt': 384,
  32397. 'bracelefttp': 494,
  32398. 'braceleftmid': 494,
  32399. 'braceleftbt': 494,
  32400. 'braceex': 494,
  32401. 'angleright': 329,
  32402. 'integral': 274,
  32403. 'integraltp': 686,
  32404. 'integralex': 686,
  32405. 'integralbt': 686,
  32406. 'parenrighttp': 384,
  32407. 'parenrightex': 384,
  32408. 'parenrightbt': 384,
  32409. 'bracketrighttp': 384,
  32410. 'bracketrightex': 384,
  32411. 'bracketrightbt': 384,
  32412. 'bracerighttp': 494,
  32413. 'bracerightmid': 494,
  32414. 'bracerightbt': 494,
  32415. 'apple': 790
  32416. },
  32417. 'Times-Roman': {
  32418. 'space': 250,
  32419. 'exclam': 333,
  32420. 'quotedbl': 408,
  32421. 'numbersign': 500,
  32422. 'dollar': 500,
  32423. 'percent': 833,
  32424. 'ampersand': 778,
  32425. 'quoteright': 333,
  32426. 'parenleft': 333,
  32427. 'parenright': 333,
  32428. 'asterisk': 500,
  32429. 'plus': 564,
  32430. 'comma': 250,
  32431. 'hyphen': 333,
  32432. 'period': 250,
  32433. 'slash': 278,
  32434. 'zero': 500,
  32435. 'one': 500,
  32436. 'two': 500,
  32437. 'three': 500,
  32438. 'four': 500,
  32439. 'five': 500,
  32440. 'six': 500,
  32441. 'seven': 500,
  32442. 'eight': 500,
  32443. 'nine': 500,
  32444. 'colon': 278,
  32445. 'semicolon': 278,
  32446. 'less': 564,
  32447. 'equal': 564,
  32448. 'greater': 564,
  32449. 'question': 444,
  32450. 'at': 921,
  32451. 'A': 722,
  32452. 'B': 667,
  32453. 'C': 667,
  32454. 'D': 722,
  32455. 'E': 611,
  32456. 'F': 556,
  32457. 'G': 722,
  32458. 'H': 722,
  32459. 'I': 333,
  32460. 'J': 389,
  32461. 'K': 722,
  32462. 'L': 611,
  32463. 'M': 889,
  32464. 'N': 722,
  32465. 'O': 722,
  32466. 'P': 556,
  32467. 'Q': 722,
  32468. 'R': 667,
  32469. 'S': 556,
  32470. 'T': 611,
  32471. 'U': 722,
  32472. 'V': 722,
  32473. 'W': 944,
  32474. 'X': 722,
  32475. 'Y': 722,
  32476. 'Z': 611,
  32477. 'bracketleft': 333,
  32478. 'backslash': 278,
  32479. 'bracketright': 333,
  32480. 'asciicircum': 469,
  32481. 'underscore': 500,
  32482. 'quoteleft': 333,
  32483. 'a': 444,
  32484. 'b': 500,
  32485. 'c': 444,
  32486. 'd': 500,
  32487. 'e': 444,
  32488. 'f': 333,
  32489. 'g': 500,
  32490. 'h': 500,
  32491. 'i': 278,
  32492. 'j': 278,
  32493. 'k': 500,
  32494. 'l': 278,
  32495. 'm': 778,
  32496. 'n': 500,
  32497. 'o': 500,
  32498. 'p': 500,
  32499. 'q': 500,
  32500. 'r': 333,
  32501. 's': 389,
  32502. 't': 278,
  32503. 'u': 500,
  32504. 'v': 500,
  32505. 'w': 722,
  32506. 'x': 500,
  32507. 'y': 500,
  32508. 'z': 444,
  32509. 'braceleft': 480,
  32510. 'bar': 200,
  32511. 'braceright': 480,
  32512. 'asciitilde': 541,
  32513. 'exclamdown': 333,
  32514. 'cent': 500,
  32515. 'sterling': 500,
  32516. 'fraction': 167,
  32517. 'yen': 500,
  32518. 'florin': 500,
  32519. 'section': 500,
  32520. 'currency': 500,
  32521. 'quotesingle': 180,
  32522. 'quotedblleft': 444,
  32523. 'guillemotleft': 500,
  32524. 'guilsinglleft': 333,
  32525. 'guilsinglright': 333,
  32526. 'fi': 556,
  32527. 'fl': 556,
  32528. 'endash': 500,
  32529. 'dagger': 500,
  32530. 'daggerdbl': 500,
  32531. 'periodcentered': 250,
  32532. 'paragraph': 453,
  32533. 'bullet': 350,
  32534. 'quotesinglbase': 333,
  32535. 'quotedblbase': 444,
  32536. 'quotedblright': 444,
  32537. 'guillemotright': 500,
  32538. 'ellipsis': 1000,
  32539. 'perthousand': 1000,
  32540. 'questiondown': 444,
  32541. 'grave': 333,
  32542. 'acute': 333,
  32543. 'circumflex': 333,
  32544. 'tilde': 333,
  32545. 'macron': 333,
  32546. 'breve': 333,
  32547. 'dotaccent': 333,
  32548. 'dieresis': 333,
  32549. 'ring': 333,
  32550. 'cedilla': 333,
  32551. 'hungarumlaut': 333,
  32552. 'ogonek': 333,
  32553. 'caron': 333,
  32554. 'emdash': 1000,
  32555. 'AE': 889,
  32556. 'ordfeminine': 276,
  32557. 'Lslash': 611,
  32558. 'Oslash': 722,
  32559. 'OE': 889,
  32560. 'ordmasculine': 310,
  32561. 'ae': 667,
  32562. 'dotlessi': 278,
  32563. 'lslash': 278,
  32564. 'oslash': 500,
  32565. 'oe': 722,
  32566. 'germandbls': 500,
  32567. 'Idieresis': 333,
  32568. 'eacute': 444,
  32569. 'abreve': 444,
  32570. 'uhungarumlaut': 500,
  32571. 'ecaron': 444,
  32572. 'Ydieresis': 722,
  32573. 'divide': 564,
  32574. 'Yacute': 722,
  32575. 'Acircumflex': 722,
  32576. 'aacute': 444,
  32577. 'Ucircumflex': 722,
  32578. 'yacute': 500,
  32579. 'scommaaccent': 389,
  32580. 'ecircumflex': 444,
  32581. 'Uring': 722,
  32582. 'Udieresis': 722,
  32583. 'aogonek': 444,
  32584. 'Uacute': 722,
  32585. 'uogonek': 500,
  32586. 'Edieresis': 611,
  32587. 'Dcroat': 722,
  32588. 'commaaccent': 250,
  32589. 'copyright': 760,
  32590. 'Emacron': 611,
  32591. 'ccaron': 444,
  32592. 'aring': 444,
  32593. 'Ncommaaccent': 722,
  32594. 'lacute': 278,
  32595. 'agrave': 444,
  32596. 'Tcommaaccent': 611,
  32597. 'Cacute': 667,
  32598. 'atilde': 444,
  32599. 'Edotaccent': 611,
  32600. 'scaron': 389,
  32601. 'scedilla': 389,
  32602. 'iacute': 278,
  32603. 'lozenge': 471,
  32604. 'Rcaron': 667,
  32605. 'Gcommaaccent': 722,
  32606. 'ucircumflex': 500,
  32607. 'acircumflex': 444,
  32608. 'Amacron': 722,
  32609. 'rcaron': 333,
  32610. 'ccedilla': 444,
  32611. 'Zdotaccent': 611,
  32612. 'Thorn': 556,
  32613. 'Omacron': 722,
  32614. 'Racute': 667,
  32615. 'Sacute': 556,
  32616. 'dcaron': 588,
  32617. 'Umacron': 722,
  32618. 'uring': 500,
  32619. 'threesuperior': 300,
  32620. 'Ograve': 722,
  32621. 'Agrave': 722,
  32622. 'Abreve': 722,
  32623. 'multiply': 564,
  32624. 'uacute': 500,
  32625. 'Tcaron': 611,
  32626. 'partialdiff': 476,
  32627. 'ydieresis': 500,
  32628. 'Nacute': 722,
  32629. 'icircumflex': 278,
  32630. 'Ecircumflex': 611,
  32631. 'adieresis': 444,
  32632. 'edieresis': 444,
  32633. 'cacute': 444,
  32634. 'nacute': 500,
  32635. 'umacron': 500,
  32636. 'Ncaron': 722,
  32637. 'Iacute': 333,
  32638. 'plusminus': 564,
  32639. 'brokenbar': 200,
  32640. 'registered': 760,
  32641. 'Gbreve': 722,
  32642. 'Idotaccent': 333,
  32643. 'summation': 600,
  32644. 'Egrave': 611,
  32645. 'racute': 333,
  32646. 'omacron': 500,
  32647. 'Zacute': 611,
  32648. 'Zcaron': 611,
  32649. 'greaterequal': 549,
  32650. 'Eth': 722,
  32651. 'Ccedilla': 667,
  32652. 'lcommaaccent': 278,
  32653. 'tcaron': 326,
  32654. 'eogonek': 444,
  32655. 'Uogonek': 722,
  32656. 'Aacute': 722,
  32657. 'Adieresis': 722,
  32658. 'egrave': 444,
  32659. 'zacute': 444,
  32660. 'iogonek': 278,
  32661. 'Oacute': 722,
  32662. 'oacute': 500,
  32663. 'amacron': 444,
  32664. 'sacute': 389,
  32665. 'idieresis': 278,
  32666. 'Ocircumflex': 722,
  32667. 'Ugrave': 722,
  32668. 'Delta': 612,
  32669. 'thorn': 500,
  32670. 'twosuperior': 300,
  32671. 'Odieresis': 722,
  32672. 'mu': 500,
  32673. 'igrave': 278,
  32674. 'ohungarumlaut': 500,
  32675. 'Eogonek': 611,
  32676. 'dcroat': 500,
  32677. 'threequarters': 750,
  32678. 'Scedilla': 556,
  32679. 'lcaron': 344,
  32680. 'Kcommaaccent': 722,
  32681. 'Lacute': 611,
  32682. 'trademark': 980,
  32683. 'edotaccent': 444,
  32684. 'Igrave': 333,
  32685. 'Imacron': 333,
  32686. 'Lcaron': 611,
  32687. 'onehalf': 750,
  32688. 'lessequal': 549,
  32689. 'ocircumflex': 500,
  32690. 'ntilde': 500,
  32691. 'Uhungarumlaut': 722,
  32692. 'Eacute': 611,
  32693. 'emacron': 444,
  32694. 'gbreve': 500,
  32695. 'onequarter': 750,
  32696. 'Scaron': 556,
  32697. 'Scommaaccent': 556,
  32698. 'Ohungarumlaut': 722,
  32699. 'degree': 400,
  32700. 'ograve': 500,
  32701. 'Ccaron': 667,
  32702. 'ugrave': 500,
  32703. 'radical': 453,
  32704. 'Dcaron': 722,
  32705. 'rcommaaccent': 333,
  32706. 'Ntilde': 722,
  32707. 'otilde': 500,
  32708. 'Rcommaaccent': 667,
  32709. 'Lcommaaccent': 611,
  32710. 'Atilde': 722,
  32711. 'Aogonek': 722,
  32712. 'Aring': 722,
  32713. 'Otilde': 722,
  32714. 'zdotaccent': 444,
  32715. 'Ecaron': 611,
  32716. 'Iogonek': 333,
  32717. 'kcommaaccent': 500,
  32718. 'minus': 564,
  32719. 'Icircumflex': 333,
  32720. 'ncaron': 500,
  32721. 'tcommaaccent': 278,
  32722. 'logicalnot': 564,
  32723. 'odieresis': 500,
  32724. 'udieresis': 500,
  32725. 'notequal': 549,
  32726. 'gcommaaccent': 500,
  32727. 'eth': 500,
  32728. 'zcaron': 444,
  32729. 'ncommaaccent': 500,
  32730. 'onesuperior': 300,
  32731. 'imacron': 278,
  32732. 'Euro': 500
  32733. },
  32734. 'Times-Bold': {
  32735. 'space': 250,
  32736. 'exclam': 333,
  32737. 'quotedbl': 555,
  32738. 'numbersign': 500,
  32739. 'dollar': 500,
  32740. 'percent': 1000,
  32741. 'ampersand': 833,
  32742. 'quoteright': 333,
  32743. 'parenleft': 333,
  32744. 'parenright': 333,
  32745. 'asterisk': 500,
  32746. 'plus': 570,
  32747. 'comma': 250,
  32748. 'hyphen': 333,
  32749. 'period': 250,
  32750. 'slash': 278,
  32751. 'zero': 500,
  32752. 'one': 500,
  32753. 'two': 500,
  32754. 'three': 500,
  32755. 'four': 500,
  32756. 'five': 500,
  32757. 'six': 500,
  32758. 'seven': 500,
  32759. 'eight': 500,
  32760. 'nine': 500,
  32761. 'colon': 333,
  32762. 'semicolon': 333,
  32763. 'less': 570,
  32764. 'equal': 570,
  32765. 'greater': 570,
  32766. 'question': 500,
  32767. 'at': 930,
  32768. 'A': 722,
  32769. 'B': 667,
  32770. 'C': 722,
  32771. 'D': 722,
  32772. 'E': 667,
  32773. 'F': 611,
  32774. 'G': 778,
  32775. 'H': 778,
  32776. 'I': 389,
  32777. 'J': 500,
  32778. 'K': 778,
  32779. 'L': 667,
  32780. 'M': 944,
  32781. 'N': 722,
  32782. 'O': 778,
  32783. 'P': 611,
  32784. 'Q': 778,
  32785. 'R': 722,
  32786. 'S': 556,
  32787. 'T': 667,
  32788. 'U': 722,
  32789. 'V': 722,
  32790. 'W': 1000,
  32791. 'X': 722,
  32792. 'Y': 722,
  32793. 'Z': 667,
  32794. 'bracketleft': 333,
  32795. 'backslash': 278,
  32796. 'bracketright': 333,
  32797. 'asciicircum': 581,
  32798. 'underscore': 500,
  32799. 'quoteleft': 333,
  32800. 'a': 500,
  32801. 'b': 556,
  32802. 'c': 444,
  32803. 'd': 556,
  32804. 'e': 444,
  32805. 'f': 333,
  32806. 'g': 500,
  32807. 'h': 556,
  32808. 'i': 278,
  32809. 'j': 333,
  32810. 'k': 556,
  32811. 'l': 278,
  32812. 'm': 833,
  32813. 'n': 556,
  32814. 'o': 500,
  32815. 'p': 556,
  32816. 'q': 556,
  32817. 'r': 444,
  32818. 's': 389,
  32819. 't': 333,
  32820. 'u': 556,
  32821. 'v': 500,
  32822. 'w': 722,
  32823. 'x': 500,
  32824. 'y': 500,
  32825. 'z': 444,
  32826. 'braceleft': 394,
  32827. 'bar': 220,
  32828. 'braceright': 394,
  32829. 'asciitilde': 520,
  32830. 'exclamdown': 333,
  32831. 'cent': 500,
  32832. 'sterling': 500,
  32833. 'fraction': 167,
  32834. 'yen': 500,
  32835. 'florin': 500,
  32836. 'section': 500,
  32837. 'currency': 500,
  32838. 'quotesingle': 278,
  32839. 'quotedblleft': 500,
  32840. 'guillemotleft': 500,
  32841. 'guilsinglleft': 333,
  32842. 'guilsinglright': 333,
  32843. 'fi': 556,
  32844. 'fl': 556,
  32845. 'endash': 500,
  32846. 'dagger': 500,
  32847. 'daggerdbl': 500,
  32848. 'periodcentered': 250,
  32849. 'paragraph': 540,
  32850. 'bullet': 350,
  32851. 'quotesinglbase': 333,
  32852. 'quotedblbase': 500,
  32853. 'quotedblright': 500,
  32854. 'guillemotright': 500,
  32855. 'ellipsis': 1000,
  32856. 'perthousand': 1000,
  32857. 'questiondown': 500,
  32858. 'grave': 333,
  32859. 'acute': 333,
  32860. 'circumflex': 333,
  32861. 'tilde': 333,
  32862. 'macron': 333,
  32863. 'breve': 333,
  32864. 'dotaccent': 333,
  32865. 'dieresis': 333,
  32866. 'ring': 333,
  32867. 'cedilla': 333,
  32868. 'hungarumlaut': 333,
  32869. 'ogonek': 333,
  32870. 'caron': 333,
  32871. 'emdash': 1000,
  32872. 'AE': 1000,
  32873. 'ordfeminine': 300,
  32874. 'Lslash': 667,
  32875. 'Oslash': 778,
  32876. 'OE': 1000,
  32877. 'ordmasculine': 330,
  32878. 'ae': 722,
  32879. 'dotlessi': 278,
  32880. 'lslash': 278,
  32881. 'oslash': 500,
  32882. 'oe': 722,
  32883. 'germandbls': 556,
  32884. 'Idieresis': 389,
  32885. 'eacute': 444,
  32886. 'abreve': 500,
  32887. 'uhungarumlaut': 556,
  32888. 'ecaron': 444,
  32889. 'Ydieresis': 722,
  32890. 'divide': 570,
  32891. 'Yacute': 722,
  32892. 'Acircumflex': 722,
  32893. 'aacute': 500,
  32894. 'Ucircumflex': 722,
  32895. 'yacute': 500,
  32896. 'scommaaccent': 389,
  32897. 'ecircumflex': 444,
  32898. 'Uring': 722,
  32899. 'Udieresis': 722,
  32900. 'aogonek': 500,
  32901. 'Uacute': 722,
  32902. 'uogonek': 556,
  32903. 'Edieresis': 667,
  32904. 'Dcroat': 722,
  32905. 'commaaccent': 250,
  32906. 'copyright': 747,
  32907. 'Emacron': 667,
  32908. 'ccaron': 444,
  32909. 'aring': 500,
  32910. 'Ncommaaccent': 722,
  32911. 'lacute': 278,
  32912. 'agrave': 500,
  32913. 'Tcommaaccent': 667,
  32914. 'Cacute': 722,
  32915. 'atilde': 500,
  32916. 'Edotaccent': 667,
  32917. 'scaron': 389,
  32918. 'scedilla': 389,
  32919. 'iacute': 278,
  32920. 'lozenge': 494,
  32921. 'Rcaron': 722,
  32922. 'Gcommaaccent': 778,
  32923. 'ucircumflex': 556,
  32924. 'acircumflex': 500,
  32925. 'Amacron': 722,
  32926. 'rcaron': 444,
  32927. 'ccedilla': 444,
  32928. 'Zdotaccent': 667,
  32929. 'Thorn': 611,
  32930. 'Omacron': 778,
  32931. 'Racute': 722,
  32932. 'Sacute': 556,
  32933. 'dcaron': 672,
  32934. 'Umacron': 722,
  32935. 'uring': 556,
  32936. 'threesuperior': 300,
  32937. 'Ograve': 778,
  32938. 'Agrave': 722,
  32939. 'Abreve': 722,
  32940. 'multiply': 570,
  32941. 'uacute': 556,
  32942. 'Tcaron': 667,
  32943. 'partialdiff': 494,
  32944. 'ydieresis': 500,
  32945. 'Nacute': 722,
  32946. 'icircumflex': 278,
  32947. 'Ecircumflex': 667,
  32948. 'adieresis': 500,
  32949. 'edieresis': 444,
  32950. 'cacute': 444,
  32951. 'nacute': 556,
  32952. 'umacron': 556,
  32953. 'Ncaron': 722,
  32954. 'Iacute': 389,
  32955. 'plusminus': 570,
  32956. 'brokenbar': 220,
  32957. 'registered': 747,
  32958. 'Gbreve': 778,
  32959. 'Idotaccent': 389,
  32960. 'summation': 600,
  32961. 'Egrave': 667,
  32962. 'racute': 444,
  32963. 'omacron': 500,
  32964. 'Zacute': 667,
  32965. 'Zcaron': 667,
  32966. 'greaterequal': 549,
  32967. 'Eth': 722,
  32968. 'Ccedilla': 722,
  32969. 'lcommaaccent': 278,
  32970. 'tcaron': 416,
  32971. 'eogonek': 444,
  32972. 'Uogonek': 722,
  32973. 'Aacute': 722,
  32974. 'Adieresis': 722,
  32975. 'egrave': 444,
  32976. 'zacute': 444,
  32977. 'iogonek': 278,
  32978. 'Oacute': 778,
  32979. 'oacute': 500,
  32980. 'amacron': 500,
  32981. 'sacute': 389,
  32982. 'idieresis': 278,
  32983. 'Ocircumflex': 778,
  32984. 'Ugrave': 722,
  32985. 'Delta': 612,
  32986. 'thorn': 556,
  32987. 'twosuperior': 300,
  32988. 'Odieresis': 778,
  32989. 'mu': 556,
  32990. 'igrave': 278,
  32991. 'ohungarumlaut': 500,
  32992. 'Eogonek': 667,
  32993. 'dcroat': 556,
  32994. 'threequarters': 750,
  32995. 'Scedilla': 556,
  32996. 'lcaron': 394,
  32997. 'Kcommaaccent': 778,
  32998. 'Lacute': 667,
  32999. 'trademark': 1000,
  33000. 'edotaccent': 444,
  33001. 'Igrave': 389,
  33002. 'Imacron': 389,
  33003. 'Lcaron': 667,
  33004. 'onehalf': 750,
  33005. 'lessequal': 549,
  33006. 'ocircumflex': 500,
  33007. 'ntilde': 556,
  33008. 'Uhungarumlaut': 722,
  33009. 'Eacute': 667,
  33010. 'emacron': 444,
  33011. 'gbreve': 500,
  33012. 'onequarter': 750,
  33013. 'Scaron': 556,
  33014. 'Scommaaccent': 556,
  33015. 'Ohungarumlaut': 778,
  33016. 'degree': 400,
  33017. 'ograve': 500,
  33018. 'Ccaron': 722,
  33019. 'ugrave': 556,
  33020. 'radical': 549,
  33021. 'Dcaron': 722,
  33022. 'rcommaaccent': 444,
  33023. 'Ntilde': 722,
  33024. 'otilde': 500,
  33025. 'Rcommaaccent': 722,
  33026. 'Lcommaaccent': 667,
  33027. 'Atilde': 722,
  33028. 'Aogonek': 722,
  33029. 'Aring': 722,
  33030. 'Otilde': 778,
  33031. 'zdotaccent': 444,
  33032. 'Ecaron': 667,
  33033. 'Iogonek': 389,
  33034. 'kcommaaccent': 556,
  33035. 'minus': 570,
  33036. 'Icircumflex': 389,
  33037. 'ncaron': 556,
  33038. 'tcommaaccent': 333,
  33039. 'logicalnot': 570,
  33040. 'odieresis': 500,
  33041. 'udieresis': 556,
  33042. 'notequal': 549,
  33043. 'gcommaaccent': 500,
  33044. 'eth': 500,
  33045. 'zcaron': 444,
  33046. 'ncommaaccent': 556,
  33047. 'onesuperior': 300,
  33048. 'imacron': 278,
  33049. 'Euro': 500
  33050. },
  33051. 'Times-BoldItalic': {
  33052. 'space': 250,
  33053. 'exclam': 389,
  33054. 'quotedbl': 555,
  33055. 'numbersign': 500,
  33056. 'dollar': 500,
  33057. 'percent': 833,
  33058. 'ampersand': 778,
  33059. 'quoteright': 333,
  33060. 'parenleft': 333,
  33061. 'parenright': 333,
  33062. 'asterisk': 500,
  33063. 'plus': 570,
  33064. 'comma': 250,
  33065. 'hyphen': 333,
  33066. 'period': 250,
  33067. 'slash': 278,
  33068. 'zero': 500,
  33069. 'one': 500,
  33070. 'two': 500,
  33071. 'three': 500,
  33072. 'four': 500,
  33073. 'five': 500,
  33074. 'six': 500,
  33075. 'seven': 500,
  33076. 'eight': 500,
  33077. 'nine': 500,
  33078. 'colon': 333,
  33079. 'semicolon': 333,
  33080. 'less': 570,
  33081. 'equal': 570,
  33082. 'greater': 570,
  33083. 'question': 500,
  33084. 'at': 832,
  33085. 'A': 667,
  33086. 'B': 667,
  33087. 'C': 667,
  33088. 'D': 722,
  33089. 'E': 667,
  33090. 'F': 667,
  33091. 'G': 722,
  33092. 'H': 778,
  33093. 'I': 389,
  33094. 'J': 500,
  33095. 'K': 667,
  33096. 'L': 611,
  33097. 'M': 889,
  33098. 'N': 722,
  33099. 'O': 722,
  33100. 'P': 611,
  33101. 'Q': 722,
  33102. 'R': 667,
  33103. 'S': 556,
  33104. 'T': 611,
  33105. 'U': 722,
  33106. 'V': 667,
  33107. 'W': 889,
  33108. 'X': 667,
  33109. 'Y': 611,
  33110. 'Z': 611,
  33111. 'bracketleft': 333,
  33112. 'backslash': 278,
  33113. 'bracketright': 333,
  33114. 'asciicircum': 570,
  33115. 'underscore': 500,
  33116. 'quoteleft': 333,
  33117. 'a': 500,
  33118. 'b': 500,
  33119. 'c': 444,
  33120. 'd': 500,
  33121. 'e': 444,
  33122. 'f': 333,
  33123. 'g': 500,
  33124. 'h': 556,
  33125. 'i': 278,
  33126. 'j': 278,
  33127. 'k': 500,
  33128. 'l': 278,
  33129. 'm': 778,
  33130. 'n': 556,
  33131. 'o': 500,
  33132. 'p': 500,
  33133. 'q': 500,
  33134. 'r': 389,
  33135. 's': 389,
  33136. 't': 278,
  33137. 'u': 556,
  33138. 'v': 444,
  33139. 'w': 667,
  33140. 'x': 500,
  33141. 'y': 444,
  33142. 'z': 389,
  33143. 'braceleft': 348,
  33144. 'bar': 220,
  33145. 'braceright': 348,
  33146. 'asciitilde': 570,
  33147. 'exclamdown': 389,
  33148. 'cent': 500,
  33149. 'sterling': 500,
  33150. 'fraction': 167,
  33151. 'yen': 500,
  33152. 'florin': 500,
  33153. 'section': 500,
  33154. 'currency': 500,
  33155. 'quotesingle': 278,
  33156. 'quotedblleft': 500,
  33157. 'guillemotleft': 500,
  33158. 'guilsinglleft': 333,
  33159. 'guilsinglright': 333,
  33160. 'fi': 556,
  33161. 'fl': 556,
  33162. 'endash': 500,
  33163. 'dagger': 500,
  33164. 'daggerdbl': 500,
  33165. 'periodcentered': 250,
  33166. 'paragraph': 500,
  33167. 'bullet': 350,
  33168. 'quotesinglbase': 333,
  33169. 'quotedblbase': 500,
  33170. 'quotedblright': 500,
  33171. 'guillemotright': 500,
  33172. 'ellipsis': 1000,
  33173. 'perthousand': 1000,
  33174. 'questiondown': 500,
  33175. 'grave': 333,
  33176. 'acute': 333,
  33177. 'circumflex': 333,
  33178. 'tilde': 333,
  33179. 'macron': 333,
  33180. 'breve': 333,
  33181. 'dotaccent': 333,
  33182. 'dieresis': 333,
  33183. 'ring': 333,
  33184. 'cedilla': 333,
  33185. 'hungarumlaut': 333,
  33186. 'ogonek': 333,
  33187. 'caron': 333,
  33188. 'emdash': 1000,
  33189. 'AE': 944,
  33190. 'ordfeminine': 266,
  33191. 'Lslash': 611,
  33192. 'Oslash': 722,
  33193. 'OE': 944,
  33194. 'ordmasculine': 300,
  33195. 'ae': 722,
  33196. 'dotlessi': 278,
  33197. 'lslash': 278,
  33198. 'oslash': 500,
  33199. 'oe': 722,
  33200. 'germandbls': 500,
  33201. 'Idieresis': 389,
  33202. 'eacute': 444,
  33203. 'abreve': 500,
  33204. 'uhungarumlaut': 556,
  33205. 'ecaron': 444,
  33206. 'Ydieresis': 611,
  33207. 'divide': 570,
  33208. 'Yacute': 611,
  33209. 'Acircumflex': 667,
  33210. 'aacute': 500,
  33211. 'Ucircumflex': 722,
  33212. 'yacute': 444,
  33213. 'scommaaccent': 389,
  33214. 'ecircumflex': 444,
  33215. 'Uring': 722,
  33216. 'Udieresis': 722,
  33217. 'aogonek': 500,
  33218. 'Uacute': 722,
  33219. 'uogonek': 556,
  33220. 'Edieresis': 667,
  33221. 'Dcroat': 722,
  33222. 'commaaccent': 250,
  33223. 'copyright': 747,
  33224. 'Emacron': 667,
  33225. 'ccaron': 444,
  33226. 'aring': 500,
  33227. 'Ncommaaccent': 722,
  33228. 'lacute': 278,
  33229. 'agrave': 500,
  33230. 'Tcommaaccent': 611,
  33231. 'Cacute': 667,
  33232. 'atilde': 500,
  33233. 'Edotaccent': 667,
  33234. 'scaron': 389,
  33235. 'scedilla': 389,
  33236. 'iacute': 278,
  33237. 'lozenge': 494,
  33238. 'Rcaron': 667,
  33239. 'Gcommaaccent': 722,
  33240. 'ucircumflex': 556,
  33241. 'acircumflex': 500,
  33242. 'Amacron': 667,
  33243. 'rcaron': 389,
  33244. 'ccedilla': 444,
  33245. 'Zdotaccent': 611,
  33246. 'Thorn': 611,
  33247. 'Omacron': 722,
  33248. 'Racute': 667,
  33249. 'Sacute': 556,
  33250. 'dcaron': 608,
  33251. 'Umacron': 722,
  33252. 'uring': 556,
  33253. 'threesuperior': 300,
  33254. 'Ograve': 722,
  33255. 'Agrave': 667,
  33256. 'Abreve': 667,
  33257. 'multiply': 570,
  33258. 'uacute': 556,
  33259. 'Tcaron': 611,
  33260. 'partialdiff': 494,
  33261. 'ydieresis': 444,
  33262. 'Nacute': 722,
  33263. 'icircumflex': 278,
  33264. 'Ecircumflex': 667,
  33265. 'adieresis': 500,
  33266. 'edieresis': 444,
  33267. 'cacute': 444,
  33268. 'nacute': 556,
  33269. 'umacron': 556,
  33270. 'Ncaron': 722,
  33271. 'Iacute': 389,
  33272. 'plusminus': 570,
  33273. 'brokenbar': 220,
  33274. 'registered': 747,
  33275. 'Gbreve': 722,
  33276. 'Idotaccent': 389,
  33277. 'summation': 600,
  33278. 'Egrave': 667,
  33279. 'racute': 389,
  33280. 'omacron': 500,
  33281. 'Zacute': 611,
  33282. 'Zcaron': 611,
  33283. 'greaterequal': 549,
  33284. 'Eth': 722,
  33285. 'Ccedilla': 667,
  33286. 'lcommaaccent': 278,
  33287. 'tcaron': 366,
  33288. 'eogonek': 444,
  33289. 'Uogonek': 722,
  33290. 'Aacute': 667,
  33291. 'Adieresis': 667,
  33292. 'egrave': 444,
  33293. 'zacute': 389,
  33294. 'iogonek': 278,
  33295. 'Oacute': 722,
  33296. 'oacute': 500,
  33297. 'amacron': 500,
  33298. 'sacute': 389,
  33299. 'idieresis': 278,
  33300. 'Ocircumflex': 722,
  33301. 'Ugrave': 722,
  33302. 'Delta': 612,
  33303. 'thorn': 500,
  33304. 'twosuperior': 300,
  33305. 'Odieresis': 722,
  33306. 'mu': 576,
  33307. 'igrave': 278,
  33308. 'ohungarumlaut': 500,
  33309. 'Eogonek': 667,
  33310. 'dcroat': 500,
  33311. 'threequarters': 750,
  33312. 'Scedilla': 556,
  33313. 'lcaron': 382,
  33314. 'Kcommaaccent': 667,
  33315. 'Lacute': 611,
  33316. 'trademark': 1000,
  33317. 'edotaccent': 444,
  33318. 'Igrave': 389,
  33319. 'Imacron': 389,
  33320. 'Lcaron': 611,
  33321. 'onehalf': 750,
  33322. 'lessequal': 549,
  33323. 'ocircumflex': 500,
  33324. 'ntilde': 556,
  33325. 'Uhungarumlaut': 722,
  33326. 'Eacute': 667,
  33327. 'emacron': 444,
  33328. 'gbreve': 500,
  33329. 'onequarter': 750,
  33330. 'Scaron': 556,
  33331. 'Scommaaccent': 556,
  33332. 'Ohungarumlaut': 722,
  33333. 'degree': 400,
  33334. 'ograve': 500,
  33335. 'Ccaron': 667,
  33336. 'ugrave': 556,
  33337. 'radical': 549,
  33338. 'Dcaron': 722,
  33339. 'rcommaaccent': 389,
  33340. 'Ntilde': 722,
  33341. 'otilde': 500,
  33342. 'Rcommaaccent': 667,
  33343. 'Lcommaaccent': 611,
  33344. 'Atilde': 667,
  33345. 'Aogonek': 667,
  33346. 'Aring': 667,
  33347. 'Otilde': 722,
  33348. 'zdotaccent': 389,
  33349. 'Ecaron': 667,
  33350. 'Iogonek': 389,
  33351. 'kcommaaccent': 500,
  33352. 'minus': 606,
  33353. 'Icircumflex': 389,
  33354. 'ncaron': 556,
  33355. 'tcommaaccent': 278,
  33356. 'logicalnot': 606,
  33357. 'odieresis': 500,
  33358. 'udieresis': 556,
  33359. 'notequal': 549,
  33360. 'gcommaaccent': 500,
  33361. 'eth': 500,
  33362. 'zcaron': 389,
  33363. 'ncommaaccent': 556,
  33364. 'onesuperior': 300,
  33365. 'imacron': 278,
  33366. 'Euro': 500
  33367. },
  33368. 'Times-Italic': {
  33369. 'space': 250,
  33370. 'exclam': 333,
  33371. 'quotedbl': 420,
  33372. 'numbersign': 500,
  33373. 'dollar': 500,
  33374. 'percent': 833,
  33375. 'ampersand': 778,
  33376. 'quoteright': 333,
  33377. 'parenleft': 333,
  33378. 'parenright': 333,
  33379. 'asterisk': 500,
  33380. 'plus': 675,
  33381. 'comma': 250,
  33382. 'hyphen': 333,
  33383. 'period': 250,
  33384. 'slash': 278,
  33385. 'zero': 500,
  33386. 'one': 500,
  33387. 'two': 500,
  33388. 'three': 500,
  33389. 'four': 500,
  33390. 'five': 500,
  33391. 'six': 500,
  33392. 'seven': 500,
  33393. 'eight': 500,
  33394. 'nine': 500,
  33395. 'colon': 333,
  33396. 'semicolon': 333,
  33397. 'less': 675,
  33398. 'equal': 675,
  33399. 'greater': 675,
  33400. 'question': 500,
  33401. 'at': 920,
  33402. 'A': 611,
  33403. 'B': 611,
  33404. 'C': 667,
  33405. 'D': 722,
  33406. 'E': 611,
  33407. 'F': 611,
  33408. 'G': 722,
  33409. 'H': 722,
  33410. 'I': 333,
  33411. 'J': 444,
  33412. 'K': 667,
  33413. 'L': 556,
  33414. 'M': 833,
  33415. 'N': 667,
  33416. 'O': 722,
  33417. 'P': 611,
  33418. 'Q': 722,
  33419. 'R': 611,
  33420. 'S': 500,
  33421. 'T': 556,
  33422. 'U': 722,
  33423. 'V': 611,
  33424. 'W': 833,
  33425. 'X': 611,
  33426. 'Y': 556,
  33427. 'Z': 556,
  33428. 'bracketleft': 389,
  33429. 'backslash': 278,
  33430. 'bracketright': 389,
  33431. 'asciicircum': 422,
  33432. 'underscore': 500,
  33433. 'quoteleft': 333,
  33434. 'a': 500,
  33435. 'b': 500,
  33436. 'c': 444,
  33437. 'd': 500,
  33438. 'e': 444,
  33439. 'f': 278,
  33440. 'g': 500,
  33441. 'h': 500,
  33442. 'i': 278,
  33443. 'j': 278,
  33444. 'k': 444,
  33445. 'l': 278,
  33446. 'm': 722,
  33447. 'n': 500,
  33448. 'o': 500,
  33449. 'p': 500,
  33450. 'q': 500,
  33451. 'r': 389,
  33452. 's': 389,
  33453. 't': 278,
  33454. 'u': 500,
  33455. 'v': 444,
  33456. 'w': 667,
  33457. 'x': 444,
  33458. 'y': 444,
  33459. 'z': 389,
  33460. 'braceleft': 400,
  33461. 'bar': 275,
  33462. 'braceright': 400,
  33463. 'asciitilde': 541,
  33464. 'exclamdown': 389,
  33465. 'cent': 500,
  33466. 'sterling': 500,
  33467. 'fraction': 167,
  33468. 'yen': 500,
  33469. 'florin': 500,
  33470. 'section': 500,
  33471. 'currency': 500,
  33472. 'quotesingle': 214,
  33473. 'quotedblleft': 556,
  33474. 'guillemotleft': 500,
  33475. 'guilsinglleft': 333,
  33476. 'guilsinglright': 333,
  33477. 'fi': 500,
  33478. 'fl': 500,
  33479. 'endash': 500,
  33480. 'dagger': 500,
  33481. 'daggerdbl': 500,
  33482. 'periodcentered': 250,
  33483. 'paragraph': 523,
  33484. 'bullet': 350,
  33485. 'quotesinglbase': 333,
  33486. 'quotedblbase': 556,
  33487. 'quotedblright': 556,
  33488. 'guillemotright': 500,
  33489. 'ellipsis': 889,
  33490. 'perthousand': 1000,
  33491. 'questiondown': 500,
  33492. 'grave': 333,
  33493. 'acute': 333,
  33494. 'circumflex': 333,
  33495. 'tilde': 333,
  33496. 'macron': 333,
  33497. 'breve': 333,
  33498. 'dotaccent': 333,
  33499. 'dieresis': 333,
  33500. 'ring': 333,
  33501. 'cedilla': 333,
  33502. 'hungarumlaut': 333,
  33503. 'ogonek': 333,
  33504. 'caron': 333,
  33505. 'emdash': 889,
  33506. 'AE': 889,
  33507. 'ordfeminine': 276,
  33508. 'Lslash': 556,
  33509. 'Oslash': 722,
  33510. 'OE': 944,
  33511. 'ordmasculine': 310,
  33512. 'ae': 667,
  33513. 'dotlessi': 278,
  33514. 'lslash': 278,
  33515. 'oslash': 500,
  33516. 'oe': 667,
  33517. 'germandbls': 500,
  33518. 'Idieresis': 333,
  33519. 'eacute': 444,
  33520. 'abreve': 500,
  33521. 'uhungarumlaut': 500,
  33522. 'ecaron': 444,
  33523. 'Ydieresis': 556,
  33524. 'divide': 675,
  33525. 'Yacute': 556,
  33526. 'Acircumflex': 611,
  33527. 'aacute': 500,
  33528. 'Ucircumflex': 722,
  33529. 'yacute': 444,
  33530. 'scommaaccent': 389,
  33531. 'ecircumflex': 444,
  33532. 'Uring': 722,
  33533. 'Udieresis': 722,
  33534. 'aogonek': 500,
  33535. 'Uacute': 722,
  33536. 'uogonek': 500,
  33537. 'Edieresis': 611,
  33538. 'Dcroat': 722,
  33539. 'commaaccent': 250,
  33540. 'copyright': 760,
  33541. 'Emacron': 611,
  33542. 'ccaron': 444,
  33543. 'aring': 500,
  33544. 'Ncommaaccent': 667,
  33545. 'lacute': 278,
  33546. 'agrave': 500,
  33547. 'Tcommaaccent': 556,
  33548. 'Cacute': 667,
  33549. 'atilde': 500,
  33550. 'Edotaccent': 611,
  33551. 'scaron': 389,
  33552. 'scedilla': 389,
  33553. 'iacute': 278,
  33554. 'lozenge': 471,
  33555. 'Rcaron': 611,
  33556. 'Gcommaaccent': 722,
  33557. 'ucircumflex': 500,
  33558. 'acircumflex': 500,
  33559. 'Amacron': 611,
  33560. 'rcaron': 389,
  33561. 'ccedilla': 444,
  33562. 'Zdotaccent': 556,
  33563. 'Thorn': 611,
  33564. 'Omacron': 722,
  33565. 'Racute': 611,
  33566. 'Sacute': 500,
  33567. 'dcaron': 544,
  33568. 'Umacron': 722,
  33569. 'uring': 500,
  33570. 'threesuperior': 300,
  33571. 'Ograve': 722,
  33572. 'Agrave': 611,
  33573. 'Abreve': 611,
  33574. 'multiply': 675,
  33575. 'uacute': 500,
  33576. 'Tcaron': 556,
  33577. 'partialdiff': 476,
  33578. 'ydieresis': 444,
  33579. 'Nacute': 667,
  33580. 'icircumflex': 278,
  33581. 'Ecircumflex': 611,
  33582. 'adieresis': 500,
  33583. 'edieresis': 444,
  33584. 'cacute': 444,
  33585. 'nacute': 500,
  33586. 'umacron': 500,
  33587. 'Ncaron': 667,
  33588. 'Iacute': 333,
  33589. 'plusminus': 675,
  33590. 'brokenbar': 275,
  33591. 'registered': 760,
  33592. 'Gbreve': 722,
  33593. 'Idotaccent': 333,
  33594. 'summation': 600,
  33595. 'Egrave': 611,
  33596. 'racute': 389,
  33597. 'omacron': 500,
  33598. 'Zacute': 556,
  33599. 'Zcaron': 556,
  33600. 'greaterequal': 549,
  33601. 'Eth': 722,
  33602. 'Ccedilla': 667,
  33603. 'lcommaaccent': 278,
  33604. 'tcaron': 300,
  33605. 'eogonek': 444,
  33606. 'Uogonek': 722,
  33607. 'Aacute': 611,
  33608. 'Adieresis': 611,
  33609. 'egrave': 444,
  33610. 'zacute': 389,
  33611. 'iogonek': 278,
  33612. 'Oacute': 722,
  33613. 'oacute': 500,
  33614. 'amacron': 500,
  33615. 'sacute': 389,
  33616. 'idieresis': 278,
  33617. 'Ocircumflex': 722,
  33618. 'Ugrave': 722,
  33619. 'Delta': 612,
  33620. 'thorn': 500,
  33621. 'twosuperior': 300,
  33622. 'Odieresis': 722,
  33623. 'mu': 500,
  33624. 'igrave': 278,
  33625. 'ohungarumlaut': 500,
  33626. 'Eogonek': 611,
  33627. 'dcroat': 500,
  33628. 'threequarters': 750,
  33629. 'Scedilla': 500,
  33630. 'lcaron': 300,
  33631. 'Kcommaaccent': 667,
  33632. 'Lacute': 556,
  33633. 'trademark': 980,
  33634. 'edotaccent': 444,
  33635. 'Igrave': 333,
  33636. 'Imacron': 333,
  33637. 'Lcaron': 611,
  33638. 'onehalf': 750,
  33639. 'lessequal': 549,
  33640. 'ocircumflex': 500,
  33641. 'ntilde': 500,
  33642. 'Uhungarumlaut': 722,
  33643. 'Eacute': 611,
  33644. 'emacron': 444,
  33645. 'gbreve': 500,
  33646. 'onequarter': 750,
  33647. 'Scaron': 500,
  33648. 'Scommaaccent': 500,
  33649. 'Ohungarumlaut': 722,
  33650. 'degree': 400,
  33651. 'ograve': 500,
  33652. 'Ccaron': 667,
  33653. 'ugrave': 500,
  33654. 'radical': 453,
  33655. 'Dcaron': 722,
  33656. 'rcommaaccent': 389,
  33657. 'Ntilde': 667,
  33658. 'otilde': 500,
  33659. 'Rcommaaccent': 611,
  33660. 'Lcommaaccent': 556,
  33661. 'Atilde': 611,
  33662. 'Aogonek': 611,
  33663. 'Aring': 611,
  33664. 'Otilde': 722,
  33665. 'zdotaccent': 389,
  33666. 'Ecaron': 611,
  33667. 'Iogonek': 333,
  33668. 'kcommaaccent': 444,
  33669. 'minus': 675,
  33670. 'Icircumflex': 333,
  33671. 'ncaron': 500,
  33672. 'tcommaaccent': 278,
  33673. 'logicalnot': 675,
  33674. 'odieresis': 500,
  33675. 'udieresis': 500,
  33676. 'notequal': 549,
  33677. 'gcommaaccent': 500,
  33678. 'eth': 500,
  33679. 'zcaron': 389,
  33680. 'ncommaaccent': 500,
  33681. 'onesuperior': 300,
  33682. 'imacron': 278,
  33683. 'Euro': 500
  33684. },
  33685. 'ZapfDingbats': {
  33686. 'space': 278,
  33687. 'a1': 974,
  33688. 'a2': 961,
  33689. 'a202': 974,
  33690. 'a3': 980,
  33691. 'a4': 719,
  33692. 'a5': 789,
  33693. 'a119': 790,
  33694. 'a118': 791,
  33695. 'a117': 690,
  33696. 'a11': 960,
  33697. 'a12': 939,
  33698. 'a13': 549,
  33699. 'a14': 855,
  33700. 'a15': 911,
  33701. 'a16': 933,
  33702. 'a105': 911,
  33703. 'a17': 945,
  33704. 'a18': 974,
  33705. 'a19': 755,
  33706. 'a20': 846,
  33707. 'a21': 762,
  33708. 'a22': 761,
  33709. 'a23': 571,
  33710. 'a24': 677,
  33711. 'a25': 763,
  33712. 'a26': 760,
  33713. 'a27': 759,
  33714. 'a28': 754,
  33715. 'a6': 494,
  33716. 'a7': 552,
  33717. 'a8': 537,
  33718. 'a9': 577,
  33719. 'a10': 692,
  33720. 'a29': 786,
  33721. 'a30': 788,
  33722. 'a31': 788,
  33723. 'a32': 790,
  33724. 'a33': 793,
  33725. 'a34': 794,
  33726. 'a35': 816,
  33727. 'a36': 823,
  33728. 'a37': 789,
  33729. 'a38': 841,
  33730. 'a39': 823,
  33731. 'a40': 833,
  33732. 'a41': 816,
  33733. 'a42': 831,
  33734. 'a43': 923,
  33735. 'a44': 744,
  33736. 'a45': 723,
  33737. 'a46': 749,
  33738. 'a47': 790,
  33739. 'a48': 792,
  33740. 'a49': 695,
  33741. 'a50': 776,
  33742. 'a51': 768,
  33743. 'a52': 792,
  33744. 'a53': 759,
  33745. 'a54': 707,
  33746. 'a55': 708,
  33747. 'a56': 682,
  33748. 'a57': 701,
  33749. 'a58': 826,
  33750. 'a59': 815,
  33751. 'a60': 789,
  33752. 'a61': 789,
  33753. 'a62': 707,
  33754. 'a63': 687,
  33755. 'a64': 696,
  33756. 'a65': 689,
  33757. 'a66': 786,
  33758. 'a67': 787,
  33759. 'a68': 713,
  33760. 'a69': 791,
  33761. 'a70': 785,
  33762. 'a71': 791,
  33763. 'a72': 873,
  33764. 'a73': 761,
  33765. 'a74': 762,
  33766. 'a203': 762,
  33767. 'a75': 759,
  33768. 'a204': 759,
  33769. 'a76': 892,
  33770. 'a77': 892,
  33771. 'a78': 788,
  33772. 'a79': 784,
  33773. 'a81': 438,
  33774. 'a82': 138,
  33775. 'a83': 277,
  33776. 'a84': 415,
  33777. 'a97': 392,
  33778. 'a98': 392,
  33779. 'a99': 668,
  33780. 'a100': 668,
  33781. 'a89': 390,
  33782. 'a90': 390,
  33783. 'a93': 317,
  33784. 'a94': 317,
  33785. 'a91': 276,
  33786. 'a92': 276,
  33787. 'a205': 509,
  33788. 'a85': 509,
  33789. 'a206': 410,
  33790. 'a86': 410,
  33791. 'a87': 234,
  33792. 'a88': 234,
  33793. 'a95': 334,
  33794. 'a96': 334,
  33795. 'a101': 732,
  33796. 'a102': 544,
  33797. 'a103': 544,
  33798. 'a104': 910,
  33799. 'a106': 667,
  33800. 'a107': 760,
  33801. 'a108': 760,
  33802. 'a112': 776,
  33803. 'a111': 595,
  33804. 'a110': 694,
  33805. 'a109': 626,
  33806. 'a120': 788,
  33807. 'a121': 788,
  33808. 'a122': 788,
  33809. 'a123': 788,
  33810. 'a124': 788,
  33811. 'a125': 788,
  33812. 'a126': 788,
  33813. 'a127': 788,
  33814. 'a128': 788,
  33815. 'a129': 788,
  33816. 'a130': 788,
  33817. 'a131': 788,
  33818. 'a132': 788,
  33819. 'a133': 788,
  33820. 'a134': 788,
  33821. 'a135': 788,
  33822. 'a136': 788,
  33823. 'a137': 788,
  33824. 'a138': 788,
  33825. 'a139': 788,
  33826. 'a140': 788,
  33827. 'a141': 788,
  33828. 'a142': 788,
  33829. 'a143': 788,
  33830. 'a144': 788,
  33831. 'a145': 788,
  33832. 'a146': 788,
  33833. 'a147': 788,
  33834. 'a148': 788,
  33835. 'a149': 788,
  33836. 'a150': 788,
  33837. 'a151': 788,
  33838. 'a152': 788,
  33839. 'a153': 788,
  33840. 'a154': 788,
  33841. 'a155': 788,
  33842. 'a156': 788,
  33843. 'a157': 788,
  33844. 'a158': 788,
  33845. 'a159': 788,
  33846. 'a160': 894,
  33847. 'a161': 838,
  33848. 'a163': 1016,
  33849. 'a164': 458,
  33850. 'a196': 748,
  33851. 'a165': 924,
  33852. 'a192': 748,
  33853. 'a166': 918,
  33854. 'a167': 927,
  33855. 'a168': 928,
  33856. 'a169': 928,
  33857. 'a170': 834,
  33858. 'a171': 873,
  33859. 'a172': 828,
  33860. 'a173': 924,
  33861. 'a162': 924,
  33862. 'a174': 917,
  33863. 'a175': 930,
  33864. 'a176': 931,
  33865. 'a177': 463,
  33866. 'a178': 883,
  33867. 'a179': 836,
  33868. 'a193': 836,
  33869. 'a180': 867,
  33870. 'a199': 867,
  33871. 'a181': 696,
  33872. 'a200': 696,
  33873. 'a182': 874,
  33874. 'a201': 874,
  33875. 'a183': 760,
  33876. 'a184': 946,
  33877. 'a197': 771,
  33878. 'a185': 865,
  33879. 'a194': 771,
  33880. 'a198': 888,
  33881. 'a186': 967,
  33882. 'a195': 888,
  33883. 'a187': 831,
  33884. 'a188': 873,
  33885. 'a189': 927,
  33886. 'a190': 970,
  33887. 'a191': 918
  33888. }
  33889. };
  33890. var EOF = {};
  33891. function isEOF(v) {
  33892. return (v === EOF);
  33893. }
  33894. var MAX_LENGTH_TO_CACHE = 1000;
  33895. var Parser = (function ParserClosure() {
  33896. function Parser(lexer, allowStreams, xref) {
  33897. this.lexer = lexer;
  33898. this.allowStreams = allowStreams;
  33899. this.xref = xref;
  33900. this.imageCache = {};
  33901. this.refill();
  33902. }
  33903. Parser.prototype = {
  33904. refill: function Parser_refill() {
  33905. this.buf1 = this.lexer.getObj();
  33906. this.buf2 = this.lexer.getObj();
  33907. },
  33908. shift: function Parser_shift() {
  33909. if (isCmd(this.buf2, 'ID')) {
  33910. this.buf1 = this.buf2;
  33911. this.buf2 = null;
  33912. } else {
  33913. this.buf1 = this.buf2;
  33914. this.buf2 = this.lexer.getObj();
  33915. }
  33916. },
  33917. getObj: function Parser_getObj(cipherTransform) {
  33918. var buf1 = this.buf1;
  33919. this.shift();
  33920. if (buf1 instanceof Cmd) {
  33921. switch (buf1.cmd) {
  33922. case 'BI': // inline image
  33923. return this.makeInlineImage(cipherTransform);
  33924. case '[': // array
  33925. var array = [];
  33926. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33927. array.push(this.getObj(cipherTransform));
  33928. }
  33929. if (isEOF(this.buf1)) {
  33930. error('End of file inside array');
  33931. }
  33932. this.shift();
  33933. return array;
  33934. case '<<': // dictionary or stream
  33935. var dict = new Dict(this.xref);
  33936. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33937. if (!isName(this.buf1)) {
  33938. info('Malformed dictionary: key must be a name object');
  33939. this.shift();
  33940. continue;
  33941. }
  33942. var key = this.buf1.name;
  33943. this.shift();
  33944. if (isEOF(this.buf1)) {
  33945. break;
  33946. }
  33947. dict.set(key, this.getObj(cipherTransform));
  33948. }
  33949. if (isEOF(this.buf1)) {
  33950. error('End of file inside dictionary');
  33951. }
  33952. // Stream objects are not allowed inside content streams or
  33953. // object streams.
  33954. if (isCmd(this.buf2, 'stream')) {
  33955. return (this.allowStreams ?
  33956. this.makeStream(dict, cipherTransform) : dict);
  33957. }
  33958. this.shift();
  33959. return dict;
  33960. default: // simple object
  33961. return buf1;
  33962. }
  33963. }
  33964. if (isInt(buf1)) { // indirect reference or integer
  33965. var num = buf1;
  33966. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33967. var ref = new Ref(num, this.buf1);
  33968. this.shift();
  33969. this.shift();
  33970. return ref;
  33971. }
  33972. return num;
  33973. }
  33974. if (isString(buf1)) { // string
  33975. var str = buf1;
  33976. if (cipherTransform) {
  33977. str = cipherTransform.decryptString(str);
  33978. }
  33979. return str;
  33980. }
  33981. // simple object
  33982. return buf1;
  33983. },
  33984. /**
  33985. * Find the end of the stream by searching for the /EI\s/.
  33986. * @returns {number} The inline stream length.
  33987. */
  33988. findDefaultInlineStreamEnd:
  33989. function Parser_findDefaultInlineStreamEnd(stream) {
  33990. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  33991. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  33992. while ((ch = stream.getByte()) !== -1) {
  33993. if (state === 0) {
  33994. state = (ch === E) ? 1 : 0;
  33995. } else if (state === 1) {
  33996. state = (ch === I) ? 2 : 0;
  33997. } else {
  33998. assert(state === 2);
  33999. if (ch === SPACE || ch === LF || ch === CR) {
  34000. // Let's check the next five bytes are ASCII... just be sure.
  34001. n = 5;
  34002. followingBytes = stream.peekBytes(n);
  34003. for (i = 0; i < n; i++) {
  34004. ch = followingBytes[i];
  34005. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  34006. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  34007. // it's binary stuff. Resetting the state.
  34008. state = 0;
  34009. break;
  34010. }
  34011. }
  34012. if (state === 2) {
  34013. break; // Finished!
  34014. }
  34015. } else {
  34016. state = 0;
  34017. }
  34018. }
  34019. }
  34020. return ((stream.pos - 4) - startPos);
  34021. },
  34022. /**
  34023. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34024. * @returns {number} The inline stream length.
  34025. */
  34026. findDCTDecodeInlineStreamEnd:
  34027. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34028. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34029. while ((b = stream.getByte()) !== -1) {
  34030. if (b !== 0xFF) { // Not a valid marker.
  34031. continue;
  34032. }
  34033. switch (stream.getByte()) {
  34034. case 0x00: // Byte stuffing.
  34035. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34036. break;
  34037. case 0xFF: // Fill byte.
  34038. // Avoid skipping a valid marker, resetting the stream position.
  34039. stream.skip(-1);
  34040. break;
  34041. case 0xD9: // EOI
  34042. foundEOI = true;
  34043. break;
  34044. case 0xC0: // SOF0
  34045. case 0xC1: // SOF1
  34046. case 0xC2: // SOF2
  34047. case 0xC3: // SOF3
  34048. case 0xC5: // SOF5
  34049. case 0xC6: // SOF6
  34050. case 0xC7: // SOF7
  34051. case 0xC9: // SOF9
  34052. case 0xCA: // SOF10
  34053. case 0xCB: // SOF11
  34054. case 0xCD: // SOF13
  34055. case 0xCE: // SOF14
  34056. case 0xCF: // SOF15
  34057. case 0xC4: // DHT
  34058. case 0xCC: // DAC
  34059. case 0xDA: // SOS
  34060. case 0xDB: // DQT
  34061. case 0xDC: // DNL
  34062. case 0xDD: // DRI
  34063. case 0xDE: // DHP
  34064. case 0xDF: // EXP
  34065. case 0xE0: // APP0
  34066. case 0xE1: // APP1
  34067. case 0xE2: // APP2
  34068. case 0xE3: // APP3
  34069. case 0xE4: // APP4
  34070. case 0xE5: // APP5
  34071. case 0xE6: // APP6
  34072. case 0xE7: // APP7
  34073. case 0xE8: // APP8
  34074. case 0xE9: // APP9
  34075. case 0xEA: // APP10
  34076. case 0xEB: // APP11
  34077. case 0xEC: // APP12
  34078. case 0xED: // APP13
  34079. case 0xEE: // APP14
  34080. case 0xEF: // APP15
  34081. case 0xFE: // COM
  34082. // The marker should be followed by the length of the segment.
  34083. markerLength = stream.getUint16();
  34084. if (markerLength > 2) {
  34085. // |markerLength| contains the byte length of the marker segment,
  34086. // including its own length (2 bytes) and excluding the marker.
  34087. stream.skip(markerLength - 2); // Jump to the next marker.
  34088. } else {
  34089. // The marker length is invalid, resetting the stream position.
  34090. stream.skip(-2);
  34091. }
  34092. break;
  34093. }
  34094. if (foundEOI) {
  34095. break;
  34096. }
  34097. }
  34098. length = stream.pos - startPos;
  34099. if (b === -1) {
  34100. warn('Inline DCTDecode image stream: ' +
  34101. 'EOI marker not found, searching for /EI/ instead.');
  34102. stream.skip(-length); // Reset the stream position.
  34103. return this.findDefaultInlineStreamEnd(stream);
  34104. }
  34105. this.inlineStreamSkipEI(stream);
  34106. return length;
  34107. },
  34108. /**
  34109. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34110. * @returns {number} The inline stream length.
  34111. */
  34112. findASCII85DecodeInlineStreamEnd:
  34113. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34114. var TILDE = 0x7E, GT = 0x3E;
  34115. var startPos = stream.pos, ch, length;
  34116. while ((ch = stream.getByte()) !== -1) {
  34117. if (ch === TILDE && stream.peekByte() === GT) {
  34118. stream.skip();
  34119. break;
  34120. }
  34121. }
  34122. length = stream.pos - startPos;
  34123. if (ch === -1) {
  34124. warn('Inline ASCII85Decode image stream: ' +
  34125. 'EOD marker not found, searching for /EI/ instead.');
  34126. stream.skip(-length); // Reset the stream position.
  34127. return this.findDefaultInlineStreamEnd(stream);
  34128. }
  34129. this.inlineStreamSkipEI(stream);
  34130. return length;
  34131. },
  34132. /**
  34133. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34134. * @returns {number} The inline stream length.
  34135. */
  34136. findASCIIHexDecodeInlineStreamEnd:
  34137. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34138. var GT = 0x3E;
  34139. var startPos = stream.pos, ch, length;
  34140. while ((ch = stream.getByte()) !== -1) {
  34141. if (ch === GT) {
  34142. break;
  34143. }
  34144. }
  34145. length = stream.pos - startPos;
  34146. if (ch === -1) {
  34147. warn('Inline ASCIIHexDecode image stream: ' +
  34148. 'EOD marker not found, searching for /EI/ instead.');
  34149. stream.skip(-length); // Reset the stream position.
  34150. return this.findDefaultInlineStreamEnd(stream);
  34151. }
  34152. this.inlineStreamSkipEI(stream);
  34153. return length;
  34154. },
  34155. /**
  34156. * Skip over the /EI/ for streams where we search for an EOD marker.
  34157. */
  34158. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34159. var E = 0x45, I = 0x49;
  34160. var state = 0, ch;
  34161. while ((ch = stream.getByte()) !== -1) {
  34162. if (state === 0) {
  34163. state = (ch === E) ? 1 : 0;
  34164. } else if (state === 1) {
  34165. state = (ch === I) ? 2 : 0;
  34166. } else if (state === 2) {
  34167. break;
  34168. }
  34169. }
  34170. },
  34171. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34172. var lexer = this.lexer;
  34173. var stream = lexer.stream;
  34174. // Parse dictionary.
  34175. var dict = new Dict(null);
  34176. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34177. if (!isName(this.buf1)) {
  34178. error('Dictionary key must be a name object');
  34179. }
  34180. var key = this.buf1.name;
  34181. this.shift();
  34182. if (isEOF(this.buf1)) {
  34183. break;
  34184. }
  34185. dict.set(key, this.getObj(cipherTransform));
  34186. }
  34187. // Extract the name of the first (i.e. the current) image filter.
  34188. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34189. if (isName(filter)) {
  34190. filterName = filter.name;
  34191. } else if (isArray(filter) && isName(filter[0])) {
  34192. filterName = filter[0].name;
  34193. }
  34194. // Parse image stream.
  34195. var startPos = stream.pos, length, i, ii;
  34196. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34197. length = this.findDCTDecodeInlineStreamEnd(stream);
  34198. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34199. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34200. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34201. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34202. } else {
  34203. length = this.findDefaultInlineStreamEnd(stream);
  34204. }
  34205. var imageStream = stream.makeSubStream(startPos, length, dict);
  34206. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34207. // adler32 checksum.
  34208. var adler32;
  34209. if (length < MAX_LENGTH_TO_CACHE) {
  34210. var imageBytes = imageStream.getBytes();
  34211. imageStream.reset();
  34212. var a = 1;
  34213. var b = 0;
  34214. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34215. // No modulo required in the loop if imageBytes.length < 5552.
  34216. a += imageBytes[i] & 0xff;
  34217. b += a;
  34218. }
  34219. adler32 = ((b % 65521) << 16) | (a % 65521);
  34220. if (this.imageCache.adler32 === adler32) {
  34221. this.buf2 = Cmd.get('EI');
  34222. this.shift();
  34223. this.imageCache[adler32].reset();
  34224. return this.imageCache[adler32];
  34225. }
  34226. }
  34227. if (cipherTransform) {
  34228. imageStream = cipherTransform.createStream(imageStream, length);
  34229. }
  34230. imageStream = this.filter(imageStream, dict, length);
  34231. imageStream.dict = dict;
  34232. if (adler32 !== undefined) {
  34233. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34234. this.imageCache[adler32] = imageStream;
  34235. }
  34236. this.buf2 = Cmd.get('EI');
  34237. this.shift();
  34238. return imageStream;
  34239. },
  34240. fetchIfRef: function Parser_fetchIfRef(obj) {
  34241. // not relying on the xref.fetchIfRef -- xref might not be set
  34242. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34243. },
  34244. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34245. var lexer = this.lexer;
  34246. var stream = lexer.stream;
  34247. // get stream start position
  34248. lexer.skipToNextLine();
  34249. var pos = stream.pos - 1;
  34250. // get length
  34251. var length = this.fetchIfRef(dict.get('Length'));
  34252. if (!isInt(length)) {
  34253. info('Bad ' + length + ' attribute in stream');
  34254. length = 0;
  34255. }
  34256. // skip over the stream data
  34257. stream.pos = pos + length;
  34258. lexer.nextChar();
  34259. this.shift(); // '>>'
  34260. this.shift(); // 'stream'
  34261. if (!isCmd(this.buf1, 'endstream')) {
  34262. // bad stream length, scanning for endstream
  34263. stream.pos = pos;
  34264. var SCAN_BLOCK_SIZE = 2048;
  34265. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34266. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34267. 0x61, 0x6D];
  34268. var skipped = 0, found = false, i, j;
  34269. while (stream.pos < stream.end) {
  34270. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34271. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34272. if (scanLength <= 0) {
  34273. break;
  34274. }
  34275. found = false;
  34276. for (i = 0, j = 0; i < scanLength; i++) {
  34277. var b = scanBytes[i];
  34278. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34279. i -= j;
  34280. j = 0;
  34281. } else {
  34282. j++;
  34283. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34284. i++;
  34285. found = true;
  34286. break;
  34287. }
  34288. }
  34289. }
  34290. if (found) {
  34291. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34292. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34293. break;
  34294. }
  34295. skipped += scanLength;
  34296. stream.pos += scanLength;
  34297. }
  34298. if (!found) {
  34299. error('Missing endstream');
  34300. }
  34301. length = skipped;
  34302. lexer.nextChar();
  34303. this.shift();
  34304. this.shift();
  34305. }
  34306. this.shift(); // 'endstream'
  34307. stream = stream.makeSubStream(pos, length, dict);
  34308. if (cipherTransform) {
  34309. stream = cipherTransform.createStream(stream, length);
  34310. }
  34311. stream = this.filter(stream, dict, length);
  34312. stream.dict = dict;
  34313. return stream;
  34314. },
  34315. filter: function Parser_filter(stream, dict, length) {
  34316. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34317. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34318. if (isName(filter)) {
  34319. return this.makeFilter(stream, filter.name, length, params);
  34320. }
  34321. var maybeLength = length;
  34322. if (isArray(filter)) {
  34323. var filterArray = filter;
  34324. var paramsArray = params;
  34325. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34326. filter = filterArray[i];
  34327. if (!isName(filter)) {
  34328. error('Bad filter name: ' + filter);
  34329. }
  34330. params = null;
  34331. if (isArray(paramsArray) && (i in paramsArray)) {
  34332. params = paramsArray[i];
  34333. }
  34334. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34335. // after the first stream the length variable is invalid
  34336. maybeLength = null;
  34337. }
  34338. }
  34339. return stream;
  34340. },
  34341. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34342. if (stream.dict.get('Length') === 0) {
  34343. return new NullStream(stream);
  34344. }
  34345. try {
  34346. if (params) {
  34347. params = this.fetchIfRef(params);
  34348. }
  34349. var xrefStreamStats = this.xref.stats.streamTypes;
  34350. if (name === 'FlateDecode' || name === 'Fl') {
  34351. xrefStreamStats[StreamType.FLATE] = true;
  34352. if (params) {
  34353. return new PredictorStream(new FlateStream(stream, maybeLength),
  34354. maybeLength, params);
  34355. }
  34356. return new FlateStream(stream, maybeLength);
  34357. }
  34358. if (name === 'LZWDecode' || name === 'LZW') {
  34359. xrefStreamStats[StreamType.LZW] = true;
  34360. var earlyChange = 1;
  34361. if (params) {
  34362. if (params.has('EarlyChange')) {
  34363. earlyChange = params.get('EarlyChange');
  34364. }
  34365. return new PredictorStream(
  34366. new LZWStream(stream, maybeLength, earlyChange),
  34367. maybeLength, params);
  34368. }
  34369. return new LZWStream(stream, maybeLength, earlyChange);
  34370. }
  34371. if (name === 'DCTDecode' || name === 'DCT') {
  34372. xrefStreamStats[StreamType.DCT] = true;
  34373. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34374. }
  34375. if (name === 'JPXDecode' || name === 'JPX') {
  34376. xrefStreamStats[StreamType.JPX] = true;
  34377. return new JpxStream(stream, maybeLength, stream.dict);
  34378. }
  34379. if (name === 'ASCII85Decode' || name === 'A85') {
  34380. xrefStreamStats[StreamType.A85] = true;
  34381. return new Ascii85Stream(stream, maybeLength);
  34382. }
  34383. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34384. xrefStreamStats[StreamType.AHX] = true;
  34385. return new AsciiHexStream(stream, maybeLength);
  34386. }
  34387. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34388. xrefStreamStats[StreamType.CCF] = true;
  34389. return new CCITTFaxStream(stream, maybeLength, params);
  34390. }
  34391. if (name === 'RunLengthDecode' || name === 'RL') {
  34392. xrefStreamStats[StreamType.RL] = true;
  34393. return new RunLengthStream(stream, maybeLength);
  34394. }
  34395. if (name === 'JBIG2Decode') {
  34396. xrefStreamStats[StreamType.JBIG] = true;
  34397. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34398. }
  34399. warn('filter "' + name + '" not supported yet');
  34400. return stream;
  34401. } catch (ex) {
  34402. if (ex instanceof MissingDataException) {
  34403. throw ex;
  34404. }
  34405. warn('Invalid stream: \"' + ex + '\"');
  34406. return new NullStream(stream);
  34407. }
  34408. }
  34409. };
  34410. return Parser;
  34411. })();
  34412. var Lexer = (function LexerClosure() {
  34413. function Lexer(stream, knownCommands) {
  34414. this.stream = stream;
  34415. this.nextChar();
  34416. // While lexing, we build up many strings one char at a time. Using += for
  34417. // this can result in lots of garbage strings. It's better to build an
  34418. // array of single-char strings and then join() them together at the end.
  34419. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34420. // purpose uses less memory than using a new array for each string.
  34421. this.strBuf = [];
  34422. // The PDFs might have "glued" commands with other commands, operands or
  34423. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34424. // commands and their prefixes. The prefixes are built the following way:
  34425. // if there a command that is a prefix of the other valid command or
  34426. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34427. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34428. // other commands or literals as a prefix. The knowCommands is optional.
  34429. this.knownCommands = knownCommands;
  34430. }
  34431. Lexer.isSpace = function Lexer_isSpace(ch) {
  34432. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34433. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34434. };
  34435. // A '1' in this array means the character is white space. A '1' or
  34436. // '2' means the character ends a name or command.
  34437. var specialChars = [
  34438. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34440. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34454. ];
  34455. function toHexDigit(ch) {
  34456. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34457. return ch & 0x0F;
  34458. }
  34459. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34460. // 'A'-'F', 'a'-'f'
  34461. return (ch & 0x0F) + 9;
  34462. }
  34463. return -1;
  34464. }
  34465. Lexer.prototype = {
  34466. nextChar: function Lexer_nextChar() {
  34467. return (this.currentChar = this.stream.getByte());
  34468. },
  34469. peekChar: function Lexer_peekChar() {
  34470. return this.stream.peekByte();
  34471. },
  34472. getNumber: function Lexer_getNumber() {
  34473. var ch = this.currentChar;
  34474. var eNotation = false;
  34475. var divideBy = 0; // different from 0 if it's a floating point value
  34476. var sign = 1;
  34477. if (ch === 0x2D) { // '-'
  34478. sign = -1;
  34479. ch = this.nextChar();
  34480. } else if (ch === 0x2B) { // '+'
  34481. ch = this.nextChar();
  34482. }
  34483. if (ch === 0x2E) { // '.'
  34484. divideBy = 10;
  34485. ch = this.nextChar();
  34486. }
  34487. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34488. error('Invalid number: ' + String.fromCharCode(ch));
  34489. return 0;
  34490. }
  34491. var baseValue = ch - 0x30; // '0'
  34492. var powerValue = 0;
  34493. var powerValueSign = 1;
  34494. while ((ch = this.nextChar()) >= 0) {
  34495. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34496. var currentDigit = ch - 0x30; // '0'
  34497. if (eNotation) { // We are after an 'e' or 'E'
  34498. powerValue = powerValue * 10 + currentDigit;
  34499. } else {
  34500. if (divideBy !== 0) { // We are after a point
  34501. divideBy *= 10;
  34502. }
  34503. baseValue = baseValue * 10 + currentDigit;
  34504. }
  34505. } else if (ch === 0x2E) { // '.'
  34506. if (divideBy === 0) {
  34507. divideBy = 1;
  34508. } else {
  34509. // A number can have only one '.'
  34510. break;
  34511. }
  34512. } else if (ch === 0x2D) { // '-'
  34513. // ignore minus signs in the middle of numbers to match
  34514. // Adobe's behavior
  34515. warn('Badly formated number');
  34516. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34517. // 'E' can be either a scientific notation or the beginning of a new
  34518. // operator
  34519. ch = this.peekChar();
  34520. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34521. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34522. this.nextChar(); // Consume the sign character
  34523. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34524. // The 'E' must be the beginning of a new operator
  34525. break;
  34526. }
  34527. eNotation = true;
  34528. } else {
  34529. // the last character doesn't belong to us
  34530. break;
  34531. }
  34532. }
  34533. if (divideBy !== 0) {
  34534. baseValue /= divideBy;
  34535. }
  34536. if (eNotation) {
  34537. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34538. }
  34539. return sign * baseValue;
  34540. },
  34541. getString: function Lexer_getString() {
  34542. var numParen = 1;
  34543. var done = false;
  34544. var strBuf = this.strBuf;
  34545. strBuf.length = 0;
  34546. var ch = this.nextChar();
  34547. while (true) {
  34548. var charBuffered = false;
  34549. switch (ch | 0) {
  34550. case -1:
  34551. warn('Unterminated string');
  34552. done = true;
  34553. break;
  34554. case 0x28: // '('
  34555. ++numParen;
  34556. strBuf.push('(');
  34557. break;
  34558. case 0x29: // ')'
  34559. if (--numParen === 0) {
  34560. this.nextChar(); // consume strings ')'
  34561. done = true;
  34562. } else {
  34563. strBuf.push(')');
  34564. }
  34565. break;
  34566. case 0x5C: // '\\'
  34567. ch = this.nextChar();
  34568. switch (ch) {
  34569. case -1:
  34570. warn('Unterminated string');
  34571. done = true;
  34572. break;
  34573. case 0x6E: // 'n'
  34574. strBuf.push('\n');
  34575. break;
  34576. case 0x72: // 'r'
  34577. strBuf.push('\r');
  34578. break;
  34579. case 0x74: // 't'
  34580. strBuf.push('\t');
  34581. break;
  34582. case 0x62: // 'b'
  34583. strBuf.push('\b');
  34584. break;
  34585. case 0x66: // 'f'
  34586. strBuf.push('\f');
  34587. break;
  34588. case 0x5C: // '\'
  34589. case 0x28: // '('
  34590. case 0x29: // ')'
  34591. strBuf.push(String.fromCharCode(ch));
  34592. break;
  34593. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34594. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34595. var x = ch & 0x0F;
  34596. ch = this.nextChar();
  34597. charBuffered = true;
  34598. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34599. x = (x << 3) + (ch & 0x0F);
  34600. ch = this.nextChar();
  34601. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34602. charBuffered = false;
  34603. x = (x << 3) + (ch & 0x0F);
  34604. }
  34605. }
  34606. strBuf.push(String.fromCharCode(x));
  34607. break;
  34608. case 0x0D: // CR
  34609. if (this.peekChar() === 0x0A) { // LF
  34610. this.nextChar();
  34611. }
  34612. break;
  34613. case 0x0A: // LF
  34614. break;
  34615. default:
  34616. strBuf.push(String.fromCharCode(ch));
  34617. break;
  34618. }
  34619. break;
  34620. default:
  34621. strBuf.push(String.fromCharCode(ch));
  34622. break;
  34623. }
  34624. if (done) {
  34625. break;
  34626. }
  34627. if (!charBuffered) {
  34628. ch = this.nextChar();
  34629. }
  34630. }
  34631. return strBuf.join('');
  34632. },
  34633. getName: function Lexer_getName() {
  34634. var ch;
  34635. var strBuf = this.strBuf;
  34636. strBuf.length = 0;
  34637. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34638. if (ch === 0x23) { // '#'
  34639. ch = this.nextChar();
  34640. var x = toHexDigit(ch);
  34641. if (x !== -1) {
  34642. var x2 = toHexDigit(this.nextChar());
  34643. if (x2 === -1) {
  34644. error('Illegal digit in hex char in name: ' + x2);
  34645. }
  34646. strBuf.push(String.fromCharCode((x << 4) | x2));
  34647. } else {
  34648. strBuf.push('#', String.fromCharCode(ch));
  34649. }
  34650. } else {
  34651. strBuf.push(String.fromCharCode(ch));
  34652. }
  34653. }
  34654. if (strBuf.length > 128) {
  34655. error('Warning: name token is longer than allowed by the spec: ' +
  34656. strBuf.length);
  34657. }
  34658. return Name.get(strBuf.join(''));
  34659. },
  34660. getHexString: function Lexer_getHexString() {
  34661. var strBuf = this.strBuf;
  34662. strBuf.length = 0;
  34663. var ch = this.currentChar;
  34664. var isFirstHex = true;
  34665. var firstDigit;
  34666. var secondDigit;
  34667. while (true) {
  34668. if (ch < 0) {
  34669. warn('Unterminated hex string');
  34670. break;
  34671. } else if (ch === 0x3E) { // '>'
  34672. this.nextChar();
  34673. break;
  34674. } else if (specialChars[ch] === 1) {
  34675. ch = this.nextChar();
  34676. continue;
  34677. } else {
  34678. if (isFirstHex) {
  34679. firstDigit = toHexDigit(ch);
  34680. if (firstDigit === -1) {
  34681. warn('Ignoring invalid character "' + ch + '" in hex string');
  34682. ch = this.nextChar();
  34683. continue;
  34684. }
  34685. } else {
  34686. secondDigit = toHexDigit(ch);
  34687. if (secondDigit === -1) {
  34688. warn('Ignoring invalid character "' + ch + '" in hex string');
  34689. ch = this.nextChar();
  34690. continue;
  34691. }
  34692. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34693. }
  34694. isFirstHex = !isFirstHex;
  34695. ch = this.nextChar();
  34696. }
  34697. }
  34698. return strBuf.join('');
  34699. },
  34700. getObj: function Lexer_getObj() {
  34701. // skip whitespace and comments
  34702. var comment = false;
  34703. var ch = this.currentChar;
  34704. while (true) {
  34705. if (ch < 0) {
  34706. return EOF;
  34707. }
  34708. if (comment) {
  34709. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34710. comment = false;
  34711. }
  34712. } else if (ch === 0x25) { // '%'
  34713. comment = true;
  34714. } else if (specialChars[ch] !== 1) {
  34715. break;
  34716. }
  34717. ch = this.nextChar();
  34718. }
  34719. // start reading token
  34720. switch (ch | 0) {
  34721. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34722. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34723. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34724. return this.getNumber();
  34725. case 0x28: // '('
  34726. return this.getString();
  34727. case 0x2F: // '/'
  34728. return this.getName();
  34729. // array punctuation
  34730. case 0x5B: // '['
  34731. this.nextChar();
  34732. return Cmd.get('[');
  34733. case 0x5D: // ']'
  34734. this.nextChar();
  34735. return Cmd.get(']');
  34736. // hex string or dict punctuation
  34737. case 0x3C: // '<'
  34738. ch = this.nextChar();
  34739. if (ch === 0x3C) {
  34740. // dict punctuation
  34741. this.nextChar();
  34742. return Cmd.get('<<');
  34743. }
  34744. return this.getHexString();
  34745. // dict punctuation
  34746. case 0x3E: // '>'
  34747. ch = this.nextChar();
  34748. if (ch === 0x3E) {
  34749. this.nextChar();
  34750. return Cmd.get('>>');
  34751. }
  34752. return Cmd.get('>');
  34753. case 0x7B: // '{'
  34754. this.nextChar();
  34755. return Cmd.get('{');
  34756. case 0x7D: // '}'
  34757. this.nextChar();
  34758. return Cmd.get('}');
  34759. case 0x29: // ')'
  34760. error('Illegal character: ' + ch);
  34761. break;
  34762. }
  34763. // command
  34764. var str = String.fromCharCode(ch);
  34765. var knownCommands = this.knownCommands;
  34766. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34767. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34768. // stop if known command is found and next character does not make
  34769. // the str a command
  34770. var possibleCommand = str + String.fromCharCode(ch);
  34771. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34772. break;
  34773. }
  34774. if (str.length === 128) {
  34775. error('Command token too long: ' + str.length);
  34776. }
  34777. str = possibleCommand;
  34778. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34779. }
  34780. if (str === 'true') {
  34781. return true;
  34782. }
  34783. if (str === 'false') {
  34784. return false;
  34785. }
  34786. if (str === 'null') {
  34787. return null;
  34788. }
  34789. return Cmd.get(str);
  34790. },
  34791. skipToNextLine: function Lexer_skipToNextLine() {
  34792. var ch = this.currentChar;
  34793. while (ch >= 0) {
  34794. if (ch === 0x0D) { // CR
  34795. ch = this.nextChar();
  34796. if (ch === 0x0A) { // LF
  34797. this.nextChar();
  34798. }
  34799. break;
  34800. } else if (ch === 0x0A) { // LF
  34801. this.nextChar();
  34802. break;
  34803. }
  34804. ch = this.nextChar();
  34805. }
  34806. }
  34807. };
  34808. return Lexer;
  34809. })();
  34810. var Linearization = {
  34811. create: function LinearizationCreate(stream) {
  34812. function getInt(name, allowZeroValue) {
  34813. var obj = linDict.get(name);
  34814. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34815. return obj;
  34816. }
  34817. throw new Error('The "' + name + '" parameter in the linearization ' +
  34818. 'dictionary is invalid.');
  34819. }
  34820. function getHints() {
  34821. var hints = linDict.get('H'), hintsLength, item;
  34822. if (isArray(hints) &&
  34823. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34824. for (var index = 0; index < hintsLength; index++) {
  34825. if (!(isInt(item = hints[index]) && item > 0)) {
  34826. throw new Error('Hint (' + index +
  34827. ') in the linearization dictionary is invalid.');
  34828. }
  34829. }
  34830. return hints;
  34831. }
  34832. throw new Error('Hint array in the linearization dictionary is invalid.');
  34833. }
  34834. var parser = new Parser(new Lexer(stream), false, null);
  34835. var obj1 = parser.getObj();
  34836. var obj2 = parser.getObj();
  34837. var obj3 = parser.getObj();
  34838. var linDict = parser.getObj();
  34839. var obj, length;
  34840. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34841. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34842. return null; // No valid linearization dictionary found.
  34843. } else if ((length = getInt('L')) !== stream.length) {
  34844. throw new Error('The "L" parameter in the linearization dictionary ' +
  34845. 'does not equal the stream length.');
  34846. }
  34847. return {
  34848. length: length,
  34849. hints: getHints(),
  34850. objectNumberFirst: getInt('O'),
  34851. endFirst: getInt('E'),
  34852. numPages: getInt('N'),
  34853. mainXRefEntriesOffset: getInt('T'),
  34854. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34855. };
  34856. }
  34857. };
  34858. var PostScriptParser = (function PostScriptParserClosure() {
  34859. function PostScriptParser(lexer) {
  34860. this.lexer = lexer;
  34861. this.operators = [];
  34862. this.token = null;
  34863. this.prev = null;
  34864. }
  34865. PostScriptParser.prototype = {
  34866. nextToken: function PostScriptParser_nextToken() {
  34867. this.prev = this.token;
  34868. this.token = this.lexer.getToken();
  34869. },
  34870. accept: function PostScriptParser_accept(type) {
  34871. if (this.token.type === type) {
  34872. this.nextToken();
  34873. return true;
  34874. }
  34875. return false;
  34876. },
  34877. expect: function PostScriptParser_expect(type) {
  34878. if (this.accept(type)) {
  34879. return true;
  34880. }
  34881. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34882. type + '.');
  34883. },
  34884. parse: function PostScriptParser_parse() {
  34885. this.nextToken();
  34886. this.expect(PostScriptTokenTypes.LBRACE);
  34887. this.parseBlock();
  34888. this.expect(PostScriptTokenTypes.RBRACE);
  34889. return this.operators;
  34890. },
  34891. parseBlock: function PostScriptParser_parseBlock() {
  34892. while (true) {
  34893. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34894. this.operators.push(this.prev.value);
  34895. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34896. this.operators.push(this.prev.value);
  34897. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34898. this.parseCondition();
  34899. } else {
  34900. return;
  34901. }
  34902. }
  34903. },
  34904. parseCondition: function PostScriptParser_parseCondition() {
  34905. // Add two place holders that will be updated later
  34906. var conditionLocation = this.operators.length;
  34907. this.operators.push(null, null);
  34908. this.parseBlock();
  34909. this.expect(PostScriptTokenTypes.RBRACE);
  34910. if (this.accept(PostScriptTokenTypes.IF)) {
  34911. // The true block is right after the 'if' so it just falls through on
  34912. // true else it jumps and skips the true block.
  34913. this.operators[conditionLocation] = this.operators.length;
  34914. this.operators[conditionLocation + 1] = 'jz';
  34915. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34916. var jumpLocation = this.operators.length;
  34917. this.operators.push(null, null);
  34918. var endOfTrue = this.operators.length;
  34919. this.parseBlock();
  34920. this.expect(PostScriptTokenTypes.RBRACE);
  34921. this.expect(PostScriptTokenTypes.IFELSE);
  34922. // The jump is added at the end of the true block to skip the false
  34923. // block.
  34924. this.operators[jumpLocation] = this.operators.length;
  34925. this.operators[jumpLocation + 1] = 'j';
  34926. this.operators[conditionLocation] = endOfTrue;
  34927. this.operators[conditionLocation + 1] = 'jz';
  34928. } else {
  34929. error('PS Function: error parsing conditional.');
  34930. }
  34931. }
  34932. };
  34933. return PostScriptParser;
  34934. })();
  34935. var PostScriptTokenTypes = {
  34936. LBRACE: 0,
  34937. RBRACE: 1,
  34938. NUMBER: 2,
  34939. OPERATOR: 3,
  34940. IF: 4,
  34941. IFELSE: 5
  34942. };
  34943. var PostScriptToken = (function PostScriptTokenClosure() {
  34944. function PostScriptToken(type, value) {
  34945. this.type = type;
  34946. this.value = value;
  34947. }
  34948. var opCache = {};
  34949. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34950. var opValue = opCache[op];
  34951. if (opValue) {
  34952. return opValue;
  34953. }
  34954. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34955. };
  34956. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34957. '{');
  34958. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34959. '}');
  34960. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34961. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34962. 'IFELSE');
  34963. return PostScriptToken;
  34964. })();
  34965. var PostScriptLexer = (function PostScriptLexerClosure() {
  34966. function PostScriptLexer(stream) {
  34967. this.stream = stream;
  34968. this.nextChar();
  34969. this.strBuf = [];
  34970. }
  34971. PostScriptLexer.prototype = {
  34972. nextChar: function PostScriptLexer_nextChar() {
  34973. return (this.currentChar = this.stream.getByte());
  34974. },
  34975. getToken: function PostScriptLexer_getToken() {
  34976. var comment = false;
  34977. var ch = this.currentChar;
  34978. // skip comments
  34979. while (true) {
  34980. if (ch < 0) {
  34981. return EOF;
  34982. }
  34983. if (comment) {
  34984. if (ch === 0x0A || ch === 0x0D) {
  34985. comment = false;
  34986. }
  34987. } else if (ch === 0x25) { // '%'
  34988. comment = true;
  34989. } else if (!Lexer.isSpace(ch)) {
  34990. break;
  34991. }
  34992. ch = this.nextChar();
  34993. }
  34994. switch (ch | 0) {
  34995. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34996. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34997. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34998. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  34999. this.getNumber());
  35000. case 0x7B: // '{'
  35001. this.nextChar();
  35002. return PostScriptToken.LBRACE;
  35003. case 0x7D: // '}'
  35004. this.nextChar();
  35005. return PostScriptToken.RBRACE;
  35006. }
  35007. // operator
  35008. var strBuf = this.strBuf;
  35009. strBuf.length = 0;
  35010. strBuf[0] = String.fromCharCode(ch);
  35011. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  35012. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  35013. strBuf.push(String.fromCharCode(ch));
  35014. }
  35015. var str = strBuf.join('');
  35016. switch (str.toLowerCase()) {
  35017. case 'if':
  35018. return PostScriptToken.IF;
  35019. case 'ifelse':
  35020. return PostScriptToken.IFELSE;
  35021. default:
  35022. return PostScriptToken.getOperator(str);
  35023. }
  35024. },
  35025. getNumber: function PostScriptLexer_getNumber() {
  35026. var ch = this.currentChar;
  35027. var strBuf = this.strBuf;
  35028. strBuf.length = 0;
  35029. strBuf[0] = String.fromCharCode(ch);
  35030. while ((ch = this.nextChar()) >= 0) {
  35031. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35032. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35033. strBuf.push(String.fromCharCode(ch));
  35034. } else {
  35035. break;
  35036. }
  35037. }
  35038. var value = parseFloat(strBuf.join(''));
  35039. if (isNaN(value)) {
  35040. error('Invalid floating point number: ' + value);
  35041. }
  35042. return value;
  35043. }
  35044. };
  35045. return PostScriptLexer;
  35046. })();
  35047. var Stream = (function StreamClosure() {
  35048. function Stream(arrayBuffer, start, length, dict) {
  35049. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35050. arrayBuffer : new Uint8Array(arrayBuffer));
  35051. this.start = start || 0;
  35052. this.pos = this.start;
  35053. this.end = (start + length) || this.bytes.length;
  35054. this.dict = dict;
  35055. }
  35056. // required methods for a stream. if a particular stream does not
  35057. // implement these, an error should be thrown
  35058. Stream.prototype = {
  35059. get length() {
  35060. return this.end - this.start;
  35061. },
  35062. get isEmpty() {
  35063. return this.length === 0;
  35064. },
  35065. getByte: function Stream_getByte() {
  35066. if (this.pos >= this.end) {
  35067. return -1;
  35068. }
  35069. return this.bytes[this.pos++];
  35070. },
  35071. getUint16: function Stream_getUint16() {
  35072. var b0 = this.getByte();
  35073. var b1 = this.getByte();
  35074. if (b0 === -1 || b1 === -1) {
  35075. return -1;
  35076. }
  35077. return (b0 << 8) + b1;
  35078. },
  35079. getInt32: function Stream_getInt32() {
  35080. var b0 = this.getByte();
  35081. var b1 = this.getByte();
  35082. var b2 = this.getByte();
  35083. var b3 = this.getByte();
  35084. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35085. },
  35086. // returns subarray of original buffer
  35087. // should only be read
  35088. getBytes: function Stream_getBytes(length) {
  35089. var bytes = this.bytes;
  35090. var pos = this.pos;
  35091. var strEnd = this.end;
  35092. if (!length) {
  35093. return bytes.subarray(pos, strEnd);
  35094. }
  35095. var end = pos + length;
  35096. if (end > strEnd) {
  35097. end = strEnd;
  35098. }
  35099. this.pos = end;
  35100. return bytes.subarray(pos, end);
  35101. },
  35102. peekByte: function Stream_peekByte() {
  35103. var peekedByte = this.getByte();
  35104. this.pos--;
  35105. return peekedByte;
  35106. },
  35107. peekBytes: function Stream_peekBytes(length) {
  35108. var bytes = this.getBytes(length);
  35109. this.pos -= bytes.length;
  35110. return bytes;
  35111. },
  35112. skip: function Stream_skip(n) {
  35113. if (!n) {
  35114. n = 1;
  35115. }
  35116. this.pos += n;
  35117. },
  35118. reset: function Stream_reset() {
  35119. this.pos = this.start;
  35120. },
  35121. moveStart: function Stream_moveStart() {
  35122. this.start = this.pos;
  35123. },
  35124. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35125. return new Stream(this.bytes.buffer, start, length, dict);
  35126. },
  35127. isStream: true
  35128. };
  35129. return Stream;
  35130. })();
  35131. var StringStream = (function StringStreamClosure() {
  35132. function StringStream(str) {
  35133. var length = str.length;
  35134. var bytes = new Uint8Array(length);
  35135. for (var n = 0; n < length; ++n) {
  35136. bytes[n] = str.charCodeAt(n);
  35137. }
  35138. Stream.call(this, bytes);
  35139. }
  35140. StringStream.prototype = Stream.prototype;
  35141. return StringStream;
  35142. })();
  35143. // super class for the decoding streams
  35144. var DecodeStream = (function DecodeStreamClosure() {
  35145. // Lots of DecodeStreams are created whose buffers are never used. For these
  35146. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35147. // having special cases that would be required if we used |null| for an empty
  35148. // buffer.
  35149. var emptyBuffer = new Uint8Array(0);
  35150. function DecodeStream(maybeMinBufferLength) {
  35151. this.pos = 0;
  35152. this.bufferLength = 0;
  35153. this.eof = false;
  35154. this.buffer = emptyBuffer;
  35155. this.minBufferLength = 512;
  35156. if (maybeMinBufferLength) {
  35157. // Compute the first power of two that is as big as maybeMinBufferLength.
  35158. while (this.minBufferLength < maybeMinBufferLength) {
  35159. this.minBufferLength *= 2;
  35160. }
  35161. }
  35162. }
  35163. DecodeStream.prototype = {
  35164. get isEmpty() {
  35165. while (!this.eof && this.bufferLength === 0) {
  35166. this.readBlock();
  35167. }
  35168. return this.bufferLength === 0;
  35169. },
  35170. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35171. var buffer = this.buffer;
  35172. if (requested <= buffer.byteLength) {
  35173. return buffer;
  35174. }
  35175. var size = this.minBufferLength;
  35176. while (size < requested) {
  35177. size *= 2;
  35178. }
  35179. var buffer2 = new Uint8Array(size);
  35180. buffer2.set(buffer);
  35181. return (this.buffer = buffer2);
  35182. },
  35183. getByte: function DecodeStream_getByte() {
  35184. var pos = this.pos;
  35185. while (this.bufferLength <= pos) {
  35186. if (this.eof) {
  35187. return -1;
  35188. }
  35189. this.readBlock();
  35190. }
  35191. return this.buffer[this.pos++];
  35192. },
  35193. getUint16: function DecodeStream_getUint16() {
  35194. var b0 = this.getByte();
  35195. var b1 = this.getByte();
  35196. if (b0 === -1 || b1 === -1) {
  35197. return -1;
  35198. }
  35199. return (b0 << 8) + b1;
  35200. },
  35201. getInt32: function DecodeStream_getInt32() {
  35202. var b0 = this.getByte();
  35203. var b1 = this.getByte();
  35204. var b2 = this.getByte();
  35205. var b3 = this.getByte();
  35206. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35207. },
  35208. getBytes: function DecodeStream_getBytes(length) {
  35209. var end, pos = this.pos;
  35210. if (length) {
  35211. this.ensureBuffer(pos + length);
  35212. end = pos + length;
  35213. while (!this.eof && this.bufferLength < end) {
  35214. this.readBlock();
  35215. }
  35216. var bufEnd = this.bufferLength;
  35217. if (end > bufEnd) {
  35218. end = bufEnd;
  35219. }
  35220. } else {
  35221. while (!this.eof) {
  35222. this.readBlock();
  35223. }
  35224. end = this.bufferLength;
  35225. }
  35226. this.pos = end;
  35227. return this.buffer.subarray(pos, end);
  35228. },
  35229. peekByte: function DecodeStream_peekByte() {
  35230. var peekedByte = this.getByte();
  35231. this.pos--;
  35232. return peekedByte;
  35233. },
  35234. peekBytes: function DecodeStream_peekBytes(length) {
  35235. var bytes = this.getBytes(length);
  35236. this.pos -= bytes.length;
  35237. return bytes;
  35238. },
  35239. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35240. var end = start + length;
  35241. while (this.bufferLength <= end && !this.eof) {
  35242. this.readBlock();
  35243. }
  35244. return new Stream(this.buffer, start, length, dict);
  35245. },
  35246. skip: function DecodeStream_skip(n) {
  35247. if (!n) {
  35248. n = 1;
  35249. }
  35250. this.pos += n;
  35251. },
  35252. reset: function DecodeStream_reset() {
  35253. this.pos = 0;
  35254. },
  35255. getBaseStreams: function DecodeStream_getBaseStreams() {
  35256. if (this.str && this.str.getBaseStreams) {
  35257. return this.str.getBaseStreams();
  35258. }
  35259. return [];
  35260. }
  35261. };
  35262. return DecodeStream;
  35263. })();
  35264. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35265. function StreamsSequenceStream(streams) {
  35266. this.streams = streams;
  35267. DecodeStream.call(this, /* maybeLength = */ null);
  35268. }
  35269. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35270. StreamsSequenceStream.prototype.readBlock =
  35271. function streamSequenceStreamReadBlock() {
  35272. var streams = this.streams;
  35273. if (streams.length === 0) {
  35274. this.eof = true;
  35275. return;
  35276. }
  35277. var stream = streams.shift();
  35278. var chunk = stream.getBytes();
  35279. var bufferLength = this.bufferLength;
  35280. var newLength = bufferLength + chunk.length;
  35281. var buffer = this.ensureBuffer(newLength);
  35282. buffer.set(chunk, bufferLength);
  35283. this.bufferLength = newLength;
  35284. };
  35285. StreamsSequenceStream.prototype.getBaseStreams =
  35286. function StreamsSequenceStream_getBaseStreams() {
  35287. var baseStreams = [];
  35288. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35289. var stream = this.streams[i];
  35290. if (stream.getBaseStreams) {
  35291. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35292. }
  35293. }
  35294. return baseStreams;
  35295. };
  35296. return StreamsSequenceStream;
  35297. })();
  35298. var FlateStream = (function FlateStreamClosure() {
  35299. var codeLenCodeMap = new Uint32Array([
  35300. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35301. ]);
  35302. var lengthDecode = new Uint32Array([
  35303. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35304. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35305. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35306. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35307. ]);
  35308. var distDecode = new Uint32Array([
  35309. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35310. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35311. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35312. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35313. ]);
  35314. var fixedLitCodeTab = [new Uint32Array([
  35315. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35316. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35317. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35318. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35319. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35320. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35321. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35322. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35323. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35324. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35325. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35326. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35327. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35328. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35329. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35330. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35331. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35332. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35333. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35334. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35335. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35336. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35337. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35338. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35339. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35340. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35341. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35342. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35343. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35344. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35345. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35346. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35347. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35348. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35349. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35350. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35351. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35352. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35353. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35354. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35355. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35356. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35357. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35358. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35359. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35360. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35361. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35362. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35363. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35364. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35365. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35366. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35367. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35368. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35369. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35370. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35371. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35372. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35373. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35374. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35375. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35376. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35377. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35378. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35379. ]), 9];
  35380. var fixedDistCodeTab = [new Uint32Array([
  35381. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35382. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35383. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35384. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35385. ]), 5];
  35386. function FlateStream(str, maybeLength) {
  35387. this.str = str;
  35388. this.dict = str.dict;
  35389. var cmf = str.getByte();
  35390. var flg = str.getByte();
  35391. if (cmf === -1 || flg === -1) {
  35392. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35393. }
  35394. if ((cmf & 0x0f) !== 0x08) {
  35395. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35396. }
  35397. if ((((cmf << 8) + flg) % 31) !== 0) {
  35398. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35399. }
  35400. if (flg & 0x20) {
  35401. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35402. }
  35403. this.codeSize = 0;
  35404. this.codeBuf = 0;
  35405. DecodeStream.call(this, maybeLength);
  35406. }
  35407. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35408. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35409. var str = this.str;
  35410. var codeSize = this.codeSize;
  35411. var codeBuf = this.codeBuf;
  35412. var b;
  35413. while (codeSize < bits) {
  35414. if ((b = str.getByte()) === -1) {
  35415. error('Bad encoding in flate stream');
  35416. }
  35417. codeBuf |= b << codeSize;
  35418. codeSize += 8;
  35419. }
  35420. b = codeBuf & ((1 << bits) - 1);
  35421. this.codeBuf = codeBuf >> bits;
  35422. this.codeSize = codeSize -= bits;
  35423. return b;
  35424. };
  35425. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35426. var str = this.str;
  35427. var codes = table[0];
  35428. var maxLen = table[1];
  35429. var codeSize = this.codeSize;
  35430. var codeBuf = this.codeBuf;
  35431. var b;
  35432. while (codeSize < maxLen) {
  35433. if ((b = str.getByte()) === -1) {
  35434. // premature end of stream. code might however still be valid.
  35435. // codeSize < codeLen check below guards against incomplete codeVal.
  35436. break;
  35437. }
  35438. codeBuf |= (b << codeSize);
  35439. codeSize += 8;
  35440. }
  35441. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35442. var codeLen = code >> 16;
  35443. var codeVal = code & 0xffff;
  35444. if (codeLen < 1 || codeSize < codeLen) {
  35445. error('Bad encoding in flate stream');
  35446. }
  35447. this.codeBuf = (codeBuf >> codeLen);
  35448. this.codeSize = (codeSize - codeLen);
  35449. return codeVal;
  35450. };
  35451. FlateStream.prototype.generateHuffmanTable =
  35452. function flateStreamGenerateHuffmanTable(lengths) {
  35453. var n = lengths.length;
  35454. // find max code length
  35455. var maxLen = 0;
  35456. var i;
  35457. for (i = 0; i < n; ++i) {
  35458. if (lengths[i] > maxLen) {
  35459. maxLen = lengths[i];
  35460. }
  35461. }
  35462. // build the table
  35463. var size = 1 << maxLen;
  35464. var codes = new Uint32Array(size);
  35465. for (var len = 1, code = 0, skip = 2;
  35466. len <= maxLen;
  35467. ++len, code <<= 1, skip <<= 1) {
  35468. for (var val = 0; val < n; ++val) {
  35469. if (lengths[val] === len) {
  35470. // bit-reverse the code
  35471. var code2 = 0;
  35472. var t = code;
  35473. for (i = 0; i < len; ++i) {
  35474. code2 = (code2 << 1) | (t & 1);
  35475. t >>= 1;
  35476. }
  35477. // fill the table entries
  35478. for (i = code2; i < size; i += skip) {
  35479. codes[i] = (len << 16) | val;
  35480. }
  35481. ++code;
  35482. }
  35483. }
  35484. }
  35485. return [codes, maxLen];
  35486. };
  35487. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35488. var buffer, len;
  35489. var str = this.str;
  35490. // read block header
  35491. var hdr = this.getBits(3);
  35492. if (hdr & 1) {
  35493. this.eof = true;
  35494. }
  35495. hdr >>= 1;
  35496. if (hdr === 0) { // uncompressed block
  35497. var b;
  35498. if ((b = str.getByte()) === -1) {
  35499. error('Bad block header in flate stream');
  35500. }
  35501. var blockLen = b;
  35502. if ((b = str.getByte()) === -1) {
  35503. error('Bad block header in flate stream');
  35504. }
  35505. blockLen |= (b << 8);
  35506. if ((b = str.getByte()) === -1) {
  35507. error('Bad block header in flate stream');
  35508. }
  35509. var check = b;
  35510. if ((b = str.getByte()) === -1) {
  35511. error('Bad block header in flate stream');
  35512. }
  35513. check |= (b << 8);
  35514. if (check !== (~blockLen & 0xffff) &&
  35515. (blockLen !== 0 || check !== 0)) {
  35516. // Ignoring error for bad "empty" block (see issue 1277)
  35517. error('Bad uncompressed block length in flate stream');
  35518. }
  35519. this.codeBuf = 0;
  35520. this.codeSize = 0;
  35521. var bufferLength = this.bufferLength;
  35522. buffer = this.ensureBuffer(bufferLength + blockLen);
  35523. var end = bufferLength + blockLen;
  35524. this.bufferLength = end;
  35525. if (blockLen === 0) {
  35526. if (str.peekByte() === -1) {
  35527. this.eof = true;
  35528. }
  35529. } else {
  35530. for (var n = bufferLength; n < end; ++n) {
  35531. if ((b = str.getByte()) === -1) {
  35532. this.eof = true;
  35533. break;
  35534. }
  35535. buffer[n] = b;
  35536. }
  35537. }
  35538. return;
  35539. }
  35540. var litCodeTable;
  35541. var distCodeTable;
  35542. if (hdr === 1) { // compressed block, fixed codes
  35543. litCodeTable = fixedLitCodeTab;
  35544. distCodeTable = fixedDistCodeTab;
  35545. } else if (hdr === 2) { // compressed block, dynamic codes
  35546. var numLitCodes = this.getBits(5) + 257;
  35547. var numDistCodes = this.getBits(5) + 1;
  35548. var numCodeLenCodes = this.getBits(4) + 4;
  35549. // build the code lengths code table
  35550. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35551. var i;
  35552. for (i = 0; i < numCodeLenCodes; ++i) {
  35553. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35554. }
  35555. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35556. // build the literal and distance code tables
  35557. len = 0;
  35558. i = 0;
  35559. var codes = numLitCodes + numDistCodes;
  35560. var codeLengths = new Uint8Array(codes);
  35561. var bitsLength, bitsOffset, what;
  35562. while (i < codes) {
  35563. var code = this.getCode(codeLenCodeTab);
  35564. if (code === 16) {
  35565. bitsLength = 2; bitsOffset = 3; what = len;
  35566. } else if (code === 17) {
  35567. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35568. } else if (code === 18) {
  35569. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35570. } else {
  35571. codeLengths[i++] = len = code;
  35572. continue;
  35573. }
  35574. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35575. while (repeatLength-- > 0) {
  35576. codeLengths[i++] = what;
  35577. }
  35578. }
  35579. litCodeTable =
  35580. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35581. distCodeTable =
  35582. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35583. } else {
  35584. error('Unknown block type in flate stream');
  35585. }
  35586. buffer = this.buffer;
  35587. var limit = buffer ? buffer.length : 0;
  35588. var pos = this.bufferLength;
  35589. while (true) {
  35590. var code1 = this.getCode(litCodeTable);
  35591. if (code1 < 256) {
  35592. if (pos + 1 >= limit) {
  35593. buffer = this.ensureBuffer(pos + 1);
  35594. limit = buffer.length;
  35595. }
  35596. buffer[pos++] = code1;
  35597. continue;
  35598. }
  35599. if (code1 === 256) {
  35600. this.bufferLength = pos;
  35601. return;
  35602. }
  35603. code1 -= 257;
  35604. code1 = lengthDecode[code1];
  35605. var code2 = code1 >> 16;
  35606. if (code2 > 0) {
  35607. code2 = this.getBits(code2);
  35608. }
  35609. len = (code1 & 0xffff) + code2;
  35610. code1 = this.getCode(distCodeTable);
  35611. code1 = distDecode[code1];
  35612. code2 = code1 >> 16;
  35613. if (code2 > 0) {
  35614. code2 = this.getBits(code2);
  35615. }
  35616. var dist = (code1 & 0xffff) + code2;
  35617. if (pos + len >= limit) {
  35618. buffer = this.ensureBuffer(pos + len);
  35619. limit = buffer.length;
  35620. }
  35621. for (var k = 0; k < len; ++k, ++pos) {
  35622. buffer[pos] = buffer[pos - dist];
  35623. }
  35624. }
  35625. };
  35626. return FlateStream;
  35627. })();
  35628. var PredictorStream = (function PredictorStreamClosure() {
  35629. function PredictorStream(str, maybeLength, params) {
  35630. var predictor = this.predictor = params.get('Predictor') || 1;
  35631. if (predictor <= 1) {
  35632. return str; // no prediction
  35633. }
  35634. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35635. error('Unsupported predictor: ' + predictor);
  35636. }
  35637. if (predictor === 2) {
  35638. this.readBlock = this.readBlockTiff;
  35639. } else {
  35640. this.readBlock = this.readBlockPng;
  35641. }
  35642. this.str = str;
  35643. this.dict = str.dict;
  35644. var colors = this.colors = params.get('Colors') || 1;
  35645. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35646. var columns = this.columns = params.get('Columns') || 1;
  35647. this.pixBytes = (colors * bits + 7) >> 3;
  35648. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35649. DecodeStream.call(this, maybeLength);
  35650. return this;
  35651. }
  35652. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35653. PredictorStream.prototype.readBlockTiff =
  35654. function predictorStreamReadBlockTiff() {
  35655. var rowBytes = this.rowBytes;
  35656. var bufferLength = this.bufferLength;
  35657. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35658. var bits = this.bits;
  35659. var colors = this.colors;
  35660. var rawBytes = this.str.getBytes(rowBytes);
  35661. this.eof = !rawBytes.length;
  35662. if (this.eof) {
  35663. return;
  35664. }
  35665. var inbuf = 0, outbuf = 0;
  35666. var inbits = 0, outbits = 0;
  35667. var pos = bufferLength;
  35668. var i;
  35669. if (bits === 1) {
  35670. for (i = 0; i < rowBytes; ++i) {
  35671. var c = rawBytes[i];
  35672. inbuf = (inbuf << 8) | c;
  35673. // bitwise addition is exclusive or
  35674. // first shift inbuf and then add
  35675. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35676. // truncate inbuf (assumes colors < 16)
  35677. inbuf &= 0xFFFF;
  35678. }
  35679. } else if (bits === 8) {
  35680. for (i = 0; i < colors; ++i) {
  35681. buffer[pos++] = rawBytes[i];
  35682. }
  35683. for (; i < rowBytes; ++i) {
  35684. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35685. pos++;
  35686. }
  35687. } else {
  35688. var compArray = new Uint8Array(colors + 1);
  35689. var bitMask = (1 << bits) - 1;
  35690. var j = 0, k = bufferLength;
  35691. var columns = this.columns;
  35692. for (i = 0; i < columns; ++i) {
  35693. for (var kk = 0; kk < colors; ++kk) {
  35694. if (inbits < bits) {
  35695. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35696. inbits += 8;
  35697. }
  35698. compArray[kk] = (compArray[kk] +
  35699. (inbuf >> (inbits - bits))) & bitMask;
  35700. inbits -= bits;
  35701. outbuf = (outbuf << bits) | compArray[kk];
  35702. outbits += bits;
  35703. if (outbits >= 8) {
  35704. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35705. outbits -= 8;
  35706. }
  35707. }
  35708. }
  35709. if (outbits > 0) {
  35710. buffer[k++] = (outbuf << (8 - outbits)) +
  35711. (inbuf & ((1 << (8 - outbits)) - 1));
  35712. }
  35713. }
  35714. this.bufferLength += rowBytes;
  35715. };
  35716. PredictorStream.prototype.readBlockPng =
  35717. function predictorStreamReadBlockPng() {
  35718. var rowBytes = this.rowBytes;
  35719. var pixBytes = this.pixBytes;
  35720. var predictor = this.str.getByte();
  35721. var rawBytes = this.str.getBytes(rowBytes);
  35722. this.eof = !rawBytes.length;
  35723. if (this.eof) {
  35724. return;
  35725. }
  35726. var bufferLength = this.bufferLength;
  35727. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35728. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35729. if (prevRow.length === 0) {
  35730. prevRow = new Uint8Array(rowBytes);
  35731. }
  35732. var i, j = bufferLength, up, c;
  35733. switch (predictor) {
  35734. case 0:
  35735. for (i = 0; i < rowBytes; ++i) {
  35736. buffer[j++] = rawBytes[i];
  35737. }
  35738. break;
  35739. case 1:
  35740. for (i = 0; i < pixBytes; ++i) {
  35741. buffer[j++] = rawBytes[i];
  35742. }
  35743. for (; i < rowBytes; ++i) {
  35744. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35745. j++;
  35746. }
  35747. break;
  35748. case 2:
  35749. for (i = 0; i < rowBytes; ++i) {
  35750. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35751. }
  35752. break;
  35753. case 3:
  35754. for (i = 0; i < pixBytes; ++i) {
  35755. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35756. }
  35757. for (; i < rowBytes; ++i) {
  35758. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35759. rawBytes[i]) & 0xFF;
  35760. j++;
  35761. }
  35762. break;
  35763. case 4:
  35764. // we need to save the up left pixels values. the simplest way
  35765. // is to create a new buffer
  35766. for (i = 0; i < pixBytes; ++i) {
  35767. up = prevRow[i];
  35768. c = rawBytes[i];
  35769. buffer[j++] = up + c;
  35770. }
  35771. for (; i < rowBytes; ++i) {
  35772. up = prevRow[i];
  35773. var upLeft = prevRow[i - pixBytes];
  35774. var left = buffer[j - pixBytes];
  35775. var p = left + up - upLeft;
  35776. var pa = p - left;
  35777. if (pa < 0) {
  35778. pa = -pa;
  35779. }
  35780. var pb = p - up;
  35781. if (pb < 0) {
  35782. pb = -pb;
  35783. }
  35784. var pc = p - upLeft;
  35785. if (pc < 0) {
  35786. pc = -pc;
  35787. }
  35788. c = rawBytes[i];
  35789. if (pa <= pb && pa <= pc) {
  35790. buffer[j++] = left + c;
  35791. } else if (pb <= pc) {
  35792. buffer[j++] = up + c;
  35793. } else {
  35794. buffer[j++] = upLeft + c;
  35795. }
  35796. }
  35797. break;
  35798. default:
  35799. error('Unsupported predictor: ' + predictor);
  35800. }
  35801. this.bufferLength += rowBytes;
  35802. };
  35803. return PredictorStream;
  35804. })();
  35805. /**
  35806. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35807. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35808. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35809. * a library to decode these images and the stream behaves like all the other
  35810. * DecodeStreams.
  35811. */
  35812. var JpegStream = (function JpegStreamClosure() {
  35813. function JpegStream(stream, maybeLength, dict, xref) {
  35814. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35815. // Note: this seems to mainly affect inline images.
  35816. var ch;
  35817. while ((ch = stream.getByte()) !== -1) {
  35818. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35819. stream.skip(-1); // Reset the stream position to the SOI.
  35820. break;
  35821. }
  35822. }
  35823. this.stream = stream;
  35824. this.maybeLength = maybeLength;
  35825. this.dict = dict;
  35826. DecodeStream.call(this, maybeLength);
  35827. }
  35828. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35829. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35830. get: function JpegStream_bytes() {
  35831. // If this.maybeLength is null, we'll get the entire stream.
  35832. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35833. },
  35834. configurable: true
  35835. });
  35836. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35837. if (this.bufferLength) {
  35838. return;
  35839. }
  35840. try {
  35841. var jpegImage = new JpegImage();
  35842. // checking if values needs to be transformed before conversion
  35843. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35844. var decodeArr = this.dict.get('Decode');
  35845. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35846. var decodeArrLength = decodeArr.length;
  35847. var transform = new Int32Array(decodeArrLength);
  35848. var transformNeeded = false;
  35849. var maxValue = (1 << bitsPerComponent) - 1;
  35850. for (var i = 0; i < decodeArrLength; i += 2) {
  35851. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35852. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35853. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35854. transformNeeded = true;
  35855. }
  35856. }
  35857. if (transformNeeded) {
  35858. jpegImage.decodeTransform = transform;
  35859. }
  35860. }
  35861. jpegImage.parse(this.bytes);
  35862. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35863. this.forceRGB);
  35864. this.buffer = data;
  35865. this.bufferLength = data.length;
  35866. this.eof = true;
  35867. } catch (e) {
  35868. error('JPEG error: ' + e);
  35869. }
  35870. };
  35871. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35872. this.ensureBuffer();
  35873. return this.buffer;
  35874. };
  35875. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35876. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35877. };
  35878. /**
  35879. * Checks if the image can be decoded and displayed by the browser without any
  35880. * further processing such as color space conversions.
  35881. */
  35882. JpegStream.prototype.isNativelySupported =
  35883. function JpegStream_isNativelySupported(xref, res) {
  35884. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35885. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35886. };
  35887. /**
  35888. * Checks if the image can be decoded by the browser.
  35889. */
  35890. JpegStream.prototype.isNativelyDecodable =
  35891. function JpegStream_isNativelyDecodable(xref, res) {
  35892. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35893. var numComps = cs.numComps;
  35894. return numComps === 1 || numComps === 3;
  35895. };
  35896. return JpegStream;
  35897. })();
  35898. /**
  35899. * For JPEG 2000's we use a library to decode these images and
  35900. * the stream behaves like all the other DecodeStreams.
  35901. */
  35902. var JpxStream = (function JpxStreamClosure() {
  35903. function JpxStream(stream, maybeLength, dict) {
  35904. this.stream = stream;
  35905. this.maybeLength = maybeLength;
  35906. this.dict = dict;
  35907. DecodeStream.call(this, maybeLength);
  35908. }
  35909. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35910. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35911. get: function JpxStream_bytes() {
  35912. // If this.maybeLength is null, we'll get the entire stream.
  35913. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35914. },
  35915. configurable: true
  35916. });
  35917. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35918. if (this.bufferLength) {
  35919. return;
  35920. }
  35921. var jpxImage = new JpxImage();
  35922. jpxImage.parse(this.bytes);
  35923. var width = jpxImage.width;
  35924. var height = jpxImage.height;
  35925. var componentsCount = jpxImage.componentsCount;
  35926. var tileCount = jpxImage.tiles.length;
  35927. if (tileCount === 1) {
  35928. this.buffer = jpxImage.tiles[0].items;
  35929. } else {
  35930. var data = new Uint8Array(width * height * componentsCount);
  35931. for (var k = 0; k < tileCount; k++) {
  35932. var tileComponents = jpxImage.tiles[k];
  35933. var tileWidth = tileComponents.width;
  35934. var tileHeight = tileComponents.height;
  35935. var tileLeft = tileComponents.left;
  35936. var tileTop = tileComponents.top;
  35937. var src = tileComponents.items;
  35938. var srcPosition = 0;
  35939. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35940. var imgRowSize = width * componentsCount;
  35941. var tileRowSize = tileWidth * componentsCount;
  35942. for (var j = 0; j < tileHeight; j++) {
  35943. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35944. data.set(rowBytes, dataPosition);
  35945. srcPosition += tileRowSize;
  35946. dataPosition += imgRowSize;
  35947. }
  35948. }
  35949. this.buffer = data;
  35950. }
  35951. this.bufferLength = this.buffer.length;
  35952. this.eof = true;
  35953. };
  35954. return JpxStream;
  35955. })();
  35956. /**
  35957. * For JBIG2's we use a library to decode these images and
  35958. * the stream behaves like all the other DecodeStreams.
  35959. */
  35960. var Jbig2Stream = (function Jbig2StreamClosure() {
  35961. function Jbig2Stream(stream, maybeLength, dict) {
  35962. this.stream = stream;
  35963. this.maybeLength = maybeLength;
  35964. this.dict = dict;
  35965. DecodeStream.call(this, maybeLength);
  35966. }
  35967. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35968. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35969. get: function Jbig2Stream_bytes() {
  35970. // If this.maybeLength is null, we'll get the entire stream.
  35971. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35972. },
  35973. configurable: true
  35974. });
  35975. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35976. if (this.bufferLength) {
  35977. return;
  35978. }
  35979. var jbig2Image = new Jbig2Image();
  35980. var chunks = [], xref = this.dict.xref;
  35981. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35982. // According to the PDF specification, DecodeParms can be either
  35983. // a dictionary, or an array whose elements are dictionaries.
  35984. if (isArray(decodeParams)) {
  35985. if (decodeParams.length > 1) {
  35986. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35987. 'not supported.');
  35988. }
  35989. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35990. }
  35991. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35992. var globalsStream = decodeParams.get('JBIG2Globals');
  35993. var globals = globalsStream.getBytes();
  35994. chunks.push({data: globals, start: 0, end: globals.length});
  35995. }
  35996. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  35997. var data = jbig2Image.parseChunks(chunks);
  35998. var dataLength = data.length;
  35999. // JBIG2 had black as 1 and white as 0, inverting the colors
  36000. for (var i = 0; i < dataLength; i++) {
  36001. data[i] ^= 0xFF;
  36002. }
  36003. this.buffer = data;
  36004. this.bufferLength = dataLength;
  36005. this.eof = true;
  36006. };
  36007. return Jbig2Stream;
  36008. })();
  36009. var DecryptStream = (function DecryptStreamClosure() {
  36010. function DecryptStream(str, maybeLength, decrypt) {
  36011. this.str = str;
  36012. this.dict = str.dict;
  36013. this.decrypt = decrypt;
  36014. this.nextChunk = null;
  36015. this.initialized = false;
  36016. DecodeStream.call(this, maybeLength);
  36017. }
  36018. var chunkSize = 512;
  36019. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36020. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36021. var chunk;
  36022. if (this.initialized) {
  36023. chunk = this.nextChunk;
  36024. } else {
  36025. chunk = this.str.getBytes(chunkSize);
  36026. this.initialized = true;
  36027. }
  36028. if (!chunk || chunk.length === 0) {
  36029. this.eof = true;
  36030. return;
  36031. }
  36032. this.nextChunk = this.str.getBytes(chunkSize);
  36033. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36034. var decrypt = this.decrypt;
  36035. chunk = decrypt(chunk, !hasMoreData);
  36036. var bufferLength = this.bufferLength;
  36037. var i, n = chunk.length;
  36038. var buffer = this.ensureBuffer(bufferLength + n);
  36039. for (i = 0; i < n; i++) {
  36040. buffer[bufferLength++] = chunk[i];
  36041. }
  36042. this.bufferLength = bufferLength;
  36043. };
  36044. return DecryptStream;
  36045. })();
  36046. var Ascii85Stream = (function Ascii85StreamClosure() {
  36047. function Ascii85Stream(str, maybeLength) {
  36048. this.str = str;
  36049. this.dict = str.dict;
  36050. this.input = new Uint8Array(5);
  36051. // Most streams increase in size when decoded, but Ascii85 streams
  36052. // typically shrink by ~20%.
  36053. if (maybeLength) {
  36054. maybeLength = 0.8 * maybeLength;
  36055. }
  36056. DecodeStream.call(this, maybeLength);
  36057. }
  36058. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36059. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36060. var TILDA_CHAR = 0x7E; // '~'
  36061. var Z_LOWER_CHAR = 0x7A; // 'z'
  36062. var EOF = -1;
  36063. var str = this.str;
  36064. var c = str.getByte();
  36065. while (Lexer.isSpace(c)) {
  36066. c = str.getByte();
  36067. }
  36068. if (c === EOF || c === TILDA_CHAR) {
  36069. this.eof = true;
  36070. return;
  36071. }
  36072. var bufferLength = this.bufferLength, buffer;
  36073. var i;
  36074. // special code for z
  36075. if (c === Z_LOWER_CHAR) {
  36076. buffer = this.ensureBuffer(bufferLength + 4);
  36077. for (i = 0; i < 4; ++i) {
  36078. buffer[bufferLength + i] = 0;
  36079. }
  36080. this.bufferLength += 4;
  36081. } else {
  36082. var input = this.input;
  36083. input[0] = c;
  36084. for (i = 1; i < 5; ++i) {
  36085. c = str.getByte();
  36086. while (Lexer.isSpace(c)) {
  36087. c = str.getByte();
  36088. }
  36089. input[i] = c;
  36090. if (c === EOF || c === TILDA_CHAR) {
  36091. break;
  36092. }
  36093. }
  36094. buffer = this.ensureBuffer(bufferLength + i - 1);
  36095. this.bufferLength += i - 1;
  36096. // partial ending;
  36097. if (i < 5) {
  36098. for (; i < 5; ++i) {
  36099. input[i] = 0x21 + 84;
  36100. }
  36101. this.eof = true;
  36102. }
  36103. var t = 0;
  36104. for (i = 0; i < 5; ++i) {
  36105. t = t * 85 + (input[i] - 0x21);
  36106. }
  36107. for (i = 3; i >= 0; --i) {
  36108. buffer[bufferLength + i] = t & 0xFF;
  36109. t >>= 8;
  36110. }
  36111. }
  36112. };
  36113. return Ascii85Stream;
  36114. })();
  36115. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36116. function AsciiHexStream(str, maybeLength) {
  36117. this.str = str;
  36118. this.dict = str.dict;
  36119. this.firstDigit = -1;
  36120. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36121. // by 50%.
  36122. if (maybeLength) {
  36123. maybeLength = 0.5 * maybeLength;
  36124. }
  36125. DecodeStream.call(this, maybeLength);
  36126. }
  36127. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36128. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36129. var UPSTREAM_BLOCK_SIZE = 8000;
  36130. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36131. if (!bytes.length) {
  36132. this.eof = true;
  36133. return;
  36134. }
  36135. var maxDecodeLength = (bytes.length + 1) >> 1;
  36136. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36137. var bufferLength = this.bufferLength;
  36138. var firstDigit = this.firstDigit;
  36139. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36140. var ch = bytes[i], digit;
  36141. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36142. digit = ch & 0x0F;
  36143. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36144. // 'A'-'Z', 'a'-'z'
  36145. digit = (ch & 0x0F) + 9;
  36146. } else if (ch === 0x3E) { // '>'
  36147. this.eof = true;
  36148. break;
  36149. } else { // probably whitespace
  36150. continue; // ignoring
  36151. }
  36152. if (firstDigit < 0) {
  36153. firstDigit = digit;
  36154. } else {
  36155. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36156. firstDigit = -1;
  36157. }
  36158. }
  36159. if (firstDigit >= 0 && this.eof) {
  36160. // incomplete byte
  36161. buffer[bufferLength++] = (firstDigit << 4);
  36162. firstDigit = -1;
  36163. }
  36164. this.firstDigit = firstDigit;
  36165. this.bufferLength = bufferLength;
  36166. };
  36167. return AsciiHexStream;
  36168. })();
  36169. var RunLengthStream = (function RunLengthStreamClosure() {
  36170. function RunLengthStream(str, maybeLength) {
  36171. this.str = str;
  36172. this.dict = str.dict;
  36173. DecodeStream.call(this, maybeLength);
  36174. }
  36175. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36176. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36177. // The repeatHeader has following format. The first byte defines type of run
  36178. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36179. // (in addition to the second byte from the header), n = 129 through 255 -
  36180. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36181. var repeatHeader = this.str.getBytes(2);
  36182. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36183. this.eof = true;
  36184. return;
  36185. }
  36186. var buffer;
  36187. var bufferLength = this.bufferLength;
  36188. var n = repeatHeader[0];
  36189. if (n < 128) {
  36190. // copy n bytes
  36191. buffer = this.ensureBuffer(bufferLength + n + 1);
  36192. buffer[bufferLength++] = repeatHeader[1];
  36193. if (n > 0) {
  36194. var source = this.str.getBytes(n);
  36195. buffer.set(source, bufferLength);
  36196. bufferLength += n;
  36197. }
  36198. } else {
  36199. n = 257 - n;
  36200. var b = repeatHeader[1];
  36201. buffer = this.ensureBuffer(bufferLength + n + 1);
  36202. for (var i = 0; i < n; i++) {
  36203. buffer[bufferLength++] = b;
  36204. }
  36205. }
  36206. this.bufferLength = bufferLength;
  36207. };
  36208. return RunLengthStream;
  36209. })();
  36210. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36211. var ccittEOL = -2;
  36212. var twoDimPass = 0;
  36213. var twoDimHoriz = 1;
  36214. var twoDimVert0 = 2;
  36215. var twoDimVertR1 = 3;
  36216. var twoDimVertL1 = 4;
  36217. var twoDimVertR2 = 5;
  36218. var twoDimVertL2 = 6;
  36219. var twoDimVertR3 = 7;
  36220. var twoDimVertL3 = 8;
  36221. var twoDimTable = [
  36222. [-1, -1], [-1, -1], // 000000x
  36223. [7, twoDimVertL3], // 0000010
  36224. [7, twoDimVertR3], // 0000011
  36225. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36226. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36227. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36228. [4, twoDimPass], [4, twoDimPass],
  36229. [4, twoDimPass], [4, twoDimPass],
  36230. [4, twoDimPass], [4, twoDimPass],
  36231. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36232. [3, twoDimHoriz], [3, twoDimHoriz],
  36233. [3, twoDimHoriz], [3, twoDimHoriz],
  36234. [3, twoDimHoriz], [3, twoDimHoriz],
  36235. [3, twoDimHoriz], [3, twoDimHoriz],
  36236. [3, twoDimHoriz], [3, twoDimHoriz],
  36237. [3, twoDimHoriz], [3, twoDimHoriz],
  36238. [3, twoDimHoriz], [3, twoDimHoriz],
  36239. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36240. [3, twoDimVertL1], [3, twoDimVertL1],
  36241. [3, twoDimVertL1], [3, twoDimVertL1],
  36242. [3, twoDimVertL1], [3, twoDimVertL1],
  36243. [3, twoDimVertL1], [3, twoDimVertL1],
  36244. [3, twoDimVertL1], [3, twoDimVertL1],
  36245. [3, twoDimVertL1], [3, twoDimVertL1],
  36246. [3, twoDimVertL1], [3, twoDimVertL1],
  36247. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36248. [3, twoDimVertR1], [3, twoDimVertR1],
  36249. [3, twoDimVertR1], [3, twoDimVertR1],
  36250. [3, twoDimVertR1], [3, twoDimVertR1],
  36251. [3, twoDimVertR1], [3, twoDimVertR1],
  36252. [3, twoDimVertR1], [3, twoDimVertR1],
  36253. [3, twoDimVertR1], [3, twoDimVertR1],
  36254. [3, twoDimVertR1], [3, twoDimVertR1],
  36255. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36256. [1, twoDimVert0], [1, twoDimVert0],
  36257. [1, twoDimVert0], [1, twoDimVert0],
  36258. [1, twoDimVert0], [1, twoDimVert0],
  36259. [1, twoDimVert0], [1, twoDimVert0],
  36260. [1, twoDimVert0], [1, twoDimVert0],
  36261. [1, twoDimVert0], [1, twoDimVert0],
  36262. [1, twoDimVert0], [1, twoDimVert0],
  36263. [1, twoDimVert0], [1, twoDimVert0],
  36264. [1, twoDimVert0], [1, twoDimVert0],
  36265. [1, twoDimVert0], [1, twoDimVert0],
  36266. [1, twoDimVert0], [1, twoDimVert0],
  36267. [1, twoDimVert0], [1, twoDimVert0],
  36268. [1, twoDimVert0], [1, twoDimVert0],
  36269. [1, twoDimVert0], [1, twoDimVert0],
  36270. [1, twoDimVert0], [1, twoDimVert0],
  36271. [1, twoDimVert0], [1, twoDimVert0],
  36272. [1, twoDimVert0], [1, twoDimVert0],
  36273. [1, twoDimVert0], [1, twoDimVert0],
  36274. [1, twoDimVert0], [1, twoDimVert0],
  36275. [1, twoDimVert0], [1, twoDimVert0],
  36276. [1, twoDimVert0], [1, twoDimVert0],
  36277. [1, twoDimVert0], [1, twoDimVert0],
  36278. [1, twoDimVert0], [1, twoDimVert0],
  36279. [1, twoDimVert0], [1, twoDimVert0],
  36280. [1, twoDimVert0], [1, twoDimVert0],
  36281. [1, twoDimVert0], [1, twoDimVert0],
  36282. [1, twoDimVert0], [1, twoDimVert0],
  36283. [1, twoDimVert0], [1, twoDimVert0],
  36284. [1, twoDimVert0], [1, twoDimVert0],
  36285. [1, twoDimVert0], [1, twoDimVert0],
  36286. [1, twoDimVert0], [1, twoDimVert0]
  36287. ];
  36288. var whiteTable1 = [
  36289. [-1, -1], // 00000
  36290. [12, ccittEOL], // 00001
  36291. [-1, -1], [-1, -1], // 0001x
  36292. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36293. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36294. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36295. [11, 1792], [11, 1792], // 1000x
  36296. [12, 1984], // 10010
  36297. [12, 2048], // 10011
  36298. [12, 2112], // 10100
  36299. [12, 2176], // 10101
  36300. [12, 2240], // 10110
  36301. [12, 2304], // 10111
  36302. [11, 1856], [11, 1856], // 1100x
  36303. [11, 1920], [11, 1920], // 1101x
  36304. [12, 2368], // 11100
  36305. [12, 2432], // 11101
  36306. [12, 2496], // 11110
  36307. [12, 2560] // 11111
  36308. ];
  36309. var whiteTable2 = [
  36310. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36311. [8, 29], [8, 29], // 00000010x
  36312. [8, 30], [8, 30], // 00000011x
  36313. [8, 45], [8, 45], // 00000100x
  36314. [8, 46], [8, 46], // 00000101x
  36315. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36316. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36317. [8, 47], [8, 47], // 00001010x
  36318. [8, 48], [8, 48], // 00001011x
  36319. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36320. [6, 13], [6, 13], [6, 13], [6, 13],
  36321. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36322. [8, 33], [8, 33], // 00010010x
  36323. [8, 34], [8, 34], // 00010011x
  36324. [8, 35], [8, 35], // 00010100x
  36325. [8, 36], [8, 36], // 00010101x
  36326. [8, 37], [8, 37], // 00010110x
  36327. [8, 38], [8, 38], // 00010111x
  36328. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36329. [8, 31], [8, 31], // 00011010x
  36330. [8, 32], [8, 32], // 00011011x
  36331. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36332. [6, 1], [6, 1], [6, 1], [6, 1],
  36333. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36334. [6, 12], [6, 12], [6, 12], [6, 12],
  36335. [8, 53], [8, 53], // 00100100x
  36336. [8, 54], [8, 54], // 00100101x
  36337. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36338. [8, 39], [8, 39], // 00101000x
  36339. [8, 40], [8, 40], // 00101001x
  36340. [8, 41], [8, 41], // 00101010x
  36341. [8, 42], [8, 42], // 00101011x
  36342. [8, 43], [8, 43], // 00101100x
  36343. [8, 44], [8, 44], // 00101101x
  36344. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36345. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36346. [8, 61], [8, 61], // 00110010x
  36347. [8, 62], [8, 62], // 00110011x
  36348. [8, 63], [8, 63], // 00110100x
  36349. [8, 0], [8, 0], // 00110101x
  36350. [8, 320], [8, 320], // 00110110x
  36351. [8, 384], [8, 384], // 00110111x
  36352. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36353. [5, 10], [5, 10], [5, 10], [5, 10],
  36354. [5, 10], [5, 10], [5, 10], [5, 10],
  36355. [5, 10], [5, 10], [5, 10], [5, 10],
  36356. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36357. [5, 11], [5, 11], [5, 11], [5, 11],
  36358. [5, 11], [5, 11], [5, 11], [5, 11],
  36359. [5, 11], [5, 11], [5, 11], [5, 11],
  36360. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36361. [8, 59], [8, 59], // 01001010x
  36362. [8, 60], [8, 60], // 01001011x
  36363. [9, 1472], // 010011000
  36364. [9, 1536], // 010011001
  36365. [9, 1600], // 010011010
  36366. [9, 1728], // 010011011
  36367. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36368. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36369. [8, 49], [8, 49], // 01010010x
  36370. [8, 50], [8, 50], // 01010011x
  36371. [8, 51], [8, 51], // 01010100x
  36372. [8, 52], [8, 52], // 01010101x
  36373. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36374. [8, 55], [8, 55], // 01011000x
  36375. [8, 56], [8, 56], // 01011001x
  36376. [8, 57], [8, 57], // 01011010x
  36377. [8, 58], [8, 58], // 01011011x
  36378. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36379. [6, 192], [6, 192], [6, 192], [6, 192],
  36380. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36381. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36382. [8, 448], [8, 448], // 01100100x
  36383. [8, 512], [8, 512], // 01100101x
  36384. [9, 704], // 011001100
  36385. [9, 768], // 011001101
  36386. [8, 640], [8, 640], // 01100111x
  36387. [8, 576], [8, 576], // 01101000x
  36388. [9, 832], // 011010010
  36389. [9, 896], // 011010011
  36390. [9, 960], // 011010100
  36391. [9, 1024], // 011010101
  36392. [9, 1088], // 011010110
  36393. [9, 1152], // 011010111
  36394. [9, 1216], // 011011000
  36395. [9, 1280], // 011011001
  36396. [9, 1344], // 011011010
  36397. [9, 1408], // 011011011
  36398. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36399. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36400. [4, 2], [4, 2], [4, 2], [4, 2],
  36401. [4, 2], [4, 2], [4, 2], [4, 2],
  36402. [4, 2], [4, 2], [4, 2], [4, 2],
  36403. [4, 2], [4, 2], [4, 2], [4, 2],
  36404. [4, 2], [4, 2], [4, 2], [4, 2],
  36405. [4, 2], [4, 2], [4, 2], [4, 2],
  36406. [4, 2], [4, 2], [4, 2], [4, 2],
  36407. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36408. [4, 3], [4, 3], [4, 3], [4, 3],
  36409. [4, 3], [4, 3], [4, 3], [4, 3],
  36410. [4, 3], [4, 3], [4, 3], [4, 3],
  36411. [4, 3], [4, 3], [4, 3], [4, 3],
  36412. [4, 3], [4, 3], [4, 3], [4, 3],
  36413. [4, 3], [4, 3], [4, 3], [4, 3],
  36414. [4, 3], [4, 3], [4, 3], [4, 3],
  36415. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36416. [5, 128], [5, 128], [5, 128], [5, 128],
  36417. [5, 128], [5, 128], [5, 128], [5, 128],
  36418. [5, 128], [5, 128], [5, 128], [5, 128],
  36419. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36420. [5, 8], [5, 8], [5, 8], [5, 8],
  36421. [5, 8], [5, 8], [5, 8], [5, 8],
  36422. [5, 8], [5, 8], [5, 8], [5, 8],
  36423. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36424. [5, 9], [5, 9], [5, 9], [5, 9],
  36425. [5, 9], [5, 9], [5, 9], [5, 9],
  36426. [5, 9], [5, 9], [5, 9], [5, 9],
  36427. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36428. [6, 16], [6, 16], [6, 16], [6, 16],
  36429. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36430. [6, 17], [6, 17], [6, 17], [6, 17],
  36431. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36432. [4, 4], [4, 4], [4, 4], [4, 4],
  36433. [4, 4], [4, 4], [4, 4], [4, 4],
  36434. [4, 4], [4, 4], [4, 4], [4, 4],
  36435. [4, 4], [4, 4], [4, 4], [4, 4],
  36436. [4, 4], [4, 4], [4, 4], [4, 4],
  36437. [4, 4], [4, 4], [4, 4], [4, 4],
  36438. [4, 4], [4, 4], [4, 4], [4, 4],
  36439. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36440. [4, 5], [4, 5], [4, 5], [4, 5],
  36441. [4, 5], [4, 5], [4, 5], [4, 5],
  36442. [4, 5], [4, 5], [4, 5], [4, 5],
  36443. [4, 5], [4, 5], [4, 5], [4, 5],
  36444. [4, 5], [4, 5], [4, 5], [4, 5],
  36445. [4, 5], [4, 5], [4, 5], [4, 5],
  36446. [4, 5], [4, 5], [4, 5], [4, 5],
  36447. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36448. [6, 14], [6, 14], [6, 14], [6, 14],
  36449. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36450. [6, 15], [6, 15], [6, 15], [6, 15],
  36451. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36452. [5, 64], [5, 64], [5, 64], [5, 64],
  36453. [5, 64], [5, 64], [5, 64], [5, 64],
  36454. [5, 64], [5, 64], [5, 64], [5, 64],
  36455. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36456. [4, 6], [4, 6], [4, 6], [4, 6],
  36457. [4, 6], [4, 6], [4, 6], [4, 6],
  36458. [4, 6], [4, 6], [4, 6], [4, 6],
  36459. [4, 6], [4, 6], [4, 6], [4, 6],
  36460. [4, 6], [4, 6], [4, 6], [4, 6],
  36461. [4, 6], [4, 6], [4, 6], [4, 6],
  36462. [4, 6], [4, 6], [4, 6], [4, 6],
  36463. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36464. [4, 7], [4, 7], [4, 7], [4, 7],
  36465. [4, 7], [4, 7], [4, 7], [4, 7],
  36466. [4, 7], [4, 7], [4, 7], [4, 7],
  36467. [4, 7], [4, 7], [4, 7], [4, 7],
  36468. [4, 7], [4, 7], [4, 7], [4, 7],
  36469. [4, 7], [4, 7], [4, 7], [4, 7],
  36470. [4, 7], [4, 7], [4, 7], [4, 7]
  36471. ];
  36472. var blackTable1 = [
  36473. [-1, -1], [-1, -1], // 000000000000x
  36474. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36475. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36476. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36477. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36478. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36479. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36480. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36481. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36482. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36483. [12, 1984], [12, 1984], // 000000010010x
  36484. [12, 2048], [12, 2048], // 000000010011x
  36485. [12, 2112], [12, 2112], // 000000010100x
  36486. [12, 2176], [12, 2176], // 000000010101x
  36487. [12, 2240], [12, 2240], // 000000010110x
  36488. [12, 2304], [12, 2304], // 000000010111x
  36489. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36490. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36491. [12, 2368], [12, 2368], // 000000011100x
  36492. [12, 2432], [12, 2432], // 000000011101x
  36493. [12, 2496], [12, 2496], // 000000011110x
  36494. [12, 2560], [12, 2560], // 000000011111x
  36495. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36496. [10, 18], [10, 18], [10, 18], [10, 18],
  36497. [12, 52], [12, 52], // 000000100100x
  36498. [13, 640], // 0000001001010
  36499. [13, 704], // 0000001001011
  36500. [13, 768], // 0000001001100
  36501. [13, 832], // 0000001001101
  36502. [12, 55], [12, 55], // 000000100111x
  36503. [12, 56], [12, 56], // 000000101000x
  36504. [13, 1280], // 0000001010010
  36505. [13, 1344], // 0000001010011
  36506. [13, 1408], // 0000001010100
  36507. [13, 1472], // 0000001010101
  36508. [12, 59], [12, 59], // 000000101011x
  36509. [12, 60], [12, 60], // 000000101100x
  36510. [13, 1536], // 0000001011010
  36511. [13, 1600], // 0000001011011
  36512. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36513. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36514. [13, 1664], // 0000001100100
  36515. [13, 1728], // 0000001100101
  36516. [12, 320], [12, 320], // 000000110011x
  36517. [12, 384], [12, 384], // 000000110100x
  36518. [12, 448], [12, 448], // 000000110101x
  36519. [13, 512], // 0000001101100
  36520. [13, 576], // 0000001101101
  36521. [12, 53], [12, 53], // 000000110111x
  36522. [12, 54], [12, 54], // 000000111000x
  36523. [13, 896], // 0000001110010
  36524. [13, 960], // 0000001110011
  36525. [13, 1024], // 0000001110100
  36526. [13, 1088], // 0000001110101
  36527. [13, 1152], // 0000001110110
  36528. [13, 1216], // 0000001110111
  36529. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36530. [10, 64], [10, 64], [10, 64], [10, 64]
  36531. ];
  36532. var blackTable2 = [
  36533. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36534. [8, 13], [8, 13], [8, 13], [8, 13],
  36535. [8, 13], [8, 13], [8, 13], [8, 13],
  36536. [8, 13], [8, 13], [8, 13], [8, 13],
  36537. [11, 23], [11, 23], // 00000101000x
  36538. [12, 50], // 000001010010
  36539. [12, 51], // 000001010011
  36540. [12, 44], // 000001010100
  36541. [12, 45], // 000001010101
  36542. [12, 46], // 000001010110
  36543. [12, 47], // 000001010111
  36544. [12, 57], // 000001011000
  36545. [12, 58], // 000001011001
  36546. [12, 61], // 000001011010
  36547. [12, 256], // 000001011011
  36548. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36549. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36550. [12, 48], // 000001100100
  36551. [12, 49], // 000001100101
  36552. [12, 62], // 000001100110
  36553. [12, 63], // 000001100111
  36554. [12, 30], // 000001101000
  36555. [12, 31], // 000001101001
  36556. [12, 32], // 000001101010
  36557. [12, 33], // 000001101011
  36558. [12, 40], // 000001101100
  36559. [12, 41], // 000001101101
  36560. [11, 22], [11, 22], // 00000110111x
  36561. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36562. [8, 14], [8, 14], [8, 14], [8, 14],
  36563. [8, 14], [8, 14], [8, 14], [8, 14],
  36564. [8, 14], [8, 14], [8, 14], [8, 14],
  36565. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36566. [7, 10], [7, 10], [7, 10], [7, 10],
  36567. [7, 10], [7, 10], [7, 10], [7, 10],
  36568. [7, 10], [7, 10], [7, 10], [7, 10],
  36569. [7, 10], [7, 10], [7, 10], [7, 10],
  36570. [7, 10], [7, 10], [7, 10], [7, 10],
  36571. [7, 10], [7, 10], [7, 10], [7, 10],
  36572. [7, 10], [7, 10], [7, 10], [7, 10],
  36573. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36574. [7, 11], [7, 11], [7, 11], [7, 11],
  36575. [7, 11], [7, 11], [7, 11], [7, 11],
  36576. [7, 11], [7, 11], [7, 11], [7, 11],
  36577. [7, 11], [7, 11], [7, 11], [7, 11],
  36578. [7, 11], [7, 11], [7, 11], [7, 11],
  36579. [7, 11], [7, 11], [7, 11], [7, 11],
  36580. [7, 11], [7, 11], [7, 11], [7, 11],
  36581. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36582. [9, 15], [9, 15], [9, 15], [9, 15],
  36583. [12, 128], // 000011001000
  36584. [12, 192], // 000011001001
  36585. [12, 26], // 000011001010
  36586. [12, 27], // 000011001011
  36587. [12, 28], // 000011001100
  36588. [12, 29], // 000011001101
  36589. [11, 19], [11, 19], // 00001100111x
  36590. [11, 20], [11, 20], // 00001101000x
  36591. [12, 34], // 000011010010
  36592. [12, 35], // 000011010011
  36593. [12, 36], // 000011010100
  36594. [12, 37], // 000011010101
  36595. [12, 38], // 000011010110
  36596. [12, 39], // 000011010111
  36597. [11, 21], [11, 21], // 00001101100x
  36598. [12, 42], // 000011011010
  36599. [12, 43], // 000011011011
  36600. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36601. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36602. [7, 12], [7, 12], [7, 12], [7, 12],
  36603. [7, 12], [7, 12], [7, 12], [7, 12],
  36604. [7, 12], [7, 12], [7, 12], [7, 12],
  36605. [7, 12], [7, 12], [7, 12], [7, 12],
  36606. [7, 12], [7, 12], [7, 12], [7, 12],
  36607. [7, 12], [7, 12], [7, 12], [7, 12],
  36608. [7, 12], [7, 12], [7, 12], [7, 12]
  36609. ];
  36610. var blackTable3 = [
  36611. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36612. [6, 9], // 000100
  36613. [6, 8], // 000101
  36614. [5, 7], [5, 7], // 00011x
  36615. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36616. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36617. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36618. [3, 1], [3, 1], [3, 1], [3, 1],
  36619. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36620. [3, 4], [3, 4], [3, 4], [3, 4],
  36621. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36622. [2, 3], [2, 3], [2, 3], [2, 3],
  36623. [2, 3], [2, 3], [2, 3], [2, 3],
  36624. [2, 3], [2, 3], [2, 3], [2, 3],
  36625. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36626. [2, 2], [2, 2], [2, 2], [2, 2],
  36627. [2, 2], [2, 2], [2, 2], [2, 2],
  36628. [2, 2], [2, 2], [2, 2], [2, 2]
  36629. ];
  36630. function CCITTFaxStream(str, maybeLength, params) {
  36631. this.str = str;
  36632. this.dict = str.dict;
  36633. params = params || Dict.empty;
  36634. this.encoding = params.get('K') || 0;
  36635. this.eoline = params.get('EndOfLine') || false;
  36636. this.byteAlign = params.get('EncodedByteAlign') || false;
  36637. this.columns = params.get('Columns') || 1728;
  36638. this.rows = params.get('Rows') || 0;
  36639. var eoblock = params.get('EndOfBlock');
  36640. if (eoblock === null || eoblock === undefined) {
  36641. eoblock = true;
  36642. }
  36643. this.eoblock = eoblock;
  36644. this.black = params.get('BlackIs1') || false;
  36645. this.codingLine = new Uint32Array(this.columns + 1);
  36646. this.refLine = new Uint32Array(this.columns + 2);
  36647. this.codingLine[0] = this.columns;
  36648. this.codingPos = 0;
  36649. this.row = 0;
  36650. this.nextLine2D = this.encoding < 0;
  36651. this.inputBits = 0;
  36652. this.inputBuf = 0;
  36653. this.outputBits = 0;
  36654. var code1;
  36655. while ((code1 = this.lookBits(12)) === 0) {
  36656. this.eatBits(1);
  36657. }
  36658. if (code1 === 1) {
  36659. this.eatBits(12);
  36660. }
  36661. if (this.encoding > 0) {
  36662. this.nextLine2D = !this.lookBits(1);
  36663. this.eatBits(1);
  36664. }
  36665. DecodeStream.call(this, maybeLength);
  36666. }
  36667. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36668. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36669. while (!this.eof) {
  36670. var c = this.lookChar();
  36671. this.ensureBuffer(this.bufferLength + 1);
  36672. this.buffer[this.bufferLength++] = c;
  36673. }
  36674. };
  36675. CCITTFaxStream.prototype.addPixels =
  36676. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36677. var codingLine = this.codingLine;
  36678. var codingPos = this.codingPos;
  36679. if (a1 > codingLine[codingPos]) {
  36680. if (a1 > this.columns) {
  36681. info('row is wrong length');
  36682. this.err = true;
  36683. a1 = this.columns;
  36684. }
  36685. if ((codingPos & 1) ^ blackPixels) {
  36686. ++codingPos;
  36687. }
  36688. codingLine[codingPos] = a1;
  36689. }
  36690. this.codingPos = codingPos;
  36691. };
  36692. CCITTFaxStream.prototype.addPixelsNeg =
  36693. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36694. var codingLine = this.codingLine;
  36695. var codingPos = this.codingPos;
  36696. if (a1 > codingLine[codingPos]) {
  36697. if (a1 > this.columns) {
  36698. info('row is wrong length');
  36699. this.err = true;
  36700. a1 = this.columns;
  36701. }
  36702. if ((codingPos & 1) ^ blackPixels) {
  36703. ++codingPos;
  36704. }
  36705. codingLine[codingPos] = a1;
  36706. } else if (a1 < codingLine[codingPos]) {
  36707. if (a1 < 0) {
  36708. info('invalid code');
  36709. this.err = true;
  36710. a1 = 0;
  36711. }
  36712. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36713. --codingPos;
  36714. }
  36715. codingLine[codingPos] = a1;
  36716. }
  36717. this.codingPos = codingPos;
  36718. };
  36719. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36720. var refLine = this.refLine;
  36721. var codingLine = this.codingLine;
  36722. var columns = this.columns;
  36723. var refPos, blackPixels, bits, i;
  36724. if (this.outputBits === 0) {
  36725. if (this.eof) {
  36726. return null;
  36727. }
  36728. this.err = false;
  36729. var code1, code2, code3;
  36730. if (this.nextLine2D) {
  36731. for (i = 0; codingLine[i] < columns; ++i) {
  36732. refLine[i] = codingLine[i];
  36733. }
  36734. refLine[i++] = columns;
  36735. refLine[i] = columns;
  36736. codingLine[0] = 0;
  36737. this.codingPos = 0;
  36738. refPos = 0;
  36739. blackPixels = 0;
  36740. while (codingLine[this.codingPos] < columns) {
  36741. code1 = this.getTwoDimCode();
  36742. switch (code1) {
  36743. case twoDimPass:
  36744. this.addPixels(refLine[refPos + 1], blackPixels);
  36745. if (refLine[refPos + 1] < columns) {
  36746. refPos += 2;
  36747. }
  36748. break;
  36749. case twoDimHoriz:
  36750. code1 = code2 = 0;
  36751. if (blackPixels) {
  36752. do {
  36753. code1 += (code3 = this.getBlackCode());
  36754. } while (code3 >= 64);
  36755. do {
  36756. code2 += (code3 = this.getWhiteCode());
  36757. } while (code3 >= 64);
  36758. } else {
  36759. do {
  36760. code1 += (code3 = this.getWhiteCode());
  36761. } while (code3 >= 64);
  36762. do {
  36763. code2 += (code3 = this.getBlackCode());
  36764. } while (code3 >= 64);
  36765. }
  36766. this.addPixels(codingLine[this.codingPos] +
  36767. code1, blackPixels);
  36768. if (codingLine[this.codingPos] < columns) {
  36769. this.addPixels(codingLine[this.codingPos] + code2,
  36770. blackPixels ^ 1);
  36771. }
  36772. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36773. refLine[refPos] < columns) {
  36774. refPos += 2;
  36775. }
  36776. break;
  36777. case twoDimVertR3:
  36778. this.addPixels(refLine[refPos] + 3, blackPixels);
  36779. blackPixels ^= 1;
  36780. if (codingLine[this.codingPos] < columns) {
  36781. ++refPos;
  36782. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36783. refLine[refPos] < columns) {
  36784. refPos += 2;
  36785. }
  36786. }
  36787. break;
  36788. case twoDimVertR2:
  36789. this.addPixels(refLine[refPos] + 2, blackPixels);
  36790. blackPixels ^= 1;
  36791. if (codingLine[this.codingPos] < columns) {
  36792. ++refPos;
  36793. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36794. refLine[refPos] < columns) {
  36795. refPos += 2;
  36796. }
  36797. }
  36798. break;
  36799. case twoDimVertR1:
  36800. this.addPixels(refLine[refPos] + 1, blackPixels);
  36801. blackPixels ^= 1;
  36802. if (codingLine[this.codingPos] < columns) {
  36803. ++refPos;
  36804. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36805. refLine[refPos] < columns) {
  36806. refPos += 2;
  36807. }
  36808. }
  36809. break;
  36810. case twoDimVert0:
  36811. this.addPixels(refLine[refPos], blackPixels);
  36812. blackPixels ^= 1;
  36813. if (codingLine[this.codingPos] < columns) {
  36814. ++refPos;
  36815. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36816. refLine[refPos] < columns) {
  36817. refPos += 2;
  36818. }
  36819. }
  36820. break;
  36821. case twoDimVertL3:
  36822. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36823. blackPixels ^= 1;
  36824. if (codingLine[this.codingPos] < columns) {
  36825. if (refPos > 0) {
  36826. --refPos;
  36827. } else {
  36828. ++refPos;
  36829. }
  36830. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36831. refLine[refPos] < columns) {
  36832. refPos += 2;
  36833. }
  36834. }
  36835. break;
  36836. case twoDimVertL2:
  36837. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36838. blackPixels ^= 1;
  36839. if (codingLine[this.codingPos] < columns) {
  36840. if (refPos > 0) {
  36841. --refPos;
  36842. } else {
  36843. ++refPos;
  36844. }
  36845. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36846. refLine[refPos] < columns) {
  36847. refPos += 2;
  36848. }
  36849. }
  36850. break;
  36851. case twoDimVertL1:
  36852. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36853. blackPixels ^= 1;
  36854. if (codingLine[this.codingPos] < columns) {
  36855. if (refPos > 0) {
  36856. --refPos;
  36857. } else {
  36858. ++refPos;
  36859. }
  36860. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36861. refLine[refPos] < columns) {
  36862. refPos += 2;
  36863. }
  36864. }
  36865. break;
  36866. case EOF:
  36867. this.addPixels(columns, 0);
  36868. this.eof = true;
  36869. break;
  36870. default:
  36871. info('bad 2d code');
  36872. this.addPixels(columns, 0);
  36873. this.err = true;
  36874. }
  36875. }
  36876. } else {
  36877. codingLine[0] = 0;
  36878. this.codingPos = 0;
  36879. blackPixels = 0;
  36880. while (codingLine[this.codingPos] < columns) {
  36881. code1 = 0;
  36882. if (blackPixels) {
  36883. do {
  36884. code1 += (code3 = this.getBlackCode());
  36885. } while (code3 >= 64);
  36886. } else {
  36887. do {
  36888. code1 += (code3 = this.getWhiteCode());
  36889. } while (code3 >= 64);
  36890. }
  36891. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36892. blackPixels ^= 1;
  36893. }
  36894. }
  36895. var gotEOL = false;
  36896. if (this.byteAlign) {
  36897. this.inputBits &= ~7;
  36898. }
  36899. if (!this.eoblock && this.row === this.rows - 1) {
  36900. this.eof = true;
  36901. } else {
  36902. code1 = this.lookBits(12);
  36903. if (this.eoline) {
  36904. while (code1 !== EOF && code1 !== 1) {
  36905. this.eatBits(1);
  36906. code1 = this.lookBits(12);
  36907. }
  36908. } else {
  36909. while (code1 === 0) {
  36910. this.eatBits(1);
  36911. code1 = this.lookBits(12);
  36912. }
  36913. }
  36914. if (code1 === 1) {
  36915. this.eatBits(12);
  36916. gotEOL = true;
  36917. } else if (code1 === EOF) {
  36918. this.eof = true;
  36919. }
  36920. }
  36921. if (!this.eof && this.encoding > 0) {
  36922. this.nextLine2D = !this.lookBits(1);
  36923. this.eatBits(1);
  36924. }
  36925. if (this.eoblock && gotEOL && this.byteAlign) {
  36926. code1 = this.lookBits(12);
  36927. if (code1 === 1) {
  36928. this.eatBits(12);
  36929. if (this.encoding > 0) {
  36930. this.lookBits(1);
  36931. this.eatBits(1);
  36932. }
  36933. if (this.encoding >= 0) {
  36934. for (i = 0; i < 4; ++i) {
  36935. code1 = this.lookBits(12);
  36936. if (code1 !== 1) {
  36937. info('bad rtc code: ' + code1);
  36938. }
  36939. this.eatBits(12);
  36940. if (this.encoding > 0) {
  36941. this.lookBits(1);
  36942. this.eatBits(1);
  36943. }
  36944. }
  36945. }
  36946. this.eof = true;
  36947. }
  36948. } else if (this.err && this.eoline) {
  36949. while (true) {
  36950. code1 = this.lookBits(13);
  36951. if (code1 === EOF) {
  36952. this.eof = true;
  36953. return null;
  36954. }
  36955. if ((code1 >> 1) === 1) {
  36956. break;
  36957. }
  36958. this.eatBits(1);
  36959. }
  36960. this.eatBits(12);
  36961. if (this.encoding > 0) {
  36962. this.eatBits(1);
  36963. this.nextLine2D = !(code1 & 1);
  36964. }
  36965. }
  36966. if (codingLine[0] > 0) {
  36967. this.outputBits = codingLine[this.codingPos = 0];
  36968. } else {
  36969. this.outputBits = codingLine[this.codingPos = 1];
  36970. }
  36971. this.row++;
  36972. }
  36973. var c;
  36974. if (this.outputBits >= 8) {
  36975. c = (this.codingPos & 1) ? 0 : 0xFF;
  36976. this.outputBits -= 8;
  36977. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36978. this.codingPos++;
  36979. this.outputBits = (codingLine[this.codingPos] -
  36980. codingLine[this.codingPos - 1]);
  36981. }
  36982. } else {
  36983. bits = 8;
  36984. c = 0;
  36985. do {
  36986. if (this.outputBits > bits) {
  36987. c <<= bits;
  36988. if (!(this.codingPos & 1)) {
  36989. c |= 0xFF >> (8 - bits);
  36990. }
  36991. this.outputBits -= bits;
  36992. bits = 0;
  36993. } else {
  36994. c <<= this.outputBits;
  36995. if (!(this.codingPos & 1)) {
  36996. c |= 0xFF >> (8 - this.outputBits);
  36997. }
  36998. bits -= this.outputBits;
  36999. this.outputBits = 0;
  37000. if (codingLine[this.codingPos] < columns) {
  37001. this.codingPos++;
  37002. this.outputBits = (codingLine[this.codingPos] -
  37003. codingLine[this.codingPos - 1]);
  37004. } else if (bits > 0) {
  37005. c <<= bits;
  37006. bits = 0;
  37007. }
  37008. }
  37009. } while (bits);
  37010. }
  37011. if (this.black) {
  37012. c ^= 0xFF;
  37013. }
  37014. return c;
  37015. };
  37016. // This functions returns the code found from the table.
  37017. // The start and end parameters set the boundaries for searching the table.
  37018. // The limit parameter is optional. Function returns an array with three
  37019. // values. The first array element indicates whether a valid code is being
  37020. // returned. The second array element is the actual code. The third array
  37021. // element indicates whether EOF was reached.
  37022. CCITTFaxStream.prototype.findTableCode =
  37023. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37024. var limitValue = limit || 0;
  37025. for (var i = start; i <= end; ++i) {
  37026. var code = this.lookBits(i);
  37027. if (code === EOF) {
  37028. return [true, 1, false];
  37029. }
  37030. if (i < end) {
  37031. code <<= end - i;
  37032. }
  37033. if (!limitValue || code >= limitValue) {
  37034. var p = table[code - limitValue];
  37035. if (p[0] === i) {
  37036. this.eatBits(i);
  37037. return [true, p[1], true];
  37038. }
  37039. }
  37040. }
  37041. return [false, 0, false];
  37042. };
  37043. CCITTFaxStream.prototype.getTwoDimCode =
  37044. function ccittFaxStreamGetTwoDimCode() {
  37045. var code = 0;
  37046. var p;
  37047. if (this.eoblock) {
  37048. code = this.lookBits(7);
  37049. p = twoDimTable[code];
  37050. if (p && p[0] > 0) {
  37051. this.eatBits(p[0]);
  37052. return p[1];
  37053. }
  37054. } else {
  37055. var result = this.findTableCode(1, 7, twoDimTable);
  37056. if (result[0] && result[2]) {
  37057. return result[1];
  37058. }
  37059. }
  37060. info('Bad two dim code');
  37061. return EOF;
  37062. };
  37063. CCITTFaxStream.prototype.getWhiteCode =
  37064. function ccittFaxStreamGetWhiteCode() {
  37065. var code = 0;
  37066. var p;
  37067. if (this.eoblock) {
  37068. code = this.lookBits(12);
  37069. if (code === EOF) {
  37070. return 1;
  37071. }
  37072. if ((code >> 5) === 0) {
  37073. p = whiteTable1[code];
  37074. } else {
  37075. p = whiteTable2[code >> 3];
  37076. }
  37077. if (p[0] > 0) {
  37078. this.eatBits(p[0]);
  37079. return p[1];
  37080. }
  37081. } else {
  37082. var result = this.findTableCode(1, 9, whiteTable2);
  37083. if (result[0]) {
  37084. return result[1];
  37085. }
  37086. result = this.findTableCode(11, 12, whiteTable1);
  37087. if (result[0]) {
  37088. return result[1];
  37089. }
  37090. }
  37091. info('bad white code');
  37092. this.eatBits(1);
  37093. return 1;
  37094. };
  37095. CCITTFaxStream.prototype.getBlackCode =
  37096. function ccittFaxStreamGetBlackCode() {
  37097. var code, p;
  37098. if (this.eoblock) {
  37099. code = this.lookBits(13);
  37100. if (code === EOF) {
  37101. return 1;
  37102. }
  37103. if ((code >> 7) === 0) {
  37104. p = blackTable1[code];
  37105. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37106. p = blackTable2[(code >> 1) - 64];
  37107. } else {
  37108. p = blackTable3[code >> 7];
  37109. }
  37110. if (p[0] > 0) {
  37111. this.eatBits(p[0]);
  37112. return p[1];
  37113. }
  37114. } else {
  37115. var result = this.findTableCode(2, 6, blackTable3);
  37116. if (result[0]) {
  37117. return result[1];
  37118. }
  37119. result = this.findTableCode(7, 12, blackTable2, 64);
  37120. if (result[0]) {
  37121. return result[1];
  37122. }
  37123. result = this.findTableCode(10, 13, blackTable1);
  37124. if (result[0]) {
  37125. return result[1];
  37126. }
  37127. }
  37128. info('bad black code');
  37129. this.eatBits(1);
  37130. return 1;
  37131. };
  37132. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37133. var c;
  37134. while (this.inputBits < n) {
  37135. if ((c = this.str.getByte()) === -1) {
  37136. if (this.inputBits === 0) {
  37137. return EOF;
  37138. }
  37139. return ((this.inputBuf << (n - this.inputBits)) &
  37140. (0xFFFF >> (16 - n)));
  37141. }
  37142. this.inputBuf = (this.inputBuf << 8) + c;
  37143. this.inputBits += 8;
  37144. }
  37145. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37146. };
  37147. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37148. if ((this.inputBits -= n) < 0) {
  37149. this.inputBits = 0;
  37150. }
  37151. };
  37152. return CCITTFaxStream;
  37153. })();
  37154. var LZWStream = (function LZWStreamClosure() {
  37155. function LZWStream(str, maybeLength, earlyChange) {
  37156. this.str = str;
  37157. this.dict = str.dict;
  37158. this.cachedData = 0;
  37159. this.bitsCached = 0;
  37160. var maxLzwDictionarySize = 4096;
  37161. var lzwState = {
  37162. earlyChange: earlyChange,
  37163. codeLength: 9,
  37164. nextCode: 258,
  37165. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37166. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37167. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37168. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37169. currentSequenceLength: 0
  37170. };
  37171. for (var i = 0; i < 256; ++i) {
  37172. lzwState.dictionaryValues[i] = i;
  37173. lzwState.dictionaryLengths[i] = 1;
  37174. }
  37175. this.lzwState = lzwState;
  37176. DecodeStream.call(this, maybeLength);
  37177. }
  37178. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37179. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37180. var bitsCached = this.bitsCached;
  37181. var cachedData = this.cachedData;
  37182. while (bitsCached < n) {
  37183. var c = this.str.getByte();
  37184. if (c === -1) {
  37185. this.eof = true;
  37186. return null;
  37187. }
  37188. cachedData = (cachedData << 8) | c;
  37189. bitsCached += 8;
  37190. }
  37191. this.bitsCached = (bitsCached -= n);
  37192. this.cachedData = cachedData;
  37193. this.lastCode = null;
  37194. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37195. };
  37196. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37197. var blockSize = 512;
  37198. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37199. var i, j, q;
  37200. var lzwState = this.lzwState;
  37201. if (!lzwState) {
  37202. return; // eof was found
  37203. }
  37204. var earlyChange = lzwState.earlyChange;
  37205. var nextCode = lzwState.nextCode;
  37206. var dictionaryValues = lzwState.dictionaryValues;
  37207. var dictionaryLengths = lzwState.dictionaryLengths;
  37208. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37209. var codeLength = lzwState.codeLength;
  37210. var prevCode = lzwState.prevCode;
  37211. var currentSequence = lzwState.currentSequence;
  37212. var currentSequenceLength = lzwState.currentSequenceLength;
  37213. var decodedLength = 0;
  37214. var currentBufferLength = this.bufferLength;
  37215. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37216. for (i = 0; i < blockSize; i++) {
  37217. var code = this.readBits(codeLength);
  37218. var hasPrev = currentSequenceLength > 0;
  37219. if (code < 256) {
  37220. currentSequence[0] = code;
  37221. currentSequenceLength = 1;
  37222. } else if (code >= 258) {
  37223. if (code < nextCode) {
  37224. currentSequenceLength = dictionaryLengths[code];
  37225. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37226. currentSequence[j] = dictionaryValues[q];
  37227. q = dictionaryPrevCodes[q];
  37228. }
  37229. } else {
  37230. currentSequence[currentSequenceLength++] = currentSequence[0];
  37231. }
  37232. } else if (code === 256) {
  37233. codeLength = 9;
  37234. nextCode = 258;
  37235. currentSequenceLength = 0;
  37236. continue;
  37237. } else {
  37238. this.eof = true;
  37239. delete this.lzwState;
  37240. break;
  37241. }
  37242. if (hasPrev) {
  37243. dictionaryPrevCodes[nextCode] = prevCode;
  37244. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37245. dictionaryValues[nextCode] = currentSequence[0];
  37246. nextCode++;
  37247. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37248. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37249. 0.6931471805599453 + 1, 12) | 0;
  37250. }
  37251. prevCode = code;
  37252. decodedLength += currentSequenceLength;
  37253. if (estimatedDecodedSize < decodedLength) {
  37254. do {
  37255. estimatedDecodedSize += decodedSizeDelta;
  37256. } while (estimatedDecodedSize < decodedLength);
  37257. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37258. }
  37259. for (j = 0; j < currentSequenceLength; j++) {
  37260. buffer[currentBufferLength++] = currentSequence[j];
  37261. }
  37262. }
  37263. lzwState.nextCode = nextCode;
  37264. lzwState.codeLength = codeLength;
  37265. lzwState.prevCode = prevCode;
  37266. lzwState.currentSequenceLength = currentSequenceLength;
  37267. this.bufferLength = currentBufferLength;
  37268. };
  37269. return LZWStream;
  37270. })();
  37271. var NullStream = (function NullStreamClosure() {
  37272. function NullStream() {
  37273. Stream.call(this, new Uint8Array(0));
  37274. }
  37275. NullStream.prototype = Stream.prototype;
  37276. return NullStream;
  37277. })();
  37278. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37279. setup: function wphSetup(handler) {
  37280. var pdfManager;
  37281. function loadDocument(recoveryMode) {
  37282. var loadDocumentCapability = createPromiseCapability();
  37283. var parseSuccess = function parseSuccess() {
  37284. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37285. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37286. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37287. Promise.all([numPagesPromise, fingerprintPromise,
  37288. encryptedPromise]).then(function onDocReady(results) {
  37289. var doc = {
  37290. numPages: results[0],
  37291. fingerprint: results[1],
  37292. encrypted: !!results[2],
  37293. };
  37294. loadDocumentCapability.resolve(doc);
  37295. },
  37296. parseFailure);
  37297. };
  37298. var parseFailure = function parseFailure(e) {
  37299. loadDocumentCapability.reject(e);
  37300. };
  37301. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37302. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37303. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37304. parseSuccess, parseFailure);
  37305. }, parseFailure);
  37306. }, parseFailure);
  37307. return loadDocumentCapability.promise;
  37308. }
  37309. function getPdfManager(data) {
  37310. var pdfManagerCapability = createPromiseCapability();
  37311. var source = data.source;
  37312. var disableRange = data.disableRange;
  37313. if (source.data) {
  37314. try {
  37315. pdfManager = new LocalPdfManager(source.data, source.password);
  37316. pdfManagerCapability.resolve();
  37317. } catch (ex) {
  37318. pdfManagerCapability.reject(ex);
  37319. }
  37320. return pdfManagerCapability.promise;
  37321. } else if (source.chunkedViewerLoading) {
  37322. try {
  37323. pdfManager = new NetworkPdfManager(source, handler);
  37324. pdfManagerCapability.resolve();
  37325. } catch (ex) {
  37326. pdfManagerCapability.reject(ex);
  37327. }
  37328. return pdfManagerCapability.promise;
  37329. }
  37330. var networkManager = new NetworkManager(source.url, {
  37331. httpHeaders: source.httpHeaders,
  37332. withCredentials: source.withCredentials
  37333. });
  37334. var cachedChunks = [];
  37335. var fullRequestXhrId = networkManager.requestFull({
  37336. onHeadersReceived: function onHeadersReceived() {
  37337. if (disableRange) {
  37338. return;
  37339. }
  37340. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37341. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37342. return;
  37343. }
  37344. var contentEncoding =
  37345. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37346. if (contentEncoding !== 'identity') {
  37347. return;
  37348. }
  37349. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37350. length = parseInt(length, 10);
  37351. if (!isInt(length)) {
  37352. return;
  37353. }
  37354. source.length = length;
  37355. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37356. // The file size is smaller than the size of two chunks, so it does
  37357. // not make any sense to abort the request and retry with a range
  37358. // request.
  37359. return;
  37360. }
  37361. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37362. // We can continue fetching when progressive loading is enabled,
  37363. // and we don't need the autoFetch feature.
  37364. source.disableAutoFetch = true;
  37365. } else {
  37366. // NOTE: by cancelling the full request, and then issuing range
  37367. // requests, there will be an issue for sites where you can only
  37368. // request the pdf once. However, if this is the case, then the
  37369. // server should not be returning that it can support range
  37370. // requests.
  37371. networkManager.abortRequest(fullRequestXhrId);
  37372. }
  37373. try {
  37374. pdfManager = new NetworkPdfManager(source, handler);
  37375. pdfManagerCapability.resolve(pdfManager);
  37376. } catch (ex) {
  37377. pdfManagerCapability.reject(ex);
  37378. }
  37379. },
  37380. onProgressiveData: source.disableStream ? null :
  37381. function onProgressiveData(chunk) {
  37382. if (!pdfManager) {
  37383. cachedChunks.push(chunk);
  37384. return;
  37385. }
  37386. pdfManager.sendProgressiveData(chunk);
  37387. },
  37388. onDone: function onDone(args) {
  37389. if (pdfManager) {
  37390. return; // already processed
  37391. }
  37392. var pdfFile;
  37393. if (args === null) {
  37394. // TODO add some streaming manager, e.g. for unknown length files.
  37395. // The data was returned in the onProgressiveData, combining...
  37396. var pdfFileLength = 0, pos = 0;
  37397. cachedChunks.forEach(function (chunk) {
  37398. pdfFileLength += chunk.byteLength;
  37399. });
  37400. if (source.length && pdfFileLength !== source.length) {
  37401. warn('reported HTTP length is different from actual');
  37402. }
  37403. var pdfFileArray = new Uint8Array(pdfFileLength);
  37404. cachedChunks.forEach(function (chunk) {
  37405. pdfFileArray.set(new Uint8Array(chunk), pos);
  37406. pos += chunk.byteLength;
  37407. });
  37408. pdfFile = pdfFileArray.buffer;
  37409. } else {
  37410. pdfFile = args.chunk;
  37411. }
  37412. // the data is array, instantiating directly from it
  37413. try {
  37414. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37415. pdfManagerCapability.resolve();
  37416. } catch (ex) {
  37417. pdfManagerCapability.reject(ex);
  37418. }
  37419. },
  37420. onError: function onError(status) {
  37421. var exception;
  37422. if (status === 404) {
  37423. exception = new MissingPDFException('Missing PDF "' +
  37424. source.url + '".');
  37425. handler.send('MissingPDF', exception);
  37426. } else {
  37427. exception = new UnexpectedResponseException(
  37428. 'Unexpected server response (' + status +
  37429. ') while retrieving PDF "' + source.url + '".', status);
  37430. handler.send('UnexpectedResponse', exception);
  37431. }
  37432. },
  37433. onProgress: function onProgress(evt) {
  37434. handler.send('DocProgress', {
  37435. loaded: evt.loaded,
  37436. total: evt.lengthComputable ? evt.total : source.length
  37437. });
  37438. }
  37439. });
  37440. return pdfManagerCapability.promise;
  37441. }
  37442. handler.on('test', function wphSetupTest(data) {
  37443. // check if Uint8Array can be sent to worker
  37444. if (!(data instanceof Uint8Array)) {
  37445. handler.send('test', false);
  37446. return;
  37447. }
  37448. // making sure postMessage transfers are working
  37449. var supportTransfers = data[0] === 255;
  37450. handler.postMessageTransfers = supportTransfers;
  37451. // check if the response property is supported by xhr
  37452. var xhr = new XMLHttpRequest();
  37453. var responseExists = 'response' in xhr;
  37454. // check if the property is actually implemented
  37455. try {
  37456. var dummy = xhr.responseType;
  37457. } catch (e) {
  37458. responseExists = false;
  37459. }
  37460. if (!responseExists) {
  37461. handler.send('test', false);
  37462. return;
  37463. }
  37464. handler.send('test', {
  37465. supportTypedArray: true,
  37466. supportTransfers: supportTransfers
  37467. });
  37468. });
  37469. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37470. var onSuccess = function(doc) {
  37471. handler.send('GetDoc', { pdfInfo: doc });
  37472. };
  37473. var onFailure = function(e) {
  37474. if (e instanceof PasswordException) {
  37475. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37476. handler.send('NeedPassword', e);
  37477. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37478. handler.send('IncorrectPassword', e);
  37479. }
  37480. } else if (e instanceof InvalidPDFException) {
  37481. handler.send('InvalidPDF', e);
  37482. } else if (e instanceof MissingPDFException) {
  37483. handler.send('MissingPDF', e);
  37484. } else if (e instanceof UnexpectedResponseException) {
  37485. handler.send('UnexpectedResponse', e);
  37486. } else {
  37487. handler.send('UnknownError',
  37488. new UnknownErrorException(e.message, e.toString()));
  37489. }
  37490. };
  37491. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37492. -1 : data.maxImageSize;
  37493. PDFJS.disableFontFace = data.disableFontFace;
  37494. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37495. PDFJS.verbosity = data.verbosity;
  37496. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37497. null : data.cMapUrl;
  37498. PDFJS.cMapPacked = data.cMapPacked === true;
  37499. getPdfManager(data).then(function () {
  37500. handler.send('PDFManagerReady', null);
  37501. pdfManager.onLoadedStream().then(function(stream) {
  37502. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37503. });
  37504. }).then(function pdfManagerReady() {
  37505. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37506. // Try again with recoveryMode == true
  37507. if (!(ex instanceof XRefParseException)) {
  37508. if (ex instanceof PasswordException) {
  37509. // after password exception prepare to receive a new password
  37510. // to repeat loading
  37511. pdfManager.passwordChanged().then(pdfManagerReady);
  37512. }
  37513. onFailure(ex);
  37514. return;
  37515. }
  37516. pdfManager.requestLoadedStream();
  37517. pdfManager.onLoadedStream().then(function() {
  37518. loadDocument(true).then(onSuccess, onFailure);
  37519. });
  37520. }, onFailure);
  37521. }, onFailure);
  37522. });
  37523. handler.on('GetPage', function wphSetupGetPage(data) {
  37524. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37525. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37526. var refPromise = pdfManager.ensure(page, 'ref');
  37527. var viewPromise = pdfManager.ensure(page, 'view');
  37528. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37529. function(results) {
  37530. return {
  37531. rotate: results[0],
  37532. ref: results[1],
  37533. view: results[2]
  37534. };
  37535. });
  37536. });
  37537. });
  37538. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37539. var ref = new Ref(data.ref.num, data.ref.gen);
  37540. var catalog = pdfManager.pdfDocument.catalog;
  37541. return catalog.getPageIndex(ref);
  37542. });
  37543. handler.on('GetDestinations',
  37544. function wphSetupGetDestinations(data) {
  37545. return pdfManager.ensureCatalog('destinations');
  37546. }
  37547. );
  37548. handler.on('GetDestination',
  37549. function wphSetupGetDestination(data) {
  37550. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37551. }
  37552. );
  37553. handler.on('GetAttachments',
  37554. function wphSetupGetAttachments(data) {
  37555. return pdfManager.ensureCatalog('attachments');
  37556. }
  37557. );
  37558. handler.on('GetJavaScript',
  37559. function wphSetupGetJavaScript(data) {
  37560. return pdfManager.ensureCatalog('javaScript');
  37561. }
  37562. );
  37563. handler.on('GetOutline',
  37564. function wphSetupGetOutline(data) {
  37565. return pdfManager.ensureCatalog('documentOutline');
  37566. }
  37567. );
  37568. handler.on('GetMetadata',
  37569. function wphSetupGetMetadata(data) {
  37570. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37571. pdfManager.ensureCatalog('metadata')]);
  37572. }
  37573. );
  37574. handler.on('GetData', function wphSetupGetData(data) {
  37575. pdfManager.requestLoadedStream();
  37576. return pdfManager.onLoadedStream().then(function(stream) {
  37577. return stream.bytes;
  37578. });
  37579. });
  37580. handler.on('GetStats',
  37581. function wphSetupGetStats(data) {
  37582. return pdfManager.pdfDocument.xref.stats;
  37583. }
  37584. );
  37585. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37586. pdfManager.updatePassword(data);
  37587. });
  37588. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37589. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37590. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37591. });
  37592. });
  37593. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37594. pdfManager.getPage(data.pageIndex).then(function(page) {
  37595. var pageNum = data.pageIndex + 1;
  37596. var start = Date.now();
  37597. // Pre compile the pdf page and fetch the fonts/images.
  37598. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37599. info('page=' + pageNum + ' - getOperatorList: time=' +
  37600. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37601. }, function(e) {
  37602. var minimumStackMessage =
  37603. 'worker.js: while trying to getPage() and getOperatorList()';
  37604. var wrappedException;
  37605. // Turn the error into an obj that can be serialized
  37606. if (typeof e === 'string') {
  37607. wrappedException = {
  37608. message: e,
  37609. stack: minimumStackMessage
  37610. };
  37611. } else if (typeof e === 'object') {
  37612. wrappedException = {
  37613. message: e.message || e.toString(),
  37614. stack: e.stack || minimumStackMessage
  37615. };
  37616. } else {
  37617. wrappedException = {
  37618. message: 'Unknown exception type: ' + (typeof e),
  37619. stack: minimumStackMessage
  37620. };
  37621. }
  37622. handler.send('PageError', {
  37623. pageNum: pageNum,
  37624. error: wrappedException,
  37625. intent: data.intent
  37626. });
  37627. });
  37628. });
  37629. }, this);
  37630. handler.on('GetTextContent', function wphExtractText(data) {
  37631. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37632. var pageNum = data.pageIndex + 1;
  37633. var start = Date.now();
  37634. return page.extractTextContent().then(function(textContent) {
  37635. info('text indexing: page=' + pageNum + ' - time=' +
  37636. (Date.now() - start) + 'ms');
  37637. return textContent;
  37638. });
  37639. });
  37640. });
  37641. handler.on('Cleanup', function wphCleanup(data) {
  37642. return pdfManager.cleanup();
  37643. });
  37644. handler.on('Terminate', function wphTerminate(data) {
  37645. pdfManager.terminate();
  37646. });
  37647. }
  37648. };
  37649. var consoleTimer = {};
  37650. var workerConsole = {
  37651. log: function log() {
  37652. var args = Array.prototype.slice.call(arguments);
  37653. globalScope.postMessage({
  37654. action: 'console_log',
  37655. data: args
  37656. });
  37657. },
  37658. error: function error() {
  37659. var args = Array.prototype.slice.call(arguments);
  37660. globalScope.postMessage({
  37661. action: 'console_error',
  37662. data: args
  37663. });
  37664. throw 'pdf.js execution error';
  37665. },
  37666. time: function time(name) {
  37667. consoleTimer[name] = Date.now();
  37668. },
  37669. timeEnd: function timeEnd(name) {
  37670. var time = consoleTimer[name];
  37671. if (!time) {
  37672. error('Unknown timer name ' + name);
  37673. }
  37674. this.log('Timer:', name, Date.now() - time);
  37675. }
  37676. };
  37677. // Worker thread?
  37678. if (typeof window === 'undefined') {
  37679. if (!('console' in globalScope)) {
  37680. globalScope.console = workerConsole;
  37681. }
  37682. // Listen for unsupported features so we can pass them on to the main thread.
  37683. PDFJS.UnsupportedManager.listen(function (msg) {
  37684. globalScope.postMessage({
  37685. action: '_unsupported_feature',
  37686. data: msg
  37687. });
  37688. });
  37689. var handler = new MessageHandler('worker_processor', this);
  37690. WorkerMessageHandler.setup(handler);
  37691. }
  37692. /* This class implements the QM Coder decoding as defined in
  37693. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37694. * Annex C.3 Arithmetic decoding procedure
  37695. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37696. *
  37697. * The arithmetic decoder is used in conjunction with context models to decode
  37698. * JPEG2000 and JBIG2 streams.
  37699. */
  37700. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37701. // Table C-2
  37702. var QeTable = [
  37703. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37704. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37705. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37706. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37707. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37708. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37709. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37710. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37711. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37712. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37713. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37714. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37715. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37716. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37717. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37718. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37719. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37720. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37721. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37722. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37723. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37724. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37725. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37726. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37727. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37728. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37729. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37730. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37731. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37732. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37733. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37734. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37735. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37736. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37737. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37738. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37739. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37740. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37741. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37742. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37743. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37744. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37745. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37746. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37747. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37748. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37749. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37750. ];
  37751. // C.3.5 Initialisation of the decoder (INITDEC)
  37752. function ArithmeticDecoder(data, start, end) {
  37753. this.data = data;
  37754. this.bp = start;
  37755. this.dataEnd = end;
  37756. this.chigh = data[start];
  37757. this.clow = 0;
  37758. this.byteIn();
  37759. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37760. this.clow = (this.clow << 7) & 0xFFFF;
  37761. this.ct -= 7;
  37762. this.a = 0x8000;
  37763. }
  37764. ArithmeticDecoder.prototype = {
  37765. // C.3.4 Compressed data input (BYTEIN)
  37766. byteIn: function ArithmeticDecoder_byteIn() {
  37767. var data = this.data;
  37768. var bp = this.bp;
  37769. if (data[bp] === 0xFF) {
  37770. var b1 = data[bp + 1];
  37771. if (b1 > 0x8F) {
  37772. this.clow += 0xFF00;
  37773. this.ct = 8;
  37774. } else {
  37775. bp++;
  37776. this.clow += (data[bp] << 9);
  37777. this.ct = 7;
  37778. this.bp = bp;
  37779. }
  37780. } else {
  37781. bp++;
  37782. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37783. this.ct = 8;
  37784. this.bp = bp;
  37785. }
  37786. if (this.clow > 0xFFFF) {
  37787. this.chigh += (this.clow >> 16);
  37788. this.clow &= 0xFFFF;
  37789. }
  37790. },
  37791. // C.3.2 Decoding a decision (DECODE)
  37792. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37793. // contexts are packed into 1 byte:
  37794. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37795. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37796. var qeTableIcx = QeTable[cx_index];
  37797. var qeIcx = qeTableIcx.qe;
  37798. var d;
  37799. var a = this.a - qeIcx;
  37800. if (this.chigh < qeIcx) {
  37801. // exchangeLps
  37802. if (a < qeIcx) {
  37803. a = qeIcx;
  37804. d = cx_mps;
  37805. cx_index = qeTableIcx.nmps;
  37806. } else {
  37807. a = qeIcx;
  37808. d = 1 ^ cx_mps;
  37809. if (qeTableIcx.switchFlag === 1) {
  37810. cx_mps = d;
  37811. }
  37812. cx_index = qeTableIcx.nlps;
  37813. }
  37814. } else {
  37815. this.chigh -= qeIcx;
  37816. if ((a & 0x8000) !== 0) {
  37817. this.a = a;
  37818. return cx_mps;
  37819. }
  37820. // exchangeMps
  37821. if (a < qeIcx) {
  37822. d = 1 ^ cx_mps;
  37823. if (qeTableIcx.switchFlag === 1) {
  37824. cx_mps = d;
  37825. }
  37826. cx_index = qeTableIcx.nlps;
  37827. } else {
  37828. d = cx_mps;
  37829. cx_index = qeTableIcx.nmps;
  37830. }
  37831. }
  37832. // C.3.3 renormD;
  37833. do {
  37834. if (this.ct === 0) {
  37835. this.byteIn();
  37836. }
  37837. a <<= 1;
  37838. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37839. this.clow = (this.clow << 1) & 0xFFFF;
  37840. this.ct--;
  37841. } while ((a & 0x8000) === 0);
  37842. this.a = a;
  37843. contexts[pos] = cx_index << 1 | cx_mps;
  37844. return d;
  37845. }
  37846. };
  37847. return ArithmeticDecoder;
  37848. })();
  37849. var JpegImage = (function jpegImage() {
  37850. var dctZigZag = new Uint8Array([
  37851. 0,
  37852. 1, 8,
  37853. 16, 9, 2,
  37854. 3, 10, 17, 24,
  37855. 32, 25, 18, 11, 4,
  37856. 5, 12, 19, 26, 33, 40,
  37857. 48, 41, 34, 27, 20, 13, 6,
  37858. 7, 14, 21, 28, 35, 42, 49, 56,
  37859. 57, 50, 43, 36, 29, 22, 15,
  37860. 23, 30, 37, 44, 51, 58,
  37861. 59, 52, 45, 38, 31,
  37862. 39, 46, 53, 60,
  37863. 61, 54, 47,
  37864. 55, 62,
  37865. 63
  37866. ]);
  37867. var dctCos1 = 4017; // cos(pi/16)
  37868. var dctSin1 = 799; // sin(pi/16)
  37869. var dctCos3 = 3406; // cos(3*pi/16)
  37870. var dctSin3 = 2276; // sin(3*pi/16)
  37871. var dctCos6 = 1567; // cos(6*pi/16)
  37872. var dctSin6 = 3784; // sin(6*pi/16)
  37873. var dctSqrt2 = 5793; // sqrt(2)
  37874. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37875. function constructor() {
  37876. }
  37877. function buildHuffmanTable(codeLengths, values) {
  37878. var k = 0, code = [], i, j, length = 16;
  37879. while (length > 0 && !codeLengths[length - 1]) {
  37880. length--;
  37881. }
  37882. code.push({children: [], index: 0});
  37883. var p = code[0], q;
  37884. for (i = 0; i < length; i++) {
  37885. for (j = 0; j < codeLengths[i]; j++) {
  37886. p = code.pop();
  37887. p.children[p.index] = values[k];
  37888. while (p.index > 0) {
  37889. p = code.pop();
  37890. }
  37891. p.index++;
  37892. code.push(p);
  37893. while (code.length <= i) {
  37894. code.push(q = {children: [], index: 0});
  37895. p.children[p.index] = q.children;
  37896. p = q;
  37897. }
  37898. k++;
  37899. }
  37900. if (i + 1 < length) {
  37901. // p here points to last code
  37902. code.push(q = {children: [], index: 0});
  37903. p.children[p.index] = q.children;
  37904. p = q;
  37905. }
  37906. }
  37907. return code[0].children;
  37908. }
  37909. function getBlockBufferOffset(component, row, col) {
  37910. return 64 * ((component.blocksPerLine + 1) * row + col);
  37911. }
  37912. function decodeScan(data, offset, frame, components, resetInterval,
  37913. spectralStart, spectralEnd, successivePrev, successive) {
  37914. var precision = frame.precision;
  37915. var samplesPerLine = frame.samplesPerLine;
  37916. var scanLines = frame.scanLines;
  37917. var mcusPerLine = frame.mcusPerLine;
  37918. var progressive = frame.progressive;
  37919. var maxH = frame.maxH, maxV = frame.maxV;
  37920. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37921. function readBit() {
  37922. if (bitsCount > 0) {
  37923. bitsCount--;
  37924. return (bitsData >> bitsCount) & 1;
  37925. }
  37926. bitsData = data[offset++];
  37927. if (bitsData === 0xFF) {
  37928. var nextByte = data[offset++];
  37929. if (nextByte) {
  37930. throw 'unexpected marker: ' +
  37931. ((bitsData << 8) | nextByte).toString(16);
  37932. }
  37933. // unstuff 0
  37934. }
  37935. bitsCount = 7;
  37936. return bitsData >>> 7;
  37937. }
  37938. function decodeHuffman(tree) {
  37939. var node = tree;
  37940. while (true) {
  37941. node = node[readBit()];
  37942. if (typeof node === 'number') {
  37943. return node;
  37944. }
  37945. if (typeof node !== 'object') {
  37946. throw 'invalid huffman sequence';
  37947. }
  37948. }
  37949. }
  37950. function receive(length) {
  37951. var n = 0;
  37952. while (length > 0) {
  37953. n = (n << 1) | readBit();
  37954. length--;
  37955. }
  37956. return n;
  37957. }
  37958. function receiveAndExtend(length) {
  37959. if (length === 1) {
  37960. return readBit() === 1 ? 1 : -1;
  37961. }
  37962. var n = receive(length);
  37963. if (n >= 1 << (length - 1)) {
  37964. return n;
  37965. }
  37966. return n + (-1 << length) + 1;
  37967. }
  37968. function decodeBaseline(component, offset) {
  37969. var t = decodeHuffman(component.huffmanTableDC);
  37970. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37971. component.blockData[offset] = (component.pred += diff);
  37972. var k = 1;
  37973. while (k < 64) {
  37974. var rs = decodeHuffman(component.huffmanTableAC);
  37975. var s = rs & 15, r = rs >> 4;
  37976. if (s === 0) {
  37977. if (r < 15) {
  37978. break;
  37979. }
  37980. k += 16;
  37981. continue;
  37982. }
  37983. k += r;
  37984. var z = dctZigZag[k];
  37985. component.blockData[offset + z] = receiveAndExtend(s);
  37986. k++;
  37987. }
  37988. }
  37989. function decodeDCFirst(component, offset) {
  37990. var t = decodeHuffman(component.huffmanTableDC);
  37991. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37992. component.blockData[offset] = (component.pred += diff);
  37993. }
  37994. function decodeDCSuccessive(component, offset) {
  37995. component.blockData[offset] |= readBit() << successive;
  37996. }
  37997. var eobrun = 0;
  37998. function decodeACFirst(component, offset) {
  37999. if (eobrun > 0) {
  38000. eobrun--;
  38001. return;
  38002. }
  38003. var k = spectralStart, e = spectralEnd;
  38004. while (k <= e) {
  38005. var rs = decodeHuffman(component.huffmanTableAC);
  38006. var s = rs & 15, r = rs >> 4;
  38007. if (s === 0) {
  38008. if (r < 15) {
  38009. eobrun = receive(r) + (1 << r) - 1;
  38010. break;
  38011. }
  38012. k += 16;
  38013. continue;
  38014. }
  38015. k += r;
  38016. var z = dctZigZag[k];
  38017. component.blockData[offset + z] =
  38018. receiveAndExtend(s) * (1 << successive);
  38019. k++;
  38020. }
  38021. }
  38022. var successiveACState = 0, successiveACNextValue;
  38023. function decodeACSuccessive(component, offset) {
  38024. var k = spectralStart;
  38025. var e = spectralEnd;
  38026. var r = 0;
  38027. var s;
  38028. var rs;
  38029. while (k <= e) {
  38030. var z = dctZigZag[k];
  38031. switch (successiveACState) {
  38032. case 0: // initial state
  38033. rs = decodeHuffman(component.huffmanTableAC);
  38034. s = rs & 15;
  38035. r = rs >> 4;
  38036. if (s === 0) {
  38037. if (r < 15) {
  38038. eobrun = receive(r) + (1 << r);
  38039. successiveACState = 4;
  38040. } else {
  38041. r = 16;
  38042. successiveACState = 1;
  38043. }
  38044. } else {
  38045. if (s !== 1) {
  38046. throw 'invalid ACn encoding';
  38047. }
  38048. successiveACNextValue = receiveAndExtend(s);
  38049. successiveACState = r ? 2 : 3;
  38050. }
  38051. continue;
  38052. case 1: // skipping r zero items
  38053. case 2:
  38054. if (component.blockData[offset + z]) {
  38055. component.blockData[offset + z] += (readBit() << successive);
  38056. } else {
  38057. r--;
  38058. if (r === 0) {
  38059. successiveACState = successiveACState === 2 ? 3 : 0;
  38060. }
  38061. }
  38062. break;
  38063. case 3: // set value for a zero item
  38064. if (component.blockData[offset + z]) {
  38065. component.blockData[offset + z] += (readBit() << successive);
  38066. } else {
  38067. component.blockData[offset + z] =
  38068. successiveACNextValue << successive;
  38069. successiveACState = 0;
  38070. }
  38071. break;
  38072. case 4: // eob
  38073. if (component.blockData[offset + z]) {
  38074. component.blockData[offset + z] += (readBit() << successive);
  38075. }
  38076. break;
  38077. }
  38078. k++;
  38079. }
  38080. if (successiveACState === 4) {
  38081. eobrun--;
  38082. if (eobrun === 0) {
  38083. successiveACState = 0;
  38084. }
  38085. }
  38086. }
  38087. function decodeMcu(component, decode, mcu, row, col) {
  38088. var mcuRow = (mcu / mcusPerLine) | 0;
  38089. var mcuCol = mcu % mcusPerLine;
  38090. var blockRow = mcuRow * component.v + row;
  38091. var blockCol = mcuCol * component.h + col;
  38092. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38093. decode(component, offset);
  38094. }
  38095. function decodeBlock(component, decode, mcu) {
  38096. var blockRow = (mcu / component.blocksPerLine) | 0;
  38097. var blockCol = mcu % component.blocksPerLine;
  38098. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38099. decode(component, offset);
  38100. }
  38101. var componentsLength = components.length;
  38102. var component, i, j, k, n;
  38103. var decodeFn;
  38104. if (progressive) {
  38105. if (spectralStart === 0) {
  38106. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38107. } else {
  38108. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38109. }
  38110. } else {
  38111. decodeFn = decodeBaseline;
  38112. }
  38113. var mcu = 0, marker;
  38114. var mcuExpected;
  38115. if (componentsLength === 1) {
  38116. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38117. } else {
  38118. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38119. }
  38120. if (!resetInterval) {
  38121. resetInterval = mcuExpected;
  38122. }
  38123. var h, v;
  38124. while (mcu < mcuExpected) {
  38125. // reset interval stuff
  38126. for (i = 0; i < componentsLength; i++) {
  38127. components[i].pred = 0;
  38128. }
  38129. eobrun = 0;
  38130. if (componentsLength === 1) {
  38131. component = components[0];
  38132. for (n = 0; n < resetInterval; n++) {
  38133. decodeBlock(component, decodeFn, mcu);
  38134. mcu++;
  38135. }
  38136. } else {
  38137. for (n = 0; n < resetInterval; n++) {
  38138. for (i = 0; i < componentsLength; i++) {
  38139. component = components[i];
  38140. h = component.h;
  38141. v = component.v;
  38142. for (j = 0; j < v; j++) {
  38143. for (k = 0; k < h; k++) {
  38144. decodeMcu(component, decodeFn, mcu, j, k);
  38145. }
  38146. }
  38147. }
  38148. mcu++;
  38149. }
  38150. }
  38151. // find marker
  38152. bitsCount = 0;
  38153. marker = (data[offset] << 8) | data[offset + 1];
  38154. if (marker <= 0xFF00) {
  38155. throw 'marker was not found';
  38156. }
  38157. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38158. offset += 2;
  38159. } else {
  38160. break;
  38161. }
  38162. }
  38163. return offset - startOffset;
  38164. }
  38165. // A port of poppler's IDCT method which in turn is taken from:
  38166. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38167. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38168. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38169. // 988-991.
  38170. function quantizeAndInverse(component, blockBufferOffset, p) {
  38171. var qt = component.quantizationTable, blockData = component.blockData;
  38172. var v0, v1, v2, v3, v4, v5, v6, v7;
  38173. var p0, p1, p2, p3, p4, p5, p6, p7;
  38174. var t;
  38175. // inverse DCT on rows
  38176. for (var row = 0; row < 64; row += 8) {
  38177. // gather block data
  38178. p0 = blockData[blockBufferOffset + row];
  38179. p1 = blockData[blockBufferOffset + row + 1];
  38180. p2 = blockData[blockBufferOffset + row + 2];
  38181. p3 = blockData[blockBufferOffset + row + 3];
  38182. p4 = blockData[blockBufferOffset + row + 4];
  38183. p5 = blockData[blockBufferOffset + row + 5];
  38184. p6 = blockData[blockBufferOffset + row + 6];
  38185. p7 = blockData[blockBufferOffset + row + 7];
  38186. // dequant p0
  38187. p0 *= qt[row];
  38188. // check for all-zero AC coefficients
  38189. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38190. t = (dctSqrt2 * p0 + 512) >> 10;
  38191. p[row] = t;
  38192. p[row + 1] = t;
  38193. p[row + 2] = t;
  38194. p[row + 3] = t;
  38195. p[row + 4] = t;
  38196. p[row + 5] = t;
  38197. p[row + 6] = t;
  38198. p[row + 7] = t;
  38199. continue;
  38200. }
  38201. // dequant p1 ... p7
  38202. p1 *= qt[row + 1];
  38203. p2 *= qt[row + 2];
  38204. p3 *= qt[row + 3];
  38205. p4 *= qt[row + 4];
  38206. p5 *= qt[row + 5];
  38207. p6 *= qt[row + 6];
  38208. p7 *= qt[row + 7];
  38209. // stage 4
  38210. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38211. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38212. v2 = p2;
  38213. v3 = p6;
  38214. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38215. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38216. v5 = p3 << 4;
  38217. v6 = p5 << 4;
  38218. // stage 3
  38219. v0 = (v0 + v1 + 1) >> 1;
  38220. v1 = v0 - v1;
  38221. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38222. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38223. v3 = t;
  38224. v4 = (v4 + v6 + 1) >> 1;
  38225. v6 = v4 - v6;
  38226. v7 = (v7 + v5 + 1) >> 1;
  38227. v5 = v7 - v5;
  38228. // stage 2
  38229. v0 = (v0 + v3 + 1) >> 1;
  38230. v3 = v0 - v3;
  38231. v1 = (v1 + v2 + 1) >> 1;
  38232. v2 = v1 - v2;
  38233. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38234. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38235. v7 = t;
  38236. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38237. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38238. v6 = t;
  38239. // stage 1
  38240. p[row] = v0 + v7;
  38241. p[row + 7] = v0 - v7;
  38242. p[row + 1] = v1 + v6;
  38243. p[row + 6] = v1 - v6;
  38244. p[row + 2] = v2 + v5;
  38245. p[row + 5] = v2 - v5;
  38246. p[row + 3] = v3 + v4;
  38247. p[row + 4] = v3 - v4;
  38248. }
  38249. // inverse DCT on columns
  38250. for (var col = 0; col < 8; ++col) {
  38251. p0 = p[col];
  38252. p1 = p[col + 8];
  38253. p2 = p[col + 16];
  38254. p3 = p[col + 24];
  38255. p4 = p[col + 32];
  38256. p5 = p[col + 40];
  38257. p6 = p[col + 48];
  38258. p7 = p[col + 56];
  38259. // check for all-zero AC coefficients
  38260. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38261. t = (dctSqrt2 * p0 + 8192) >> 14;
  38262. // convert to 8 bit
  38263. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38264. blockData[blockBufferOffset + col] = t;
  38265. blockData[blockBufferOffset + col + 8] = t;
  38266. blockData[blockBufferOffset + col + 16] = t;
  38267. blockData[blockBufferOffset + col + 24] = t;
  38268. blockData[blockBufferOffset + col + 32] = t;
  38269. blockData[blockBufferOffset + col + 40] = t;
  38270. blockData[blockBufferOffset + col + 48] = t;
  38271. blockData[blockBufferOffset + col + 56] = t;
  38272. continue;
  38273. }
  38274. // stage 4
  38275. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38276. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38277. v2 = p2;
  38278. v3 = p6;
  38279. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38280. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38281. v5 = p3;
  38282. v6 = p5;
  38283. // stage 3
  38284. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38285. // converting to UInt8 range later.
  38286. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38287. v1 = v0 - v1;
  38288. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38289. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38290. v3 = t;
  38291. v4 = (v4 + v6 + 1) >> 1;
  38292. v6 = v4 - v6;
  38293. v7 = (v7 + v5 + 1) >> 1;
  38294. v5 = v7 - v5;
  38295. // stage 2
  38296. v0 = (v0 + v3 + 1) >> 1;
  38297. v3 = v0 - v3;
  38298. v1 = (v1 + v2 + 1) >> 1;
  38299. v2 = v1 - v2;
  38300. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38301. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38302. v7 = t;
  38303. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38304. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38305. v6 = t;
  38306. // stage 1
  38307. p0 = v0 + v7;
  38308. p7 = v0 - v7;
  38309. p1 = v1 + v6;
  38310. p6 = v1 - v6;
  38311. p2 = v2 + v5;
  38312. p5 = v2 - v5;
  38313. p3 = v3 + v4;
  38314. p4 = v3 - v4;
  38315. // convert to 8-bit integers
  38316. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38317. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38318. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38319. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38320. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38321. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38322. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38323. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38324. // store block data
  38325. blockData[blockBufferOffset + col] = p0;
  38326. blockData[blockBufferOffset + col + 8] = p1;
  38327. blockData[blockBufferOffset + col + 16] = p2;
  38328. blockData[blockBufferOffset + col + 24] = p3;
  38329. blockData[blockBufferOffset + col + 32] = p4;
  38330. blockData[blockBufferOffset + col + 40] = p5;
  38331. blockData[blockBufferOffset + col + 48] = p6;
  38332. blockData[blockBufferOffset + col + 56] = p7;
  38333. }
  38334. }
  38335. function buildComponentData(frame, component) {
  38336. var blocksPerLine = component.blocksPerLine;
  38337. var blocksPerColumn = component.blocksPerColumn;
  38338. var computationBuffer = new Int16Array(64);
  38339. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38340. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38341. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38342. quantizeAndInverse(component, offset, computationBuffer);
  38343. }
  38344. }
  38345. return component.blockData;
  38346. }
  38347. function clamp0to255(a) {
  38348. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38349. }
  38350. constructor.prototype = {
  38351. parse: function parse(data) {
  38352. function readUint16() {
  38353. var value = (data[offset] << 8) | data[offset + 1];
  38354. offset += 2;
  38355. return value;
  38356. }
  38357. function readDataBlock() {
  38358. var length = readUint16();
  38359. var array = data.subarray(offset, offset + length - 2);
  38360. offset += array.length;
  38361. return array;
  38362. }
  38363. function prepareComponents(frame) {
  38364. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38365. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38366. for (var i = 0; i < frame.components.length; i++) {
  38367. component = frame.components[i];
  38368. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38369. component.h / frame.maxH);
  38370. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38371. component.v / frame.maxV);
  38372. var blocksPerLineForMcu = mcusPerLine * component.h;
  38373. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38374. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38375. (blocksPerLineForMcu + 1);
  38376. component.blockData = new Int16Array(blocksBufferSize);
  38377. component.blocksPerLine = blocksPerLine;
  38378. component.blocksPerColumn = blocksPerColumn;
  38379. }
  38380. frame.mcusPerLine = mcusPerLine;
  38381. frame.mcusPerColumn = mcusPerColumn;
  38382. }
  38383. var offset = 0, length = data.length;
  38384. var jfif = null;
  38385. var adobe = null;
  38386. var pixels = null;
  38387. var frame, resetInterval;
  38388. var quantizationTables = [];
  38389. var huffmanTablesAC = [], huffmanTablesDC = [];
  38390. var fileMarker = readUint16();
  38391. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38392. throw 'SOI not found';
  38393. }
  38394. fileMarker = readUint16();
  38395. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38396. var i, j, l;
  38397. switch(fileMarker) {
  38398. case 0xFFE0: // APP0 (Application Specific)
  38399. case 0xFFE1: // APP1
  38400. case 0xFFE2: // APP2
  38401. case 0xFFE3: // APP3
  38402. case 0xFFE4: // APP4
  38403. case 0xFFE5: // APP5
  38404. case 0xFFE6: // APP6
  38405. case 0xFFE7: // APP7
  38406. case 0xFFE8: // APP8
  38407. case 0xFFE9: // APP9
  38408. case 0xFFEA: // APP10
  38409. case 0xFFEB: // APP11
  38410. case 0xFFEC: // APP12
  38411. case 0xFFED: // APP13
  38412. case 0xFFEE: // APP14
  38413. case 0xFFEF: // APP15
  38414. case 0xFFFE: // COM (Comment)
  38415. var appData = readDataBlock();
  38416. if (fileMarker === 0xFFE0) {
  38417. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38418. appData[2] === 0x49 && appData[3] === 0x46 &&
  38419. appData[4] === 0) { // 'JFIF\x00'
  38420. jfif = {
  38421. version: { major: appData[5], minor: appData[6] },
  38422. densityUnits: appData[7],
  38423. xDensity: (appData[8] << 8) | appData[9],
  38424. yDensity: (appData[10] << 8) | appData[11],
  38425. thumbWidth: appData[12],
  38426. thumbHeight: appData[13],
  38427. thumbData: appData.subarray(14, 14 +
  38428. 3 * appData[12] * appData[13])
  38429. };
  38430. }
  38431. }
  38432. // TODO APP1 - Exif
  38433. if (fileMarker === 0xFFEE) {
  38434. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38435. appData[2] === 0x6F && appData[3] === 0x62 &&
  38436. appData[4] === 0x65) { // 'Adobe'
  38437. adobe = {
  38438. version: (appData[5] << 8) | appData[6],
  38439. flags0: (appData[7] << 8) | appData[8],
  38440. flags1: (appData[9] << 8) | appData[10],
  38441. transformCode: appData[11]
  38442. };
  38443. }
  38444. }
  38445. break;
  38446. case 0xFFDB: // DQT (Define Quantization Tables)
  38447. var quantizationTablesLength = readUint16();
  38448. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38449. var z;
  38450. while (offset < quantizationTablesEnd) {
  38451. var quantizationTableSpec = data[offset++];
  38452. var tableData = new Uint16Array(64);
  38453. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38454. for (j = 0; j < 64; j++) {
  38455. z = dctZigZag[j];
  38456. tableData[z] = data[offset++];
  38457. }
  38458. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38459. for (j = 0; j < 64; j++) {
  38460. z = dctZigZag[j];
  38461. tableData[z] = readUint16();
  38462. }
  38463. } else {
  38464. throw 'DQT: invalid table spec';
  38465. }
  38466. quantizationTables[quantizationTableSpec & 15] = tableData;
  38467. }
  38468. break;
  38469. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38470. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38471. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38472. if (frame) {
  38473. throw 'Only single frame JPEGs supported';
  38474. }
  38475. readUint16(); // skip data length
  38476. frame = {};
  38477. frame.extended = (fileMarker === 0xFFC1);
  38478. frame.progressive = (fileMarker === 0xFFC2);
  38479. frame.precision = data[offset++];
  38480. frame.scanLines = readUint16();
  38481. frame.samplesPerLine = readUint16();
  38482. frame.components = [];
  38483. frame.componentIds = {};
  38484. var componentsCount = data[offset++], componentId;
  38485. var maxH = 0, maxV = 0;
  38486. for (i = 0; i < componentsCount; i++) {
  38487. componentId = data[offset];
  38488. var h = data[offset + 1] >> 4;
  38489. var v = data[offset + 1] & 15;
  38490. if (maxH < h) {
  38491. maxH = h;
  38492. }
  38493. if (maxV < v) {
  38494. maxV = v;
  38495. }
  38496. var qId = data[offset + 2];
  38497. l = frame.components.push({
  38498. h: h,
  38499. v: v,
  38500. quantizationTable: quantizationTables[qId]
  38501. });
  38502. frame.componentIds[componentId] = l - 1;
  38503. offset += 3;
  38504. }
  38505. frame.maxH = maxH;
  38506. frame.maxV = maxV;
  38507. prepareComponents(frame);
  38508. break;
  38509. case 0xFFC4: // DHT (Define Huffman Tables)
  38510. var huffmanLength = readUint16();
  38511. for (i = 2; i < huffmanLength;) {
  38512. var huffmanTableSpec = data[offset++];
  38513. var codeLengths = new Uint8Array(16);
  38514. var codeLengthSum = 0;
  38515. for (j = 0; j < 16; j++, offset++) {
  38516. codeLengthSum += (codeLengths[j] = data[offset]);
  38517. }
  38518. var huffmanValues = new Uint8Array(codeLengthSum);
  38519. for (j = 0; j < codeLengthSum; j++, offset++) {
  38520. huffmanValues[j] = data[offset];
  38521. }
  38522. i += 17 + codeLengthSum;
  38523. ((huffmanTableSpec >> 4) === 0 ?
  38524. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38525. buildHuffmanTable(codeLengths, huffmanValues);
  38526. }
  38527. break;
  38528. case 0xFFDD: // DRI (Define Restart Interval)
  38529. readUint16(); // skip data length
  38530. resetInterval = readUint16();
  38531. break;
  38532. case 0xFFDA: // SOS (Start of Scan)
  38533. var scanLength = readUint16();
  38534. var selectorsCount = data[offset++];
  38535. var components = [], component;
  38536. for (i = 0; i < selectorsCount; i++) {
  38537. var componentIndex = frame.componentIds[data[offset++]];
  38538. component = frame.components[componentIndex];
  38539. var tableSpec = data[offset++];
  38540. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38541. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38542. components.push(component);
  38543. }
  38544. var spectralStart = data[offset++];
  38545. var spectralEnd = data[offset++];
  38546. var successiveApproximation = data[offset++];
  38547. var processed = decodeScan(data, offset,
  38548. frame, components, resetInterval,
  38549. spectralStart, spectralEnd,
  38550. successiveApproximation >> 4, successiveApproximation & 15);
  38551. offset += processed;
  38552. break;
  38553. case 0xFFFF: // Fill bytes
  38554. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  38555. offset--;
  38556. }
  38557. break;
  38558. default:
  38559. if (data[offset - 3] === 0xFF &&
  38560. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38561. // could be incorrect encoding -- last 0xFF byte of the previous
  38562. // block was eaten by the encoder
  38563. offset -= 3;
  38564. break;
  38565. }
  38566. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38567. }
  38568. fileMarker = readUint16();
  38569. }
  38570. this.width = frame.samplesPerLine;
  38571. this.height = frame.scanLines;
  38572. this.jfif = jfif;
  38573. this.adobe = adobe;
  38574. this.components = [];
  38575. for (i = 0; i < frame.components.length; i++) {
  38576. component = frame.components[i];
  38577. this.components.push({
  38578. output: buildComponentData(frame, component),
  38579. scaleX: component.h / frame.maxH,
  38580. scaleY: component.v / frame.maxV,
  38581. blocksPerLine: component.blocksPerLine,
  38582. blocksPerColumn: component.blocksPerColumn
  38583. });
  38584. }
  38585. this.numComponents = this.components.length;
  38586. },
  38587. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38588. var scaleX = this.width / width, scaleY = this.height / height;
  38589. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38590. var x, y, i, j, k;
  38591. var index;
  38592. var offset = 0;
  38593. var output;
  38594. var numComponents = this.components.length;
  38595. var dataLength = width * height * numComponents;
  38596. var data = new Uint8Array(dataLength);
  38597. var xScaleBlockOffset = new Uint32Array(width);
  38598. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38599. for (i = 0; i < numComponents; i++) {
  38600. component = this.components[i];
  38601. componentScaleX = component.scaleX * scaleX;
  38602. componentScaleY = component.scaleY * scaleY;
  38603. offset = i;
  38604. output = component.output;
  38605. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38606. // precalculate the xScaleBlockOffset
  38607. for (x = 0; x < width; x++) {
  38608. j = 0 | (x * componentScaleX);
  38609. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38610. }
  38611. // linearize the blocks of the component
  38612. for (y = 0; y < height; y++) {
  38613. j = 0 | (y * componentScaleY);
  38614. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38615. for (x = 0; x < width; x++) {
  38616. data[offset] = output[index + xScaleBlockOffset[x]];
  38617. offset += numComponents;
  38618. }
  38619. }
  38620. }
  38621. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38622. var transform = this.decodeTransform;
  38623. if (transform) {
  38624. for (i = 0; i < dataLength;) {
  38625. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38626. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38627. }
  38628. }
  38629. }
  38630. return data;
  38631. },
  38632. _isColorConversionNeeded: function isColorConversionNeeded() {
  38633. if (this.adobe && this.adobe.transformCode) {
  38634. // The adobe transform marker overrides any previous setting
  38635. return true;
  38636. } else if (this.numComponents === 3) {
  38637. return true;
  38638. } else {
  38639. return false;
  38640. }
  38641. },
  38642. _convertYccToRgb: function convertYccToRgb(data) {
  38643. var Y, Cb, Cr;
  38644. for (var i = 0, length = data.length; i < length; i += 3) {
  38645. Y = data[i ];
  38646. Cb = data[i + 1];
  38647. Cr = data[i + 2];
  38648. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38649. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38650. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38651. }
  38652. return data;
  38653. },
  38654. _convertYcckToRgb: function convertYcckToRgb(data) {
  38655. var Y, Cb, Cr, k;
  38656. var offset = 0;
  38657. for (var i = 0, length = data.length; i < length; i += 4) {
  38658. Y = data[i];
  38659. Cb = data[i + 1];
  38660. Cr = data[i + 2];
  38661. k = data[i + 3];
  38662. var r = -122.67195406894 +
  38663. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38664. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38665. 0.154362151871126) +
  38666. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38667. 0.00477271405408747 * k + 1.53380253221734) +
  38668. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38669. 0.48357088451265) +
  38670. k * (-0.000336197177618394 * k + 0.484791561490776);
  38671. var g = 107.268039397724 +
  38672. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38673. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38674. 0.176491792462875) +
  38675. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38676. 0.000770482631801132 * k - 0.151051492775562) +
  38677. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38678. 0.25802910206845) +
  38679. k * (-0.000318913117588328 * k - 0.213742400323665);
  38680. var b = -20.810012546947 +
  38681. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38682. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38683. 0.814272968359295) +
  38684. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38685. 0.000560833691242812 * k - 0.195152027534049) +
  38686. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38687. 0.116935020465145) +
  38688. k * (-0.000343531996510555 * k + 0.24165260232407);
  38689. data[offset++] = clamp0to255(r);
  38690. data[offset++] = clamp0to255(g);
  38691. data[offset++] = clamp0to255(b);
  38692. }
  38693. return data;
  38694. },
  38695. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38696. var Y, Cb, Cr;
  38697. for (var i = 0, length = data.length; i < length; i += 4) {
  38698. Y = data[i];
  38699. Cb = data[i + 1];
  38700. Cr = data[i + 2];
  38701. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38702. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38703. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38704. // K in data[i + 3] is unchanged
  38705. }
  38706. return data;
  38707. },
  38708. _convertCmykToRgb: function convertCmykToRgb(data) {
  38709. var c, m, y, k;
  38710. var offset = 0;
  38711. var min = -255 * 255 * 255;
  38712. var scale = 1 / 255 / 255;
  38713. for (var i = 0, length = data.length; i < length; i += 4) {
  38714. c = data[i];
  38715. m = data[i + 1];
  38716. y = data[i + 2];
  38717. k = data[i + 3];
  38718. var r =
  38719. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38720. 18.82290502165302 * y + 212.25662451639585 * k -
  38721. 72734.4411664936) +
  38722. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38723. 17.873870861415444 * k - 1401.7366389350734) +
  38724. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38725. 4465.541406466231) -
  38726. k * (21.86122147463605 * k + 48317.86113160301);
  38727. var g =
  38728. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38729. 6.871425592049007 * y + 31.159100130055922 * k -
  38730. 20220.756542821975) +
  38731. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38732. 131.35250912493976 * k - 48691.05921601825) +
  38733. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38734. 6341.191035517494) -
  38735. k * (20.737325471181034 * k + 47890.15695978492);
  38736. var b =
  38737. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38738. 30.89978309703729 * y - 0.23883238689178934 * k -
  38739. 3616.812083916688) +
  38740. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38741. 50.606957656360734 * k - 28620.90484698408) +
  38742. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38743. 49363.43385999684) -
  38744. k * (22.33816807309886 * k + 45932.16563550634);
  38745. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38746. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38747. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38748. }
  38749. return data;
  38750. },
  38751. getData: function getData(width, height, forceRGBoutput) {
  38752. if (this.numComponents > 4) {
  38753. throw 'Unsupported color mode';
  38754. }
  38755. // type of data: Uint8Array(width * height * numComponents)
  38756. var data = this._getLinearizedBlockData(width, height);
  38757. if (this.numComponents === 3) {
  38758. return this._convertYccToRgb(data);
  38759. } else if (this.numComponents === 4) {
  38760. if (this._isColorConversionNeeded()) {
  38761. if (forceRGBoutput) {
  38762. return this._convertYcckToRgb(data);
  38763. } else {
  38764. return this._convertYcckToCmyk(data);
  38765. }
  38766. } else if (forceRGBoutput) {
  38767. return this._convertCmykToRgb(data);
  38768. }
  38769. }
  38770. return data;
  38771. }
  38772. };
  38773. return constructor;
  38774. })();
  38775. var JpxImage = (function JpxImageClosure() {
  38776. // Table E.1
  38777. var SubbandsGainLog2 = {
  38778. 'LL': 0,
  38779. 'LH': 1,
  38780. 'HL': 1,
  38781. 'HH': 2
  38782. };
  38783. function JpxImage() {
  38784. this.failOnCorruptedImage = false;
  38785. }
  38786. JpxImage.prototype = {
  38787. parse: function JpxImage_parse(data) {
  38788. var head = readUint16(data, 0);
  38789. // No box header, immediate start of codestream (SOC)
  38790. if (head === 0xFF4F) {
  38791. this.parseCodestream(data, 0, data.length);
  38792. return;
  38793. }
  38794. var position = 0, length = data.length;
  38795. while (position < length) {
  38796. var headerSize = 8;
  38797. var lbox = readUint32(data, position);
  38798. var tbox = readUint32(data, position + 4);
  38799. position += headerSize;
  38800. if (lbox === 1) {
  38801. // XLBox: read UInt64 according to spec.
  38802. // JavaScript's int precision of 53 bit should be sufficient here.
  38803. lbox = readUint32(data, position) * 4294967296 +
  38804. readUint32(data, position + 4);
  38805. position += 8;
  38806. headerSize += 8;
  38807. }
  38808. if (lbox === 0) {
  38809. lbox = length - position + headerSize;
  38810. }
  38811. if (lbox < headerSize) {
  38812. throw new Error('JPX Error: Invalid box field size');
  38813. }
  38814. var dataLength = lbox - headerSize;
  38815. var jumpDataLength = true;
  38816. switch (tbox) {
  38817. case 0x6A703268: // 'jp2h'
  38818. jumpDataLength = false; // parsing child boxes
  38819. break;
  38820. case 0x636F6C72: // 'colr'
  38821. // Colorspaces are not used, the CS from the PDF is used.
  38822. var method = data[position];
  38823. var precedence = data[position + 1];
  38824. var approximation = data[position + 2];
  38825. if (method === 1) {
  38826. // enumerated colorspace
  38827. var colorspace = readUint32(data, position + 3);
  38828. switch (colorspace) {
  38829. case 16: // this indicates a sRGB colorspace
  38830. case 17: // this indicates a grayscale colorspace
  38831. case 18: // this indicates a YUV colorspace
  38832. break;
  38833. default:
  38834. warn('Unknown colorspace ' + colorspace);
  38835. break;
  38836. }
  38837. } else if (method === 2) {
  38838. info('ICC profile not supported');
  38839. }
  38840. break;
  38841. case 0x6A703263: // 'jp2c'
  38842. this.parseCodestream(data, position, position + dataLength);
  38843. break;
  38844. case 0x6A502020: // 'jP\024\024'
  38845. if (0x0d0a870a !== readUint32(data, position)) {
  38846. warn('Invalid JP2 signature');
  38847. }
  38848. break;
  38849. // The following header types are valid but currently not used:
  38850. case 0x6A501A1A: // 'jP\032\032'
  38851. case 0x66747970: // 'ftyp'
  38852. case 0x72726571: // 'rreq'
  38853. case 0x72657320: // 'res '
  38854. case 0x69686472: // 'ihdr'
  38855. break;
  38856. default:
  38857. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38858. (tbox >> 16) & 0xFF,
  38859. (tbox >> 8) & 0xFF,
  38860. tbox & 0xFF);
  38861. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38862. break;
  38863. }
  38864. if (jumpDataLength) {
  38865. position += dataLength;
  38866. }
  38867. }
  38868. },
  38869. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38870. var newByte = stream.getByte();
  38871. while (newByte >= 0) {
  38872. var oldByte = newByte;
  38873. newByte = stream.getByte();
  38874. var code = (oldByte << 8) | newByte;
  38875. // Image and tile size (SIZ)
  38876. if (code === 0xFF51) {
  38877. stream.skip(4);
  38878. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38879. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38880. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38881. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38882. stream.skip(16);
  38883. var Csiz = stream.getUint16(); // Byte 36
  38884. this.width = Xsiz - XOsiz;
  38885. this.height = Ysiz - YOsiz;
  38886. this.componentsCount = Csiz;
  38887. // Results are always returned as Uint8Arrays
  38888. this.bitsPerComponent = 8;
  38889. return;
  38890. }
  38891. }
  38892. throw new Error('JPX Error: No size marker found in JPX stream');
  38893. },
  38894. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38895. var context = {};
  38896. try {
  38897. var doNotRecover = false;
  38898. var position = start;
  38899. while (position + 1 < end) {
  38900. var code = readUint16(data, position);
  38901. position += 2;
  38902. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38903. switch (code) {
  38904. case 0xFF4F: // Start of codestream (SOC)
  38905. context.mainHeader = true;
  38906. break;
  38907. case 0xFFD9: // End of codestream (EOC)
  38908. break;
  38909. case 0xFF51: // Image and tile size (SIZ)
  38910. length = readUint16(data, position);
  38911. var siz = {};
  38912. siz.Xsiz = readUint32(data, position + 4);
  38913. siz.Ysiz = readUint32(data, position + 8);
  38914. siz.XOsiz = readUint32(data, position + 12);
  38915. siz.YOsiz = readUint32(data, position + 16);
  38916. siz.XTsiz = readUint32(data, position + 20);
  38917. siz.YTsiz = readUint32(data, position + 24);
  38918. siz.XTOsiz = readUint32(data, position + 28);
  38919. siz.YTOsiz = readUint32(data, position + 32);
  38920. var componentsCount = readUint16(data, position + 36);
  38921. siz.Csiz = componentsCount;
  38922. var components = [];
  38923. j = position + 38;
  38924. for (var i = 0; i < componentsCount; i++) {
  38925. var component = {
  38926. precision: (data[j] & 0x7F) + 1,
  38927. isSigned: !!(data[j] & 0x80),
  38928. XRsiz: data[j + 1],
  38929. YRsiz: data[j + 1]
  38930. };
  38931. calculateComponentDimensions(component, siz);
  38932. components.push(component);
  38933. }
  38934. context.SIZ = siz;
  38935. context.components = components;
  38936. calculateTileGrids(context, components);
  38937. context.QCC = [];
  38938. context.COC = [];
  38939. break;
  38940. case 0xFF5C: // Quantization default (QCD)
  38941. length = readUint16(data, position);
  38942. var qcd = {};
  38943. j = position + 2;
  38944. sqcd = data[j++];
  38945. switch (sqcd & 0x1F) {
  38946. case 0:
  38947. spqcdSize = 8;
  38948. scalarExpounded = true;
  38949. break;
  38950. case 1:
  38951. spqcdSize = 16;
  38952. scalarExpounded = false;
  38953. break;
  38954. case 2:
  38955. spqcdSize = 16;
  38956. scalarExpounded = true;
  38957. break;
  38958. default:
  38959. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38960. }
  38961. qcd.noQuantization = (spqcdSize === 8);
  38962. qcd.scalarExpounded = scalarExpounded;
  38963. qcd.guardBits = sqcd >> 5;
  38964. spqcds = [];
  38965. while (j < length + position) {
  38966. var spqcd = {};
  38967. if (spqcdSize === 8) {
  38968. spqcd.epsilon = data[j++] >> 3;
  38969. spqcd.mu = 0;
  38970. } else {
  38971. spqcd.epsilon = data[j] >> 3;
  38972. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38973. j += 2;
  38974. }
  38975. spqcds.push(spqcd);
  38976. }
  38977. qcd.SPqcds = spqcds;
  38978. if (context.mainHeader) {
  38979. context.QCD = qcd;
  38980. } else {
  38981. context.currentTile.QCD = qcd;
  38982. context.currentTile.QCC = [];
  38983. }
  38984. break;
  38985. case 0xFF5D: // Quantization component (QCC)
  38986. length = readUint16(data, position);
  38987. var qcc = {};
  38988. j = position + 2;
  38989. var cqcc;
  38990. if (context.SIZ.Csiz < 257) {
  38991. cqcc = data[j++];
  38992. } else {
  38993. cqcc = readUint16(data, j);
  38994. j += 2;
  38995. }
  38996. sqcd = data[j++];
  38997. switch (sqcd & 0x1F) {
  38998. case 0:
  38999. spqcdSize = 8;
  39000. scalarExpounded = true;
  39001. break;
  39002. case 1:
  39003. spqcdSize = 16;
  39004. scalarExpounded = false;
  39005. break;
  39006. case 2:
  39007. spqcdSize = 16;
  39008. scalarExpounded = true;
  39009. break;
  39010. default:
  39011. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39012. }
  39013. qcc.noQuantization = (spqcdSize === 8);
  39014. qcc.scalarExpounded = scalarExpounded;
  39015. qcc.guardBits = sqcd >> 5;
  39016. spqcds = [];
  39017. while (j < (length + position)) {
  39018. spqcd = {};
  39019. if (spqcdSize === 8) {
  39020. spqcd.epsilon = data[j++] >> 3;
  39021. spqcd.mu = 0;
  39022. } else {
  39023. spqcd.epsilon = data[j] >> 3;
  39024. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39025. j += 2;
  39026. }
  39027. spqcds.push(spqcd);
  39028. }
  39029. qcc.SPqcds = spqcds;
  39030. if (context.mainHeader) {
  39031. context.QCC[cqcc] = qcc;
  39032. } else {
  39033. context.currentTile.QCC[cqcc] = qcc;
  39034. }
  39035. break;
  39036. case 0xFF52: // Coding style default (COD)
  39037. length = readUint16(data, position);
  39038. var cod = {};
  39039. j = position + 2;
  39040. var scod = data[j++];
  39041. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39042. cod.sopMarkerUsed = !!(scod & 2);
  39043. cod.ephMarkerUsed = !!(scod & 4);
  39044. cod.progressionOrder = data[j++];
  39045. cod.layersCount = readUint16(data, j);
  39046. j += 2;
  39047. cod.multipleComponentTransform = data[j++];
  39048. cod.decompositionLevelsCount = data[j++];
  39049. cod.xcb = (data[j++] & 0xF) + 2;
  39050. cod.ycb = (data[j++] & 0xF) + 2;
  39051. var blockStyle = data[j++];
  39052. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39053. cod.resetContextProbabilities = !!(blockStyle & 2);
  39054. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39055. cod.verticalyStripe = !!(blockStyle & 8);
  39056. cod.predictableTermination = !!(blockStyle & 16);
  39057. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39058. cod.reversibleTransformation = data[j++];
  39059. if (cod.entropyCoderWithCustomPrecincts) {
  39060. var precinctsSizes = [];
  39061. while (j < length + position) {
  39062. var precinctsSize = data[j++];
  39063. precinctsSizes.push({
  39064. PPx: precinctsSize & 0xF,
  39065. PPy: precinctsSize >> 4
  39066. });
  39067. }
  39068. cod.precinctsSizes = precinctsSizes;
  39069. }
  39070. var unsupported = [];
  39071. if (cod.selectiveArithmeticCodingBypass) {
  39072. unsupported.push('selectiveArithmeticCodingBypass');
  39073. }
  39074. if (cod.resetContextProbabilities) {
  39075. unsupported.push('resetContextProbabilities');
  39076. }
  39077. if (cod.terminationOnEachCodingPass) {
  39078. unsupported.push('terminationOnEachCodingPass');
  39079. }
  39080. if (cod.verticalyStripe) {
  39081. unsupported.push('verticalyStripe');
  39082. }
  39083. if (cod.predictableTermination) {
  39084. unsupported.push('predictableTermination');
  39085. }
  39086. if (unsupported.length > 0) {
  39087. doNotRecover = true;
  39088. throw new Error('JPX Error: Unsupported COD options (' +
  39089. unsupported.join(', ') + ')');
  39090. }
  39091. if (context.mainHeader) {
  39092. context.COD = cod;
  39093. } else {
  39094. context.currentTile.COD = cod;
  39095. context.currentTile.COC = [];
  39096. }
  39097. break;
  39098. case 0xFF90: // Start of tile-part (SOT)
  39099. length = readUint16(data, position);
  39100. tile = {};
  39101. tile.index = readUint16(data, position + 2);
  39102. tile.length = readUint32(data, position + 4);
  39103. tile.dataEnd = tile.length + position - 2;
  39104. tile.partIndex = data[position + 8];
  39105. tile.partsCount = data[position + 9];
  39106. context.mainHeader = false;
  39107. if (tile.partIndex === 0) {
  39108. // reset component specific settings
  39109. tile.COD = context.COD;
  39110. tile.COC = context.COC.slice(0); // clone of the global COC
  39111. tile.QCD = context.QCD;
  39112. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39113. }
  39114. context.currentTile = tile;
  39115. break;
  39116. case 0xFF93: // Start of data (SOD)
  39117. tile = context.currentTile;
  39118. if (tile.partIndex === 0) {
  39119. initializeTile(context, tile.index);
  39120. buildPackets(context);
  39121. }
  39122. // moving to the end of the data
  39123. length = tile.dataEnd - position;
  39124. parseTilePackets(context, data, position, length);
  39125. break;
  39126. case 0xFF55: // Tile-part lengths, main header (TLM)
  39127. case 0xFF57: // Packet length, main header (PLM)
  39128. case 0xFF58: // Packet length, tile-part header (PLT)
  39129. case 0xFF64: // Comment (COM)
  39130. length = readUint16(data, position);
  39131. // skipping content
  39132. break;
  39133. case 0xFF53: // Coding style component (COC)
  39134. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39135. 'not implemented');
  39136. default:
  39137. throw new Error('JPX Error: Unknown codestream code: ' +
  39138. code.toString(16));
  39139. }
  39140. position += length;
  39141. }
  39142. } catch (e) {
  39143. if (doNotRecover || this.failOnCorruptedImage) {
  39144. throw e;
  39145. } else {
  39146. warn('Trying to recover from ' + e.message);
  39147. }
  39148. }
  39149. this.tiles = transformComponents(context);
  39150. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39151. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39152. this.componentsCount = context.SIZ.Csiz;
  39153. }
  39154. };
  39155. function calculateComponentDimensions(component, siz) {
  39156. // Section B.2 Component mapping
  39157. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39158. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39159. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39160. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39161. component.width = component.x1 - component.x0;
  39162. component.height = component.y1 - component.y0;
  39163. }
  39164. function calculateTileGrids(context, components) {
  39165. var siz = context.SIZ;
  39166. // Section B.3 Division into tile and tile-components
  39167. var tile, tiles = [];
  39168. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39169. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39170. for (var q = 0; q < numYtiles; q++) {
  39171. for (var p = 0; p < numXtiles; p++) {
  39172. tile = {};
  39173. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39174. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39175. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39176. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39177. tile.width = tile.tx1 - tile.tx0;
  39178. tile.height = tile.ty1 - tile.ty0;
  39179. tile.components = [];
  39180. tiles.push(tile);
  39181. }
  39182. }
  39183. context.tiles = tiles;
  39184. var componentsCount = siz.Csiz;
  39185. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39186. var component = components[i];
  39187. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39188. var tileComponent = {};
  39189. tile = tiles[j];
  39190. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39191. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39192. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39193. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39194. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39195. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39196. tile.components[i] = tileComponent;
  39197. }
  39198. }
  39199. }
  39200. function getBlocksDimensions(context, component, r) {
  39201. var codOrCoc = component.codingStyleParameters;
  39202. var result = {};
  39203. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39204. result.PPx = 15;
  39205. result.PPy = 15;
  39206. } else {
  39207. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39208. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39209. }
  39210. // calculate codeblock size as described in section B.7
  39211. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39212. Math.min(codOrCoc.xcb, result.PPx));
  39213. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39214. Math.min(codOrCoc.ycb, result.PPy));
  39215. return result;
  39216. }
  39217. function buildPrecincts(context, resolution, dimensions) {
  39218. // Section B.6 Division resolution to precincts
  39219. var precinctWidth = 1 << dimensions.PPx;
  39220. var precinctHeight = 1 << dimensions.PPy;
  39221. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39222. // to precincts. Precinct partition divides a resolution according to width
  39223. // and height parameters. The subband that belongs to the resolution level
  39224. // has a different size than the level, unless it is the zero resolution.
  39225. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39226. // The precinct partitioning for a particular subband is derived from a
  39227. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39228. // resolution level)... The LL band associated with each resolution level is
  39229. // divided into precincts... Each of the resulting precinct regions is then
  39230. // mapped into its child subbands (if any) at the next lower resolution
  39231. // level. This is accomplished by using the coordinate transformation
  39232. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39233. // coordinates of a point in the LL band and child subband, respectively.
  39234. var isZeroRes = resolution.resLevel === 0;
  39235. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39236. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39237. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39238. Math.ceil(resolution.trx1 / precinctWidth) -
  39239. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39240. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39241. Math.ceil(resolution.try1 / precinctHeight) -
  39242. Math.floor(resolution.try0 / precinctHeight) : 0);
  39243. var numprecincts = numprecinctswide * numprecinctshigh;
  39244. resolution.precinctParameters = {
  39245. precinctWidth: precinctWidth,
  39246. precinctHeight: precinctHeight,
  39247. numprecinctswide: numprecinctswide,
  39248. numprecinctshigh: numprecinctshigh,
  39249. numprecincts: numprecincts,
  39250. precinctWidthInSubband: precinctWidthInSubband,
  39251. precinctHeightInSubband: precinctHeightInSubband
  39252. };
  39253. }
  39254. function buildCodeblocks(context, subband, dimensions) {
  39255. // Section B.7 Division sub-band into code-blocks
  39256. var xcb_ = dimensions.xcb_;
  39257. var ycb_ = dimensions.ycb_;
  39258. var codeblockWidth = 1 << xcb_;
  39259. var codeblockHeight = 1 << ycb_;
  39260. var cbx0 = subband.tbx0 >> xcb_;
  39261. var cby0 = subband.tby0 >> ycb_;
  39262. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39263. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39264. var precinctParameters = subband.resolution.precinctParameters;
  39265. var codeblocks = [];
  39266. var precincts = [];
  39267. var i, j, codeblock, precinctNumber;
  39268. for (j = cby0; j < cby1; j++) {
  39269. for (i = cbx0; i < cbx1; i++) {
  39270. codeblock = {
  39271. cbx: i,
  39272. cby: j,
  39273. tbx0: codeblockWidth * i,
  39274. tby0: codeblockHeight * j,
  39275. tbx1: codeblockWidth * (i + 1),
  39276. tby1: codeblockHeight * (j + 1)
  39277. };
  39278. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39279. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39280. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39281. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39282. // Calculate precinct number for this codeblock, codeblock position
  39283. // should be relative to its subband, use actual dimension and position
  39284. // See comment about codeblock group width and height
  39285. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39286. precinctParameters.precinctWidthInSubband);
  39287. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39288. precinctParameters.precinctHeightInSubband);
  39289. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39290. codeblock.precinctNumber = precinctNumber;
  39291. codeblock.subbandType = subband.type;
  39292. codeblock.Lblock = 3;
  39293. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39294. codeblock.tby1_ <= codeblock.tby0_) {
  39295. continue;
  39296. }
  39297. codeblocks.push(codeblock);
  39298. // building precinct for the sub-band
  39299. var precinct = precincts[precinctNumber];
  39300. if (precinct !== undefined) {
  39301. if (i < precinct.cbxMin) {
  39302. precinct.cbxMin = i;
  39303. } else if (i > precinct.cbxMax) {
  39304. precinct.cbxMax = i;
  39305. }
  39306. if (j < precinct.cbyMin) {
  39307. precinct.cbxMin = j;
  39308. } else if (j > precinct.cbyMax) {
  39309. precinct.cbyMax = j;
  39310. }
  39311. } else {
  39312. precincts[precinctNumber] = precinct = {
  39313. cbxMin: i,
  39314. cbyMin: j,
  39315. cbxMax: i,
  39316. cbyMax: j
  39317. };
  39318. }
  39319. codeblock.precinct = precinct;
  39320. }
  39321. }
  39322. subband.codeblockParameters = {
  39323. codeblockWidth: xcb_,
  39324. codeblockHeight: ycb_,
  39325. numcodeblockwide: cbx1 - cbx0 + 1,
  39326. numcodeblockhigh: cby1 - cby0 + 1
  39327. };
  39328. subband.codeblocks = codeblocks;
  39329. subband.precincts = precincts;
  39330. }
  39331. function createPacket(resolution, precinctNumber, layerNumber) {
  39332. var precinctCodeblocks = [];
  39333. // Section B.10.8 Order of info in packet
  39334. var subbands = resolution.subbands;
  39335. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39336. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39337. var subband = subbands[i];
  39338. var codeblocks = subband.codeblocks;
  39339. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39340. var codeblock = codeblocks[j];
  39341. if (codeblock.precinctNumber !== precinctNumber) {
  39342. continue;
  39343. }
  39344. precinctCodeblocks.push(codeblock);
  39345. }
  39346. }
  39347. return {
  39348. layerNumber: layerNumber,
  39349. codeblocks: precinctCodeblocks
  39350. };
  39351. }
  39352. function LayerResolutionComponentPositionIterator(context) {
  39353. var siz = context.SIZ;
  39354. var tileIndex = context.currentTile.index;
  39355. var tile = context.tiles[tileIndex];
  39356. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39357. var componentsCount = siz.Csiz;
  39358. var maxDecompositionLevelsCount = 0;
  39359. for (var q = 0; q < componentsCount; q++) {
  39360. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39361. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39362. }
  39363. var l = 0, r = 0, i = 0, k = 0;
  39364. this.nextPacket = function JpxImage_nextPacket() {
  39365. // Section B.12.1.1 Layer-resolution-component-position
  39366. for (; l < layersCount; l++) {
  39367. for (; r <= maxDecompositionLevelsCount; r++) {
  39368. for (; i < componentsCount; i++) {
  39369. var component = tile.components[i];
  39370. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39371. continue;
  39372. }
  39373. var resolution = component.resolutions[r];
  39374. var numprecincts = resolution.precinctParameters.numprecincts;
  39375. for (; k < numprecincts;) {
  39376. var packet = createPacket(resolution, k, l);
  39377. k++;
  39378. return packet;
  39379. }
  39380. k = 0;
  39381. }
  39382. i = 0;
  39383. }
  39384. r = 0;
  39385. }
  39386. throw new Error('JPX Error: Out of packets');
  39387. };
  39388. }
  39389. function ResolutionLayerComponentPositionIterator(context) {
  39390. var siz = context.SIZ;
  39391. var tileIndex = context.currentTile.index;
  39392. var tile = context.tiles[tileIndex];
  39393. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39394. var componentsCount = siz.Csiz;
  39395. var maxDecompositionLevelsCount = 0;
  39396. for (var q = 0; q < componentsCount; q++) {
  39397. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39398. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39399. }
  39400. var r = 0, l = 0, i = 0, k = 0;
  39401. this.nextPacket = function JpxImage_nextPacket() {
  39402. // Section B.12.1.2 Resolution-layer-component-position
  39403. for (; r <= maxDecompositionLevelsCount; r++) {
  39404. for (; l < layersCount; l++) {
  39405. for (; i < componentsCount; i++) {
  39406. var component = tile.components[i];
  39407. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39408. continue;
  39409. }
  39410. var resolution = component.resolutions[r];
  39411. var numprecincts = resolution.precinctParameters.numprecincts;
  39412. for (; k < numprecincts;) {
  39413. var packet = createPacket(resolution, k, l);
  39414. k++;
  39415. return packet;
  39416. }
  39417. k = 0;
  39418. }
  39419. i = 0;
  39420. }
  39421. l = 0;
  39422. }
  39423. throw new Error('JPX Error: Out of packets');
  39424. };
  39425. }
  39426. function ResolutionPositionComponentLayerIterator(context) {
  39427. var siz = context.SIZ;
  39428. var tileIndex = context.currentTile.index;
  39429. var tile = context.tiles[tileIndex];
  39430. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39431. var componentsCount = siz.Csiz;
  39432. var l, r, c, p;
  39433. var maxDecompositionLevelsCount = 0;
  39434. for (c = 0; c < componentsCount; c++) {
  39435. var component = tile.components[c];
  39436. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39437. component.codingStyleParameters.decompositionLevelsCount);
  39438. }
  39439. var maxNumPrecinctsInLevel = new Int32Array(
  39440. maxDecompositionLevelsCount + 1);
  39441. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39442. var maxNumPrecincts = 0;
  39443. for (c = 0; c < componentsCount; ++c) {
  39444. var resolutions = tile.components[c].resolutions;
  39445. if (r < resolutions.length) {
  39446. maxNumPrecincts = Math.max(maxNumPrecincts,
  39447. resolutions[r].precinctParameters.numprecincts);
  39448. }
  39449. }
  39450. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39451. }
  39452. l = 0;
  39453. r = 0;
  39454. c = 0;
  39455. p = 0;
  39456. this.nextPacket = function JpxImage_nextPacket() {
  39457. // Section B.12.1.3 Resolution-position-component-layer
  39458. for (; r <= maxDecompositionLevelsCount; r++) {
  39459. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39460. for (; c < componentsCount; c++) {
  39461. var component = tile.components[c];
  39462. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39463. continue;
  39464. }
  39465. var resolution = component.resolutions[r];
  39466. var numprecincts = resolution.precinctParameters.numprecincts;
  39467. if (p >= numprecincts) {
  39468. continue;
  39469. }
  39470. for (; l < layersCount;) {
  39471. var packet = createPacket(resolution, p, l);
  39472. l++;
  39473. return packet;
  39474. }
  39475. l = 0;
  39476. }
  39477. c = 0;
  39478. }
  39479. p = 0;
  39480. }
  39481. throw new Error('JPX Error: Out of packets');
  39482. };
  39483. }
  39484. function PositionComponentResolutionLayerIterator(context) {
  39485. var siz = context.SIZ;
  39486. var tileIndex = context.currentTile.index;
  39487. var tile = context.tiles[tileIndex];
  39488. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39489. var componentsCount = siz.Csiz;
  39490. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39491. var precinctsIterationSizes = precinctsSizes;
  39492. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39493. this.nextPacket = function JpxImage_nextPacket() {
  39494. // Section B.12.1.4 Position-component-resolution-layer
  39495. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39496. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39497. for (; c < componentsCount; c++) {
  39498. var component = tile.components[c];
  39499. var decompositionLevelsCount =
  39500. component.codingStyleParameters.decompositionLevelsCount;
  39501. for (; r <= decompositionLevelsCount; r++) {
  39502. var resolution = component.resolutions[r];
  39503. var sizeInImageScale =
  39504. precinctsSizes.components[c].resolutions[r];
  39505. var k = getPrecinctIndexIfExist(
  39506. px,
  39507. py,
  39508. sizeInImageScale,
  39509. precinctsIterationSizes,
  39510. resolution);
  39511. if (k === null) {
  39512. continue;
  39513. }
  39514. for (; l < layersCount;) {
  39515. var packet = createPacket(resolution, k, l);
  39516. l++;
  39517. return packet;
  39518. }
  39519. l = 0;
  39520. }
  39521. r = 0;
  39522. }
  39523. c = 0;
  39524. }
  39525. px = 0;
  39526. }
  39527. throw new Error('JPX Error: Out of packets');
  39528. };
  39529. }
  39530. function ComponentPositionResolutionLayerIterator(context) {
  39531. var siz = context.SIZ;
  39532. var tileIndex = context.currentTile.index;
  39533. var tile = context.tiles[tileIndex];
  39534. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39535. var componentsCount = siz.Csiz;
  39536. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39537. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39538. this.nextPacket = function JpxImage_nextPacket() {
  39539. // Section B.12.1.5 Component-position-resolution-layer
  39540. for (; c < componentsCount; ++c) {
  39541. var component = tile.components[c];
  39542. var precinctsIterationSizes = precinctsSizes.components[c];
  39543. var decompositionLevelsCount =
  39544. component.codingStyleParameters.decompositionLevelsCount;
  39545. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39546. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39547. for (; r <= decompositionLevelsCount; r++) {
  39548. var resolution = component.resolutions[r];
  39549. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39550. var k = getPrecinctIndexIfExist(
  39551. px,
  39552. py,
  39553. sizeInImageScale,
  39554. precinctsIterationSizes,
  39555. resolution);
  39556. if (k === null) {
  39557. continue;
  39558. }
  39559. for (; l < layersCount;) {
  39560. var packet = createPacket(resolution, k, l);
  39561. l++;
  39562. return packet;
  39563. }
  39564. l = 0;
  39565. }
  39566. r = 0;
  39567. }
  39568. px = 0;
  39569. }
  39570. py = 0;
  39571. }
  39572. throw new Error('JPX Error: Out of packets');
  39573. };
  39574. }
  39575. function getPrecinctIndexIfExist(
  39576. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39577. var posX = pxIndex * precinctIterationSizes.minWidth;
  39578. var posY = pyIndex * precinctIterationSizes.minHeight;
  39579. if (posX % sizeInImageScale.width !== 0 ||
  39580. posY % sizeInImageScale.height !== 0) {
  39581. return null;
  39582. }
  39583. var startPrecinctRowIndex =
  39584. (posY / sizeInImageScale.width) *
  39585. resolution.precinctParameters.numprecinctswide;
  39586. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39587. }
  39588. function getPrecinctSizesInImageScale(tile) {
  39589. var componentsCount = tile.components.length;
  39590. var minWidth = Number.MAX_VALUE;
  39591. var minHeight = Number.MAX_VALUE;
  39592. var maxNumWide = 0;
  39593. var maxNumHigh = 0;
  39594. var sizePerComponent = new Array(componentsCount);
  39595. for (var c = 0; c < componentsCount; c++) {
  39596. var component = tile.components[c];
  39597. var decompositionLevelsCount =
  39598. component.codingStyleParameters.decompositionLevelsCount;
  39599. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39600. var minWidthCurrentComponent = Number.MAX_VALUE;
  39601. var minHeightCurrentComponent = Number.MAX_VALUE;
  39602. var maxNumWideCurrentComponent = 0;
  39603. var maxNumHighCurrentComponent = 0;
  39604. var scale = 1;
  39605. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39606. var resolution = component.resolutions[r];
  39607. var widthCurrentResolution =
  39608. scale * resolution.precinctParameters.precinctWidth;
  39609. var heightCurrentResolution =
  39610. scale * resolution.precinctParameters.precinctHeight;
  39611. minWidthCurrentComponent = Math.min(
  39612. minWidthCurrentComponent,
  39613. widthCurrentResolution);
  39614. minHeightCurrentComponent = Math.min(
  39615. minHeightCurrentComponent,
  39616. heightCurrentResolution);
  39617. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39618. resolution.precinctParameters.numprecinctswide);
  39619. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39620. resolution.precinctParameters.numprecinctshigh);
  39621. sizePerResolution[r] = {
  39622. width: widthCurrentResolution,
  39623. height: heightCurrentResolution
  39624. };
  39625. scale <<= 1;
  39626. }
  39627. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39628. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39629. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39630. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39631. sizePerComponent[c] = {
  39632. resolutions: sizePerResolution,
  39633. minWidth: minWidthCurrentComponent,
  39634. minHeight: minHeightCurrentComponent,
  39635. maxNumWide: maxNumWideCurrentComponent,
  39636. maxNumHigh: maxNumHighCurrentComponent
  39637. };
  39638. }
  39639. return {
  39640. components: sizePerComponent,
  39641. minWidth: minWidth,
  39642. minHeight: minHeight,
  39643. maxNumWide: maxNumWide,
  39644. maxNumHigh: maxNumHigh
  39645. };
  39646. }
  39647. function buildPackets(context) {
  39648. var siz = context.SIZ;
  39649. var tileIndex = context.currentTile.index;
  39650. var tile = context.tiles[tileIndex];
  39651. var componentsCount = siz.Csiz;
  39652. // Creating resolutions and sub-bands for each component
  39653. for (var c = 0; c < componentsCount; c++) {
  39654. var component = tile.components[c];
  39655. var decompositionLevelsCount =
  39656. component.codingStyleParameters.decompositionLevelsCount;
  39657. // Section B.5 Resolution levels and sub-bands
  39658. var resolutions = [];
  39659. var subbands = [];
  39660. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39661. var blocksDimensions = getBlocksDimensions(context, component, r);
  39662. var resolution = {};
  39663. var scale = 1 << (decompositionLevelsCount - r);
  39664. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39665. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39666. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39667. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39668. resolution.resLevel = r;
  39669. buildPrecincts(context, resolution, blocksDimensions);
  39670. resolutions.push(resolution);
  39671. var subband;
  39672. if (r === 0) {
  39673. // one sub-band (LL) with last decomposition
  39674. subband = {};
  39675. subband.type = 'LL';
  39676. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39677. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39678. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39679. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39680. subband.resolution = resolution;
  39681. buildCodeblocks(context, subband, blocksDimensions);
  39682. subbands.push(subband);
  39683. resolution.subbands = [subband];
  39684. } else {
  39685. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39686. var resolutionSubbands = [];
  39687. // three sub-bands (HL, LH and HH) with rest of decompositions
  39688. subband = {};
  39689. subband.type = 'HL';
  39690. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39691. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39692. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39693. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39694. subband.resolution = resolution;
  39695. buildCodeblocks(context, subband, blocksDimensions);
  39696. subbands.push(subband);
  39697. resolutionSubbands.push(subband);
  39698. subband = {};
  39699. subband.type = 'LH';
  39700. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39701. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39702. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39703. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39704. subband.resolution = resolution;
  39705. buildCodeblocks(context, subband, blocksDimensions);
  39706. subbands.push(subband);
  39707. resolutionSubbands.push(subband);
  39708. subband = {};
  39709. subband.type = 'HH';
  39710. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39711. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39712. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39713. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39714. subband.resolution = resolution;
  39715. buildCodeblocks(context, subband, blocksDimensions);
  39716. subbands.push(subband);
  39717. resolutionSubbands.push(subband);
  39718. resolution.subbands = resolutionSubbands;
  39719. }
  39720. }
  39721. component.resolutions = resolutions;
  39722. component.subbands = subbands;
  39723. }
  39724. // Generate the packets sequence
  39725. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39726. switch (progressionOrder) {
  39727. case 0:
  39728. tile.packetsIterator =
  39729. new LayerResolutionComponentPositionIterator(context);
  39730. break;
  39731. case 1:
  39732. tile.packetsIterator =
  39733. new ResolutionLayerComponentPositionIterator(context);
  39734. break;
  39735. case 2:
  39736. tile.packetsIterator =
  39737. new ResolutionPositionComponentLayerIterator(context);
  39738. break;
  39739. case 3:
  39740. tile.packetsIterator =
  39741. new PositionComponentResolutionLayerIterator(context);
  39742. break;
  39743. case 4:
  39744. tile.packetsIterator =
  39745. new ComponentPositionResolutionLayerIterator(context);
  39746. break;
  39747. default:
  39748. throw new Error('JPX Error: Unsupported progression order ' +
  39749. progressionOrder);
  39750. }
  39751. }
  39752. function parseTilePackets(context, data, offset, dataLength) {
  39753. var position = 0;
  39754. var buffer, bufferSize = 0, skipNextBit = false;
  39755. function readBits(count) {
  39756. while (bufferSize < count) {
  39757. var b = data[offset + position];
  39758. position++;
  39759. if (skipNextBit) {
  39760. buffer = (buffer << 7) | b;
  39761. bufferSize += 7;
  39762. skipNextBit = false;
  39763. } else {
  39764. buffer = (buffer << 8) | b;
  39765. bufferSize += 8;
  39766. }
  39767. if (b === 0xFF) {
  39768. skipNextBit = true;
  39769. }
  39770. }
  39771. bufferSize -= count;
  39772. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39773. }
  39774. function skipMarkerIfEqual(value) {
  39775. if (data[offset + position - 1] === 0xFF &&
  39776. data[offset + position] === value) {
  39777. skipBytes(1);
  39778. return true;
  39779. } else if (data[offset + position] === 0xFF &&
  39780. data[offset + position + 1] === value) {
  39781. skipBytes(2);
  39782. return true;
  39783. }
  39784. return false;
  39785. }
  39786. function skipBytes(count) {
  39787. position += count;
  39788. }
  39789. function alignToByte() {
  39790. bufferSize = 0;
  39791. if (skipNextBit) {
  39792. position++;
  39793. skipNextBit = false;
  39794. }
  39795. }
  39796. function readCodingpasses() {
  39797. if (readBits(1) === 0) {
  39798. return 1;
  39799. }
  39800. if (readBits(1) === 0) {
  39801. return 2;
  39802. }
  39803. var value = readBits(2);
  39804. if (value < 3) {
  39805. return value + 3;
  39806. }
  39807. value = readBits(5);
  39808. if (value < 31) {
  39809. return value + 6;
  39810. }
  39811. value = readBits(7);
  39812. return value + 37;
  39813. }
  39814. var tileIndex = context.currentTile.index;
  39815. var tile = context.tiles[tileIndex];
  39816. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39817. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39818. var packetsIterator = tile.packetsIterator;
  39819. while (position < dataLength) {
  39820. alignToByte();
  39821. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39822. // Skip also marker segment length and packet sequence ID
  39823. skipBytes(4);
  39824. }
  39825. var packet = packetsIterator.nextPacket();
  39826. if (!readBits(1)) {
  39827. continue;
  39828. }
  39829. var layerNumber = packet.layerNumber;
  39830. var queue = [], codeblock;
  39831. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39832. codeblock = packet.codeblocks[i];
  39833. var precinct = codeblock.precinct;
  39834. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39835. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39836. var codeblockIncluded = false;
  39837. var firstTimeInclusion = false;
  39838. var valueReady;
  39839. if (codeblock['included'] !== undefined) {
  39840. codeblockIncluded = !!readBits(1);
  39841. } else {
  39842. // reading inclusion tree
  39843. precinct = codeblock.precinct;
  39844. var inclusionTree, zeroBitPlanesTree;
  39845. if (precinct['inclusionTree'] !== undefined) {
  39846. inclusionTree = precinct.inclusionTree;
  39847. } else {
  39848. // building inclusion and zero bit-planes trees
  39849. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39850. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39851. inclusionTree = new InclusionTree(width, height, layerNumber);
  39852. zeroBitPlanesTree = new TagTree(width, height);
  39853. precinct.inclusionTree = inclusionTree;
  39854. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39855. }
  39856. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39857. while (true) {
  39858. if (readBits(1)) {
  39859. valueReady = !inclusionTree.nextLevel();
  39860. if (valueReady) {
  39861. codeblock.included = true;
  39862. codeblockIncluded = firstTimeInclusion = true;
  39863. break;
  39864. }
  39865. } else {
  39866. inclusionTree.incrementValue(layerNumber);
  39867. break;
  39868. }
  39869. }
  39870. }
  39871. }
  39872. if (!codeblockIncluded) {
  39873. continue;
  39874. }
  39875. if (firstTimeInclusion) {
  39876. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39877. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39878. while (true) {
  39879. if (readBits(1)) {
  39880. valueReady = !zeroBitPlanesTree.nextLevel();
  39881. if (valueReady) {
  39882. break;
  39883. }
  39884. } else {
  39885. zeroBitPlanesTree.incrementValue();
  39886. }
  39887. }
  39888. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39889. }
  39890. var codingpasses = readCodingpasses();
  39891. while (readBits(1)) {
  39892. codeblock.Lblock++;
  39893. }
  39894. var codingpassesLog2 = log2(codingpasses);
  39895. // rounding down log2
  39896. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39897. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39898. var codedDataLength = readBits(bits);
  39899. queue.push({
  39900. codeblock: codeblock,
  39901. codingpasses: codingpasses,
  39902. dataLength: codedDataLength
  39903. });
  39904. }
  39905. alignToByte();
  39906. if (ephMarkerUsed) {
  39907. skipMarkerIfEqual(0x92);
  39908. }
  39909. while (queue.length > 0) {
  39910. var packetItem = queue.shift();
  39911. codeblock = packetItem.codeblock;
  39912. if (codeblock['data'] === undefined) {
  39913. codeblock.data = [];
  39914. }
  39915. codeblock.data.push({
  39916. data: data,
  39917. start: offset + position,
  39918. end: offset + position + packetItem.dataLength,
  39919. codingpasses: packetItem.codingpasses
  39920. });
  39921. position += packetItem.dataLength;
  39922. }
  39923. }
  39924. return position;
  39925. }
  39926. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39927. delta, mb, reversible, segmentationSymbolUsed) {
  39928. var x0 = subband.tbx0;
  39929. var y0 = subband.tby0;
  39930. var width = subband.tbx1 - subband.tbx0;
  39931. var codeblocks = subband.codeblocks;
  39932. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39933. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39934. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39935. var codeblock = codeblocks[i];
  39936. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39937. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39938. if (blockWidth === 0 || blockHeight === 0) {
  39939. continue;
  39940. }
  39941. if (codeblock['data'] === undefined) {
  39942. continue;
  39943. }
  39944. var bitModel, currentCodingpassType;
  39945. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39946. codeblock.zeroBitPlanes, mb);
  39947. currentCodingpassType = 2; // first bit plane starts from cleanup
  39948. // collect data
  39949. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39950. var j, jj, dataItem;
  39951. for (j = 0, jj = data.length; j < jj; j++) {
  39952. dataItem = data[j];
  39953. totalLength += dataItem.end - dataItem.start;
  39954. codingpasses += dataItem.codingpasses;
  39955. }
  39956. var encodedData = new Uint8Array(totalLength);
  39957. var position = 0;
  39958. for (j = 0, jj = data.length; j < jj; j++) {
  39959. dataItem = data[j];
  39960. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39961. encodedData.set(chunk, position);
  39962. position += chunk.length;
  39963. }
  39964. // decoding the item
  39965. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39966. bitModel.setDecoder(decoder);
  39967. for (j = 0; j < codingpasses; j++) {
  39968. switch (currentCodingpassType) {
  39969. case 0:
  39970. bitModel.runSignificancePropogationPass();
  39971. break;
  39972. case 1:
  39973. bitModel.runMagnitudeRefinementPass();
  39974. break;
  39975. case 2:
  39976. bitModel.runCleanupPass();
  39977. if (segmentationSymbolUsed) {
  39978. bitModel.checkSegmentationSymbol();
  39979. }
  39980. break;
  39981. }
  39982. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39983. }
  39984. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39985. var sign = bitModel.coefficentsSign;
  39986. var magnitude = bitModel.coefficentsMagnitude;
  39987. var bitsDecoded = bitModel.bitsDecoded;
  39988. var magnitudeCorrection = reversible ? 0 : 0.5;
  39989. var k, n, nb;
  39990. position = 0;
  39991. // Do the interleaving of Section F.3.3 here, so we do not need
  39992. // to copy later. LL level is not interleaved, just copied.
  39993. var interleave = (subband.type !== 'LL');
  39994. for (j = 0; j < blockHeight; j++) {
  39995. var row = (offset / width) | 0; // row in the non-interleaved subband
  39996. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  39997. for (k = 0; k < blockWidth; k++) {
  39998. n = magnitude[position];
  39999. if (n !== 0) {
  40000. n = (n + magnitudeCorrection) * delta;
  40001. if (sign[position] !== 0) {
  40002. n = -n;
  40003. }
  40004. nb = bitsDecoded[position];
  40005. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  40006. if (reversible && (nb >= mb)) {
  40007. coefficients[pos] = n;
  40008. } else {
  40009. coefficients[pos] = n * (1 << (mb - nb));
  40010. }
  40011. }
  40012. offset++;
  40013. position++;
  40014. }
  40015. offset += width - blockWidth;
  40016. }
  40017. }
  40018. }
  40019. function transformTile(context, tile, c) {
  40020. var component = tile.components[c];
  40021. var codingStyleParameters = component.codingStyleParameters;
  40022. var quantizationParameters = component.quantizationParameters;
  40023. var decompositionLevelsCount =
  40024. codingStyleParameters.decompositionLevelsCount;
  40025. var spqcds = quantizationParameters.SPqcds;
  40026. var scalarExpounded = quantizationParameters.scalarExpounded;
  40027. var guardBits = quantizationParameters.guardBits;
  40028. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40029. var precision = context.components[c].precision;
  40030. var reversible = codingStyleParameters.reversibleTransformation;
  40031. var transform = (reversible ? new ReversibleTransform() :
  40032. new IrreversibleTransform());
  40033. var subbandCoefficients = [];
  40034. var b = 0;
  40035. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40036. var resolution = component.resolutions[i];
  40037. var width = resolution.trx1 - resolution.trx0;
  40038. var height = resolution.try1 - resolution.try0;
  40039. // Allocate space for the whole sublevel.
  40040. var coefficients = new Float32Array(width * height);
  40041. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40042. var mu, epsilon;
  40043. if (!scalarExpounded) {
  40044. // formula E-5
  40045. mu = spqcds[0].mu;
  40046. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40047. } else {
  40048. mu = spqcds[b].mu;
  40049. epsilon = spqcds[b].epsilon;
  40050. b++;
  40051. }
  40052. var subband = resolution.subbands[j];
  40053. var gainLog2 = SubbandsGainLog2[subband.type];
  40054. // calulate quantization coefficient (Section E.1.1.1)
  40055. var delta = (reversible ? 1 :
  40056. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40057. var mb = (guardBits + epsilon - 1);
  40058. // In the first resolution level, copyCoefficients will fill the
  40059. // whole array with coefficients. In the succeding passes,
  40060. // copyCoefficients will consecutively fill in the values that belong
  40061. // to the interleaved positions of the HL, LH, and HH coefficients.
  40062. // The LL coefficients will then be interleaved in Transform.iterate().
  40063. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40064. reversible, segmentationSymbolUsed);
  40065. }
  40066. subbandCoefficients.push({
  40067. width: width,
  40068. height: height,
  40069. items: coefficients
  40070. });
  40071. }
  40072. var result = transform.calculate(subbandCoefficients,
  40073. component.tcx0, component.tcy0);
  40074. return {
  40075. left: component.tcx0,
  40076. top: component.tcy0,
  40077. width: result.width,
  40078. height: result.height,
  40079. items: result.items
  40080. };
  40081. }
  40082. function transformComponents(context) {
  40083. var siz = context.SIZ;
  40084. var components = context.components;
  40085. var componentsCount = siz.Csiz;
  40086. var resultImages = [];
  40087. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40088. var tile = context.tiles[i];
  40089. var transformedTiles = [];
  40090. var c;
  40091. for (c = 0; c < componentsCount; c++) {
  40092. transformedTiles[c] = transformTile(context, tile, c);
  40093. }
  40094. var tile0 = transformedTiles[0];
  40095. var out = new Uint8Array(tile0.items.length * componentsCount);
  40096. var result = {
  40097. left: tile0.left,
  40098. top: tile0.top,
  40099. width: tile0.width,
  40100. height: tile0.height,
  40101. items: out
  40102. };
  40103. // Section G.2.2 Inverse multi component transform
  40104. var shift, offset, max, min, maxK;
  40105. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40106. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40107. var fourComponents = componentsCount === 4;
  40108. var y0items = transformedTiles[0].items;
  40109. var y1items = transformedTiles[1].items;
  40110. var y2items = transformedTiles[2].items;
  40111. var y3items = fourComponents ? transformedTiles[3].items : null;
  40112. // HACK: The multiple component transform formulas below assume that
  40113. // all components have the same precision. With this in mind, we
  40114. // compute shift and offset only once.
  40115. shift = components[0].precision - 8;
  40116. offset = (128 << shift) + 0.5;
  40117. max = 255 * (1 << shift);
  40118. maxK = max * 0.5;
  40119. min = -maxK;
  40120. var component0 = tile.components[0];
  40121. var alpha01 = componentsCount - 3;
  40122. jj = y0items.length;
  40123. if (!component0.codingStyleParameters.reversibleTransformation) {
  40124. // inverse irreversible multiple component transform
  40125. for (j = 0; j < jj; j++, pos += alpha01) {
  40126. y0 = y0items[j] + offset;
  40127. y1 = y1items[j];
  40128. y2 = y2items[j];
  40129. r = y0 + 1.402 * y2;
  40130. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40131. b = y0 + 1.772 * y1;
  40132. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40133. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40134. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40135. }
  40136. } else {
  40137. // inverse reversible multiple component transform
  40138. for (j = 0; j < jj; j++, pos += alpha01) {
  40139. y0 = y0items[j] + offset;
  40140. y1 = y1items[j];
  40141. y2 = y2items[j];
  40142. g = y0 - ((y2 + y1) >> 2);
  40143. r = g + y2;
  40144. b = g + y1;
  40145. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40146. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40147. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40148. }
  40149. }
  40150. if (fourComponents) {
  40151. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40152. k = y3items[j];
  40153. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40154. }
  40155. }
  40156. } else { // no multi-component transform
  40157. for (c = 0; c < componentsCount; c++) {
  40158. var items = transformedTiles[c].items;
  40159. shift = components[c].precision - 8;
  40160. offset = (128 << shift) + 0.5;
  40161. max = (127.5 * (1 << shift));
  40162. min = -max;
  40163. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40164. val = items[j];
  40165. out[pos] = val <= min ? 0 :
  40166. val >= max ? 255 : (val + offset) >> shift;
  40167. pos += componentsCount;
  40168. }
  40169. }
  40170. }
  40171. resultImages.push(result);
  40172. }
  40173. return resultImages;
  40174. }
  40175. function initializeTile(context, tileIndex) {
  40176. var siz = context.SIZ;
  40177. var componentsCount = siz.Csiz;
  40178. var tile = context.tiles[tileIndex];
  40179. for (var c = 0; c < componentsCount; c++) {
  40180. var component = tile.components[c];
  40181. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40182. context.currentTile.QCC[c] : context.currentTile.QCD);
  40183. component.quantizationParameters = qcdOrQcc;
  40184. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40185. context.currentTile.COC[c] : context.currentTile.COD);
  40186. component.codingStyleParameters = codOrCoc;
  40187. }
  40188. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40189. }
  40190. // Section B.10.2 Tag trees
  40191. var TagTree = (function TagTreeClosure() {
  40192. function TagTree(width, height) {
  40193. var levelsLength = log2(Math.max(width, height)) + 1;
  40194. this.levels = [];
  40195. for (var i = 0; i < levelsLength; i++) {
  40196. var level = {
  40197. width: width,
  40198. height: height,
  40199. items: []
  40200. };
  40201. this.levels.push(level);
  40202. width = Math.ceil(width / 2);
  40203. height = Math.ceil(height / 2);
  40204. }
  40205. }
  40206. TagTree.prototype = {
  40207. reset: function TagTree_reset(i, j) {
  40208. var currentLevel = 0, value = 0, level;
  40209. while (currentLevel < this.levels.length) {
  40210. level = this.levels[currentLevel];
  40211. var index = i + j * level.width;
  40212. if (level.items[index] !== undefined) {
  40213. value = level.items[index];
  40214. break;
  40215. }
  40216. level.index = index;
  40217. i >>= 1;
  40218. j >>= 1;
  40219. currentLevel++;
  40220. }
  40221. currentLevel--;
  40222. level = this.levels[currentLevel];
  40223. level.items[level.index] = value;
  40224. this.currentLevel = currentLevel;
  40225. delete this.value;
  40226. },
  40227. incrementValue: function TagTree_incrementValue() {
  40228. var level = this.levels[this.currentLevel];
  40229. level.items[level.index]++;
  40230. },
  40231. nextLevel: function TagTree_nextLevel() {
  40232. var currentLevel = this.currentLevel;
  40233. var level = this.levels[currentLevel];
  40234. var value = level.items[level.index];
  40235. currentLevel--;
  40236. if (currentLevel < 0) {
  40237. this.value = value;
  40238. return false;
  40239. }
  40240. this.currentLevel = currentLevel;
  40241. level = this.levels[currentLevel];
  40242. level.items[level.index] = value;
  40243. return true;
  40244. }
  40245. };
  40246. return TagTree;
  40247. })();
  40248. var InclusionTree = (function InclusionTreeClosure() {
  40249. function InclusionTree(width, height, defaultValue) {
  40250. var levelsLength = log2(Math.max(width, height)) + 1;
  40251. this.levels = [];
  40252. for (var i = 0; i < levelsLength; i++) {
  40253. var items = new Uint8Array(width * height);
  40254. for (var j = 0, jj = items.length; j < jj; j++) {
  40255. items[j] = defaultValue;
  40256. }
  40257. var level = {
  40258. width: width,
  40259. height: height,
  40260. items: items
  40261. };
  40262. this.levels.push(level);
  40263. width = Math.ceil(width / 2);
  40264. height = Math.ceil(height / 2);
  40265. }
  40266. }
  40267. InclusionTree.prototype = {
  40268. reset: function InclusionTree_reset(i, j, stopValue) {
  40269. var currentLevel = 0;
  40270. while (currentLevel < this.levels.length) {
  40271. var level = this.levels[currentLevel];
  40272. var index = i + j * level.width;
  40273. level.index = index;
  40274. var value = level.items[index];
  40275. if (value === 0xFF) {
  40276. break;
  40277. }
  40278. if (value > stopValue) {
  40279. this.currentLevel = currentLevel;
  40280. // already know about this one, propagating the value to top levels
  40281. this.propagateValues();
  40282. return false;
  40283. }
  40284. i >>= 1;
  40285. j >>= 1;
  40286. currentLevel++;
  40287. }
  40288. this.currentLevel = currentLevel - 1;
  40289. return true;
  40290. },
  40291. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40292. var level = this.levels[this.currentLevel];
  40293. level.items[level.index] = stopValue + 1;
  40294. this.propagateValues();
  40295. },
  40296. propagateValues: function InclusionTree_propagateValues() {
  40297. var levelIndex = this.currentLevel;
  40298. var level = this.levels[levelIndex];
  40299. var currentValue = level.items[level.index];
  40300. while (--levelIndex >= 0) {
  40301. level = this.levels[levelIndex];
  40302. level.items[level.index] = currentValue;
  40303. }
  40304. },
  40305. nextLevel: function InclusionTree_nextLevel() {
  40306. var currentLevel = this.currentLevel;
  40307. var level = this.levels[currentLevel];
  40308. var value = level.items[level.index];
  40309. level.items[level.index] = 0xFF;
  40310. currentLevel--;
  40311. if (currentLevel < 0) {
  40312. return false;
  40313. }
  40314. this.currentLevel = currentLevel;
  40315. level = this.levels[currentLevel];
  40316. level.items[level.index] = value;
  40317. return true;
  40318. }
  40319. };
  40320. return InclusionTree;
  40321. })();
  40322. // Section D. Coefficient bit modeling
  40323. var BitModel = (function BitModelClosure() {
  40324. var UNIFORM_CONTEXT = 17;
  40325. var RUNLENGTH_CONTEXT = 18;
  40326. // Table D-1
  40327. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40328. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40329. var LLAndLHContextsLabel = new Uint8Array([
  40330. 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,
  40331. 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,
  40332. 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
  40333. ]);
  40334. var HLContextLabel = new Uint8Array([
  40335. 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,
  40336. 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,
  40337. 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
  40338. ]);
  40339. var HHContextLabel = new Uint8Array([
  40340. 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,
  40341. 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,
  40342. 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
  40343. ]);
  40344. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40345. this.width = width;
  40346. this.height = height;
  40347. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40348. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40349. var coefficientCount = width * height;
  40350. // coefficients outside the encoding region treated as insignificant
  40351. // add border state cells for significanceState
  40352. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40353. this.coefficentsSign = new Uint8Array(coefficientCount);
  40354. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40355. mb > 6 ? new Uint16Array(coefficientCount) :
  40356. new Uint8Array(coefficientCount);
  40357. this.processingFlags = new Uint8Array(coefficientCount);
  40358. var bitsDecoded = new Uint8Array(coefficientCount);
  40359. if (zeroBitPlanes !== 0) {
  40360. for (var i = 0; i < coefficientCount; i++) {
  40361. bitsDecoded[i] = zeroBitPlanes;
  40362. }
  40363. }
  40364. this.bitsDecoded = bitsDecoded;
  40365. this.reset();
  40366. }
  40367. BitModel.prototype = {
  40368. setDecoder: function BitModel_setDecoder(decoder) {
  40369. this.decoder = decoder;
  40370. },
  40371. reset: function BitModel_reset() {
  40372. // We have 17 contexts that are accessed via context labels,
  40373. // plus the uniform and runlength context.
  40374. this.contexts = new Int8Array(19);
  40375. // Contexts are packed into 1 byte:
  40376. // highest 7 bits carry the index, lowest bit carries mps
  40377. this.contexts[0] = (4 << 1) | 0;
  40378. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40379. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40380. },
  40381. setNeighborsSignificance:
  40382. function BitModel_setNeighborsSignificance(row, column, index) {
  40383. var neighborsSignificance = this.neighborsSignificance;
  40384. var width = this.width, height = this.height;
  40385. var left = (column > 0);
  40386. var right = (column + 1 < width);
  40387. var i;
  40388. if (row > 0) {
  40389. i = index - width;
  40390. if (left) {
  40391. neighborsSignificance[i - 1] += 0x10;
  40392. }
  40393. if (right) {
  40394. neighborsSignificance[i + 1] += 0x10;
  40395. }
  40396. neighborsSignificance[i] += 0x04;
  40397. }
  40398. if (row + 1 < height) {
  40399. i = index + width;
  40400. if (left) {
  40401. neighborsSignificance[i - 1] += 0x10;
  40402. }
  40403. if (right) {
  40404. neighborsSignificance[i + 1] += 0x10;
  40405. }
  40406. neighborsSignificance[i] += 0x04;
  40407. }
  40408. if (left) {
  40409. neighborsSignificance[index - 1] += 0x01;
  40410. }
  40411. if (right) {
  40412. neighborsSignificance[index + 1] += 0x01;
  40413. }
  40414. neighborsSignificance[index] |= 0x80;
  40415. },
  40416. runSignificancePropogationPass:
  40417. function BitModel_runSignificancePropogationPass() {
  40418. var decoder = this.decoder;
  40419. var width = this.width, height = this.height;
  40420. var coefficentsMagnitude = this.coefficentsMagnitude;
  40421. var coefficentsSign = this.coefficentsSign;
  40422. var neighborsSignificance = this.neighborsSignificance;
  40423. var processingFlags = this.processingFlags;
  40424. var contexts = this.contexts;
  40425. var labels = this.contextLabelTable;
  40426. var bitsDecoded = this.bitsDecoded;
  40427. var processedInverseMask = ~1;
  40428. var processedMask = 1;
  40429. var firstMagnitudeBitMask = 2;
  40430. for (var i0 = 0; i0 < height; i0 += 4) {
  40431. for (var j = 0; j < width; j++) {
  40432. var index = i0 * width + j;
  40433. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40434. var i = i0 + i1;
  40435. if (i >= height) {
  40436. break;
  40437. }
  40438. // clear processed flag first
  40439. processingFlags[index] &= processedInverseMask;
  40440. if (coefficentsMagnitude[index] ||
  40441. !neighborsSignificance[index]) {
  40442. continue;
  40443. }
  40444. var contextLabel = labels[neighborsSignificance[index]];
  40445. var decision = decoder.readBit(contexts, contextLabel);
  40446. if (decision) {
  40447. var sign = this.decodeSignBit(i, j, index);
  40448. coefficentsSign[index] = sign;
  40449. coefficentsMagnitude[index] = 1;
  40450. this.setNeighborsSignificance(i, j, index);
  40451. processingFlags[index] |= firstMagnitudeBitMask;
  40452. }
  40453. bitsDecoded[index]++;
  40454. processingFlags[index] |= processedMask;
  40455. }
  40456. }
  40457. }
  40458. },
  40459. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40460. var width = this.width, height = this.height;
  40461. var coefficentsMagnitude = this.coefficentsMagnitude;
  40462. var coefficentsSign = this.coefficentsSign;
  40463. var contribution, sign0, sign1, significance1;
  40464. var contextLabel, decoded;
  40465. // calculate horizontal contribution
  40466. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40467. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40468. sign1 = coefficentsSign[index + 1];
  40469. if (significance1) {
  40470. sign0 = coefficentsSign[index - 1];
  40471. contribution = 1 - sign1 - sign0;
  40472. } else {
  40473. contribution = 1 - sign1 - sign1;
  40474. }
  40475. } else if (significance1) {
  40476. sign0 = coefficentsSign[index - 1];
  40477. contribution = 1 - sign0 - sign0;
  40478. } else {
  40479. contribution = 0;
  40480. }
  40481. var horizontalContribution = 3 * contribution;
  40482. // calculate vertical contribution and combine with the horizontal
  40483. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40484. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40485. sign1 = coefficentsSign[index + width];
  40486. if (significance1) {
  40487. sign0 = coefficentsSign[index - width];
  40488. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40489. } else {
  40490. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40491. }
  40492. } else if (significance1) {
  40493. sign0 = coefficentsSign[index - width];
  40494. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40495. } else {
  40496. contribution = horizontalContribution;
  40497. }
  40498. if (contribution >= 0) {
  40499. contextLabel = 9 + contribution;
  40500. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40501. } else {
  40502. contextLabel = 9 - contribution;
  40503. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40504. }
  40505. return decoded;
  40506. },
  40507. runMagnitudeRefinementPass:
  40508. function BitModel_runMagnitudeRefinementPass() {
  40509. var decoder = this.decoder;
  40510. var width = this.width, height = this.height;
  40511. var coefficentsMagnitude = this.coefficentsMagnitude;
  40512. var neighborsSignificance = this.neighborsSignificance;
  40513. var contexts = this.contexts;
  40514. var bitsDecoded = this.bitsDecoded;
  40515. var processingFlags = this.processingFlags;
  40516. var processedMask = 1;
  40517. var firstMagnitudeBitMask = 2;
  40518. var length = width * height;
  40519. var width4 = width * 4;
  40520. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40521. indexNext = Math.min(length, index0 + width4);
  40522. for (var j = 0; j < width; j++) {
  40523. for (var index = index0 + j; index < indexNext; index += width) {
  40524. // significant but not those that have just become
  40525. if (!coefficentsMagnitude[index] ||
  40526. (processingFlags[index] & processedMask) !== 0) {
  40527. continue;
  40528. }
  40529. var contextLabel = 16;
  40530. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40531. processingFlags[index] ^= firstMagnitudeBitMask;
  40532. // first refinement
  40533. var significance = neighborsSignificance[index] & 127;
  40534. contextLabel = significance === 0 ? 15 : 14;
  40535. }
  40536. var bit = decoder.readBit(contexts, contextLabel);
  40537. coefficentsMagnitude[index] =
  40538. (coefficentsMagnitude[index] << 1) | bit;
  40539. bitsDecoded[index]++;
  40540. processingFlags[index] |= processedMask;
  40541. }
  40542. }
  40543. }
  40544. },
  40545. runCleanupPass: function BitModel_runCleanupPass() {
  40546. var decoder = this.decoder;
  40547. var width = this.width, height = this.height;
  40548. var neighborsSignificance = this.neighborsSignificance;
  40549. var coefficentsMagnitude = this.coefficentsMagnitude;
  40550. var coefficentsSign = this.coefficentsSign;
  40551. var contexts = this.contexts;
  40552. var labels = this.contextLabelTable;
  40553. var bitsDecoded = this.bitsDecoded;
  40554. var processingFlags = this.processingFlags;
  40555. var processedMask = 1;
  40556. var firstMagnitudeBitMask = 2;
  40557. var oneRowDown = width;
  40558. var twoRowsDown = width * 2;
  40559. var threeRowsDown = width * 3;
  40560. var iNext;
  40561. for (var i0 = 0; i0 < height; i0 = iNext) {
  40562. iNext = Math.min(i0 + 4, height);
  40563. var indexBase = i0 * width;
  40564. var checkAllEmpty = i0 + 3 < height;
  40565. for (var j = 0; j < width; j++) {
  40566. var index0 = indexBase + j;
  40567. // using the property: labels[neighborsSignificance[index]] === 0
  40568. // when neighborsSignificance[index] === 0
  40569. var allEmpty = (checkAllEmpty &&
  40570. processingFlags[index0] === 0 &&
  40571. processingFlags[index0 + oneRowDown] === 0 &&
  40572. processingFlags[index0 + twoRowsDown] === 0 &&
  40573. processingFlags[index0 + threeRowsDown] === 0 &&
  40574. neighborsSignificance[index0] === 0 &&
  40575. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40576. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40577. neighborsSignificance[index0 + threeRowsDown] === 0);
  40578. var i1 = 0, index = index0;
  40579. var i = i0, sign;
  40580. if (allEmpty) {
  40581. var hasSignificantCoefficent =
  40582. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40583. if (!hasSignificantCoefficent) {
  40584. bitsDecoded[index0]++;
  40585. bitsDecoded[index0 + oneRowDown]++;
  40586. bitsDecoded[index0 + twoRowsDown]++;
  40587. bitsDecoded[index0 + threeRowsDown]++;
  40588. continue; // next column
  40589. }
  40590. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40591. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40592. if (i1 !== 0) {
  40593. i = i0 + i1;
  40594. index += i1 * width;
  40595. }
  40596. sign = this.decodeSignBit(i, j, index);
  40597. coefficentsSign[index] = sign;
  40598. coefficentsMagnitude[index] = 1;
  40599. this.setNeighborsSignificance(i, j, index);
  40600. processingFlags[index] |= firstMagnitudeBitMask;
  40601. index = index0;
  40602. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40603. bitsDecoded[index]++;
  40604. }
  40605. i1++;
  40606. }
  40607. for (i = i0 + i1; i < iNext; i++, index += width) {
  40608. if (coefficentsMagnitude[index] ||
  40609. (processingFlags[index] & processedMask) !== 0) {
  40610. continue;
  40611. }
  40612. var contextLabel = labels[neighborsSignificance[index]];
  40613. var decision = decoder.readBit(contexts, contextLabel);
  40614. if (decision === 1) {
  40615. sign = this.decodeSignBit(i, j, index);
  40616. coefficentsSign[index] = sign;
  40617. coefficentsMagnitude[index] = 1;
  40618. this.setNeighborsSignificance(i, j, index);
  40619. processingFlags[index] |= firstMagnitudeBitMask;
  40620. }
  40621. bitsDecoded[index]++;
  40622. }
  40623. }
  40624. }
  40625. },
  40626. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40627. var decoder = this.decoder;
  40628. var contexts = this.contexts;
  40629. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40630. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40631. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40632. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40633. if (symbol !== 0xA) {
  40634. throw new Error('JPX Error: Invalid segmentation symbol');
  40635. }
  40636. }
  40637. };
  40638. return BitModel;
  40639. })();
  40640. // Section F, Discrete wavelet transformation
  40641. var Transform = (function TransformClosure() {
  40642. function Transform() {}
  40643. Transform.prototype.calculate =
  40644. function transformCalculate(subbands, u0, v0) {
  40645. var ll = subbands[0];
  40646. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40647. ll = this.iterate(ll, subbands[i], u0, v0);
  40648. }
  40649. return ll;
  40650. };
  40651. Transform.prototype.extend = function extend(buffer, offset, size) {
  40652. // Section F.3.7 extending... using max extension of 4
  40653. var i1 = offset - 1, j1 = offset + 1;
  40654. var i2 = offset + size - 2, j2 = offset + size;
  40655. buffer[i1--] = buffer[j1++];
  40656. buffer[j2++] = buffer[i2--];
  40657. buffer[i1--] = buffer[j1++];
  40658. buffer[j2++] = buffer[i2--];
  40659. buffer[i1--] = buffer[j1++];
  40660. buffer[j2++] = buffer[i2--];
  40661. buffer[i1] = buffer[j1];
  40662. buffer[j2] = buffer[i2];
  40663. };
  40664. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40665. u0, v0) {
  40666. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40667. var width = hl_lh_hh.width;
  40668. var height = hl_lh_hh.height;
  40669. var items = hl_lh_hh.items;
  40670. var i, j, k, l, u, v;
  40671. // Interleave LL according to Section F.3.3
  40672. for (k = 0, i = 0; i < llHeight; i++) {
  40673. l = i * 2 * width;
  40674. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40675. items[l] = llItems[k];
  40676. }
  40677. }
  40678. // The LL band is not needed anymore.
  40679. llItems = ll.items = null;
  40680. var bufferPadding = 4;
  40681. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40682. // Section F.3.4 HOR_SR
  40683. if (width === 1) {
  40684. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40685. if ((u0 & 1) !== 0) {
  40686. for (v = 0, k = 0; v < height; v++, k += width) {
  40687. items[k] *= 0.5;
  40688. }
  40689. }
  40690. } else {
  40691. for (v = 0, k = 0; v < height; v++, k += width) {
  40692. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40693. this.extend(rowBuffer, bufferPadding, width);
  40694. this.filter(rowBuffer, bufferPadding, width);
  40695. items.set(
  40696. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40697. k);
  40698. }
  40699. }
  40700. // Accesses to the items array can take long, because it may not fit into
  40701. // CPU cache and has to be fetched from main memory. Since subsequent
  40702. // accesses to the items array are not local when reading columns, we
  40703. // have a cache miss every time. To reduce cache misses, get up to
  40704. // 'numBuffers' items at a time and store them into the individual
  40705. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40706. var numBuffers = 16;
  40707. var colBuffers = [];
  40708. for (i = 0; i < numBuffers; i++) {
  40709. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40710. }
  40711. var b, currentBuffer = 0;
  40712. ll = bufferPadding + height;
  40713. // Section F.3.5 VER_SR
  40714. if (height === 1) {
  40715. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40716. if ((v0 & 1) !== 0) {
  40717. for (u = 0; u < width; u++) {
  40718. items[u] *= 0.5;
  40719. }
  40720. }
  40721. } else {
  40722. for (u = 0; u < width; u++) {
  40723. // if we ran out of buffers, copy several image columns at once
  40724. if (currentBuffer === 0) {
  40725. numBuffers = Math.min(width - u, numBuffers);
  40726. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40727. for (b = 0; b < numBuffers; b++) {
  40728. colBuffers[b][l] = items[k + b];
  40729. }
  40730. }
  40731. currentBuffer = numBuffers;
  40732. }
  40733. currentBuffer--;
  40734. var buffer = colBuffers[currentBuffer];
  40735. this.extend(buffer, bufferPadding, height);
  40736. this.filter(buffer, bufferPadding, height);
  40737. // If this is last buffer in this group of buffers, flush all buffers.
  40738. if (currentBuffer === 0) {
  40739. k = u - numBuffers + 1;
  40740. for (l = bufferPadding; l < ll; k += width, l++) {
  40741. for (b = 0; b < numBuffers; b++) {
  40742. items[k + b] = colBuffers[b][l];
  40743. }
  40744. }
  40745. }
  40746. }
  40747. }
  40748. return {
  40749. width: width,
  40750. height: height,
  40751. items: items
  40752. };
  40753. };
  40754. return Transform;
  40755. })();
  40756. // Section 3.8.2 Irreversible 9-7 filter
  40757. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40758. function IrreversibleTransform() {
  40759. Transform.call(this);
  40760. }
  40761. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40762. IrreversibleTransform.prototype.filter =
  40763. function irreversibleTransformFilter(x, offset, length) {
  40764. var len = length >> 1;
  40765. offset = offset | 0;
  40766. var j, n, current, next;
  40767. var alpha = -1.586134342059924;
  40768. var beta = -0.052980118572961;
  40769. var gamma = 0.882911075530934;
  40770. var delta = 0.443506852043971;
  40771. var K = 1.230174104914001;
  40772. var K_ = 1 / K;
  40773. // step 1 is combined with step 3
  40774. // step 2
  40775. j = offset - 3;
  40776. for (n = len + 4; n--; j += 2) {
  40777. x[j] *= K_;
  40778. }
  40779. // step 1 & 3
  40780. j = offset - 2;
  40781. current = delta * x[j -1];
  40782. for (n = len + 3; n--; j += 2) {
  40783. next = delta * x[j + 1];
  40784. x[j] = K * x[j] - current - next;
  40785. if (n--) {
  40786. j += 2;
  40787. current = delta * x[j + 1];
  40788. x[j] = K * x[j] - current - next;
  40789. } else {
  40790. break;
  40791. }
  40792. }
  40793. // step 4
  40794. j = offset - 1;
  40795. current = gamma * x[j - 1];
  40796. for (n = len + 2; n--; j += 2) {
  40797. next = gamma * x[j + 1];
  40798. x[j] -= current + next;
  40799. if (n--) {
  40800. j += 2;
  40801. current = gamma * x[j + 1];
  40802. x[j] -= current + next;
  40803. } else {
  40804. break;
  40805. }
  40806. }
  40807. // step 5
  40808. j = offset;
  40809. current = beta * x[j - 1];
  40810. for (n = len + 1; n--; j += 2) {
  40811. next = beta * x[j + 1];
  40812. x[j] -= current + next;
  40813. if (n--) {
  40814. j += 2;
  40815. current = beta * x[j + 1];
  40816. x[j] -= current + next;
  40817. } else {
  40818. break;
  40819. }
  40820. }
  40821. // step 6
  40822. if (len !== 0) {
  40823. j = offset + 1;
  40824. current = alpha * x[j - 1];
  40825. for (n = len; n--; j += 2) {
  40826. next = alpha * x[j + 1];
  40827. x[j] -= current + next;
  40828. if (n--) {
  40829. j += 2;
  40830. current = alpha * x[j + 1];
  40831. x[j] -= current + next;
  40832. } else {
  40833. break;
  40834. }
  40835. }
  40836. }
  40837. };
  40838. return IrreversibleTransform;
  40839. })();
  40840. // Section 3.8.1 Reversible 5-3 filter
  40841. var ReversibleTransform = (function ReversibleTransformClosure() {
  40842. function ReversibleTransform() {
  40843. Transform.call(this);
  40844. }
  40845. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40846. ReversibleTransform.prototype.filter =
  40847. function reversibleTransformFilter(x, offset, length) {
  40848. var len = length >> 1;
  40849. offset = offset | 0;
  40850. var j, n;
  40851. for (j = offset, n = len + 1; n--; j += 2) {
  40852. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40853. }
  40854. for (j = offset + 1, n = len; n--; j += 2) {
  40855. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40856. }
  40857. };
  40858. return ReversibleTransform;
  40859. })();
  40860. return JpxImage;
  40861. })();
  40862. var Jbig2Image = (function Jbig2ImageClosure() {
  40863. // Utility data structures
  40864. function ContextCache() {}
  40865. ContextCache.prototype = {
  40866. getContexts: function(id) {
  40867. if (id in this) {
  40868. return this[id];
  40869. }
  40870. return (this[id] = new Int8Array(1 << 16));
  40871. }
  40872. };
  40873. function DecodingContext(data, start, end) {
  40874. this.data = data;
  40875. this.start = start;
  40876. this.end = end;
  40877. }
  40878. DecodingContext.prototype = {
  40879. get decoder() {
  40880. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40881. return shadow(this, 'decoder', decoder);
  40882. },
  40883. get contextCache() {
  40884. var cache = new ContextCache();
  40885. return shadow(this, 'contextCache', cache);
  40886. }
  40887. };
  40888. // Annex A. Arithmetic Integer Decoding Procedure
  40889. // A.2 Procedure for decoding values
  40890. function decodeInteger(contextCache, procedure, decoder) {
  40891. var contexts = contextCache.getContexts(procedure);
  40892. var prev = 1;
  40893. function readBits(length) {
  40894. var v = 0;
  40895. for (var i = 0; i < length; i++) {
  40896. var bit = decoder.readBit(contexts, prev);
  40897. prev = (prev < 256 ? (prev << 1) | bit :
  40898. (((prev << 1) | bit) & 511) | 256);
  40899. v = (v << 1) | bit;
  40900. }
  40901. return v >>> 0;
  40902. }
  40903. var sign = readBits(1);
  40904. var value = readBits(1) ?
  40905. (readBits(1) ?
  40906. (readBits(1) ?
  40907. (readBits(1) ?
  40908. (readBits(1) ?
  40909. (readBits(32) + 4436) :
  40910. readBits(12) + 340) :
  40911. readBits(8) + 84) :
  40912. readBits(6) + 20) :
  40913. readBits(4) + 4) :
  40914. readBits(2);
  40915. return (sign === 0 ? value : (value > 0 ? -value : null));
  40916. }
  40917. // A.3 The IAID decoding procedure
  40918. function decodeIAID(contextCache, decoder, codeLength) {
  40919. var contexts = contextCache.getContexts('IAID');
  40920. var prev = 1;
  40921. for (var i = 0; i < codeLength; i++) {
  40922. var bit = decoder.readBit(contexts, prev);
  40923. prev = (prev << 1) | bit;
  40924. }
  40925. if (codeLength < 31) {
  40926. return prev & ((1 << codeLength) - 1);
  40927. }
  40928. return prev & 0x7FFFFFFF;
  40929. }
  40930. // 7.3 Segment types
  40931. var SegmentTypes = [
  40932. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40933. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40934. null, null, null, null, null, 'patternDictionary', null, null, null,
  40935. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40936. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40937. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40938. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40939. 'IntermediateGenericRefinementRegion', null,
  40940. 'ImmediateGenericRefinementRegion',
  40941. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40942. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40943. 'Tables', null, null, null, null, null, null, null, null,
  40944. 'Extension'
  40945. ];
  40946. var CodingTemplates = [
  40947. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40948. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40949. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40950. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40951. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40952. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40953. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40954. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40955. {x: -1, y: 0}],
  40956. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40957. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40958. ];
  40959. var RefinementTemplates = [
  40960. {
  40961. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40962. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40963. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40964. },
  40965. {
  40966. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40967. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40968. {x: 0, y: 1}, {x: 1, y: 1}]
  40969. }
  40970. ];
  40971. // See 6.2.5.7 Decoding the bitmap.
  40972. var ReusedContexts = [
  40973. 0x9B25, // 10011 0110010 0101
  40974. 0x0795, // 0011 110010 101
  40975. 0x00E5, // 001 11001 01
  40976. 0x0195 // 011001 0101
  40977. ];
  40978. var RefinementReusedContexts = [
  40979. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40980. 0x0008 // '0000' + '001000'
  40981. ];
  40982. function decodeBitmapTemplate0(width, height, decodingContext) {
  40983. var decoder = decodingContext.decoder;
  40984. var contexts = decodingContext.contextCache.getContexts('GB');
  40985. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40986. // ...ooooo....
  40987. // ..ooooooo... Context template for current pixel (X)
  40988. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40989. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40990. for (i = 0; i < height; i++) {
  40991. row = bitmap[i] = new Uint8Array(width);
  40992. row1 = (i < 1) ? row : bitmap[i - 1];
  40993. row2 = (i < 2) ? row : bitmap[i - 2];
  40994. // At the beginning of each row:
  40995. // Fill contextLabel with pixels that are above/right of (X)
  40996. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  40997. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  40998. (row1[3] << 4);
  40999. for (j = 0; j < width; j++) {
  41000. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  41001. // At each pixel: Clear contextLabel pixels that are shifted
  41002. // out of the context, then add new ones.
  41003. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  41004. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  41005. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  41006. }
  41007. }
  41008. return bitmap;
  41009. }
  41010. // 6.2 Generic Region Decoding Procedure
  41011. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  41012. decodingContext) {
  41013. if (mmr) {
  41014. error('JBIG2 error: MMR encoding is not supported');
  41015. }
  41016. // Use optimized version for the most common case
  41017. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41018. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41019. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41020. return decodeBitmapTemplate0(width, height, decodingContext);
  41021. }
  41022. var useskip = !!skip;
  41023. var template = CodingTemplates[templateIndex].concat(at);
  41024. // Sorting is non-standard, and it is not required. But sorting increases
  41025. // the number of template bits that can be reused from the previous
  41026. // contextLabel in the main loop.
  41027. template.sort(function (a, b) {
  41028. return (a.y - b.y) || (a.x - b.x);
  41029. });
  41030. var templateLength = template.length;
  41031. var templateX = new Int8Array(templateLength);
  41032. var templateY = new Int8Array(templateLength);
  41033. var changingTemplateEntries = [];
  41034. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41035. var c, k;
  41036. for (k = 0; k < templateLength; k++) {
  41037. templateX[k] = template[k].x;
  41038. templateY[k] = template[k].y;
  41039. minX = Math.min(minX, template[k].x);
  41040. maxX = Math.max(maxX, template[k].x);
  41041. minY = Math.min(minY, template[k].y);
  41042. // Check if the template pixel appears in two consecutive context labels,
  41043. // so it can be reused. Otherwise, we add it to the list of changing
  41044. // template entries.
  41045. if (k < templateLength - 1 &&
  41046. template[k].y === template[k + 1].y &&
  41047. template[k].x === template[k + 1].x - 1) {
  41048. reuseMask |= 1 << (templateLength - 1 - k);
  41049. } else {
  41050. changingTemplateEntries.push(k);
  41051. }
  41052. }
  41053. var changingEntriesLength = changingTemplateEntries.length;
  41054. var changingTemplateX = new Int8Array(changingEntriesLength);
  41055. var changingTemplateY = new Int8Array(changingEntriesLength);
  41056. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41057. for (c = 0; c < changingEntriesLength; c++) {
  41058. k = changingTemplateEntries[c];
  41059. changingTemplateX[c] = template[k].x;
  41060. changingTemplateY[c] = template[k].y;
  41061. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41062. }
  41063. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41064. var sbb_left = -minX;
  41065. var sbb_top = -minY;
  41066. var sbb_right = width - maxX;
  41067. var pseudoPixelContext = ReusedContexts[templateIndex];
  41068. var row = new Uint8Array(width);
  41069. var bitmap = [];
  41070. var decoder = decodingContext.decoder;
  41071. var contexts = decodingContext.contextCache.getContexts('GB');
  41072. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41073. for (var i = 0; i < height; i++) {
  41074. if (prediction) {
  41075. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41076. ltp ^= sltp;
  41077. if (ltp) {
  41078. bitmap.push(row); // duplicate previous row
  41079. continue;
  41080. }
  41081. }
  41082. row = new Uint8Array(row);
  41083. bitmap.push(row);
  41084. for (j = 0; j < width; j++) {
  41085. if (useskip && skip[i][j]) {
  41086. row[j] = 0;
  41087. continue;
  41088. }
  41089. // Are we in the middle of a scanline, so we can reuse contextLabel
  41090. // bits?
  41091. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41092. // If yes, we can just shift the bits that are reusable and only
  41093. // fetch the remaining ones.
  41094. contextLabel = (contextLabel << 1) & reuseMask;
  41095. for (k = 0; k < changingEntriesLength; k++) {
  41096. i0 = i + changingTemplateY[k];
  41097. j0 = j + changingTemplateX[k];
  41098. bit = bitmap[i0][j0];
  41099. if (bit) {
  41100. bit = changingTemplateBit[k];
  41101. contextLabel |= bit;
  41102. }
  41103. }
  41104. } else {
  41105. // compute the contextLabel from scratch
  41106. contextLabel = 0;
  41107. shift = templateLength - 1;
  41108. for (k = 0; k < templateLength; k++, shift--) {
  41109. j0 = j + templateX[k];
  41110. if (j0 >= 0 && j0 < width) {
  41111. i0 = i + templateY[k];
  41112. if (i0 >= 0) {
  41113. bit = bitmap[i0][j0];
  41114. if (bit) {
  41115. contextLabel |= bit << shift;
  41116. }
  41117. }
  41118. }
  41119. }
  41120. }
  41121. var pixel = decoder.readBit(contexts, contextLabel);
  41122. row[j] = pixel;
  41123. }
  41124. }
  41125. return bitmap;
  41126. }
  41127. // 6.3.2 Generic Refinement Region Decoding Procedure
  41128. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41129. offsetX, offsetY, prediction, at,
  41130. decodingContext) {
  41131. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41132. if (templateIndex === 0) {
  41133. codingTemplate = codingTemplate.concat([at[0]]);
  41134. }
  41135. var codingTemplateLength = codingTemplate.length;
  41136. var codingTemplateX = new Int32Array(codingTemplateLength);
  41137. var codingTemplateY = new Int32Array(codingTemplateLength);
  41138. var k;
  41139. for (k = 0; k < codingTemplateLength; k++) {
  41140. codingTemplateX[k] = codingTemplate[k].x;
  41141. codingTemplateY[k] = codingTemplate[k].y;
  41142. }
  41143. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41144. if (templateIndex === 0) {
  41145. referenceTemplate = referenceTemplate.concat([at[1]]);
  41146. }
  41147. var referenceTemplateLength = referenceTemplate.length;
  41148. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41149. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41150. for (k = 0; k < referenceTemplateLength; k++) {
  41151. referenceTemplateX[k] = referenceTemplate[k].x;
  41152. referenceTemplateY[k] = referenceTemplate[k].y;
  41153. }
  41154. var referenceWidth = referenceBitmap[0].length;
  41155. var referenceHeight = referenceBitmap.length;
  41156. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41157. var bitmap = [];
  41158. var decoder = decodingContext.decoder;
  41159. var contexts = decodingContext.contextCache.getContexts('GR');
  41160. var ltp = 0;
  41161. for (var i = 0; i < height; i++) {
  41162. if (prediction) {
  41163. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41164. ltp ^= sltp;
  41165. if (ltp) {
  41166. error('JBIG2 error: prediction is not supported');
  41167. }
  41168. }
  41169. var row = new Uint8Array(width);
  41170. bitmap.push(row);
  41171. for (var j = 0; j < width; j++) {
  41172. var i0, j0;
  41173. var contextLabel = 0;
  41174. for (k = 0; k < codingTemplateLength; k++) {
  41175. i0 = i + codingTemplateY[k];
  41176. j0 = j + codingTemplateX[k];
  41177. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41178. contextLabel <<= 1; // out of bound pixel
  41179. } else {
  41180. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41181. }
  41182. }
  41183. for (k = 0; k < referenceTemplateLength; k++) {
  41184. i0 = i + referenceTemplateY[k] + offsetY;
  41185. j0 = j + referenceTemplateX[k] + offsetX;
  41186. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41187. j0 >= referenceWidth) {
  41188. contextLabel <<= 1; // out of bound pixel
  41189. } else {
  41190. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41191. }
  41192. }
  41193. var pixel = decoder.readBit(contexts, contextLabel);
  41194. row[j] = pixel;
  41195. }
  41196. }
  41197. return bitmap;
  41198. }
  41199. // 6.5.5 Decoding the symbol dictionary
  41200. function decodeSymbolDictionary(huffman, refinement, symbols,
  41201. numberOfNewSymbols, numberOfExportedSymbols,
  41202. huffmanTables, templateIndex, at,
  41203. refinementTemplateIndex, refinementAt,
  41204. decodingContext) {
  41205. if (huffman) {
  41206. error('JBIG2 error: huffman is not supported');
  41207. }
  41208. var newSymbols = [];
  41209. var currentHeight = 0;
  41210. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41211. var decoder = decodingContext.decoder;
  41212. var contextCache = decodingContext.contextCache;
  41213. while (newSymbols.length < numberOfNewSymbols) {
  41214. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41215. currentHeight += deltaHeight;
  41216. var currentWidth = 0;
  41217. var totalWidth = 0;
  41218. while (true) {
  41219. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41220. if (deltaWidth === null) {
  41221. break; // OOB
  41222. }
  41223. currentWidth += deltaWidth;
  41224. totalWidth += currentWidth;
  41225. var bitmap;
  41226. if (refinement) {
  41227. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41228. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41229. if (numberOfInstances > 1) {
  41230. bitmap = decodeTextRegion(huffman, refinement,
  41231. currentWidth, currentHeight, 0,
  41232. numberOfInstances, 1, //strip size
  41233. symbols.concat(newSymbols),
  41234. symbolCodeLength,
  41235. 0, //transposed
  41236. 0, //ds offset
  41237. 1, //top left 7.4.3.1.1
  41238. 0, //OR operator
  41239. huffmanTables,
  41240. refinementTemplateIndex, refinementAt,
  41241. decodingContext);
  41242. } else {
  41243. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41244. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41245. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41246. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41247. newSymbols[symbolId - symbols.length]);
  41248. bitmap = decodeRefinement(currentWidth, currentHeight,
  41249. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41250. decodingContext);
  41251. }
  41252. } else {
  41253. // 6.5.8.1 Direct-coded symbol bitmap
  41254. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41255. templateIndex, false, null, at, decodingContext);
  41256. }
  41257. newSymbols.push(bitmap);
  41258. }
  41259. }
  41260. // 6.5.10 Exported symbols
  41261. var exportedSymbols = [];
  41262. var flags = [], currentFlag = false;
  41263. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41264. while (flags.length < totalSymbolsLength) {
  41265. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41266. while (runLength--) {
  41267. flags.push(currentFlag);
  41268. }
  41269. currentFlag = !currentFlag;
  41270. }
  41271. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41272. if (flags[i]) {
  41273. exportedSymbols.push(symbols[i]);
  41274. }
  41275. }
  41276. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41277. if (flags[i]) {
  41278. exportedSymbols.push(newSymbols[j]);
  41279. }
  41280. }
  41281. return exportedSymbols;
  41282. }
  41283. function decodeTextRegion(huffman, refinement, width, height,
  41284. defaultPixelValue, numberOfSymbolInstances,
  41285. stripSize, inputSymbols, symbolCodeLength,
  41286. transposed, dsOffset, referenceCorner,
  41287. combinationOperator, huffmanTables,
  41288. refinementTemplateIndex, refinementAt,
  41289. decodingContext) {
  41290. if (huffman) {
  41291. error('JBIG2 error: huffman is not supported');
  41292. }
  41293. // Prepare bitmap
  41294. var bitmap = [];
  41295. var i, row;
  41296. for (i = 0; i < height; i++) {
  41297. row = new Uint8Array(width);
  41298. if (defaultPixelValue) {
  41299. for (var j = 0; j < width; j++) {
  41300. row[j] = defaultPixelValue;
  41301. }
  41302. }
  41303. bitmap.push(row);
  41304. }
  41305. var decoder = decodingContext.decoder;
  41306. var contextCache = decodingContext.contextCache;
  41307. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41308. var firstS = 0;
  41309. i = 0;
  41310. while (i < numberOfSymbolInstances) {
  41311. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41312. stripT += deltaT;
  41313. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41314. firstS += deltaFirstS;
  41315. var currentS = firstS;
  41316. do {
  41317. var currentT = (stripSize === 1 ? 0 :
  41318. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41319. var t = stripSize * stripT + currentT;
  41320. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41321. var applyRefinement = (refinement &&
  41322. decodeInteger(contextCache, 'IARI', decoder));
  41323. var symbolBitmap = inputSymbols[symbolId];
  41324. var symbolWidth = symbolBitmap[0].length;
  41325. var symbolHeight = symbolBitmap.length;
  41326. if (applyRefinement) {
  41327. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41328. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41329. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41330. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41331. symbolWidth += rdw;
  41332. symbolHeight += rdh;
  41333. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41334. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41335. (rdh >> 1) + rdy, false, refinementAt,
  41336. decodingContext);
  41337. }
  41338. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41339. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41340. var s2, t2, symbolRow;
  41341. if (transposed) {
  41342. // Place Symbol Bitmap from T1,S1
  41343. for (s2 = 0; s2 < symbolHeight; s2++) {
  41344. row = bitmap[offsetS + s2];
  41345. if (!row) {
  41346. continue;
  41347. }
  41348. symbolRow = symbolBitmap[s2];
  41349. // To ignore Parts of Symbol bitmap which goes
  41350. // outside bitmap region
  41351. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41352. switch (combinationOperator) {
  41353. case 0: // OR
  41354. for (t2 = 0; t2 < maxWidth; t2++) {
  41355. row[offsetT + t2] |= symbolRow[t2];
  41356. }
  41357. break;
  41358. case 2: // XOR
  41359. for (t2 = 0; t2 < maxWidth; t2++) {
  41360. row[offsetT + t2] ^= symbolRow[t2];
  41361. }
  41362. break;
  41363. default:
  41364. error('JBIG2 error: operator ' + combinationOperator +
  41365. ' is not supported');
  41366. }
  41367. }
  41368. currentS += symbolHeight - 1;
  41369. } else {
  41370. for (t2 = 0; t2 < symbolHeight; t2++) {
  41371. row = bitmap[offsetT + t2];
  41372. if (!row) {
  41373. continue;
  41374. }
  41375. symbolRow = symbolBitmap[t2];
  41376. switch (combinationOperator) {
  41377. case 0: // OR
  41378. for (s2 = 0; s2 < symbolWidth; s2++) {
  41379. row[offsetS + s2] |= symbolRow[s2];
  41380. }
  41381. break;
  41382. case 2: // XOR
  41383. for (s2 = 0; s2 < symbolWidth; s2++) {
  41384. row[offsetS + s2] ^= symbolRow[s2];
  41385. }
  41386. break;
  41387. default:
  41388. error('JBIG2 error: operator ' + combinationOperator +
  41389. ' is not supported');
  41390. }
  41391. }
  41392. currentS += symbolWidth - 1;
  41393. }
  41394. i++;
  41395. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41396. if (deltaS === null) {
  41397. break; // OOB
  41398. }
  41399. currentS += deltaS + dsOffset;
  41400. } while (true);
  41401. }
  41402. return bitmap;
  41403. }
  41404. function readSegmentHeader(data, start) {
  41405. var segmentHeader = {};
  41406. segmentHeader.number = readUint32(data, start);
  41407. var flags = data[start + 4];
  41408. var segmentType = flags & 0x3F;
  41409. if (!SegmentTypes[segmentType]) {
  41410. error('JBIG2 error: invalid segment type: ' + segmentType);
  41411. }
  41412. segmentHeader.type = segmentType;
  41413. segmentHeader.typeName = SegmentTypes[segmentType];
  41414. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41415. var pageAssociationFieldSize = !!(flags & 0x40);
  41416. var referredFlags = data[start + 5];
  41417. var referredToCount = (referredFlags >> 5) & 7;
  41418. var retainBits = [referredFlags & 31];
  41419. var position = start + 6;
  41420. if (referredFlags === 7) {
  41421. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41422. position += 3;
  41423. var bytes = (referredToCount + 7) >> 3;
  41424. retainBits[0] = data[position++];
  41425. while (--bytes > 0) {
  41426. retainBits.push(data[position++]);
  41427. }
  41428. } else if (referredFlags === 5 || referredFlags === 6) {
  41429. error('JBIG2 error: invalid referred-to flags');
  41430. }
  41431. segmentHeader.retainBits = retainBits;
  41432. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41433. (segmentHeader.number <= 65536 ? 2 : 4));
  41434. var referredTo = [];
  41435. var i, ii;
  41436. for (i = 0; i < referredToCount; i++) {
  41437. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41438. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41439. readUint32(data, position)));
  41440. referredTo.push(number);
  41441. position += referredToSegmentNumberSize;
  41442. }
  41443. segmentHeader.referredTo = referredTo;
  41444. if (!pageAssociationFieldSize) {
  41445. segmentHeader.pageAssociation = data[position++];
  41446. } else {
  41447. segmentHeader.pageAssociation = readUint32(data, position);
  41448. position += 4;
  41449. }
  41450. segmentHeader.length = readUint32(data, position);
  41451. position += 4;
  41452. if (segmentHeader.length === 0xFFFFFFFF) {
  41453. // 7.2.7 Segment data length, unknown segment length
  41454. if (segmentType === 38) { // ImmediateGenericRegion
  41455. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41456. var genericRegionSegmentFlags = data[position +
  41457. RegionSegmentInformationFieldLength];
  41458. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41459. // searching for the segment end
  41460. var searchPatternLength = 6;
  41461. var searchPattern = new Uint8Array(searchPatternLength);
  41462. if (!genericRegionMmr) {
  41463. searchPattern[0] = 0xFF;
  41464. searchPattern[1] = 0xAC;
  41465. }
  41466. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41467. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41468. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41469. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41470. for (i = position, ii = data.length; i < ii; i++) {
  41471. var j = 0;
  41472. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41473. j++;
  41474. }
  41475. if (j === searchPatternLength) {
  41476. segmentHeader.length = i + searchPatternLength;
  41477. break;
  41478. }
  41479. }
  41480. if (segmentHeader.length === 0xFFFFFFFF) {
  41481. error('JBIG2 error: segment end was not found');
  41482. }
  41483. } else {
  41484. error('JBIG2 error: invalid unknown segment length');
  41485. }
  41486. }
  41487. segmentHeader.headerEnd = position;
  41488. return segmentHeader;
  41489. }
  41490. function readSegments(header, data, start, end) {
  41491. var segments = [];
  41492. var position = start;
  41493. while (position < end) {
  41494. var segmentHeader = readSegmentHeader(data, position);
  41495. position = segmentHeader.headerEnd;
  41496. var segment = {
  41497. header: segmentHeader,
  41498. data: data
  41499. };
  41500. if (!header.randomAccess) {
  41501. segment.start = position;
  41502. position += segmentHeader.length;
  41503. segment.end = position;
  41504. }
  41505. segments.push(segment);
  41506. if (segmentHeader.type === 51) {
  41507. break; // end of file is found
  41508. }
  41509. }
  41510. if (header.randomAccess) {
  41511. for (var i = 0, ii = segments.length; i < ii; i++) {
  41512. segments[i].start = position;
  41513. position += segments[i].header.length;
  41514. segments[i].end = position;
  41515. }
  41516. }
  41517. return segments;
  41518. }
  41519. // 7.4.1 Region segment information field
  41520. function readRegionSegmentInformation(data, start) {
  41521. return {
  41522. width: readUint32(data, start),
  41523. height: readUint32(data, start + 4),
  41524. x: readUint32(data, start + 8),
  41525. y: readUint32(data, start + 12),
  41526. combinationOperator: data[start + 16] & 7
  41527. };
  41528. }
  41529. var RegionSegmentInformationFieldLength = 17;
  41530. function processSegment(segment, visitor) {
  41531. var header = segment.header;
  41532. var data = segment.data, position = segment.start, end = segment.end;
  41533. var args, at, i, atLength;
  41534. switch (header.type) {
  41535. case 0: // SymbolDictionary
  41536. // 7.4.2 Symbol dictionary segment syntax
  41537. var dictionary = {};
  41538. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41539. dictionary.huffman = !!(dictionaryFlags & 1);
  41540. dictionary.refinement = !!(dictionaryFlags & 2);
  41541. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41542. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41543. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41544. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41545. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41546. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41547. dictionary.template = (dictionaryFlags >> 10) & 3;
  41548. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41549. position += 2;
  41550. if (!dictionary.huffman) {
  41551. atLength = dictionary.template === 0 ? 4 : 1;
  41552. at = [];
  41553. for (i = 0; i < atLength; i++) {
  41554. at.push({
  41555. x: readInt8(data, position),
  41556. y: readInt8(data, position + 1)
  41557. });
  41558. position += 2;
  41559. }
  41560. dictionary.at = at;
  41561. }
  41562. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41563. at = [];
  41564. for (i = 0; i < 2; i++) {
  41565. at.push({
  41566. x: readInt8(data, position),
  41567. y: readInt8(data, position + 1)
  41568. });
  41569. position += 2;
  41570. }
  41571. dictionary.refinementAt = at;
  41572. }
  41573. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41574. position += 4;
  41575. dictionary.numberOfNewSymbols = readUint32(data, position);
  41576. position += 4;
  41577. args = [dictionary, header.number, header.referredTo,
  41578. data, position, end];
  41579. break;
  41580. case 6: // ImmediateTextRegion
  41581. case 7: // ImmediateLosslessTextRegion
  41582. var textRegion = {};
  41583. textRegion.info = readRegionSegmentInformation(data, position);
  41584. position += RegionSegmentInformationFieldLength;
  41585. var textRegionSegmentFlags = readUint16(data, position);
  41586. position += 2;
  41587. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41588. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41589. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41590. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41591. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41592. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41593. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41594. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41595. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41596. if (textRegion.huffman) {
  41597. var textRegionHuffmanFlags = readUint16(data, position);
  41598. position += 2;
  41599. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41600. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41601. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41602. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41603. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41604. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41605. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41606. textRegion.huffmanRefinementSizeSelector =
  41607. !!(textRegionHuffmanFlags & 14);
  41608. }
  41609. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41610. at = [];
  41611. for (i = 0; i < 2; i++) {
  41612. at.push({
  41613. x: readInt8(data, position),
  41614. y: readInt8(data, position + 1)
  41615. });
  41616. position += 2;
  41617. }
  41618. textRegion.refinementAt = at;
  41619. }
  41620. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41621. position += 4;
  41622. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41623. if (textRegion.huffman) {
  41624. error('JBIG2 error: huffman is not supported');
  41625. }
  41626. args = [textRegion, header.referredTo, data, position, end];
  41627. break;
  41628. case 38: // ImmediateGenericRegion
  41629. case 39: // ImmediateLosslessGenericRegion
  41630. var genericRegion = {};
  41631. genericRegion.info = readRegionSegmentInformation(data, position);
  41632. position += RegionSegmentInformationFieldLength;
  41633. var genericRegionSegmentFlags = data[position++];
  41634. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41635. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41636. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41637. if (!genericRegion.mmr) {
  41638. atLength = genericRegion.template === 0 ? 4 : 1;
  41639. at = [];
  41640. for (i = 0; i < atLength; i++) {
  41641. at.push({
  41642. x: readInt8(data, position),
  41643. y: readInt8(data, position + 1)
  41644. });
  41645. position += 2;
  41646. }
  41647. genericRegion.at = at;
  41648. }
  41649. args = [genericRegion, data, position, end];
  41650. break;
  41651. case 48: // PageInformation
  41652. var pageInfo = {
  41653. width: readUint32(data, position),
  41654. height: readUint32(data, position + 4),
  41655. resolutionX: readUint32(data, position + 8),
  41656. resolutionY: readUint32(data, position + 12)
  41657. };
  41658. if (pageInfo.height === 0xFFFFFFFF) {
  41659. delete pageInfo.height;
  41660. }
  41661. var pageSegmentFlags = data[position + 16];
  41662. var pageStripingInformatiom = readUint16(data, position + 17);
  41663. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41664. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41665. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41666. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41667. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41668. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41669. args = [pageInfo];
  41670. break;
  41671. case 49: // EndOfPage
  41672. break;
  41673. case 50: // EndOfStripe
  41674. break;
  41675. case 51: // EndOfFile
  41676. break;
  41677. case 62: // 7.4.15 defines 2 extension types which
  41678. // are comments and can be ignored.
  41679. break;
  41680. default:
  41681. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41682. header.type + ') is not implemented');
  41683. }
  41684. var callbackName = 'on' + header.typeName;
  41685. if (callbackName in visitor) {
  41686. visitor[callbackName].apply(visitor, args);
  41687. }
  41688. }
  41689. function processSegments(segments, visitor) {
  41690. for (var i = 0, ii = segments.length; i < ii; i++) {
  41691. processSegment(segments[i], visitor);
  41692. }
  41693. }
  41694. function parseJbig2(data, start, end) {
  41695. var position = start;
  41696. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41697. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41698. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41699. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41700. error('JBIG2 error: invalid header');
  41701. }
  41702. var header = {};
  41703. position += 8;
  41704. var flags = data[position++];
  41705. header.randomAccess = !(flags & 1);
  41706. if (!(flags & 2)) {
  41707. header.numberOfPages = readUint32(data, position);
  41708. position += 4;
  41709. }
  41710. var segments = readSegments(header, data, position, end);
  41711. error('Not implemented');
  41712. // processSegments(segments, new SimpleSegmentVisitor());
  41713. }
  41714. function parseJbig2Chunks(chunks) {
  41715. var visitor = new SimpleSegmentVisitor();
  41716. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41717. var chunk = chunks[i];
  41718. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41719. processSegments(segments, visitor);
  41720. }
  41721. return visitor.buffer;
  41722. }
  41723. function SimpleSegmentVisitor() {}
  41724. SimpleSegmentVisitor.prototype = {
  41725. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41726. this.currentPageInfo = info;
  41727. var rowSize = (info.width + 7) >> 3;
  41728. var buffer = new Uint8Array(rowSize * info.height);
  41729. // The contents of ArrayBuffers are initialized to 0.
  41730. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41731. if (info.defaultPixelValue) {
  41732. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41733. buffer[i] = 0xFF;
  41734. }
  41735. }
  41736. this.buffer = buffer;
  41737. },
  41738. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41739. var pageInfo = this.currentPageInfo;
  41740. var width = regionInfo.width, height = regionInfo.height;
  41741. var rowSize = (pageInfo.width + 7) >> 3;
  41742. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41743. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41744. var buffer = this.buffer;
  41745. var mask0 = 128 >> (regionInfo.x & 7);
  41746. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41747. var i, j, mask, offset;
  41748. switch (combinationOperator) {
  41749. case 0: // OR
  41750. for (i = 0; i < height; i++) {
  41751. mask = mask0;
  41752. offset = offset0;
  41753. for (j = 0; j < width; j++) {
  41754. if (bitmap[i][j]) {
  41755. buffer[offset] |= mask;
  41756. }
  41757. mask >>= 1;
  41758. if (!mask) {
  41759. mask = 128;
  41760. offset++;
  41761. }
  41762. }
  41763. offset0 += rowSize;
  41764. }
  41765. break;
  41766. case 2: // XOR
  41767. for (i = 0; i < height; i++) {
  41768. mask = mask0;
  41769. offset = offset0;
  41770. for (j = 0; j < width; j++) {
  41771. if (bitmap[i][j]) {
  41772. buffer[offset] ^= mask;
  41773. }
  41774. mask >>= 1;
  41775. if (!mask) {
  41776. mask = 128;
  41777. offset++;
  41778. }
  41779. }
  41780. offset0 += rowSize;
  41781. }
  41782. break;
  41783. default:
  41784. error('JBIG2 error: operator ' + combinationOperator +
  41785. ' is not supported');
  41786. }
  41787. },
  41788. onImmediateGenericRegion:
  41789. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41790. start, end) {
  41791. var regionInfo = region.info;
  41792. var decodingContext = new DecodingContext(data, start, end);
  41793. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41794. region.template, region.prediction, null,
  41795. region.at, decodingContext);
  41796. this.drawBitmap(regionInfo, bitmap);
  41797. },
  41798. onImmediateLosslessGenericRegion:
  41799. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41800. this.onImmediateGenericRegion.apply(this, arguments);
  41801. },
  41802. onSymbolDictionary:
  41803. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41804. currentSegment,
  41805. referredSegments,
  41806. data, start, end) {
  41807. var huffmanTables;
  41808. if (dictionary.huffman) {
  41809. error('JBIG2 error: huffman is not supported');
  41810. }
  41811. // Combines exported symbols from all referred segments
  41812. var symbols = this.symbols;
  41813. if (!symbols) {
  41814. this.symbols = symbols = {};
  41815. }
  41816. var inputSymbols = [];
  41817. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41818. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41819. }
  41820. var decodingContext = new DecodingContext(data, start, end);
  41821. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41822. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41823. dictionary.numberOfExportedSymbols, huffmanTables,
  41824. dictionary.template, dictionary.at,
  41825. dictionary.refinementTemplate, dictionary.refinementAt,
  41826. decodingContext);
  41827. },
  41828. onImmediateTextRegion:
  41829. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41830. referredSegments,
  41831. data, start, end) {
  41832. var regionInfo = region.info;
  41833. var huffmanTables;
  41834. // Combines exported symbols from all referred segments
  41835. var symbols = this.symbols;
  41836. var inputSymbols = [];
  41837. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41838. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41839. }
  41840. var symbolCodeLength = log2(inputSymbols.length);
  41841. var decodingContext = new DecodingContext(data, start, end);
  41842. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41843. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41844. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41845. symbolCodeLength, region.transposed, region.dsOffset,
  41846. region.referenceCorner, region.combinationOperator, huffmanTables,
  41847. region.refinementTemplate, region.refinementAt, decodingContext);
  41848. this.drawBitmap(regionInfo, bitmap);
  41849. },
  41850. onImmediateLosslessTextRegion:
  41851. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41852. this.onImmediateTextRegion.apply(this, arguments);
  41853. }
  41854. };
  41855. function Jbig2Image() {}
  41856. Jbig2Image.prototype = {
  41857. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41858. return parseJbig2Chunks(chunks);
  41859. }
  41860. };
  41861. return Jbig2Image;
  41862. })();
  41863. var bidi = PDFJS.bidi = (function bidiClosure() {
  41864. // Character types for symbols from 0000 to 00FF.
  41865. var baseTypes = [
  41866. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41867. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41868. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41869. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41870. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41871. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41872. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41873. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41874. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41875. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41876. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41877. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41878. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41879. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41880. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41881. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41882. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41883. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41884. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41885. ];
  41886. // Character types for symbols from 0600 to 06FF
  41887. var arabicTypes = [
  41888. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41889. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41890. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41891. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41892. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41893. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41894. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41895. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41896. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41897. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41898. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41899. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41900. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41901. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41902. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41903. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41904. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41905. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41906. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41907. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41908. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41909. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41910. ];
  41911. function isOdd(i) {
  41912. return (i & 1) !== 0;
  41913. }
  41914. function isEven(i) {
  41915. return (i & 1) === 0;
  41916. }
  41917. function findUnequal(arr, start, value) {
  41918. for (var j = start, jj = arr.length; j < jj; ++j) {
  41919. if (arr[j] !== value) {
  41920. return j;
  41921. }
  41922. }
  41923. return j;
  41924. }
  41925. function setValues(arr, start, end, value) {
  41926. for (var j = start; j < end; ++j) {
  41927. arr[j] = value;
  41928. }
  41929. }
  41930. function reverseValues(arr, start, end) {
  41931. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41932. var temp = arr[i];
  41933. arr[i] = arr[j];
  41934. arr[j] = temp;
  41935. }
  41936. }
  41937. function createBidiText(str, isLTR, vertical) {
  41938. return {
  41939. str: str,
  41940. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41941. };
  41942. }
  41943. // These are used in bidi(), which is called frequently. We re-use them on
  41944. // each call to avoid unnecessary allocations.
  41945. var chars = [];
  41946. var types = [];
  41947. function bidi(str, startLevel, vertical) {
  41948. var isLTR = true;
  41949. var strLength = str.length;
  41950. if (strLength === 0 || vertical) {
  41951. return createBidiText(str, isLTR, vertical);
  41952. }
  41953. // Get types and fill arrays
  41954. chars.length = strLength;
  41955. types.length = strLength;
  41956. var numBidi = 0;
  41957. var i, ii;
  41958. for (i = 0; i < strLength; ++i) {
  41959. chars[i] = str.charAt(i);
  41960. var charCode = str.charCodeAt(i);
  41961. var charType = 'L';
  41962. if (charCode <= 0x00ff) {
  41963. charType = baseTypes[charCode];
  41964. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41965. charType = 'R';
  41966. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41967. charType = arabicTypes[charCode & 0xff];
  41968. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41969. charType = 'AL';
  41970. }
  41971. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41972. numBidi++;
  41973. }
  41974. types[i] = charType;
  41975. }
  41976. // Detect the bidi method
  41977. // - If there are no rtl characters then no bidi needed
  41978. // - If less than 30% chars are rtl then string is primarily ltr
  41979. // - If more than 30% chars are rtl then string is primarily rtl
  41980. if (numBidi === 0) {
  41981. isLTR = true;
  41982. return createBidiText(str, isLTR);
  41983. }
  41984. if (startLevel === -1) {
  41985. if ((strLength / numBidi) < 0.3) {
  41986. isLTR = true;
  41987. startLevel = 0;
  41988. } else {
  41989. isLTR = false;
  41990. startLevel = 1;
  41991. }
  41992. }
  41993. var levels = [];
  41994. for (i = 0; i < strLength; ++i) {
  41995. levels[i] = startLevel;
  41996. }
  41997. /*
  41998. X1-X10: skip most of this, since we are NOT doing the embeddings.
  41999. */
  42000. var e = (isOdd(startLevel) ? 'R' : 'L');
  42001. var sor = e;
  42002. var eor = sor;
  42003. /*
  42004. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  42005. type of the NSM to the type of the previous character. If the NSM is at the
  42006. start of the level run, it will get the type of sor.
  42007. */
  42008. var lastType = sor;
  42009. for (i = 0; i < strLength; ++i) {
  42010. if (types[i] === 'NSM') {
  42011. types[i] = lastType;
  42012. } else {
  42013. lastType = types[i];
  42014. }
  42015. }
  42016. /*
  42017. W2. Search backwards from each instance of a European number until the
  42018. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42019. the type of the European number to Arabic number.
  42020. */
  42021. lastType = sor;
  42022. var t;
  42023. for (i = 0; i < strLength; ++i) {
  42024. t = types[i];
  42025. if (t === 'EN') {
  42026. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42027. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42028. lastType = t;
  42029. }
  42030. }
  42031. /*
  42032. W3. Change all ALs to R.
  42033. */
  42034. for (i = 0; i < strLength; ++i) {
  42035. t = types[i];
  42036. if (t === 'AL') {
  42037. types[i] = 'R';
  42038. }
  42039. }
  42040. /*
  42041. W4. A single European separator between two European numbers changes to a
  42042. European number. A single common separator between two numbers of the same
  42043. type changes to that type:
  42044. */
  42045. for (i = 1; i < strLength - 1; ++i) {
  42046. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42047. types[i] = 'EN';
  42048. }
  42049. if (types[i] === 'CS' &&
  42050. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42051. types[i + 1] === types[i - 1]) {
  42052. types[i] = types[i - 1];
  42053. }
  42054. }
  42055. /*
  42056. W5. A sequence of European terminators adjacent to European numbers changes
  42057. to all European numbers:
  42058. */
  42059. for (i = 0; i < strLength; ++i) {
  42060. if (types[i] === 'EN') {
  42061. // do before
  42062. var j;
  42063. for (j = i - 1; j >= 0; --j) {
  42064. if (types[j] !== 'ET') {
  42065. break;
  42066. }
  42067. types[j] = 'EN';
  42068. }
  42069. // do after
  42070. for (j = i + 1; j < strLength; --j) {
  42071. if (types[j] !== 'ET') {
  42072. break;
  42073. }
  42074. types[j] = 'EN';
  42075. }
  42076. }
  42077. }
  42078. /*
  42079. W6. Otherwise, separators and terminators change to Other Neutral:
  42080. */
  42081. for (i = 0; i < strLength; ++i) {
  42082. t = types[i];
  42083. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42084. types[i] = 'ON';
  42085. }
  42086. }
  42087. /*
  42088. W7. Search backwards from each instance of a European number until the
  42089. first strong type (R, L, or sor) is found. If an L is found, then change
  42090. the type of the European number to L.
  42091. */
  42092. lastType = sor;
  42093. for (i = 0; i < strLength; ++i) {
  42094. t = types[i];
  42095. if (t === 'EN') {
  42096. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42097. } else if (t === 'R' || t === 'L') {
  42098. lastType = t;
  42099. }
  42100. }
  42101. /*
  42102. N1. A sequence of neutrals takes the direction of the surrounding strong
  42103. text if the text on both sides has the same direction. European and Arabic
  42104. numbers are treated as though they were R. Start-of-level-run (sor) and
  42105. end-of-level-run (eor) are used at level run boundaries.
  42106. */
  42107. for (i = 0; i < strLength; ++i) {
  42108. if (types[i] === 'ON') {
  42109. var end = findUnequal(types, i + 1, 'ON');
  42110. var before = sor;
  42111. if (i > 0) {
  42112. before = types[i - 1];
  42113. }
  42114. var after = eor;
  42115. if (end + 1 < strLength) {
  42116. after = types[end + 1];
  42117. }
  42118. if (before !== 'L') {
  42119. before = 'R';
  42120. }
  42121. if (after !== 'L') {
  42122. after = 'R';
  42123. }
  42124. if (before === after) {
  42125. setValues(types, i, end, before);
  42126. }
  42127. i = end - 1; // reset to end (-1 so next iteration is ok)
  42128. }
  42129. }
  42130. /*
  42131. N2. Any remaining neutrals take the embedding direction.
  42132. */
  42133. for (i = 0; i < strLength; ++i) {
  42134. if (types[i] === 'ON') {
  42135. types[i] = e;
  42136. }
  42137. }
  42138. /*
  42139. I1. For all characters with an even (left-to-right) embedding direction,
  42140. those of type R go up one level and those of type AN or EN go up two
  42141. levels.
  42142. I2. For all characters with an odd (right-to-left) embedding direction,
  42143. those of type L, EN or AN go up one level.
  42144. */
  42145. for (i = 0; i < strLength; ++i) {
  42146. t = types[i];
  42147. if (isEven(levels[i])) {
  42148. if (t === 'R') {
  42149. levels[i] += 1;
  42150. } else if (t === 'AN' || t === 'EN') {
  42151. levels[i] += 2;
  42152. }
  42153. } else { // isOdd
  42154. if (t === 'L' || t === 'AN' || t === 'EN') {
  42155. levels[i] += 1;
  42156. }
  42157. }
  42158. }
  42159. /*
  42160. L1. On each line, reset the embedding level of the following characters to
  42161. the paragraph embedding level:
  42162. segment separators,
  42163. paragraph separators,
  42164. any sequence of whitespace characters preceding a segment separator or
  42165. paragraph separator, and any sequence of white space characters at the end
  42166. of the line.
  42167. */
  42168. // don't bother as text is only single line
  42169. /*
  42170. L2. From the highest level found in the text to the lowest odd level on
  42171. each line, reverse any contiguous sequence of characters that are at that
  42172. level or higher.
  42173. */
  42174. // find highest level & lowest odd level
  42175. var highestLevel = -1;
  42176. var lowestOddLevel = 99;
  42177. var level;
  42178. for (i = 0, ii = levels.length; i < ii; ++i) {
  42179. level = levels[i];
  42180. if (highestLevel < level) {
  42181. highestLevel = level;
  42182. }
  42183. if (lowestOddLevel > level && isOdd(level)) {
  42184. lowestOddLevel = level;
  42185. }
  42186. }
  42187. // now reverse between those limits
  42188. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42189. // find segments to reverse
  42190. var start = -1;
  42191. for (i = 0, ii = levels.length; i < ii; ++i) {
  42192. if (levels[i] < level) {
  42193. if (start >= 0) {
  42194. reverseValues(chars, start, i);
  42195. start = -1;
  42196. }
  42197. } else if (start < 0) {
  42198. start = i;
  42199. }
  42200. }
  42201. if (start >= 0) {
  42202. reverseValues(chars, start, levels.length);
  42203. }
  42204. }
  42205. /*
  42206. L3. Combining marks applied to a right-to-left base character will at this
  42207. point precede their base character. If the rendering engine expects them to
  42208. follow the base characters in the final display process, then the ordering
  42209. of the marks and the base character must be reversed.
  42210. */
  42211. // don't bother for now
  42212. /*
  42213. L4. A character that possesses the mirrored property as specified by
  42214. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42215. directionality of that character is R.
  42216. */
  42217. // don't mirror as characters are already mirrored in the pdf
  42218. // Finally, return string
  42219. var result = '';
  42220. for (i = 0, ii = chars.length; i < ii; ++i) {
  42221. var ch = chars[i];
  42222. if (ch !== '<' && ch !== '>') {
  42223. result += ch;
  42224. }
  42225. }
  42226. return createBidiText(result, isLTR);
  42227. }
  42228. return bidi;
  42229. })();
  42230. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42231. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42232. /* Copyright 2014 Opera Software ASA
  42233. *
  42234. * Licensed under the Apache License, Version 2.0 (the "License");
  42235. * you may not use this file except in compliance with the License.
  42236. * You may obtain a copy of the License at
  42237. *
  42238. * http://www.apache.org/licenses/LICENSE-2.0
  42239. *
  42240. * Unless required by applicable law or agreed to in writing, software
  42241. * distributed under the License is distributed on an "AS IS" BASIS,
  42242. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42243. * See the License for the specific language governing permissions and
  42244. * limitations under the License.
  42245. *
  42246. *
  42247. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42248. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42249. */
  42250. /* globals Uint32ArrayView */
  42251. 'use strict';
  42252. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42253. // Workaround for missing math precison in JS.
  42254. var MASK_HIGH = 0xffff0000;
  42255. var MASK_LOW = 0xffff;
  42256. function MurmurHash3_64 (seed) {
  42257. var SEED = 0xc3d2e1f0;
  42258. this.h1 = seed ? seed & 0xffffffff : SEED;
  42259. this.h2 = seed ? seed & 0xffffffff : SEED;
  42260. }
  42261. var alwaysUseUint32ArrayView = false;
  42262. // old webkits have issues with non-aligned arrays
  42263. try {
  42264. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42265. } catch (e) {
  42266. alwaysUseUint32ArrayView = true;
  42267. }
  42268. MurmurHash3_64.prototype = {
  42269. update: function MurmurHash3_64_update(input) {
  42270. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42271. var i;
  42272. if (typeof input === 'string') {
  42273. var data = new Uint8Array(input.length * 2);
  42274. var length = 0;
  42275. for (i = 0; i < input.length; i++) {
  42276. var code = input.charCodeAt(i);
  42277. if (code <= 0xff) {
  42278. data[length++] = code;
  42279. }
  42280. else {
  42281. data[length++] = code >>> 8;
  42282. data[length++] = code & 0xff;
  42283. }
  42284. }
  42285. } else if (input instanceof Uint8Array) {
  42286. data = input;
  42287. length = data.length;
  42288. } else if (typeof input === 'object' && ('length' in input)) {
  42289. // processing regular arrays as well, e.g. for IE9
  42290. data = input;
  42291. length = data.length;
  42292. useUint32ArrayView = true;
  42293. } else {
  42294. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42295. 'Input must be a string or array.');
  42296. }
  42297. var blockCounts = length >> 2;
  42298. var tailLength = length - blockCounts * 4;
  42299. // we don't care about endianness here
  42300. var dataUint32 = useUint32ArrayView ?
  42301. new Uint32ArrayView(data, blockCounts) :
  42302. new Uint32Array(data.buffer, 0, blockCounts);
  42303. var k1 = 0;
  42304. var k2 = 0;
  42305. var h1 = this.h1;
  42306. var h2 = this.h2;
  42307. var C1 = 0xcc9e2d51;
  42308. var C2 = 0x1b873593;
  42309. var C1_LOW = C1 & MASK_LOW;
  42310. var C2_LOW = C2 & MASK_LOW;
  42311. for (i = 0; i < blockCounts; i++) {
  42312. if (i & 1) {
  42313. k1 = dataUint32[i];
  42314. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42315. k1 = k1 << 15 | k1 >>> 17;
  42316. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42317. h1 ^= k1;
  42318. h1 = h1 << 13 | h1 >>> 19;
  42319. h1 = h1 * 5 + 0xe6546b64;
  42320. } else {
  42321. k2 = dataUint32[i];
  42322. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42323. k2 = k2 << 15 | k2 >>> 17;
  42324. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42325. h2 ^= k2;
  42326. h2 = h2 << 13 | h2 >>> 19;
  42327. h2 = h2 * 5 + 0xe6546b64;
  42328. }
  42329. }
  42330. k1 = 0;
  42331. switch (tailLength) {
  42332. case 3:
  42333. k1 ^= data[blockCounts * 4 + 2] << 16;
  42334. /* falls through */
  42335. case 2:
  42336. k1 ^= data[blockCounts * 4 + 1] << 8;
  42337. /* falls through */
  42338. case 1:
  42339. k1 ^= data[blockCounts * 4];
  42340. /* falls through */
  42341. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42342. k1 = k1 << 15 | k1 >>> 17;
  42343. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42344. if (blockCounts & 1) {
  42345. h1 ^= k1;
  42346. } else {
  42347. h2 ^= k1;
  42348. }
  42349. }
  42350. this.h1 = h1;
  42351. this.h2 = h2;
  42352. return this;
  42353. },
  42354. hexdigest: function MurmurHash3_64_hexdigest () {
  42355. var h1 = this.h1;
  42356. var h2 = this.h2;
  42357. h1 ^= h2 >>> 1;
  42358. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42359. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42360. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42361. h1 ^= h2 >>> 1;
  42362. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42363. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42364. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42365. h1 ^= h2 >>> 1;
  42366. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42367. var hex = (arr[i] >>> 0).toString(16);
  42368. while (hex.length < 8) {
  42369. hex = '0' + hex;
  42370. }
  42371. str += hex;
  42372. }
  42373. return str;
  42374. }
  42375. };
  42376. return MurmurHash3_64;
  42377. })();
  42378. }).call((typeof window === 'undefined') ? this : window);
  42379. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42380. // workerSrc is not set -- using last script url to define default location
  42381. PDFJS.workerSrc = (function () {
  42382. 'use strict';
  42383. var scriptTagContainer = document.body ||
  42384. document.getElementsByTagName('head')[0];
  42385. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42386. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42387. })();
  42388. }