pdf.combined.js 1.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666
  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.635';
  24. PDFJS.build = '5e18614';
  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. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToArray(str) {
  417. var length = str.length;
  418. var array = new Uint16Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. array[i] = str.charCodeAt(i);
  421. }
  422. return array;
  423. }
  424. function stringToBytes(str) {
  425. var length = str.length;
  426. var bytes = new Uint8Array(length);
  427. for (var i = 0; i < length; ++i) {
  428. bytes[i] = str.charCodeAt(i) & 0xFF;
  429. }
  430. return bytes;
  431. }
  432. function string32(value) {
  433. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  434. (value >> 8) & 0xff, value & 0xff);
  435. }
  436. function log2(x) {
  437. var n = 1, i = 0;
  438. while (x > n) {
  439. n <<= 1;
  440. i++;
  441. }
  442. return i;
  443. }
  444. function readInt8(data, start) {
  445. return (data[start] << 24) >> 24;
  446. }
  447. function readUint16(data, offset) {
  448. return (data[offset] << 8) | data[offset + 1];
  449. }
  450. function readUint32(data, offset) {
  451. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  452. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  453. }
  454. // Lazy test the endianness of the platform
  455. // NOTE: This will be 'true' for simulated TypedArrays
  456. function isLittleEndian() {
  457. var buffer8 = new Uint8Array(2);
  458. buffer8[0] = 1;
  459. var buffer16 = new Uint16Array(buffer8.buffer);
  460. return (buffer16[0] === 1);
  461. }
  462. Object.defineProperty(PDFJS, 'isLittleEndian', {
  463. configurable: true,
  464. get: function PDFJS_isLittleEndian() {
  465. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  466. }
  467. });
  468. // Lazy test if the userAgant support CanvasTypedArrays
  469. function hasCanvasTypedArrays() {
  470. var canvas = document.createElement('canvas');
  471. canvas.width = canvas.height = 1;
  472. var ctx = canvas.getContext('2d');
  473. var imageData = ctx.createImageData(1, 1);
  474. return (typeof imageData.data.buffer !== 'undefined');
  475. }
  476. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  477. configurable: true,
  478. get: function PDFJS_hasCanvasTypedArrays() {
  479. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  480. }
  481. });
  482. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  483. function Uint32ArrayView(buffer, length) {
  484. this.buffer = buffer;
  485. this.byteLength = buffer.length;
  486. this.length = length === undefined ? (this.byteLength >> 2) : length;
  487. ensureUint32ArrayViewProps(this.length);
  488. }
  489. Uint32ArrayView.prototype = Object.create(null);
  490. var uint32ArrayViewSetters = 0;
  491. function createUint32ArrayProp(index) {
  492. return {
  493. get: function () {
  494. var buffer = this.buffer, offset = index << 2;
  495. return (buffer[offset] | (buffer[offset + 1] << 8) |
  496. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  497. },
  498. set: function (value) {
  499. var buffer = this.buffer, offset = index << 2;
  500. buffer[offset] = value & 255;
  501. buffer[offset + 1] = (value >> 8) & 255;
  502. buffer[offset + 2] = (value >> 16) & 255;
  503. buffer[offset + 3] = (value >>> 24) & 255;
  504. }
  505. };
  506. }
  507. function ensureUint32ArrayViewProps(length) {
  508. while (uint32ArrayViewSetters < length) {
  509. Object.defineProperty(Uint32ArrayView.prototype,
  510. uint32ArrayViewSetters,
  511. createUint32ArrayProp(uint32ArrayViewSetters));
  512. uint32ArrayViewSetters++;
  513. }
  514. }
  515. return Uint32ArrayView;
  516. })();
  517. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  518. var Util = PDFJS.Util = (function UtilClosure() {
  519. function Util() {}
  520. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  521. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  522. // creating many intermediate strings.
  523. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  524. rgbBuf[1] = rgb[0];
  525. rgbBuf[3] = rgb[1];
  526. rgbBuf[5] = rgb[2];
  527. return rgbBuf.join('');
  528. };
  529. // Concatenates two transformation matrices together and returns the result.
  530. Util.transform = function Util_transform(m1, m2) {
  531. return [
  532. m1[0] * m2[0] + m1[2] * m2[1],
  533. m1[1] * m2[0] + m1[3] * m2[1],
  534. m1[0] * m2[2] + m1[2] * m2[3],
  535. m1[1] * m2[2] + m1[3] * m2[3],
  536. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  537. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  538. ];
  539. };
  540. // For 2d affine transforms
  541. Util.applyTransform = function Util_applyTransform(p, m) {
  542. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  543. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  544. return [xt, yt];
  545. };
  546. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  547. var d = m[0] * m[3] - m[1] * m[2];
  548. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  549. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  550. return [xt, yt];
  551. };
  552. // Applies the transform to the rectangle and finds the minimum axially
  553. // aligned bounding box.
  554. Util.getAxialAlignedBoundingBox =
  555. function Util_getAxialAlignedBoundingBox(r, m) {
  556. var p1 = Util.applyTransform(r, m);
  557. var p2 = Util.applyTransform(r.slice(2, 4), m);
  558. var p3 = Util.applyTransform([r[0], r[3]], m);
  559. var p4 = Util.applyTransform([r[2], r[1]], m);
  560. return [
  561. Math.min(p1[0], p2[0], p3[0], p4[0]),
  562. Math.min(p1[1], p2[1], p3[1], p4[1]),
  563. Math.max(p1[0], p2[0], p3[0], p4[0]),
  564. Math.max(p1[1], p2[1], p3[1], p4[1])
  565. ];
  566. };
  567. Util.inverseTransform = function Util_inverseTransform(m) {
  568. var d = m[0] * m[3] - m[1] * m[2];
  569. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  570. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  571. };
  572. // Apply a generic 3d matrix M on a 3-vector v:
  573. // | a b c | | X |
  574. // | d e f | x | Y |
  575. // | g h i | | Z |
  576. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  577. // with v as [X,Y,Z]
  578. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  579. return [
  580. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  581. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  582. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  583. ];
  584. };
  585. // This calculation uses Singular Value Decomposition.
  586. // The SVD can be represented with formula A = USV. We are interested in the
  587. // matrix S here because it represents the scale values.
  588. Util.singularValueDecompose2dScale =
  589. function Util_singularValueDecompose2dScale(m) {
  590. var transpose = [m[0], m[2], m[1], m[3]];
  591. // Multiply matrix m with its transpose.
  592. var a = m[0] * transpose[0] + m[1] * transpose[2];
  593. var b = m[0] * transpose[1] + m[1] * transpose[3];
  594. var c = m[2] * transpose[0] + m[3] * transpose[2];
  595. var d = m[2] * transpose[1] + m[3] * transpose[3];
  596. // Solve the second degree polynomial to get roots.
  597. var first = (a + d) / 2;
  598. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  599. var sx = first + second || 1;
  600. var sy = first - second || 1;
  601. // Scale values are the square roots of the eigenvalues.
  602. return [Math.sqrt(sx), Math.sqrt(sy)];
  603. };
  604. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  605. // For coordinate systems whose origin lies in the bottom-left, this
  606. // means normalization to (BL,TR) ordering. For systems with origin in the
  607. // top-left, this means (TL,BR) ordering.
  608. Util.normalizeRect = function Util_normalizeRect(rect) {
  609. var r = rect.slice(0); // clone rect
  610. if (rect[0] > rect[2]) {
  611. r[0] = rect[2];
  612. r[2] = rect[0];
  613. }
  614. if (rect[1] > rect[3]) {
  615. r[1] = rect[3];
  616. r[3] = rect[1];
  617. }
  618. return r;
  619. };
  620. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  621. // intersection of rect1 and rect2. If no intersection, returns 'false'
  622. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  623. Util.intersect = function Util_intersect(rect1, rect2) {
  624. function compare(a, b) {
  625. return a - b;
  626. }
  627. // Order points along the axes
  628. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  629. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  630. result = [];
  631. rect1 = Util.normalizeRect(rect1);
  632. rect2 = Util.normalizeRect(rect2);
  633. // X: first and second points belong to different rectangles?
  634. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  635. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  636. // Intersection must be between second and third points
  637. result[0] = orderedX[1];
  638. result[2] = orderedX[2];
  639. } else {
  640. return false;
  641. }
  642. // Y: first and second points belong to different rectangles?
  643. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  644. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  645. // Intersection must be between second and third points
  646. result[1] = orderedY[1];
  647. result[3] = orderedY[2];
  648. } else {
  649. return false;
  650. }
  651. return result;
  652. };
  653. Util.sign = function Util_sign(num) {
  654. return num < 0 ? -1 : 1;
  655. };
  656. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  657. Array.prototype.push.apply(arr1, arr2);
  658. };
  659. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  660. Array.prototype.unshift.apply(arr1, arr2);
  661. };
  662. Util.extendObj = function extendObj(obj1, obj2) {
  663. for (var key in obj2) {
  664. obj1[key] = obj2[key];
  665. }
  666. };
  667. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  668. name) {
  669. while (dict && !dict.has(name)) {
  670. dict = dict.get('Parent');
  671. }
  672. if (!dict) {
  673. return null;
  674. }
  675. return dict.get(name);
  676. };
  677. Util.inherit = function Util_inherit(sub, base, prototype) {
  678. sub.prototype = Object.create(base.prototype);
  679. sub.prototype.constructor = sub;
  680. for (var prop in prototype) {
  681. sub.prototype[prop] = prototype[prop];
  682. }
  683. };
  684. Util.loadScript = function Util_loadScript(src, callback) {
  685. var script = document.createElement('script');
  686. var loaded = false;
  687. script.setAttribute('src', src);
  688. if (callback) {
  689. script.onload = function() {
  690. if (!loaded) {
  691. callback();
  692. }
  693. loaded = true;
  694. };
  695. }
  696. document.getElementsByTagName('head')[0].appendChild(script);
  697. };
  698. return Util;
  699. })();
  700. /**
  701. * PDF page viewport created based on scale, rotation and offset.
  702. * @class
  703. * @alias PDFJS.PageViewport
  704. */
  705. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  706. /**
  707. * @constructor
  708. * @private
  709. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  710. * @param scale {number} scale of the viewport.
  711. * @param rotation {number} rotations of the viewport in degrees.
  712. * @param offsetX {number} offset X
  713. * @param offsetY {number} offset Y
  714. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  715. */
  716. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  717. this.viewBox = viewBox;
  718. this.scale = scale;
  719. this.rotation = rotation;
  720. this.offsetX = offsetX;
  721. this.offsetY = offsetY;
  722. // creating transform to convert pdf coordinate system to the normal
  723. // canvas like coordinates taking in account scale and rotation
  724. var centerX = (viewBox[2] + viewBox[0]) / 2;
  725. var centerY = (viewBox[3] + viewBox[1]) / 2;
  726. var rotateA, rotateB, rotateC, rotateD;
  727. rotation = rotation % 360;
  728. rotation = rotation < 0 ? rotation + 360 : rotation;
  729. switch (rotation) {
  730. case 180:
  731. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  732. break;
  733. case 90:
  734. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  735. break;
  736. case 270:
  737. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  738. break;
  739. //case 0:
  740. default:
  741. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  742. break;
  743. }
  744. if (dontFlip) {
  745. rotateC = -rotateC; rotateD = -rotateD;
  746. }
  747. var offsetCanvasX, offsetCanvasY;
  748. var width, height;
  749. if (rotateA === 0) {
  750. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  751. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  752. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  753. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  754. } else {
  755. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  756. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  757. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  758. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. }
  760. // creating transform for the following operations:
  761. // translate(-centerX, -centerY), rotate and flip vertically,
  762. // scale, and translate(offsetCanvasX, offsetCanvasY)
  763. this.transform = [
  764. rotateA * scale,
  765. rotateB * scale,
  766. rotateC * scale,
  767. rotateD * scale,
  768. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  769. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  770. ];
  771. this.width = width;
  772. this.height = height;
  773. this.fontScale = scale;
  774. }
  775. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  776. /**
  777. * Clones viewport with additional properties.
  778. * @param args {Object} (optional) If specified, may contain the 'scale' or
  779. * 'rotation' properties to override the corresponding properties in
  780. * the cloned viewport.
  781. * @returns {PDFJS.PageViewport} Cloned viewport.
  782. */
  783. clone: function PageViewPort_clone(args) {
  784. args = args || {};
  785. var scale = 'scale' in args ? args.scale : this.scale;
  786. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  787. return new PageViewport(this.viewBox.slice(), scale, rotation,
  788. this.offsetX, this.offsetY, args.dontFlip);
  789. },
  790. /**
  791. * Converts PDF point to the viewport coordinates. For examples, useful for
  792. * converting PDF location into canvas pixel coordinates.
  793. * @param x {number} X coordinate.
  794. * @param y {number} Y coordinate.
  795. * @returns {Object} Object that contains 'x' and 'y' properties of the
  796. * point in the viewport coordinate space.
  797. * @see {@link convertToPdfPoint}
  798. * @see {@link convertToViewportRectangle}
  799. */
  800. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  801. return Util.applyTransform([x, y], this.transform);
  802. },
  803. /**
  804. * Converts PDF rectangle to the viewport coordinates.
  805. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  806. * @returns {Array} Contains corresponding coordinates of the rectangle
  807. * in the viewport coordinate space.
  808. * @see {@link convertToViewportPoint}
  809. */
  810. convertToViewportRectangle:
  811. function PageViewport_convertToViewportRectangle(rect) {
  812. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  813. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  814. return [tl[0], tl[1], br[0], br[1]];
  815. },
  816. /**
  817. * Converts viewport coordinates to the PDF location. For examples, useful
  818. * for converting canvas pixel location into PDF one.
  819. * @param x {number} X coordinate.
  820. * @param y {number} Y coordinate.
  821. * @returns {Object} Object that contains 'x' and 'y' properties of the
  822. * point in the PDF coordinate space.
  823. * @see {@link convertToViewportPoint}
  824. */
  825. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  826. return Util.applyInverseTransform([x, y], this.transform);
  827. }
  828. };
  829. return PageViewport;
  830. })();
  831. var PDFStringTranslateTable = [
  832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  833. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  834. 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,
  835. 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,
  836. 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,
  837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  838. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  839. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  840. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  841. ];
  842. function stringToPDFString(str) {
  843. var i, n = str.length, strBuf = [];
  844. if (str[0] === '\xFE' && str[1] === '\xFF') {
  845. // UTF16BE BOM
  846. for (i = 2; i < n; i += 2) {
  847. strBuf.push(String.fromCharCode(
  848. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  849. }
  850. } else {
  851. for (i = 0; i < n; ++i) {
  852. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  853. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  854. }
  855. }
  856. return strBuf.join('');
  857. }
  858. function stringToUTF8String(str) {
  859. return decodeURIComponent(escape(str));
  860. }
  861. function isEmptyObj(obj) {
  862. for (var key in obj) {
  863. return false;
  864. }
  865. return true;
  866. }
  867. function isBool(v) {
  868. return typeof v === 'boolean';
  869. }
  870. function isInt(v) {
  871. return typeof v === 'number' && ((v | 0) === v);
  872. }
  873. function isNum(v) {
  874. return typeof v === 'number';
  875. }
  876. function isString(v) {
  877. return typeof v === 'string';
  878. }
  879. function isNull(v) {
  880. return v === null;
  881. }
  882. function isName(v) {
  883. return v instanceof Name;
  884. }
  885. function isCmd(v, cmd) {
  886. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  887. }
  888. function isDict(v, type) {
  889. if (!(v instanceof Dict)) {
  890. return false;
  891. }
  892. if (!type) {
  893. return true;
  894. }
  895. var dictType = v.get('Type');
  896. return isName(dictType) && dictType.name === type;
  897. }
  898. function isArray(v) {
  899. return v instanceof Array;
  900. }
  901. function isStream(v) {
  902. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  903. }
  904. function isArrayBuffer(v) {
  905. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  906. }
  907. function isRef(v) {
  908. return v instanceof Ref;
  909. }
  910. /**
  911. * Promise Capability object.
  912. *
  913. * @typedef {Object} PromiseCapability
  914. * @property {Promise} promise - A promise object.
  915. * @property {function} resolve - Fullfills the promise.
  916. * @property {function} reject - Rejects the promise.
  917. */
  918. /**
  919. * Creates a promise capability object.
  920. * @alias PDFJS.createPromiseCapability
  921. *
  922. * @return {PromiseCapability} A capability object contains:
  923. * - a Promise, resolve and reject methods.
  924. */
  925. function createPromiseCapability() {
  926. var capability = {};
  927. capability.promise = new Promise(function (resolve, reject) {
  928. capability.resolve = resolve;
  929. capability.reject = reject;
  930. });
  931. return capability;
  932. }
  933. PDFJS.createPromiseCapability = createPromiseCapability;
  934. /**
  935. * Polyfill for Promises:
  936. * The following promise implementation tries to generally implement the
  937. * Promise/A+ spec. Some notable differences from other promise libaries are:
  938. * - There currently isn't a seperate deferred and promise object.
  939. * - Unhandled rejections eventually show an error if they aren't handled.
  940. *
  941. * Based off of the work in:
  942. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  943. */
  944. (function PromiseClosure() {
  945. if (globalScope.Promise) {
  946. // Promises existing in the DOM/Worker, checking presence of all/resolve
  947. if (typeof globalScope.Promise.all !== 'function') {
  948. globalScope.Promise.all = function (iterable) {
  949. var count = 0, results = [], resolve, reject;
  950. var promise = new globalScope.Promise(function (resolve_, reject_) {
  951. resolve = resolve_;
  952. reject = reject_;
  953. });
  954. iterable.forEach(function (p, i) {
  955. count++;
  956. p.then(function (result) {
  957. results[i] = result;
  958. count--;
  959. if (count === 0) {
  960. resolve(results);
  961. }
  962. }, reject);
  963. });
  964. if (count === 0) {
  965. resolve(results);
  966. }
  967. return promise;
  968. };
  969. }
  970. if (typeof globalScope.Promise.resolve !== 'function') {
  971. globalScope.Promise.resolve = function (value) {
  972. return new globalScope.Promise(function (resolve) { resolve(value); });
  973. };
  974. }
  975. if (typeof globalScope.Promise.reject !== 'function') {
  976. globalScope.Promise.reject = function (reason) {
  977. return new globalScope.Promise(function (resolve, reject) {
  978. reject(reason);
  979. });
  980. };
  981. }
  982. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  983. globalScope.Promise.prototype.catch = function (onReject) {
  984. return globalScope.Promise.prototype.then(undefined, onReject);
  985. };
  986. }
  987. return;
  988. }
  989. var STATUS_PENDING = 0;
  990. var STATUS_RESOLVED = 1;
  991. var STATUS_REJECTED = 2;
  992. // In an attempt to avoid silent exceptions, unhandled rejections are
  993. // tracked and if they aren't handled in a certain amount of time an
  994. // error is logged.
  995. var REJECTION_TIMEOUT = 500;
  996. var HandlerManager = {
  997. handlers: [],
  998. running: false,
  999. unhandledRejections: [],
  1000. pendingRejectionCheck: false,
  1001. scheduleHandlers: function scheduleHandlers(promise) {
  1002. if (promise._status === STATUS_PENDING) {
  1003. return;
  1004. }
  1005. this.handlers = this.handlers.concat(promise._handlers);
  1006. promise._handlers = [];
  1007. if (this.running) {
  1008. return;
  1009. }
  1010. this.running = true;
  1011. setTimeout(this.runHandlers.bind(this), 0);
  1012. },
  1013. runHandlers: function runHandlers() {
  1014. var RUN_TIMEOUT = 1; // ms
  1015. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1016. while (this.handlers.length > 0) {
  1017. var handler = this.handlers.shift();
  1018. var nextStatus = handler.thisPromise._status;
  1019. var nextValue = handler.thisPromise._value;
  1020. try {
  1021. if (nextStatus === STATUS_RESOLVED) {
  1022. if (typeof handler.onResolve === 'function') {
  1023. nextValue = handler.onResolve(nextValue);
  1024. }
  1025. } else if (typeof handler.onReject === 'function') {
  1026. nextValue = handler.onReject(nextValue);
  1027. nextStatus = STATUS_RESOLVED;
  1028. if (handler.thisPromise._unhandledRejection) {
  1029. this.removeUnhandeledRejection(handler.thisPromise);
  1030. }
  1031. }
  1032. } catch (ex) {
  1033. nextStatus = STATUS_REJECTED;
  1034. nextValue = ex;
  1035. }
  1036. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1037. if (Date.now() >= timeoutAt) {
  1038. break;
  1039. }
  1040. }
  1041. if (this.handlers.length > 0) {
  1042. setTimeout(this.runHandlers.bind(this), 0);
  1043. return;
  1044. }
  1045. this.running = false;
  1046. },
  1047. addUnhandledRejection: function addUnhandledRejection(promise) {
  1048. this.unhandledRejections.push({
  1049. promise: promise,
  1050. time: Date.now()
  1051. });
  1052. this.scheduleRejectionCheck();
  1053. },
  1054. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1055. promise._unhandledRejection = false;
  1056. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1057. if (this.unhandledRejections[i].promise === promise) {
  1058. this.unhandledRejections.splice(i);
  1059. i--;
  1060. }
  1061. }
  1062. },
  1063. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1064. if (this.pendingRejectionCheck) {
  1065. return;
  1066. }
  1067. this.pendingRejectionCheck = true;
  1068. setTimeout(function rejectionCheck() {
  1069. this.pendingRejectionCheck = false;
  1070. var now = Date.now();
  1071. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1072. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1073. var unhandled = this.unhandledRejections[i].promise._value;
  1074. var msg = 'Unhandled rejection: ' + unhandled;
  1075. if (unhandled.stack) {
  1076. msg += '\n' + unhandled.stack;
  1077. }
  1078. warn(msg);
  1079. this.unhandledRejections.splice(i);
  1080. i--;
  1081. }
  1082. }
  1083. if (this.unhandledRejections.length) {
  1084. this.scheduleRejectionCheck();
  1085. }
  1086. }.bind(this), REJECTION_TIMEOUT);
  1087. }
  1088. };
  1089. function Promise(resolver) {
  1090. this._status = STATUS_PENDING;
  1091. this._handlers = [];
  1092. try {
  1093. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1094. } catch (e) {
  1095. this._reject(e);
  1096. }
  1097. }
  1098. /**
  1099. * Builds a promise that is resolved when all the passed in promises are
  1100. * resolved.
  1101. * @param {array} array of data and/or promises to wait for.
  1102. * @return {Promise} New dependant promise.
  1103. */
  1104. Promise.all = function Promise_all(promises) {
  1105. var resolveAll, rejectAll;
  1106. var deferred = new Promise(function (resolve, reject) {
  1107. resolveAll = resolve;
  1108. rejectAll = reject;
  1109. });
  1110. var unresolved = promises.length;
  1111. var results = [];
  1112. if (unresolved === 0) {
  1113. resolveAll(results);
  1114. return deferred;
  1115. }
  1116. function reject(reason) {
  1117. if (deferred._status === STATUS_REJECTED) {
  1118. return;
  1119. }
  1120. results = [];
  1121. rejectAll(reason);
  1122. }
  1123. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1124. var promise = promises[i];
  1125. var resolve = (function(i) {
  1126. return function(value) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results[i] = value;
  1131. unresolved--;
  1132. if (unresolved === 0) {
  1133. resolveAll(results);
  1134. }
  1135. };
  1136. })(i);
  1137. if (Promise.isPromise(promise)) {
  1138. promise.then(resolve, reject);
  1139. } else {
  1140. resolve(promise);
  1141. }
  1142. }
  1143. return deferred;
  1144. };
  1145. /**
  1146. * Checks if the value is likely a promise (has a 'then' function).
  1147. * @return {boolean} true if value is thenable
  1148. */
  1149. Promise.isPromise = function Promise_isPromise(value) {
  1150. return value && typeof value.then === 'function';
  1151. };
  1152. /**
  1153. * Creates resolved promise
  1154. * @param value resolve value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.resolve = function Promise_resolve(value) {
  1158. return new Promise(function (resolve) { resolve(value); });
  1159. };
  1160. /**
  1161. * Creates rejected promise
  1162. * @param reason rejection value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.reject = function Promise_reject(reason) {
  1166. return new Promise(function (resolve, reject) { reject(reason); });
  1167. };
  1168. Promise.prototype = {
  1169. _status: null,
  1170. _value: null,
  1171. _handlers: null,
  1172. _unhandledRejection: null,
  1173. _updateStatus: function Promise__updateStatus(status, value) {
  1174. if (this._status === STATUS_RESOLVED ||
  1175. this._status === STATUS_REJECTED) {
  1176. return;
  1177. }
  1178. if (status === STATUS_RESOLVED &&
  1179. Promise.isPromise(value)) {
  1180. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1181. this._updateStatus.bind(this, STATUS_REJECTED));
  1182. return;
  1183. }
  1184. this._status = status;
  1185. this._value = value;
  1186. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1187. this._unhandledRejection = true;
  1188. HandlerManager.addUnhandledRejection(this);
  1189. }
  1190. HandlerManager.scheduleHandlers(this);
  1191. },
  1192. _resolve: function Promise_resolve(value) {
  1193. this._updateStatus(STATUS_RESOLVED, value);
  1194. },
  1195. _reject: function Promise_reject(reason) {
  1196. this._updateStatus(STATUS_REJECTED, reason);
  1197. },
  1198. then: function Promise_then(onResolve, onReject) {
  1199. var nextPromise = new Promise(function (resolve, reject) {
  1200. this.resolve = resolve;
  1201. this.reject = reject;
  1202. });
  1203. this._handlers.push({
  1204. thisPromise: this,
  1205. onResolve: onResolve,
  1206. onReject: onReject,
  1207. nextPromise: nextPromise
  1208. });
  1209. HandlerManager.scheduleHandlers(this);
  1210. return nextPromise;
  1211. },
  1212. catch: function Promise_catch(onReject) {
  1213. return this.then(undefined, onReject);
  1214. }
  1215. };
  1216. globalScope.Promise = Promise;
  1217. })();
  1218. var StatTimer = (function StatTimerClosure() {
  1219. function rpad(str, pad, length) {
  1220. while (str.length < length) {
  1221. str += pad;
  1222. }
  1223. return str;
  1224. }
  1225. function StatTimer() {
  1226. this.started = {};
  1227. this.times = [];
  1228. this.enabled = true;
  1229. }
  1230. StatTimer.prototype = {
  1231. time: function StatTimer_time(name) {
  1232. if (!this.enabled) {
  1233. return;
  1234. }
  1235. if (name in this.started) {
  1236. warn('Timer is already running for ' + name);
  1237. }
  1238. this.started[name] = Date.now();
  1239. },
  1240. timeEnd: function StatTimer_timeEnd(name) {
  1241. if (!this.enabled) {
  1242. return;
  1243. }
  1244. if (!(name in this.started)) {
  1245. warn('Timer has not been started for ' + name);
  1246. }
  1247. this.times.push({
  1248. 'name': name,
  1249. 'start': this.started[name],
  1250. 'end': Date.now()
  1251. });
  1252. // Remove timer from started so it can be called again.
  1253. delete this.started[name];
  1254. },
  1255. toString: function StatTimer_toString() {
  1256. var i, ii;
  1257. var times = this.times;
  1258. var out = '';
  1259. // Find the longest name for padding purposes.
  1260. var longest = 0;
  1261. for (i = 0, ii = times.length; i < ii; ++i) {
  1262. var name = times[i]['name'];
  1263. if (name.length > longest) {
  1264. longest = name.length;
  1265. }
  1266. }
  1267. for (i = 0, ii = times.length; i < ii; ++i) {
  1268. var span = times[i];
  1269. var duration = span.end - span.start;
  1270. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1271. }
  1272. return out;
  1273. }
  1274. };
  1275. return StatTimer;
  1276. })();
  1277. PDFJS.createBlob = function createBlob(data, contentType) {
  1278. if (typeof Blob !== 'undefined') {
  1279. return new Blob([data], { type: contentType });
  1280. }
  1281. // Blob builder is deprecated in FF14 and removed in FF18.
  1282. var bb = new MozBlobBuilder();
  1283. bb.append(data);
  1284. return bb.getBlob(contentType);
  1285. };
  1286. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1287. // Blob/createObjectURL is not available, falling back to data schema.
  1288. var digits =
  1289. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1290. return function createObjectURL(data, contentType) {
  1291. if (!PDFJS.disableCreateObjectURL &&
  1292. typeof URL !== 'undefined' && URL.createObjectURL) {
  1293. var blob = PDFJS.createBlob(data, contentType);
  1294. return URL.createObjectURL(blob);
  1295. }
  1296. var buffer = 'data:' + contentType + ';base64,';
  1297. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1298. var b1 = data[i] & 0xFF;
  1299. var b2 = data[i + 1] & 0xFF;
  1300. var b3 = data[i + 2] & 0xFF;
  1301. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1302. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1303. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1304. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1305. }
  1306. return buffer;
  1307. };
  1308. })();
  1309. function MessageHandler(name, comObj) {
  1310. this.name = name;
  1311. this.comObj = comObj;
  1312. this.callbackIndex = 1;
  1313. this.postMessageTransfers = true;
  1314. var callbacksCapabilities = this.callbacksCapabilities = {};
  1315. var ah = this.actionHandler = {};
  1316. ah['console_log'] = [function ahConsoleLog(data) {
  1317. console.log.apply(console, data);
  1318. }];
  1319. ah['console_error'] = [function ahConsoleError(data) {
  1320. console.error.apply(console, data);
  1321. }];
  1322. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1323. UnsupportedManager.notify(data);
  1324. }];
  1325. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1326. var data = event.data;
  1327. if (data.isReply) {
  1328. var callbackId = data.callbackId;
  1329. if (data.callbackId in callbacksCapabilities) {
  1330. var callback = callbacksCapabilities[callbackId];
  1331. delete callbacksCapabilities[callbackId];
  1332. if ('error' in data) {
  1333. callback.reject(data.error);
  1334. } else {
  1335. callback.resolve(data.data);
  1336. }
  1337. } else {
  1338. error('Cannot resolve callback ' + callbackId);
  1339. }
  1340. } else if (data.action in ah) {
  1341. var action = ah[data.action];
  1342. if (data.callbackId) {
  1343. Promise.resolve().then(function () {
  1344. return action[0].call(action[1], data.data);
  1345. }).then(function (result) {
  1346. comObj.postMessage({
  1347. isReply: true,
  1348. callbackId: data.callbackId,
  1349. data: result
  1350. });
  1351. }, function (reason) {
  1352. comObj.postMessage({
  1353. isReply: true,
  1354. callbackId: data.callbackId,
  1355. error: reason
  1356. });
  1357. });
  1358. } else {
  1359. action[0].call(action[1], data.data);
  1360. }
  1361. } else {
  1362. error('Unknown action from worker: ' + data.action);
  1363. }
  1364. };
  1365. }
  1366. MessageHandler.prototype = {
  1367. on: function messageHandlerOn(actionName, handler, scope) {
  1368. var ah = this.actionHandler;
  1369. if (ah[actionName]) {
  1370. error('There is already an actionName called "' + actionName + '"');
  1371. }
  1372. ah[actionName] = [handler, scope];
  1373. },
  1374. /**
  1375. * Sends a message to the comObj to invoke the action with the supplied data.
  1376. * @param {String} actionName Action to call.
  1377. * @param {JSON} data JSON data to send.
  1378. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1379. */
  1380. send: function messageHandlerSend(actionName, data, transfers) {
  1381. var message = {
  1382. action: actionName,
  1383. data: data
  1384. };
  1385. this.postMessage(message, transfers);
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * Expects that other side will callback with the response.
  1390. * @param {String} actionName Action to call.
  1391. * @param {JSON} data JSON data to send.
  1392. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1393. * @returns {Promise} Promise to be resolved with response data.
  1394. */
  1395. sendWithPromise:
  1396. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1397. var callbackId = this.callbackIndex++;
  1398. var message = {
  1399. action: actionName,
  1400. data: data,
  1401. callbackId: callbackId
  1402. };
  1403. var capability = createPromiseCapability();
  1404. this.callbacksCapabilities[callbackId] = capability;
  1405. try {
  1406. this.postMessage(message, transfers);
  1407. } catch (e) {
  1408. capability.reject(e);
  1409. }
  1410. return capability.promise;
  1411. },
  1412. /**
  1413. * Sends raw message to the comObj.
  1414. * @private
  1415. * @param message {Object} Raw message.
  1416. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1417. */
  1418. postMessage: function (message, transfers) {
  1419. if (transfers && this.postMessageTransfers) {
  1420. this.comObj.postMessage(message, transfers);
  1421. } else {
  1422. this.comObj.postMessage(message);
  1423. }
  1424. }
  1425. };
  1426. function loadJpegStream(id, imageUrl, objs) {
  1427. var img = new Image();
  1428. img.onload = (function loadJpegStream_onloadClosure() {
  1429. objs.resolve(id, img);
  1430. });
  1431. img.onerror = (function loadJpegStream_onerrorClosure() {
  1432. objs.resolve(id, null);
  1433. warn('Error during JPEG image loading');
  1434. });
  1435. img.src = imageUrl;
  1436. }
  1437. /**
  1438. * The maximum allowed image size in total pixels e.g. width * height. Images
  1439. * above this value will not be drawn. Use -1 for no limit.
  1440. * @var {number}
  1441. */
  1442. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1443. -1 : PDFJS.maxImageSize);
  1444. /**
  1445. * The url of where the predefined Adobe CMaps are located. Include trailing
  1446. * slash.
  1447. * @var {string}
  1448. */
  1449. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1450. /**
  1451. * Specifies if CMaps are binary packed.
  1452. * @var {boolean}
  1453. */
  1454. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1455. /*
  1456. * By default fonts are converted to OpenType fonts and loaded via font face
  1457. * rules. If disabled, the font will be rendered using a built in font renderer
  1458. * that constructs the glyphs with primitive path commands.
  1459. * @var {boolean}
  1460. */
  1461. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1462. false : PDFJS.disableFontFace);
  1463. /**
  1464. * Path for image resources, mainly for annotation icons. Include trailing
  1465. * slash.
  1466. * @var {string}
  1467. */
  1468. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1469. '' : PDFJS.imageResourcesPath);
  1470. /**
  1471. * Disable the web worker and run all code on the main thread. This will happen
  1472. * automatically if the browser doesn't support workers or sending typed arrays
  1473. * to workers.
  1474. * @var {boolean}
  1475. */
  1476. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1477. false : PDFJS.disableWorker);
  1478. /**
  1479. * Path and filename of the worker file. Required when the worker is enabled in
  1480. * development mode. If unspecified in the production build, the worker will be
  1481. * loaded based on the location of the pdf.js file.
  1482. * @var {string}
  1483. */
  1484. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1485. /**
  1486. * Disable range request loading of PDF files. When enabled and if the server
  1487. * supports partial content requests then the PDF will be fetched in chunks.
  1488. * Enabled (false) by default.
  1489. * @var {boolean}
  1490. */
  1491. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1492. false : PDFJS.disableRange);
  1493. /**
  1494. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1495. * will automatically keep fetching more data even if it isn't needed to display
  1496. * the current page. This default behavior can be disabled.
  1497. * @var {boolean}
  1498. */
  1499. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1500. false : PDFJS.disableAutoFetch);
  1501. /**
  1502. * Enables special hooks for debugging PDF.js.
  1503. * @var {boolean}
  1504. */
  1505. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1506. /**
  1507. * Enables transfer usage in postMessage for ArrayBuffers.
  1508. * @var {boolean}
  1509. */
  1510. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1511. true : PDFJS.postMessageTransfers);
  1512. /**
  1513. * Disables URL.createObjectURL usage.
  1514. * @var {boolean}
  1515. */
  1516. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1517. false : PDFJS.disableCreateObjectURL);
  1518. /**
  1519. * Disables WebGL usage.
  1520. * @var {boolean}
  1521. */
  1522. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1523. true : PDFJS.disableWebGL);
  1524. /**
  1525. * Enables CSS only zooming.
  1526. * @var {boolean}
  1527. */
  1528. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1529. false : PDFJS.useOnlyCssZoom);
  1530. /**
  1531. * Controls the logging level.
  1532. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1533. * - errors
  1534. * - warnings [default]
  1535. * - infos
  1536. * @var {number}
  1537. */
  1538. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1539. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1540. /**
  1541. * The maximum supported canvas size in total pixels e.g. width * height.
  1542. * The default value is 4096 * 4096. Use -1 for no limit.
  1543. * @var {number}
  1544. */
  1545. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1546. 16777216 : PDFJS.maxCanvasPixels);
  1547. /**
  1548. * Document initialization / loading parameters object.
  1549. *
  1550. * @typedef {Object} DocumentInitParameters
  1551. * @property {string} url - The URL of the PDF.
  1552. * @property {TypedArray} data - A typed array with PDF data.
  1553. * @property {Object} httpHeaders - Basic authentication headers.
  1554. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1555. * Access-Control requests should be made using credentials such as cookies
  1556. * or authorization headers. The default is false.
  1557. * @property {string} password - For decrypting password-protected PDFs.
  1558. * @property {TypedArray} initialData - A typed array with the first portion or
  1559. * all of the pdf data. Used by the extension since some data is already
  1560. * loaded before the switch to range requests.
  1561. */
  1562. /**
  1563. * @typedef {Object} PDFDocumentStats
  1564. * @property {Array} streamTypes - Used stream types in the document (an item
  1565. * is set to true if specific stream ID was used in the document).
  1566. * @property {Array} fontTypes - Used font type in the document (an item is set
  1567. * to true if specific font ID was used in the document).
  1568. */
  1569. /**
  1570. * This is the main entry point for loading a PDF and interacting with it.
  1571. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1572. * is used, which means it must follow the same origin rules that any XHR does
  1573. * e.g. No cross domain requests without CORS.
  1574. *
  1575. * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
  1576. * where a PDF is located, a typed array (Uint8Array) already populated with
  1577. * data or parameter object.
  1578. *
  1579. * @param {Object} pdfDataRangeTransport is optional. It is used if you want
  1580. * to manually serve range requests for data in the PDF. See viewer.js for
  1581. * an example of pdfDataRangeTransport's interface.
  1582. *
  1583. * @param {function} passwordCallback is optional. It is used to request a
  1584. * password if wrong or no password was provided. The callback receives two
  1585. * parameters: function that needs to be called with new password and reason
  1586. * (see {PasswordResponses}).
  1587. *
  1588. * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
  1589. * object.
  1590. */
  1591. PDFJS.getDocument = function getDocument(source,
  1592. pdfDataRangeTransport,
  1593. passwordCallback,
  1594. progressCallback) {
  1595. var workerInitializedCapability, workerReadyCapability, transport;
  1596. if (typeof source === 'string') {
  1597. source = { url: source };
  1598. } else if (isArrayBuffer(source)) {
  1599. source = { data: source };
  1600. } else if (typeof source !== 'object') {
  1601. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1602. 'string or a parameter object');
  1603. }
  1604. if (!source.url && !source.data) {
  1605. error('Invalid parameter array, need either .data or .url');
  1606. }
  1607. // copy/use all keys as is except 'url' -- full path is required
  1608. var params = {};
  1609. for (var key in source) {
  1610. if (key === 'url' && typeof window !== 'undefined') {
  1611. params[key] = combineUrl(window.location.href, source[key]);
  1612. continue;
  1613. }
  1614. params[key] = source[key];
  1615. }
  1616. workerInitializedCapability = createPromiseCapability();
  1617. workerReadyCapability = createPromiseCapability();
  1618. transport = new WorkerTransport(workerInitializedCapability,
  1619. workerReadyCapability, pdfDataRangeTransport,
  1620. progressCallback);
  1621. workerInitializedCapability.promise.then(function transportInitialized() {
  1622. transport.passwordCallback = passwordCallback;
  1623. transport.fetchDocument(params);
  1624. });
  1625. return workerReadyCapability.promise;
  1626. };
  1627. /**
  1628. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1629. * properties that can be read synchronously.
  1630. * @class
  1631. */
  1632. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1633. function PDFDocumentProxy(pdfInfo, transport) {
  1634. this.pdfInfo = pdfInfo;
  1635. this.transport = transport;
  1636. }
  1637. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1638. /**
  1639. * @return {number} Total number of pages the PDF contains.
  1640. */
  1641. get numPages() {
  1642. return this.pdfInfo.numPages;
  1643. },
  1644. /**
  1645. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1646. * unique.
  1647. */
  1648. get fingerprint() {
  1649. return this.pdfInfo.fingerprint;
  1650. },
  1651. /**
  1652. * @param {number} pageNumber The page number to get. The first page is 1.
  1653. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1654. * object.
  1655. */
  1656. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1657. return this.transport.getPage(pageNumber);
  1658. },
  1659. /**
  1660. * @param {{num: number, gen: number}} ref The page reference. Must have
  1661. * the 'num' and 'gen' properties.
  1662. * @return {Promise} A promise that is resolved with the page index that is
  1663. * associated with the reference.
  1664. */
  1665. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1666. return this.transport.getPageIndex(ref);
  1667. },
  1668. /**
  1669. * @return {Promise} A promise that is resolved with a lookup table for
  1670. * mapping named destinations to reference numbers.
  1671. */
  1672. getDestinations: function PDFDocumentProxy_getDestinations() {
  1673. return this.transport.getDestinations();
  1674. },
  1675. /**
  1676. * @return {Promise} A promise that is resolved with a lookup table for
  1677. * mapping named attachments to their content.
  1678. */
  1679. getAttachments: function PDFDocumentProxy_getAttachments() {
  1680. return this.transport.getAttachments();
  1681. },
  1682. /**
  1683. * @return {Promise} A promise that is resolved with an array of all the
  1684. * JavaScript strings in the name tree.
  1685. */
  1686. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1687. return this.transport.getJavaScript();
  1688. },
  1689. /**
  1690. * @return {Promise} A promise that is resolved with an {Array} that is a
  1691. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1692. * [
  1693. * {
  1694. * title: string,
  1695. * bold: boolean,
  1696. * italic: boolean,
  1697. * color: rgb array,
  1698. * dest: dest obj,
  1699. * items: array of more items like this
  1700. * },
  1701. * ...
  1702. * ].
  1703. */
  1704. getOutline: function PDFDocumentProxy_getOutline() {
  1705. return this.transport.getOutline();
  1706. },
  1707. /**
  1708. * @return {Promise} A promise that is resolved with an {Object} that has
  1709. * info and metadata properties. Info is an {Object} filled with anything
  1710. * available in the information dictionary and similarly metadata is a
  1711. * {Metadata} object with information from the metadata section of the PDF.
  1712. */
  1713. getMetadata: function PDFDocumentProxy_getMetadata() {
  1714. return this.transport.getMetadata();
  1715. },
  1716. /**
  1717. * @return {Promise} A promise that is resolved with a TypedArray that has
  1718. * the raw data from the PDF.
  1719. */
  1720. getData: function PDFDocumentProxy_getData() {
  1721. return this.transport.getData();
  1722. },
  1723. /**
  1724. * @return {Promise} A promise that is resolved when the document's data
  1725. * is loaded. It is resolved with an {Object} that contains the length
  1726. * property that indicates size of the PDF data in bytes.
  1727. */
  1728. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1729. return this.transport.downloadInfoCapability.promise;
  1730. },
  1731. /**
  1732. * @returns {Promise} A promise this is resolved with current stats about
  1733. * document structures (see {@link PDFDocumentStats}).
  1734. */
  1735. getStats: function PDFDocumentProxy_getStats() {
  1736. return this.transport.getStats();
  1737. },
  1738. /**
  1739. * Cleans up resources allocated by the document, e.g. created @font-face.
  1740. */
  1741. cleanup: function PDFDocumentProxy_cleanup() {
  1742. this.transport.startCleanup();
  1743. },
  1744. /**
  1745. * Destroys current document instance and terminates worker.
  1746. */
  1747. destroy: function PDFDocumentProxy_destroy() {
  1748. this.transport.destroy();
  1749. }
  1750. };
  1751. return PDFDocumentProxy;
  1752. })();
  1753. /**
  1754. * Page text content.
  1755. *
  1756. * @typedef {Object} TextContent
  1757. * @property {array} items - array of {@link TextItem}
  1758. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1759. * name.
  1760. */
  1761. /**
  1762. * Page text content part.
  1763. *
  1764. * @typedef {Object} TextItem
  1765. * @property {string} str - text content.
  1766. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1767. * @property {array} transform - transformation matrix.
  1768. * @property {number} width - width in device space.
  1769. * @property {number} height - height in device space.
  1770. * @property {string} fontName - font name used by pdf.js for converted font.
  1771. */
  1772. /**
  1773. * Text style.
  1774. *
  1775. * @typedef {Object} TextStyle
  1776. * @property {number} ascent - font ascent.
  1777. * @property {number} descent - font descent.
  1778. * @property {boolean} vertical - text is in vertical mode.
  1779. * @property {string} fontFamily - possible font family
  1780. */
  1781. /**
  1782. * Page render parameters.
  1783. *
  1784. * @typedef {Object} RenderParameters
  1785. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1786. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1787. * calling of PDFPage.getViewport method.
  1788. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1789. * (default value is 'display').
  1790. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1791. * endLayout and appendImage functions.
  1792. * @property {function} continueCallback - (optional) A function that will be
  1793. * called each time the rendering is paused. To continue
  1794. * rendering call the function that is the first argument
  1795. * to the callback.
  1796. */
  1797. /**
  1798. * PDF page operator list.
  1799. *
  1800. * @typedef {Object} PDFOperatorList
  1801. * @property {Array} fnArray - Array containing the operator functions.
  1802. * @property {Array} argsArray - Array containing the arguments of the
  1803. * functions.
  1804. */
  1805. /**
  1806. * Proxy to a PDFPage in the worker thread.
  1807. * @class
  1808. */
  1809. var PDFPageProxy = (function PDFPageProxyClosure() {
  1810. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1811. this.pageIndex = pageIndex;
  1812. this.pageInfo = pageInfo;
  1813. this.transport = transport;
  1814. this.stats = new StatTimer();
  1815. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1816. this.commonObjs = transport.commonObjs;
  1817. this.objs = new PDFObjects();
  1818. this.cleanupAfterRender = false;
  1819. this.pendingDestroy = false;
  1820. this.intentStates = {};
  1821. }
  1822. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1823. /**
  1824. * @return {number} Page number of the page. First page is 1.
  1825. */
  1826. get pageNumber() {
  1827. return this.pageIndex + 1;
  1828. },
  1829. /**
  1830. * @return {number} The number of degrees the page is rotated clockwise.
  1831. */
  1832. get rotate() {
  1833. return this.pageInfo.rotate;
  1834. },
  1835. /**
  1836. * @return {Object} The reference that points to this page. It has 'num' and
  1837. * 'gen' properties.
  1838. */
  1839. get ref() {
  1840. return this.pageInfo.ref;
  1841. },
  1842. /**
  1843. * @return {Array} An array of the visible portion of the PDF page in the
  1844. * user space units - [x1, y1, x2, y2].
  1845. */
  1846. get view() {
  1847. return this.pageInfo.view;
  1848. },
  1849. /**
  1850. * @param {number} scale The desired scale of the viewport.
  1851. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1852. * defaults to the page rotation.
  1853. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1854. * along with transforms required for rendering.
  1855. */
  1856. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1857. if (arguments.length < 2) {
  1858. rotate = this.rotate;
  1859. }
  1860. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1861. },
  1862. /**
  1863. * @return {Promise} A promise that is resolved with an {Array} of the
  1864. * annotation objects.
  1865. */
  1866. getAnnotations: function PDFPageProxy_getAnnotations() {
  1867. if (this.annotationsPromise) {
  1868. return this.annotationsPromise;
  1869. }
  1870. var promise = this.transport.getAnnotations(this.pageIndex);
  1871. this.annotationsPromise = promise;
  1872. return promise;
  1873. },
  1874. /**
  1875. * Begins the process of rendering a page to the desired context.
  1876. * @param {RenderParameters} params Page render parameters.
  1877. * @return {RenderTask} An object that contains the promise, which
  1878. * is resolved when the page finishes rendering.
  1879. */
  1880. render: function PDFPageProxy_render(params) {
  1881. var stats = this.stats;
  1882. stats.time('Overall');
  1883. // If there was a pending destroy cancel it so no cleanup happens during
  1884. // this call to render.
  1885. this.pendingDestroy = false;
  1886. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1887. if (!this.intentStates[renderingIntent]) {
  1888. this.intentStates[renderingIntent] = {};
  1889. }
  1890. var intentState = this.intentStates[renderingIntent];
  1891. // If there's no displayReadyCapability yet, then the operatorList
  1892. // was never requested before. Make the request and create the promise.
  1893. if (!intentState.displayReadyCapability) {
  1894. intentState.receivingOperatorList = true;
  1895. intentState.displayReadyCapability = createPromiseCapability();
  1896. intentState.operatorList = {
  1897. fnArray: [],
  1898. argsArray: [],
  1899. lastChunk: false
  1900. };
  1901. this.stats.time('Page Request');
  1902. this.transport.messageHandler.send('RenderPageRequest', {
  1903. pageIndex: this.pageNumber - 1,
  1904. intent: renderingIntent
  1905. });
  1906. }
  1907. var internalRenderTask = new InternalRenderTask(complete, params,
  1908. this.objs,
  1909. this.commonObjs,
  1910. intentState.operatorList,
  1911. this.pageNumber);
  1912. if (!intentState.renderTasks) {
  1913. intentState.renderTasks = [];
  1914. }
  1915. intentState.renderTasks.push(internalRenderTask);
  1916. var renderTask = new RenderTask(internalRenderTask);
  1917. var self = this;
  1918. intentState.displayReadyCapability.promise.then(
  1919. function pageDisplayReadyPromise(transparency) {
  1920. if (self.pendingDestroy) {
  1921. complete();
  1922. return;
  1923. }
  1924. stats.time('Rendering');
  1925. internalRenderTask.initalizeGraphics(transparency);
  1926. internalRenderTask.operatorListChanged();
  1927. },
  1928. function pageDisplayReadPromiseError(reason) {
  1929. complete(reason);
  1930. }
  1931. );
  1932. function complete(error) {
  1933. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1934. if (i >= 0) {
  1935. intentState.renderTasks.splice(i, 1);
  1936. }
  1937. if (self.cleanupAfterRender) {
  1938. self.pendingDestroy = true;
  1939. }
  1940. self._tryDestroy();
  1941. if (error) {
  1942. internalRenderTask.capability.reject(error);
  1943. } else {
  1944. internalRenderTask.capability.resolve();
  1945. }
  1946. stats.timeEnd('Rendering');
  1947. stats.timeEnd('Overall');
  1948. }
  1949. return renderTask;
  1950. },
  1951. /**
  1952. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1953. * object that represents page's operator list.
  1954. */
  1955. getOperatorList: function PDFPageProxy_getOperatorList() {
  1956. function operatorListChanged() {
  1957. if (intentState.operatorList.lastChunk) {
  1958. intentState.opListReadCapability.resolve(intentState.operatorList);
  1959. }
  1960. }
  1961. var renderingIntent = 'oplist';
  1962. if (!this.intentStates[renderingIntent]) {
  1963. this.intentStates[renderingIntent] = {};
  1964. }
  1965. var intentState = this.intentStates[renderingIntent];
  1966. if (!intentState.opListReadCapability) {
  1967. var opListTask = {};
  1968. opListTask.operatorListChanged = operatorListChanged;
  1969. intentState.receivingOperatorList = true;
  1970. intentState.opListReadCapability = createPromiseCapability();
  1971. intentState.renderTasks = [];
  1972. intentState.renderTasks.push(opListTask);
  1973. intentState.operatorList = {
  1974. fnArray: [],
  1975. argsArray: [],
  1976. lastChunk: false
  1977. };
  1978. this.transport.messageHandler.send('RenderPageRequest', {
  1979. pageIndex: this.pageIndex,
  1980. intent: renderingIntent
  1981. });
  1982. }
  1983. return intentState.opListReadCapability.promise;
  1984. },
  1985. /**
  1986. * @return {Promise} That is resolved a {@link TextContent}
  1987. * object that represent the page text content.
  1988. */
  1989. getTextContent: function PDFPageProxy_getTextContent() {
  1990. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  1991. pageIndex: this.pageNumber - 1
  1992. });
  1993. },
  1994. /**
  1995. * Destroys resources allocated by the page.
  1996. */
  1997. destroy: function PDFPageProxy_destroy() {
  1998. this.pendingDestroy = true;
  1999. this._tryDestroy();
  2000. },
  2001. /**
  2002. * For internal use only. Attempts to clean up if rendering is in a state
  2003. * where that's possible.
  2004. * @ignore
  2005. */
  2006. _tryDestroy: function PDFPageProxy__destroy() {
  2007. if (!this.pendingDestroy ||
  2008. Object.keys(this.intentStates).some(function(intent) {
  2009. var intentState = this.intentStates[intent];
  2010. return (intentState.renderTasks.length !== 0 ||
  2011. intentState.receivingOperatorList);
  2012. }, this)) {
  2013. return;
  2014. }
  2015. Object.keys(this.intentStates).forEach(function(intent) {
  2016. delete this.intentStates[intent];
  2017. }, this);
  2018. this.objs.clear();
  2019. this.annotationsPromise = null;
  2020. this.pendingDestroy = false;
  2021. },
  2022. /**
  2023. * For internal use only.
  2024. * @ignore
  2025. */
  2026. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2027. intent) {
  2028. var intentState = this.intentStates[intent];
  2029. // TODO Refactor RenderPageRequest to separate rendering
  2030. // and operator list logic
  2031. if (intentState.displayReadyCapability) {
  2032. intentState.displayReadyCapability.resolve(transparency);
  2033. }
  2034. },
  2035. /**
  2036. * For internal use only.
  2037. * @ignore
  2038. */
  2039. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2040. intent) {
  2041. var intentState = this.intentStates[intent];
  2042. var i, ii;
  2043. // Add the new chunk to the current operator list.
  2044. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2045. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2046. intentState.operatorList.argsArray.push(
  2047. operatorListChunk.argsArray[i]);
  2048. }
  2049. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2050. // Notify all the rendering tasks there are more operators to be consumed.
  2051. for (i = 0; i < intentState.renderTasks.length; i++) {
  2052. intentState.renderTasks[i].operatorListChanged();
  2053. }
  2054. if (operatorListChunk.lastChunk) {
  2055. intentState.receivingOperatorList = false;
  2056. this._tryDestroy();
  2057. }
  2058. }
  2059. };
  2060. return PDFPageProxy;
  2061. })();
  2062. /**
  2063. * For internal use only.
  2064. * @ignore
  2065. */
  2066. var WorkerTransport = (function WorkerTransportClosure() {
  2067. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2068. pdfDataRangeTransport, progressCallback) {
  2069. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2070. this.workerInitializedCapability = workerInitializedCapability;
  2071. this.workerReadyCapability = workerReadyCapability;
  2072. this.progressCallback = progressCallback;
  2073. this.commonObjs = new PDFObjects();
  2074. this.pageCache = [];
  2075. this.pagePromises = [];
  2076. this.downloadInfoCapability = createPromiseCapability();
  2077. this.passwordCallback = null;
  2078. // If worker support isn't disabled explicit and the browser has worker
  2079. // support, create a new web worker and test if it/the browser fullfills
  2080. // all requirements to run parts of pdf.js in a web worker.
  2081. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2082. // as it arrives on the worker. Chrome added this with version 15.
  2083. // Either workers are disabled, not supported or have thrown an exception.
  2084. // Thus, we fallback to a faked worker.
  2085. this.setupFakeWorker();
  2086. }
  2087. WorkerTransport.prototype = {
  2088. destroy: function WorkerTransport_destroy() {
  2089. this.pageCache = [];
  2090. this.pagePromises = [];
  2091. var self = this;
  2092. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2093. FontLoader.clear();
  2094. if (self.worker) {
  2095. self.worker.terminate();
  2096. }
  2097. });
  2098. },
  2099. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2100. globalScope.PDFJS.disableWorker = true;
  2101. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2102. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2103. // In the developer build load worker_loader which in turn loads all the
  2104. // other files and resolves the promise. In production only the
  2105. // pdf.worker.js file is needed.
  2106. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2107. }
  2108. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2109. warn('Setting up fake worker.');
  2110. // If we don't use a worker, just post/sendMessage to the main thread.
  2111. var fakeWorker = {
  2112. postMessage: function WorkerTransport_postMessage(obj) {
  2113. fakeWorker.onmessage({data: obj});
  2114. },
  2115. terminate: function WorkerTransport_terminate() {}
  2116. };
  2117. var messageHandler = new MessageHandler('main', fakeWorker);
  2118. this.setupMessageHandler(messageHandler);
  2119. // If the main thread is our worker, setup the handling for the messages
  2120. // the main thread sends to it self.
  2121. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2122. this.workerInitializedCapability.resolve();
  2123. }.bind(this));
  2124. },
  2125. setupMessageHandler:
  2126. function WorkerTransport_setupMessageHandler(messageHandler) {
  2127. this.messageHandler = messageHandler;
  2128. function updatePassword(password) {
  2129. messageHandler.send('UpdatePassword', password);
  2130. }
  2131. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2132. if (pdfDataRangeTransport) {
  2133. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2134. messageHandler.send('OnDataRange', {
  2135. begin: begin,
  2136. chunk: chunk
  2137. });
  2138. });
  2139. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2140. messageHandler.send('OnDataProgress', {
  2141. loaded: loaded
  2142. });
  2143. });
  2144. messageHandler.on('RequestDataRange',
  2145. function transportDataRange(data) {
  2146. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2147. }, this);
  2148. }
  2149. messageHandler.on('GetDoc', function transportDoc(data) {
  2150. var pdfInfo = data.pdfInfo;
  2151. this.numPages = data.pdfInfo.numPages;
  2152. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2153. this.pdfDocument = pdfDocument;
  2154. this.workerReadyCapability.resolve(pdfDocument);
  2155. }, this);
  2156. messageHandler.on('NeedPassword', function transportPassword(data) {
  2157. if (this.passwordCallback) {
  2158. return this.passwordCallback(updatePassword,
  2159. PasswordResponses.NEED_PASSWORD);
  2160. }
  2161. this.workerReadyCapability.reject(data.exception.message,
  2162. data.exception);
  2163. }, this);
  2164. messageHandler.on('IncorrectPassword', function transportBadPass(data) {
  2165. if (this.passwordCallback) {
  2166. return this.passwordCallback(updatePassword,
  2167. PasswordResponses.INCORRECT_PASSWORD);
  2168. }
  2169. this.workerReadyCapability.reject(data.exception.message,
  2170. data.exception);
  2171. }, this);
  2172. messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
  2173. this.workerReadyCapability.reject(data.exception.name, data.exception);
  2174. }, this);
  2175. messageHandler.on('MissingPDF', function transportMissingPDF(data) {
  2176. this.workerReadyCapability.reject(data.exception.message,
  2177. data.exception);
  2178. }, this);
  2179. messageHandler.on('UnknownError', function transportUnknownError(data) {
  2180. this.workerReadyCapability.reject(data.exception.message,
  2181. data.exception);
  2182. }, this);
  2183. messageHandler.on('DataLoaded', function transportPage(data) {
  2184. this.downloadInfoCapability.resolve(data);
  2185. }, this);
  2186. messageHandler.on('StartRenderPage', function transportRender(data) {
  2187. var page = this.pageCache[data.pageIndex];
  2188. page.stats.timeEnd('Page Request');
  2189. page._startRenderPage(data.transparency, data.intent);
  2190. }, this);
  2191. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2192. var page = this.pageCache[data.pageIndex];
  2193. page._renderPageChunk(data.operatorList, data.intent);
  2194. }, this);
  2195. messageHandler.on('commonobj', function transportObj(data) {
  2196. var id = data[0];
  2197. var type = data[1];
  2198. if (this.commonObjs.hasData(id)) {
  2199. return;
  2200. }
  2201. switch (type) {
  2202. case 'Font':
  2203. var exportedData = data[2];
  2204. var font;
  2205. if ('error' in exportedData) {
  2206. var error = exportedData.error;
  2207. warn('Error during font loading: ' + error);
  2208. this.commonObjs.resolve(id, error);
  2209. break;
  2210. } else {
  2211. font = new FontFace(exportedData);
  2212. }
  2213. FontLoader.bind(
  2214. [font],
  2215. function fontReady(fontObjs) {
  2216. this.commonObjs.resolve(id, font);
  2217. }.bind(this)
  2218. );
  2219. break;
  2220. case 'FontPath':
  2221. this.commonObjs.resolve(id, data[2]);
  2222. break;
  2223. default:
  2224. error('Got unknown common object type ' + type);
  2225. }
  2226. }, this);
  2227. messageHandler.on('obj', function transportObj(data) {
  2228. var id = data[0];
  2229. var pageIndex = data[1];
  2230. var type = data[2];
  2231. var pageProxy = this.pageCache[pageIndex];
  2232. var imageData;
  2233. if (pageProxy.objs.hasData(id)) {
  2234. return;
  2235. }
  2236. switch (type) {
  2237. case 'JpegStream':
  2238. imageData = data[3];
  2239. loadJpegStream(id, imageData, pageProxy.objs);
  2240. break;
  2241. case 'Image':
  2242. imageData = data[3];
  2243. pageProxy.objs.resolve(id, imageData);
  2244. // heuristics that will allow not to store large data
  2245. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2246. if (imageData && 'data' in imageData &&
  2247. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2248. pageProxy.cleanupAfterRender = true;
  2249. }
  2250. break;
  2251. default:
  2252. error('Got unknown object type ' + type);
  2253. }
  2254. }, this);
  2255. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2256. if (this.progressCallback) {
  2257. this.progressCallback({
  2258. loaded: data.loaded,
  2259. total: data.total
  2260. });
  2261. }
  2262. }, this);
  2263. messageHandler.on('DocError', function transportDocError(data) {
  2264. this.workerReadyCapability.reject(data);
  2265. }, this);
  2266. messageHandler.on('PageError', function transportError(data) {
  2267. var page = this.pageCache[data.pageNum - 1];
  2268. var intentState = page.intentStates[data.intent];
  2269. if (intentState.displayReadyCapability.promise) {
  2270. intentState.displayReadyCapability.reject(data.error);
  2271. } else {
  2272. error(data.error);
  2273. }
  2274. }, this);
  2275. messageHandler.on('JpegDecode', function(data) {
  2276. var imageUrl = data[0];
  2277. var components = data[1];
  2278. if (components !== 3 && components !== 1) {
  2279. return Promise.reject(
  2280. new Error('Only 3 components or 1 component can be returned'));
  2281. }
  2282. return new Promise(function (resolve, reject) {
  2283. var img = new Image();
  2284. img.onload = function () {
  2285. var width = img.width;
  2286. var height = img.height;
  2287. var size = width * height;
  2288. var rgbaLength = size * 4;
  2289. var buf = new Uint8Array(size * components);
  2290. var tmpCanvas = createScratchCanvas(width, height);
  2291. var tmpCtx = tmpCanvas.getContext('2d');
  2292. tmpCtx.drawImage(img, 0, 0);
  2293. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2294. var i, j;
  2295. if (components === 3) {
  2296. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2297. buf[j] = data[i];
  2298. buf[j + 1] = data[i + 1];
  2299. buf[j + 2] = data[i + 2];
  2300. }
  2301. } else if (components === 1) {
  2302. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2303. buf[j] = data[i];
  2304. }
  2305. }
  2306. resolve({ data: buf, width: width, height: height});
  2307. };
  2308. img.onerror = function () {
  2309. reject(new Error('JpegDecode failed to load image'));
  2310. };
  2311. img.src = imageUrl;
  2312. });
  2313. });
  2314. },
  2315. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2316. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2317. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2318. this.messageHandler.send('GetDocRequest', {
  2319. source: source,
  2320. disableRange: PDFJS.disableRange,
  2321. maxImageSize: PDFJS.maxImageSize,
  2322. cMapUrl: PDFJS.cMapUrl,
  2323. cMapPacked: PDFJS.cMapPacked,
  2324. disableFontFace: PDFJS.disableFontFace,
  2325. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2326. verbosity: PDFJS.verbosity
  2327. });
  2328. },
  2329. getData: function WorkerTransport_getData() {
  2330. return this.messageHandler.sendWithPromise('GetData', null);
  2331. },
  2332. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2333. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2334. (pageNumber|0) !== pageNumber) {
  2335. return Promise.reject(new Error('Invalid page request'));
  2336. }
  2337. var pageIndex = pageNumber - 1;
  2338. if (pageIndex in this.pagePromises) {
  2339. return this.pagePromises[pageIndex];
  2340. }
  2341. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2342. pageIndex: pageIndex
  2343. }).then(function (pageInfo) {
  2344. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2345. this.pageCache[pageIndex] = page;
  2346. return page;
  2347. }.bind(this));
  2348. this.pagePromises[pageIndex] = promise;
  2349. return promise;
  2350. },
  2351. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2352. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2353. },
  2354. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2355. return this.messageHandler.sendWithPromise('GetAnnotations',
  2356. { pageIndex: pageIndex });
  2357. },
  2358. getDestinations: function WorkerTransport_getDestinations() {
  2359. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2360. },
  2361. getAttachments: function WorkerTransport_getAttachments() {
  2362. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2363. },
  2364. getJavaScript: function WorkerTransport_getJavaScript() {
  2365. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2366. },
  2367. getOutline: function WorkerTransport_getOutline() {
  2368. return this.messageHandler.sendWithPromise('GetOutline', null);
  2369. },
  2370. getMetadata: function WorkerTransport_getMetadata() {
  2371. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2372. then(function transportMetadata(results) {
  2373. return {
  2374. info: results[0],
  2375. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2376. };
  2377. });
  2378. },
  2379. getStats: function WorkerTransport_getStats() {
  2380. return this.messageHandler.sendWithPromise('GetStats', null);
  2381. },
  2382. startCleanup: function WorkerTransport_startCleanup() {
  2383. this.messageHandler.sendWithPromise('Cleanup', null).
  2384. then(function endCleanup() {
  2385. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2386. var page = this.pageCache[i];
  2387. if (page) {
  2388. page.destroy();
  2389. }
  2390. }
  2391. this.commonObjs.clear();
  2392. FontLoader.clear();
  2393. }.bind(this));
  2394. }
  2395. };
  2396. return WorkerTransport;
  2397. })();
  2398. /**
  2399. * A PDF document and page is built of many objects. E.g. there are objects
  2400. * for fonts, images, rendering code and such. These objects might get processed
  2401. * inside of a worker. The `PDFObjects` implements some basic functions to
  2402. * manage these objects.
  2403. * @ignore
  2404. */
  2405. var PDFObjects = (function PDFObjectsClosure() {
  2406. function PDFObjects() {
  2407. this.objs = {};
  2408. }
  2409. PDFObjects.prototype = {
  2410. /**
  2411. * Internal function.
  2412. * Ensures there is an object defined for `objId`.
  2413. */
  2414. ensureObj: function PDFObjects_ensureObj(objId) {
  2415. if (this.objs[objId]) {
  2416. return this.objs[objId];
  2417. }
  2418. var obj = {
  2419. capability: createPromiseCapability(),
  2420. data: null,
  2421. resolved: false
  2422. };
  2423. this.objs[objId] = obj;
  2424. return obj;
  2425. },
  2426. /**
  2427. * If called *without* callback, this returns the data of `objId` but the
  2428. * object needs to be resolved. If it isn't, this function throws.
  2429. *
  2430. * If called *with* a callback, the callback is called with the data of the
  2431. * object once the object is resolved. That means, if you call this
  2432. * function and the object is already resolved, the callback gets called
  2433. * right away.
  2434. */
  2435. get: function PDFObjects_get(objId, callback) {
  2436. // If there is a callback, then the get can be async and the object is
  2437. // not required to be resolved right now
  2438. if (callback) {
  2439. this.ensureObj(objId).capability.promise.then(callback);
  2440. return null;
  2441. }
  2442. // If there isn't a callback, the user expects to get the resolved data
  2443. // directly.
  2444. var obj = this.objs[objId];
  2445. // If there isn't an object yet or the object isn't resolved, then the
  2446. // data isn't ready yet!
  2447. if (!obj || !obj.resolved) {
  2448. error('Requesting object that isn\'t resolved yet ' + objId);
  2449. }
  2450. return obj.data;
  2451. },
  2452. /**
  2453. * Resolves the object `objId` with optional `data`.
  2454. */
  2455. resolve: function PDFObjects_resolve(objId, data) {
  2456. var obj = this.ensureObj(objId);
  2457. obj.resolved = true;
  2458. obj.data = data;
  2459. obj.capability.resolve(data);
  2460. },
  2461. isResolved: function PDFObjects_isResolved(objId) {
  2462. var objs = this.objs;
  2463. if (!objs[objId]) {
  2464. return false;
  2465. } else {
  2466. return objs[objId].resolved;
  2467. }
  2468. },
  2469. hasData: function PDFObjects_hasData(objId) {
  2470. return this.isResolved(objId);
  2471. },
  2472. /**
  2473. * Returns the data of `objId` if object exists, null otherwise.
  2474. */
  2475. getData: function PDFObjects_getData(objId) {
  2476. var objs = this.objs;
  2477. if (!objs[objId] || !objs[objId].resolved) {
  2478. return null;
  2479. } else {
  2480. return objs[objId].data;
  2481. }
  2482. },
  2483. clear: function PDFObjects_clear() {
  2484. this.objs = {};
  2485. }
  2486. };
  2487. return PDFObjects;
  2488. })();
  2489. /**
  2490. * Allows controlling of the rendering tasks.
  2491. * @class
  2492. */
  2493. var RenderTask = (function RenderTaskClosure() {
  2494. function RenderTask(internalRenderTask) {
  2495. this.internalRenderTask = internalRenderTask;
  2496. /**
  2497. * Promise for rendering task completion.
  2498. * @type {Promise}
  2499. */
  2500. this.promise = this.internalRenderTask.capability.promise;
  2501. }
  2502. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2503. /**
  2504. * Cancels the rendering task. If the task is currently rendering it will
  2505. * not be cancelled until graphics pauses with a timeout. The promise that
  2506. * this object extends will resolved when cancelled.
  2507. */
  2508. cancel: function RenderTask_cancel() {
  2509. this.internalRenderTask.cancel();
  2510. },
  2511. /**
  2512. * Registers callback to indicate the rendering task completion.
  2513. *
  2514. * @param {function} onFulfilled The callback for the rendering completion.
  2515. * @param {function} onRejected The callback for the rendering failure.
  2516. * @return {Promise} A promise that is resolved after the onFulfilled or
  2517. * onRejected callback.
  2518. */
  2519. then: function RenderTask_then(onFulfilled, onRejected) {
  2520. return this.promise.then(onFulfilled, onRejected);
  2521. }
  2522. };
  2523. return RenderTask;
  2524. })();
  2525. /**
  2526. * For internal use only.
  2527. * @ignore
  2528. */
  2529. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2530. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2531. pageNumber) {
  2532. this.callback = callback;
  2533. this.params = params;
  2534. this.objs = objs;
  2535. this.commonObjs = commonObjs;
  2536. this.operatorListIdx = null;
  2537. this.operatorList = operatorList;
  2538. this.pageNumber = pageNumber;
  2539. this.running = false;
  2540. this.graphicsReadyCallback = null;
  2541. this.graphicsReady = false;
  2542. this.cancelled = false;
  2543. this.capability = createPromiseCapability();
  2544. // caching this-bound methods
  2545. this._continueBound = this._continue.bind(this);
  2546. this._scheduleNextBound = this._scheduleNext.bind(this);
  2547. this._nextBound = this._next.bind(this);
  2548. }
  2549. InternalRenderTask.prototype = {
  2550. initalizeGraphics:
  2551. function InternalRenderTask_initalizeGraphics(transparency) {
  2552. if (this.cancelled) {
  2553. return;
  2554. }
  2555. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2556. globalScope.StepperManager.enabled) {
  2557. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2558. this.stepper.init(this.operatorList);
  2559. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2560. }
  2561. var params = this.params;
  2562. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2563. this.objs, params.imageLayer);
  2564. this.gfx.beginDrawing(params.viewport, transparency);
  2565. this.operatorListIdx = 0;
  2566. this.graphicsReady = true;
  2567. if (this.graphicsReadyCallback) {
  2568. this.graphicsReadyCallback();
  2569. }
  2570. },
  2571. cancel: function InternalRenderTask_cancel() {
  2572. this.running = false;
  2573. this.cancelled = true;
  2574. this.callback('cancelled');
  2575. },
  2576. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2577. if (!this.graphicsReady) {
  2578. if (!this.graphicsReadyCallback) {
  2579. this.graphicsReadyCallback = this._continueBound;
  2580. }
  2581. return;
  2582. }
  2583. if (this.stepper) {
  2584. this.stepper.updateOperatorList(this.operatorList);
  2585. }
  2586. if (this.running) {
  2587. return;
  2588. }
  2589. this._continue();
  2590. },
  2591. _continue: function InternalRenderTask__continue() {
  2592. this.running = true;
  2593. if (this.cancelled) {
  2594. return;
  2595. }
  2596. if (this.params.continueCallback) {
  2597. this.params.continueCallback(this._scheduleNextBound);
  2598. } else {
  2599. this._scheduleNext();
  2600. }
  2601. },
  2602. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2603. window.requestAnimationFrame(this._nextBound);
  2604. },
  2605. _next: function InternalRenderTask__next() {
  2606. if (this.cancelled) {
  2607. return;
  2608. }
  2609. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2610. this.operatorListIdx,
  2611. this._continueBound,
  2612. this.stepper);
  2613. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2614. this.running = false;
  2615. if (this.operatorList.lastChunk) {
  2616. this.gfx.endDrawing();
  2617. this.callback();
  2618. }
  2619. }
  2620. }
  2621. };
  2622. return InternalRenderTask;
  2623. })();
  2624. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2625. function fixMetadata(meta) {
  2626. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2627. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2628. function(code, d1, d2, d3) {
  2629. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2630. });
  2631. var chars = '';
  2632. for (var i = 0; i < bytes.length; i += 2) {
  2633. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2634. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2635. code !== 38 && false ? String.fromCharCode(code) :
  2636. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2637. }
  2638. return '>' + chars;
  2639. });
  2640. }
  2641. function Metadata(meta) {
  2642. if (typeof meta === 'string') {
  2643. // Ghostscript produces invalid metadata
  2644. meta = fixMetadata(meta);
  2645. var parser = new DOMParser();
  2646. meta = parser.parseFromString(meta, 'application/xml');
  2647. } else if (!(meta instanceof Document)) {
  2648. error('Metadata: Invalid metadata object');
  2649. }
  2650. this.metaDocument = meta;
  2651. this.metadata = {};
  2652. this.parse();
  2653. }
  2654. Metadata.prototype = {
  2655. parse: function Metadata_parse() {
  2656. var doc = this.metaDocument;
  2657. var rdf = doc.documentElement;
  2658. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2659. rdf = rdf.firstChild;
  2660. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2661. rdf = rdf.nextSibling;
  2662. }
  2663. }
  2664. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2665. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2666. return;
  2667. }
  2668. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2669. for (i = 0, length = children.length; i < length; i++) {
  2670. desc = children[i];
  2671. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2672. continue;
  2673. }
  2674. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2675. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2676. entry = desc.childNodes[ii];
  2677. name = entry.nodeName.toLowerCase();
  2678. this.metadata[name] = entry.textContent.trim();
  2679. }
  2680. }
  2681. }
  2682. },
  2683. get: function Metadata_get(name) {
  2684. return this.metadata[name] || null;
  2685. },
  2686. has: function Metadata_has(name) {
  2687. return typeof this.metadata[name] !== 'undefined';
  2688. }
  2689. };
  2690. return Metadata;
  2691. })();
  2692. // <canvas> contexts store most of the state we need natively.
  2693. // However, PDF needs a bit more state, which we store here.
  2694. // Minimal font size that would be used during canvas fillText operations.
  2695. var MIN_FONT_SIZE = 16;
  2696. var MAX_GROUP_SIZE = 4096;
  2697. var COMPILE_TYPE3_GLYPHS = true;
  2698. function createScratchCanvas(width, height) {
  2699. var canvas = document.createElement('canvas');
  2700. canvas.width = width;
  2701. canvas.height = height;
  2702. return canvas;
  2703. }
  2704. function addContextCurrentTransform(ctx) {
  2705. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2706. if (!ctx.mozCurrentTransform) {
  2707. // Store the original context
  2708. ctx._scaleX = ctx._scaleX || 1.0;
  2709. ctx._scaleY = ctx._scaleY || 1.0;
  2710. ctx._originalSave = ctx.save;
  2711. ctx._originalRestore = ctx.restore;
  2712. ctx._originalRotate = ctx.rotate;
  2713. ctx._originalScale = ctx.scale;
  2714. ctx._originalTranslate = ctx.translate;
  2715. ctx._originalTransform = ctx.transform;
  2716. ctx._originalSetTransform = ctx.setTransform;
  2717. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2718. ctx._transformStack = [];
  2719. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2720. get: function getCurrentTransform() {
  2721. return this._transformMatrix;
  2722. }
  2723. });
  2724. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2725. get: function getCurrentTransformInverse() {
  2726. // Calculation done using WolframAlpha:
  2727. // http://www.wolframalpha.com/input/?
  2728. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2729. var m = this._transformMatrix;
  2730. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2731. var ad_bc = a * d - b * c;
  2732. var bc_ad = b * c - a * d;
  2733. return [
  2734. d / ad_bc,
  2735. b / bc_ad,
  2736. c / bc_ad,
  2737. a / ad_bc,
  2738. (d * e - c * f) / bc_ad,
  2739. (b * e - a * f) / ad_bc
  2740. ];
  2741. }
  2742. });
  2743. ctx.save = function ctxSave() {
  2744. var old = this._transformMatrix;
  2745. this._transformStack.push(old);
  2746. this._transformMatrix = old.slice(0, 6);
  2747. this._originalSave();
  2748. };
  2749. ctx.restore = function ctxRestore() {
  2750. var prev = this._transformStack.pop();
  2751. if (prev) {
  2752. this._transformMatrix = prev;
  2753. this._originalRestore();
  2754. }
  2755. };
  2756. ctx.translate = function ctxTranslate(x, y) {
  2757. var m = this._transformMatrix;
  2758. m[4] = m[0] * x + m[2] * y + m[4];
  2759. m[5] = m[1] * x + m[3] * y + m[5];
  2760. this._originalTranslate(x, y);
  2761. };
  2762. ctx.scale = function ctxScale(x, y) {
  2763. var m = this._transformMatrix;
  2764. m[0] = m[0] * x;
  2765. m[1] = m[1] * x;
  2766. m[2] = m[2] * y;
  2767. m[3] = m[3] * y;
  2768. this._originalScale(x, y);
  2769. };
  2770. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2771. var m = this._transformMatrix;
  2772. this._transformMatrix = [
  2773. m[0] * a + m[2] * b,
  2774. m[1] * a + m[3] * b,
  2775. m[0] * c + m[2] * d,
  2776. m[1] * c + m[3] * d,
  2777. m[0] * e + m[2] * f + m[4],
  2778. m[1] * e + m[3] * f + m[5]
  2779. ];
  2780. ctx._originalTransform(a, b, c, d, e, f);
  2781. };
  2782. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2783. this._transformMatrix = [a, b, c, d, e, f];
  2784. ctx._originalSetTransform(a, b, c, d, e, f);
  2785. };
  2786. ctx.rotate = function ctxRotate(angle) {
  2787. var cosValue = Math.cos(angle);
  2788. var sinValue = Math.sin(angle);
  2789. var m = this._transformMatrix;
  2790. this._transformMatrix = [
  2791. m[0] * cosValue + m[2] * sinValue,
  2792. m[1] * cosValue + m[3] * sinValue,
  2793. m[0] * (-sinValue) + m[2] * cosValue,
  2794. m[1] * (-sinValue) + m[3] * cosValue,
  2795. m[4],
  2796. m[5]
  2797. ];
  2798. this._originalRotate(angle);
  2799. };
  2800. }
  2801. }
  2802. var CachedCanvases = (function CachedCanvasesClosure() {
  2803. var cache = {};
  2804. return {
  2805. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2806. trackTransform) {
  2807. var canvasEntry;
  2808. if (id in cache) {
  2809. canvasEntry = cache[id];
  2810. canvasEntry.canvas.width = width;
  2811. canvasEntry.canvas.height = height;
  2812. // reset canvas transform for emulated mozCurrentTransform, if needed
  2813. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2814. } else {
  2815. var canvas = createScratchCanvas(width, height);
  2816. var ctx = canvas.getContext('2d');
  2817. if (trackTransform) {
  2818. addContextCurrentTransform(ctx);
  2819. }
  2820. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2821. }
  2822. return canvasEntry;
  2823. },
  2824. clear: function () {
  2825. for (var id in cache) {
  2826. var canvasEntry = cache[id];
  2827. // Zeroing the width and height causes Firefox to release graphics
  2828. // resources immediately, which can greatly reduce memory consumption.
  2829. canvasEntry.canvas.width = 0;
  2830. canvasEntry.canvas.height = 0;
  2831. delete cache[id];
  2832. }
  2833. }
  2834. };
  2835. })();
  2836. function compileType3Glyph(imgData) {
  2837. var POINT_TO_PROCESS_LIMIT = 1000;
  2838. var width = imgData.width, height = imgData.height;
  2839. var i, j, j0, width1 = width + 1;
  2840. var points = new Uint8Array(width1 * (height + 1));
  2841. var POINT_TYPES =
  2842. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2843. // decodes bit-packed mask data
  2844. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2845. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2846. for (i = 0, ii = data0.length; i < ii; i++) {
  2847. var mask = 128, elem = data0[i];
  2848. while (mask > 0) {
  2849. data[pos++] = (elem & mask) ? 0 : 255;
  2850. mask >>= 1;
  2851. }
  2852. }
  2853. // finding iteresting points: every point is located between mask pixels,
  2854. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2855. // will have flags assigned based on neighboring mask pixels:
  2856. // 4 | 8
  2857. // --P--
  2858. // 2 | 1
  2859. // We are interested only in points with the flags:
  2860. // - outside corners: 1, 2, 4, 8;
  2861. // - inside corners: 7, 11, 13, 14;
  2862. // - and, intersections: 5, 10.
  2863. var count = 0;
  2864. pos = 0;
  2865. if (data[pos] !== 0) {
  2866. points[0] = 1;
  2867. ++count;
  2868. }
  2869. for (j = 1; j < width; j++) {
  2870. if (data[pos] !== data[pos + 1]) {
  2871. points[j] = data[pos] ? 2 : 1;
  2872. ++count;
  2873. }
  2874. pos++;
  2875. }
  2876. if (data[pos] !== 0) {
  2877. points[j] = 2;
  2878. ++count;
  2879. }
  2880. for (i = 1; i < height; i++) {
  2881. pos = i * lineSize;
  2882. j0 = i * width1;
  2883. if (data[pos - lineSize] !== data[pos]) {
  2884. points[j0] = data[pos] ? 1 : 8;
  2885. ++count;
  2886. }
  2887. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2888. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2889. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2890. for (j = 1; j < width; j++) {
  2891. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2892. (data[pos - lineSize + 1] ? 8 : 0);
  2893. if (POINT_TYPES[sum]) {
  2894. points[j0 + j] = POINT_TYPES[sum];
  2895. ++count;
  2896. }
  2897. pos++;
  2898. }
  2899. if (data[pos - lineSize] !== data[pos]) {
  2900. points[j0 + j] = data[pos] ? 2 : 4;
  2901. ++count;
  2902. }
  2903. if (count > POINT_TO_PROCESS_LIMIT) {
  2904. return null;
  2905. }
  2906. }
  2907. pos = lineSize * (height - 1);
  2908. j0 = i * width1;
  2909. if (data[pos] !== 0) {
  2910. points[j0] = 8;
  2911. ++count;
  2912. }
  2913. for (j = 1; j < width; j++) {
  2914. if (data[pos] !== data[pos + 1]) {
  2915. points[j0 + j] = data[pos] ? 4 : 8;
  2916. ++count;
  2917. }
  2918. pos++;
  2919. }
  2920. if (data[pos] !== 0) {
  2921. points[j0 + j] = 4;
  2922. ++count;
  2923. }
  2924. if (count > POINT_TO_PROCESS_LIMIT) {
  2925. return null;
  2926. }
  2927. // building outlines
  2928. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2929. var outlines = [];
  2930. for (i = 0; count && i <= height; i++) {
  2931. var p = i * width1;
  2932. var end = p + width;
  2933. while (p < end && !points[p]) {
  2934. p++;
  2935. }
  2936. if (p === end) {
  2937. continue;
  2938. }
  2939. var coords = [p % width1, i];
  2940. var type = points[p], p0 = p, pp;
  2941. do {
  2942. var step = steps[type];
  2943. do {
  2944. p += step;
  2945. } while (!points[p]);
  2946. pp = points[p];
  2947. if (pp !== 5 && pp !== 10) {
  2948. // set new direction
  2949. type = pp;
  2950. // delete mark
  2951. points[p] = 0;
  2952. } else { // type is 5 or 10, ie, a crossing
  2953. // set new direction
  2954. type = pp & ((0x33 * type) >> 4);
  2955. // set new type for "future hit"
  2956. points[p] &= (type >> 2 | type << 2);
  2957. }
  2958. coords.push(p % width1);
  2959. coords.push((p / width1) | 0);
  2960. --count;
  2961. } while (p0 !== p);
  2962. outlines.push(coords);
  2963. --i;
  2964. }
  2965. var drawOutline = function(c) {
  2966. c.save();
  2967. // the path shall be painted in [0..1]x[0..1] space
  2968. c.scale(1 / width, -1 / height);
  2969. c.translate(0, -height);
  2970. c.beginPath();
  2971. for (var i = 0, ii = outlines.length; i < ii; i++) {
  2972. var o = outlines[i];
  2973. c.moveTo(o[0], o[1]);
  2974. for (var j = 2, jj = o.length; j < jj; j += 2) {
  2975. c.lineTo(o[j], o[j+1]);
  2976. }
  2977. }
  2978. c.fill();
  2979. c.beginPath();
  2980. c.restore();
  2981. };
  2982. return drawOutline;
  2983. }
  2984. var CanvasExtraState = (function CanvasExtraStateClosure() {
  2985. function CanvasExtraState(old) {
  2986. // Are soft masks and alpha values shapes or opacities?
  2987. this.alphaIsShape = false;
  2988. this.fontSize = 0;
  2989. this.fontSizeScale = 1;
  2990. this.textMatrix = IDENTITY_MATRIX;
  2991. this.textMatrixScale = 1;
  2992. this.fontMatrix = FONT_IDENTITY_MATRIX;
  2993. this.leading = 0;
  2994. // Current point (in user coordinates)
  2995. this.x = 0;
  2996. this.y = 0;
  2997. // Start of text line (in text coordinates)
  2998. this.lineX = 0;
  2999. this.lineY = 0;
  3000. // Character and word spacing
  3001. this.charSpacing = 0;
  3002. this.wordSpacing = 0;
  3003. this.textHScale = 1;
  3004. this.textRenderingMode = TextRenderingMode.FILL;
  3005. this.textRise = 0;
  3006. // Default fore and background colors
  3007. this.fillColor = '#000000';
  3008. this.strokeColor = '#000000';
  3009. // Note: fill alpha applies to all non-stroking operations
  3010. this.fillAlpha = 1;
  3011. this.strokeAlpha = 1;
  3012. this.lineWidth = 1;
  3013. this.activeSMask = null; // nonclonable field (see the save method below)
  3014. this.old = old;
  3015. }
  3016. CanvasExtraState.prototype = {
  3017. clone: function CanvasExtraState_clone() {
  3018. return Object.create(this);
  3019. },
  3020. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3021. this.x = x;
  3022. this.y = y;
  3023. }
  3024. };
  3025. return CanvasExtraState;
  3026. })();
  3027. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3028. // Defines the time the executeOperatorList is going to be executing
  3029. // before it stops and shedules a continue of execution.
  3030. var EXECUTION_TIME = 15;
  3031. // Defines the number of steps before checking the execution time
  3032. var EXECUTION_STEPS = 10;
  3033. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3034. this.ctx = canvasCtx;
  3035. this.current = new CanvasExtraState();
  3036. this.stateStack = [];
  3037. this.pendingClip = null;
  3038. this.pendingEOFill = false;
  3039. this.res = null;
  3040. this.xobjs = null;
  3041. this.commonObjs = commonObjs;
  3042. this.objs = objs;
  3043. this.imageLayer = imageLayer;
  3044. this.groupStack = [];
  3045. this.processingType3 = null;
  3046. // Patterns are painted relative to the initial page/form transform, see pdf
  3047. // spec 8.7.2 NOTE 1.
  3048. this.baseTransform = null;
  3049. this.baseTransformStack = [];
  3050. this.groupLevel = 0;
  3051. this.smaskStack = [];
  3052. this.smaskCounter = 0;
  3053. this.tempSMask = null;
  3054. if (canvasCtx) {
  3055. addContextCurrentTransform(canvasCtx);
  3056. }
  3057. }
  3058. function putBinaryImageData(ctx, imgData) {
  3059. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3060. ctx.putImageData(imgData, 0, 0);
  3061. return;
  3062. }
  3063. // Put the image data to the canvas in chunks, rather than putting the
  3064. // whole image at once. This saves JS memory, because the ImageData object
  3065. // is smaller. It also possibly saves C++ memory within the implementation
  3066. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3067. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3068. // because too many putImageData() calls will slow things down.
  3069. //
  3070. // Note: as written, if the last chunk is partial, the putImageData() call
  3071. // will (conceptually) put pixels past the bounds of the canvas. But
  3072. // that's ok; any such pixels are ignored.
  3073. var height = imgData.height, width = imgData.width;
  3074. var fullChunkHeight = 16;
  3075. var fracChunks = height / fullChunkHeight;
  3076. var fullChunks = Math.floor(fracChunks);
  3077. var totalChunks = Math.ceil(fracChunks);
  3078. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3079. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3080. var srcPos = 0, destPos;
  3081. var src = imgData.data;
  3082. var dest = chunkImgData.data;
  3083. var i, j, thisChunkHeight, elemsInThisChunk;
  3084. // There are multiple forms in which the pixel data can be passed, and
  3085. // imgData.kind tells us which one this is.
  3086. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3087. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3088. var srcLength = src.byteLength;
  3089. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3090. new Uint32ArrayView(dest);
  3091. var dest32DataLength = dest32.length;
  3092. var fullSrcDiff = (width + 7) >> 3;
  3093. var white = 0xFFFFFFFF;
  3094. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3095. 0xFF000000 : 0x000000FF;
  3096. for (i = 0; i < totalChunks; i++) {
  3097. thisChunkHeight =
  3098. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3099. destPos = 0;
  3100. for (j = 0; j < thisChunkHeight; j++) {
  3101. var srcDiff = srcLength - srcPos;
  3102. var k = 0;
  3103. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3104. var kEndUnrolled = kEnd & ~7;
  3105. var mask = 0;
  3106. var srcByte = 0;
  3107. for (; k < kEndUnrolled; k += 8) {
  3108. srcByte = src[srcPos++];
  3109. dest32[destPos++] = (srcByte & 128) ? white : black;
  3110. dest32[destPos++] = (srcByte & 64) ? white : black;
  3111. dest32[destPos++] = (srcByte & 32) ? white : black;
  3112. dest32[destPos++] = (srcByte & 16) ? white : black;
  3113. dest32[destPos++] = (srcByte & 8) ? white : black;
  3114. dest32[destPos++] = (srcByte & 4) ? white : black;
  3115. dest32[destPos++] = (srcByte & 2) ? white : black;
  3116. dest32[destPos++] = (srcByte & 1) ? white : black;
  3117. }
  3118. for (; k < kEnd; k++) {
  3119. if (mask === 0) {
  3120. srcByte = src[srcPos++];
  3121. mask = 128;
  3122. }
  3123. dest32[destPos++] = (srcByte & mask) ? white : black;
  3124. mask >>= 1;
  3125. }
  3126. }
  3127. // We ran out of input. Make all remaining pixels transparent.
  3128. while (destPos < dest32DataLength) {
  3129. dest32[destPos++] = 0;
  3130. }
  3131. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3132. }
  3133. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3134. // RGBA, 32-bits per pixel.
  3135. j = 0;
  3136. elemsInThisChunk = width * fullChunkHeight * 4;
  3137. for (i = 0; i < fullChunks; i++) {
  3138. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3139. srcPos += elemsInThisChunk;
  3140. ctx.putImageData(chunkImgData, 0, j);
  3141. j += fullChunkHeight;
  3142. }
  3143. if (i < totalChunks) {
  3144. elemsInThisChunk = width * partialChunkHeight * 4;
  3145. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3146. ctx.putImageData(chunkImgData, 0, j);
  3147. }
  3148. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3149. // RGB, 24-bits per pixel.
  3150. thisChunkHeight = fullChunkHeight;
  3151. elemsInThisChunk = width * thisChunkHeight;
  3152. for (i = 0; i < totalChunks; i++) {
  3153. if (i >= fullChunks) {
  3154. thisChunkHeight =partialChunkHeight;
  3155. elemsInThisChunk = width * thisChunkHeight;
  3156. }
  3157. destPos = 0;
  3158. for (j = elemsInThisChunk; j--;) {
  3159. dest[destPos++] = src[srcPos++];
  3160. dest[destPos++] = src[srcPos++];
  3161. dest[destPos++] = src[srcPos++];
  3162. dest[destPos++] = 255;
  3163. }
  3164. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3165. }
  3166. } else {
  3167. error('bad image kind: ' + imgData.kind);
  3168. }
  3169. }
  3170. function putBinaryImageMask(ctx, imgData) {
  3171. var height = imgData.height, width = imgData.width;
  3172. var fullChunkHeight = 16;
  3173. var fracChunks = height / fullChunkHeight;
  3174. var fullChunks = Math.floor(fracChunks);
  3175. var totalChunks = Math.ceil(fracChunks);
  3176. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3177. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3178. var srcPos = 0;
  3179. var src = imgData.data;
  3180. var dest = chunkImgData.data;
  3181. for (var i = 0; i < totalChunks; i++) {
  3182. var thisChunkHeight =
  3183. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3184. // Expand the mask so it can be used by the canvas. Any required
  3185. // inversion has already been handled.
  3186. var destPos = 3; // alpha component offset
  3187. for (var j = 0; j < thisChunkHeight; j++) {
  3188. var mask = 0;
  3189. for (var k = 0; k < width; k++) {
  3190. if (!mask) {
  3191. var elem = src[srcPos++];
  3192. mask = 128;
  3193. }
  3194. dest[destPos] = (elem & mask) ? 0 : 255;
  3195. destPos += 4;
  3196. mask >>= 1;
  3197. }
  3198. }
  3199. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3200. }
  3201. }
  3202. function copyCtxState(sourceCtx, destCtx) {
  3203. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3204. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3205. 'globalCompositeOperation', 'font'];
  3206. for (var i = 0, ii = properties.length; i < ii; i++) {
  3207. var property = properties[i];
  3208. if (property in sourceCtx) {
  3209. destCtx[property] = sourceCtx[property];
  3210. }
  3211. }
  3212. if ('setLineDash' in sourceCtx) {
  3213. destCtx.setLineDash(sourceCtx.getLineDash());
  3214. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3215. } else if ('mozDash' in sourceCtx) {
  3216. destCtx.mozDash = sourceCtx.mozDash;
  3217. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3218. }
  3219. }
  3220. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3221. var length = bytes.length;
  3222. for (var i = 3; i < length; i += 4) {
  3223. var alpha = bytes[i];
  3224. if (alpha === 0) {
  3225. bytes[i - 3] = r0;
  3226. bytes[i - 2] = g0;
  3227. bytes[i - 1] = b0;
  3228. } else if (alpha < 255) {
  3229. var alpha_ = 255 - alpha;
  3230. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3231. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3232. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3233. }
  3234. }
  3235. }
  3236. function composeSMaskAlpha(maskData, layerData) {
  3237. var length = maskData.length;
  3238. var scale = 1 / 255;
  3239. for (var i = 3; i < length; i += 4) {
  3240. var alpha = maskData[i];
  3241. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3242. }
  3243. }
  3244. function composeSMaskLuminosity(maskData, layerData) {
  3245. var length = maskData.length;
  3246. for (var i = 3; i < length; i += 4) {
  3247. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3248. (maskData[i - 2] * 152) + // * 0.59 ....
  3249. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3250. layerData[i] = (layerData[i] * y) >> 16;
  3251. }
  3252. }
  3253. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3254. subtype, backdrop) {
  3255. var hasBackdrop = !!backdrop;
  3256. var r0 = hasBackdrop ? backdrop[0] : 0;
  3257. var g0 = hasBackdrop ? backdrop[1] : 0;
  3258. var b0 = hasBackdrop ? backdrop[2] : 0;
  3259. var composeFn;
  3260. if (subtype === 'Luminosity') {
  3261. composeFn = composeSMaskLuminosity;
  3262. } else {
  3263. composeFn = composeSMaskAlpha;
  3264. }
  3265. // processing image in chunks to save memory
  3266. var PIXELS_TO_PROCESS = 65536;
  3267. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3268. for (var row = 0; row < height; row += chunkSize) {
  3269. var chunkHeight = Math.min(chunkSize, height - row);
  3270. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3271. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3272. if (hasBackdrop) {
  3273. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3274. }
  3275. composeFn(maskData.data, layerData.data);
  3276. maskCtx.putImageData(layerData, 0, row);
  3277. }
  3278. }
  3279. function composeSMask(ctx, smask, layerCtx) {
  3280. var mask = smask.canvas;
  3281. var maskCtx = smask.context;
  3282. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3283. smask.offsetX, smask.offsetY);
  3284. var backdrop = smask.backdrop || null;
  3285. if (WebGLUtils.isEnabled) {
  3286. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3287. {subtype: smask.subtype, backdrop: backdrop});
  3288. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3289. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3290. return;
  3291. }
  3292. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3293. smask.subtype, backdrop);
  3294. ctx.drawImage(mask, 0, 0);
  3295. }
  3296. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3297. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3298. var NORMAL_CLIP = {};
  3299. var EO_CLIP = {};
  3300. CanvasGraphics.prototype = {
  3301. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3302. // For pdfs that use blend modes we have to clear the canvas else certain
  3303. // blend modes can look wrong since we'd be blending with a white
  3304. // backdrop. The problem with a transparent backdrop though is we then
  3305. // don't get sub pixel anti aliasing on text, so we fill with white if
  3306. // we can.
  3307. var width = this.ctx.canvas.width;
  3308. var height = this.ctx.canvas.height;
  3309. if (transparency) {
  3310. this.ctx.clearRect(0, 0, width, height);
  3311. } else {
  3312. this.ctx.mozOpaque = true;
  3313. this.ctx.save();
  3314. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3315. this.ctx.fillRect(0, 0, width, height);
  3316. this.ctx.restore();
  3317. }
  3318. var transform = viewport.transform;
  3319. this.ctx.save();
  3320. this.ctx.transform.apply(this.ctx, transform);
  3321. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3322. if (this.imageLayer) {
  3323. this.imageLayer.beginLayout();
  3324. }
  3325. },
  3326. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3327. operatorList,
  3328. executionStartIdx, continueCallback,
  3329. stepper) {
  3330. var argsArray = operatorList.argsArray;
  3331. var fnArray = operatorList.fnArray;
  3332. var i = executionStartIdx || 0;
  3333. var argsArrayLen = argsArray.length;
  3334. // Sometimes the OperatorList to execute is empty.
  3335. if (argsArrayLen === i) {
  3336. return i;
  3337. }
  3338. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3339. typeof continueCallback === 'function');
  3340. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3341. var steps = 0;
  3342. var commonObjs = this.commonObjs;
  3343. var objs = this.objs;
  3344. var fnId;
  3345. while (true) {
  3346. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3347. stepper.breakIt(i, continueCallback);
  3348. return i;
  3349. }
  3350. fnId = fnArray[i];
  3351. if (fnId !== OPS.dependency) {
  3352. this[fnId].apply(this, argsArray[i]);
  3353. } else {
  3354. var deps = argsArray[i];
  3355. for (var n = 0, nn = deps.length; n < nn; n++) {
  3356. var depObjId = deps[n];
  3357. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3358. var objsPool = common ? commonObjs : objs;
  3359. // If the promise isn't resolved yet, add the continueCallback
  3360. // to the promise and bail out.
  3361. if (!objsPool.isResolved(depObjId)) {
  3362. objsPool.get(depObjId, continueCallback);
  3363. return i;
  3364. }
  3365. }
  3366. }
  3367. i++;
  3368. // If the entire operatorList was executed, stop as were done.
  3369. if (i === argsArrayLen) {
  3370. return i;
  3371. }
  3372. // If the execution took longer then a certain amount of time and
  3373. // `continueCallback` is specified, interrupt the execution.
  3374. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3375. if (Date.now() > endTime) {
  3376. continueCallback();
  3377. return i;
  3378. }
  3379. steps = 0;
  3380. }
  3381. // If the operatorList isn't executed completely yet OR the execution
  3382. // time was short enough, do another execution round.
  3383. }
  3384. },
  3385. endDrawing: function CanvasGraphics_endDrawing() {
  3386. this.ctx.restore();
  3387. CachedCanvases.clear();
  3388. WebGLUtils.clear();
  3389. if (this.imageLayer) {
  3390. this.imageLayer.endLayout();
  3391. }
  3392. },
  3393. // Graphics state
  3394. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3395. this.current.lineWidth = width;
  3396. this.ctx.lineWidth = width;
  3397. },
  3398. setLineCap: function CanvasGraphics_setLineCap(style) {
  3399. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3400. },
  3401. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3402. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3403. },
  3404. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3405. this.ctx.miterLimit = limit;
  3406. },
  3407. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3408. var ctx = this.ctx;
  3409. if ('setLineDash' in ctx) {
  3410. ctx.setLineDash(dashArray);
  3411. ctx.lineDashOffset = dashPhase;
  3412. } else {
  3413. ctx.mozDash = dashArray;
  3414. ctx.mozDashOffset = dashPhase;
  3415. }
  3416. },
  3417. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3418. // Maybe if we one day fully support color spaces this will be important
  3419. // for now we can ignore.
  3420. // TODO set rendering intent?
  3421. },
  3422. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3423. // There's no way to control this with canvas, but we can safely ignore.
  3424. // TODO set flatness?
  3425. },
  3426. setGState: function CanvasGraphics_setGState(states) {
  3427. for (var i = 0, ii = states.length; i < ii; i++) {
  3428. var state = states[i];
  3429. var key = state[0];
  3430. var value = state[1];
  3431. switch (key) {
  3432. case 'LW':
  3433. this.setLineWidth(value);
  3434. break;
  3435. case 'LC':
  3436. this.setLineCap(value);
  3437. break;
  3438. case 'LJ':
  3439. this.setLineJoin(value);
  3440. break;
  3441. case 'ML':
  3442. this.setMiterLimit(value);
  3443. break;
  3444. case 'D':
  3445. this.setDash(value[0], value[1]);
  3446. break;
  3447. case 'RI':
  3448. this.setRenderingIntent(value);
  3449. break;
  3450. case 'FL':
  3451. this.setFlatness(value);
  3452. break;
  3453. case 'Font':
  3454. this.setFont(value[0], value[1]);
  3455. break;
  3456. case 'CA':
  3457. this.current.strokeAlpha = state[1];
  3458. break;
  3459. case 'ca':
  3460. this.current.fillAlpha = state[1];
  3461. this.ctx.globalAlpha = state[1];
  3462. break;
  3463. case 'BM':
  3464. if (value && value.name && (value.name !== 'Normal')) {
  3465. var mode = value.name.replace(/([A-Z])/g,
  3466. function(c) {
  3467. return '-' + c.toLowerCase();
  3468. }
  3469. ).substring(1);
  3470. this.ctx.globalCompositeOperation = mode;
  3471. if (this.ctx.globalCompositeOperation !== mode) {
  3472. warn('globalCompositeOperation "' + mode +
  3473. '" is not supported');
  3474. }
  3475. } else {
  3476. this.ctx.globalCompositeOperation = 'source-over';
  3477. }
  3478. break;
  3479. case 'SMask':
  3480. if (this.current.activeSMask) {
  3481. this.endSMaskGroup();
  3482. }
  3483. this.current.activeSMask = value ? this.tempSMask : null;
  3484. if (this.current.activeSMask) {
  3485. this.beginSMaskGroup();
  3486. }
  3487. this.tempSMask = null;
  3488. break;
  3489. }
  3490. }
  3491. },
  3492. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3493. var activeSMask = this.current.activeSMask;
  3494. var drawnWidth = activeSMask.canvas.width;
  3495. var drawnHeight = activeSMask.canvas.height;
  3496. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3497. var scratchCanvas = CachedCanvases.getCanvas(
  3498. cacheId, drawnWidth, drawnHeight, true);
  3499. var currentCtx = this.ctx;
  3500. var currentTransform = currentCtx.mozCurrentTransform;
  3501. this.ctx.save();
  3502. var groupCtx = scratchCanvas.context;
  3503. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3504. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3505. groupCtx.transform.apply(groupCtx, currentTransform);
  3506. copyCtxState(currentCtx, groupCtx);
  3507. this.ctx = groupCtx;
  3508. this.setGState([
  3509. ['BM', 'Normal'],
  3510. ['ca', 1],
  3511. ['CA', 1]
  3512. ]);
  3513. this.groupStack.push(currentCtx);
  3514. this.groupLevel++;
  3515. },
  3516. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3517. var groupCtx = this.ctx;
  3518. this.groupLevel--;
  3519. this.ctx = this.groupStack.pop();
  3520. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3521. this.ctx.restore();
  3522. },
  3523. save: function CanvasGraphics_save() {
  3524. this.ctx.save();
  3525. var old = this.current;
  3526. this.stateStack.push(old);
  3527. this.current = old.clone();
  3528. this.current.activeSMask = null;
  3529. },
  3530. restore: function CanvasGraphics_restore() {
  3531. if (this.stateStack.length !== 0) {
  3532. if (this.current.activeSMask !== null) {
  3533. this.endSMaskGroup();
  3534. }
  3535. this.current = this.stateStack.pop();
  3536. this.ctx.restore();
  3537. }
  3538. },
  3539. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3540. this.ctx.transform(a, b, c, d, e, f);
  3541. },
  3542. // Path
  3543. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3544. var ctx = this.ctx;
  3545. var current = this.current;
  3546. var x = current.x, y = current.y;
  3547. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3548. switch (ops[i] | 0) {
  3549. case OPS.rectangle:
  3550. x = args[j++];
  3551. y = args[j++];
  3552. var width = args[j++];
  3553. var height = args[j++];
  3554. if (width === 0) {
  3555. width = this.getSinglePixelWidth();
  3556. }
  3557. if (height === 0) {
  3558. height = this.getSinglePixelWidth();
  3559. }
  3560. var xw = x + width;
  3561. var yh = y + height;
  3562. this.ctx.moveTo(x, y);
  3563. this.ctx.lineTo(xw, y);
  3564. this.ctx.lineTo(xw, yh);
  3565. this.ctx.lineTo(x, yh);
  3566. this.ctx.lineTo(x, y);
  3567. this.ctx.closePath();
  3568. break;
  3569. case OPS.moveTo:
  3570. x = args[j++];
  3571. y = args[j++];
  3572. ctx.moveTo(x, y);
  3573. break;
  3574. case OPS.lineTo:
  3575. x = args[j++];
  3576. y = args[j++];
  3577. ctx.lineTo(x, y);
  3578. break;
  3579. case OPS.curveTo:
  3580. x = args[j + 4];
  3581. y = args[j + 5];
  3582. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3583. x, y);
  3584. j += 6;
  3585. break;
  3586. case OPS.curveTo2:
  3587. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3588. args[j + 2], args[j + 3]);
  3589. x = args[j + 2];
  3590. y = args[j + 3];
  3591. j += 4;
  3592. break;
  3593. case OPS.curveTo3:
  3594. x = args[j + 2];
  3595. y = args[j + 3];
  3596. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3597. j += 4;
  3598. break;
  3599. case OPS.closePath:
  3600. ctx.closePath();
  3601. break;
  3602. }
  3603. }
  3604. current.setCurrentPoint(x, y);
  3605. },
  3606. closePath: function CanvasGraphics_closePath() {
  3607. this.ctx.closePath();
  3608. },
  3609. stroke: function CanvasGraphics_stroke(consumePath) {
  3610. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3611. var ctx = this.ctx;
  3612. var strokeColor = this.current.strokeColor;
  3613. if (this.current.lineWidth === 0) {
  3614. ctx.lineWidth = this.getSinglePixelWidth();
  3615. }
  3616. // For stroke we want to temporarily change the global alpha to the
  3617. // stroking alpha.
  3618. ctx.globalAlpha = this.current.strokeAlpha;
  3619. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3620. strokeColor.type === 'Pattern') {
  3621. // for patterns, we transform to pattern space, calculate
  3622. // the pattern, call stroke, and restore to user space
  3623. ctx.save();
  3624. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3625. ctx.stroke();
  3626. ctx.restore();
  3627. } else {
  3628. ctx.stroke();
  3629. }
  3630. if (consumePath) {
  3631. this.consumePath();
  3632. }
  3633. // Restore the global alpha to the fill alpha
  3634. ctx.globalAlpha = this.current.fillAlpha;
  3635. },
  3636. closeStroke: function CanvasGraphics_closeStroke() {
  3637. this.closePath();
  3638. this.stroke();
  3639. },
  3640. fill: function CanvasGraphics_fill(consumePath) {
  3641. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3642. var ctx = this.ctx;
  3643. var fillColor = this.current.fillColor;
  3644. var needRestore = false;
  3645. if (fillColor && fillColor.hasOwnProperty('type') &&
  3646. fillColor.type === 'Pattern') {
  3647. ctx.save();
  3648. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3649. needRestore = true;
  3650. }
  3651. if (this.pendingEOFill) {
  3652. if (ctx.mozFillRule !== undefined) {
  3653. ctx.mozFillRule = 'evenodd';
  3654. ctx.fill();
  3655. ctx.mozFillRule = 'nonzero';
  3656. } else {
  3657. try {
  3658. ctx.fill('evenodd');
  3659. } catch (ex) {
  3660. // shouldn't really happen, but browsers might think differently
  3661. ctx.fill();
  3662. }
  3663. }
  3664. this.pendingEOFill = false;
  3665. } else {
  3666. ctx.fill();
  3667. }
  3668. if (needRestore) {
  3669. ctx.restore();
  3670. }
  3671. if (consumePath) {
  3672. this.consumePath();
  3673. }
  3674. },
  3675. eoFill: function CanvasGraphics_eoFill() {
  3676. this.pendingEOFill = true;
  3677. this.fill();
  3678. },
  3679. fillStroke: function CanvasGraphics_fillStroke() {
  3680. this.fill(false);
  3681. this.stroke(false);
  3682. this.consumePath();
  3683. },
  3684. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3685. this.pendingEOFill = true;
  3686. this.fillStroke();
  3687. },
  3688. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3689. this.closePath();
  3690. this.fillStroke();
  3691. },
  3692. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3693. this.pendingEOFill = true;
  3694. this.closePath();
  3695. this.fillStroke();
  3696. },
  3697. endPath: function CanvasGraphics_endPath() {
  3698. this.consumePath();
  3699. },
  3700. // Clipping
  3701. clip: function CanvasGraphics_clip() {
  3702. this.pendingClip = NORMAL_CLIP;
  3703. },
  3704. eoClip: function CanvasGraphics_eoClip() {
  3705. this.pendingClip = EO_CLIP;
  3706. },
  3707. // Text
  3708. beginText: function CanvasGraphics_beginText() {
  3709. this.current.textMatrix = IDENTITY_MATRIX;
  3710. this.current.textMatrixScale = 1;
  3711. this.current.x = this.current.lineX = 0;
  3712. this.current.y = this.current.lineY = 0;
  3713. },
  3714. endText: function CanvasGraphics_endText() {
  3715. var paths = this.pendingTextPaths;
  3716. var ctx = this.ctx;
  3717. if (paths === undefined) {
  3718. ctx.beginPath();
  3719. return;
  3720. }
  3721. ctx.save();
  3722. ctx.beginPath();
  3723. for (var i = 0; i < paths.length; i++) {
  3724. var path = paths[i];
  3725. ctx.setTransform.apply(ctx, path.transform);
  3726. ctx.translate(path.x, path.y);
  3727. path.addToPath(ctx, path.fontSize);
  3728. }
  3729. ctx.restore();
  3730. ctx.clip();
  3731. ctx.beginPath();
  3732. delete this.pendingTextPaths;
  3733. },
  3734. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3735. this.current.charSpacing = spacing;
  3736. },
  3737. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3738. this.current.wordSpacing = spacing;
  3739. },
  3740. setHScale: function CanvasGraphics_setHScale(scale) {
  3741. this.current.textHScale = scale / 100;
  3742. },
  3743. setLeading: function CanvasGraphics_setLeading(leading) {
  3744. this.current.leading = -leading;
  3745. },
  3746. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3747. var fontObj = this.commonObjs.get(fontRefName);
  3748. var current = this.current;
  3749. if (!fontObj) {
  3750. error('Can\'t find font for ' + fontRefName);
  3751. }
  3752. current.fontMatrix = (fontObj.fontMatrix ?
  3753. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3754. // A valid matrix needs all main diagonal elements to be non-zero
  3755. // This also ensures we bypass FF bugzilla bug #719844.
  3756. if (current.fontMatrix[0] === 0 ||
  3757. current.fontMatrix[3] === 0) {
  3758. warn('Invalid font matrix for font ' + fontRefName);
  3759. }
  3760. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3761. // and in some docs this can be negative (inverted x-y axes).
  3762. if (size < 0) {
  3763. size = -size;
  3764. current.fontDirection = -1;
  3765. } else {
  3766. current.fontDirection = 1;
  3767. }
  3768. this.current.font = fontObj;
  3769. this.current.fontSize = size;
  3770. if (fontObj.isType3Font) {
  3771. return; // we don't need ctx.font for Type3 fonts
  3772. }
  3773. var name = fontObj.loadedName || 'sans-serif';
  3774. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3775. (fontObj.bold ? 'bold' : 'normal');
  3776. var italic = fontObj.italic ? 'italic' : 'normal';
  3777. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3778. // Some font backends cannot handle fonts below certain size.
  3779. // Keeping the font at minimal size and using the fontSizeScale to change
  3780. // the current transformation matrix before the fillText/strokeText.
  3781. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3782. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3783. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3784. size / MIN_FONT_SIZE;
  3785. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3786. this.ctx.font = rule;
  3787. },
  3788. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3789. this.current.textRenderingMode = mode;
  3790. },
  3791. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3792. this.current.textRise = rise;
  3793. },
  3794. moveText: function CanvasGraphics_moveText(x, y) {
  3795. this.current.x = this.current.lineX += x;
  3796. this.current.y = this.current.lineY += y;
  3797. },
  3798. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3799. this.setLeading(-y);
  3800. this.moveText(x, y);
  3801. },
  3802. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3803. this.current.textMatrix = [a, b, c, d, e, f];
  3804. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3805. this.current.x = this.current.lineX = 0;
  3806. this.current.y = this.current.lineY = 0;
  3807. },
  3808. nextLine: function CanvasGraphics_nextLine() {
  3809. this.moveText(0, this.current.leading);
  3810. },
  3811. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3812. var ctx = this.ctx;
  3813. var current = this.current;
  3814. var font = current.font;
  3815. var textRenderingMode = current.textRenderingMode;
  3816. var fontSize = current.fontSize / current.fontSizeScale;
  3817. var fillStrokeMode = textRenderingMode &
  3818. TextRenderingMode.FILL_STROKE_MASK;
  3819. var isAddToPathSet = !!(textRenderingMode &
  3820. TextRenderingMode.ADD_TO_PATH_FLAG);
  3821. var addToPath;
  3822. if (font.disableFontFace || isAddToPathSet) {
  3823. addToPath = font.getPathGenerator(this.commonObjs, character);
  3824. }
  3825. if (font.disableFontFace) {
  3826. ctx.save();
  3827. ctx.translate(x, y);
  3828. ctx.beginPath();
  3829. addToPath(ctx, fontSize);
  3830. if (fillStrokeMode === TextRenderingMode.FILL ||
  3831. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3832. ctx.fill();
  3833. }
  3834. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3835. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3836. ctx.stroke();
  3837. }
  3838. ctx.restore();
  3839. } else {
  3840. if (fillStrokeMode === TextRenderingMode.FILL ||
  3841. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3842. ctx.fillText(character, x, y);
  3843. }
  3844. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3845. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3846. ctx.strokeText(character, x, y);
  3847. }
  3848. }
  3849. if (isAddToPathSet) {
  3850. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3851. paths.push({
  3852. transform: ctx.mozCurrentTransform,
  3853. x: x,
  3854. y: y,
  3855. fontSize: fontSize,
  3856. addToPath: addToPath
  3857. });
  3858. }
  3859. },
  3860. get isFontSubpixelAAEnabled() {
  3861. // Checks if anti-aliasing is enabled when scaled text is painted.
  3862. // On Windows GDI scaled fonts looks bad.
  3863. var ctx = document.createElement('canvas').getContext('2d');
  3864. ctx.scale(1.5, 1);
  3865. ctx.fillText('I', 0, 10);
  3866. var data = ctx.getImageData(0, 0, 10, 10).data;
  3867. var enabled = false;
  3868. for (var i = 3; i < data.length; i += 4) {
  3869. if (data[i] > 0 && data[i] < 255) {
  3870. enabled = true;
  3871. break;
  3872. }
  3873. }
  3874. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3875. },
  3876. showText: function CanvasGraphics_showText(glyphs) {
  3877. var current = this.current;
  3878. var font = current.font;
  3879. if (font.isType3Font) {
  3880. return this.showType3Text(glyphs);
  3881. }
  3882. var fontSize = current.fontSize;
  3883. if (fontSize === 0) {
  3884. return;
  3885. }
  3886. var ctx = this.ctx;
  3887. var fontSizeScale = current.fontSizeScale;
  3888. var charSpacing = current.charSpacing;
  3889. var wordSpacing = current.wordSpacing;
  3890. var fontDirection = current.fontDirection;
  3891. var textHScale = current.textHScale * fontDirection;
  3892. var glyphsLength = glyphs.length;
  3893. var vertical = font.vertical;
  3894. var defaultVMetrics = font.defaultVMetrics;
  3895. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3896. var simpleFillText =
  3897. current.textRenderingMode === TextRenderingMode.FILL &&
  3898. !font.disableFontFace;
  3899. ctx.save();
  3900. ctx.transform.apply(ctx, current.textMatrix);
  3901. ctx.translate(current.x, current.y + current.textRise);
  3902. if (fontDirection > 0) {
  3903. ctx.scale(textHScale, -1);
  3904. } else {
  3905. ctx.scale(textHScale, 1);
  3906. }
  3907. var lineWidth = current.lineWidth;
  3908. var scale = current.textMatrixScale;
  3909. if (scale === 0 || lineWidth === 0) {
  3910. lineWidth = this.getSinglePixelWidth();
  3911. } else {
  3912. lineWidth /= scale;
  3913. }
  3914. if (fontSizeScale !== 1.0) {
  3915. ctx.scale(fontSizeScale, fontSizeScale);
  3916. lineWidth /= fontSizeScale;
  3917. }
  3918. ctx.lineWidth = lineWidth;
  3919. var x = 0, i;
  3920. for (i = 0; i < glyphsLength; ++i) {
  3921. var glyph = glyphs[i];
  3922. if (glyph === null) {
  3923. // word break
  3924. x += fontDirection * wordSpacing;
  3925. continue;
  3926. } else if (isNum(glyph)) {
  3927. x += -glyph * fontSize * 0.001;
  3928. continue;
  3929. }
  3930. var restoreNeeded = false;
  3931. var character = glyph.fontChar;
  3932. var accent = glyph.accent;
  3933. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3934. var width = glyph.width;
  3935. if (vertical) {
  3936. var vmetric, vx, vy;
  3937. vmetric = glyph.vmetric || defaultVMetrics;
  3938. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3939. vx = -vx * widthAdvanceScale;
  3940. vy = vmetric[2] * widthAdvanceScale;
  3941. width = vmetric ? -vmetric[0] : width;
  3942. scaledX = vx / fontSizeScale;
  3943. scaledY = (x + vy) / fontSizeScale;
  3944. } else {
  3945. scaledX = x / fontSizeScale;
  3946. scaledY = 0;
  3947. }
  3948. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3949. // some standard fonts may not have the exact width, trying to
  3950. // rescale per character
  3951. var measuredWidth = ctx.measureText(character).width * 1000 /
  3952. fontSize * fontSizeScale;
  3953. var characterScaleX = width / measuredWidth;
  3954. restoreNeeded = true;
  3955. ctx.save();
  3956. ctx.scale(characterScaleX, 1);
  3957. scaledX /= characterScaleX;
  3958. }
  3959. if (simpleFillText && !accent) {
  3960. // common case
  3961. ctx.fillText(character, scaledX, scaledY);
  3962. } else {
  3963. this.paintChar(character, scaledX, scaledY);
  3964. if (accent) {
  3965. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  3966. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  3967. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  3968. }
  3969. }
  3970. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  3971. x += charWidth;
  3972. if (restoreNeeded) {
  3973. ctx.restore();
  3974. }
  3975. }
  3976. if (vertical) {
  3977. current.y -= x * textHScale;
  3978. } else {
  3979. current.x += x * textHScale;
  3980. }
  3981. ctx.restore();
  3982. },
  3983. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  3984. // Type3 fonts - each glyph is a "mini-PDF"
  3985. var ctx = this.ctx;
  3986. var current = this.current;
  3987. var font = current.font;
  3988. var fontSize = current.fontSize;
  3989. var fontDirection = current.fontDirection;
  3990. var charSpacing = current.charSpacing;
  3991. var wordSpacing = current.wordSpacing;
  3992. var textHScale = current.textHScale * fontDirection;
  3993. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  3994. var glyphsLength = glyphs.length;
  3995. var i, glyph, width;
  3996. if (fontSize === 0) {
  3997. return;
  3998. }
  3999. ctx.save();
  4000. ctx.transform.apply(ctx, current.textMatrix);
  4001. ctx.translate(current.x, current.y);
  4002. ctx.scale(textHScale, 1);
  4003. for (i = 0; i < glyphsLength; ++i) {
  4004. glyph = glyphs[i];
  4005. if (glyph === null) {
  4006. // word break
  4007. this.ctx.translate(wordSpacing, 0);
  4008. current.x += wordSpacing * textHScale;
  4009. continue;
  4010. } else if (isNum(glyph)) {
  4011. var spacingLength = -glyph * 0.001 * fontSize;
  4012. this.ctx.translate(spacingLength, 0);
  4013. current.x += spacingLength * textHScale;
  4014. continue;
  4015. }
  4016. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4017. if (!operatorList) {
  4018. warn('Type3 character \"' + glyph.operatorListId +
  4019. '\" is not available');
  4020. continue;
  4021. }
  4022. this.processingType3 = glyph;
  4023. this.save();
  4024. ctx.scale(fontSize, fontSize);
  4025. ctx.transform.apply(ctx, fontMatrix);
  4026. this.executeOperatorList(operatorList);
  4027. this.restore();
  4028. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4029. width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
  4030. ctx.translate(width, 0);
  4031. current.x += width * textHScale;
  4032. }
  4033. ctx.restore();
  4034. this.processingType3 = null;
  4035. },
  4036. // Type3 fonts
  4037. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4038. // We can safely ignore this since the width should be the same
  4039. // as the width in the Widths array.
  4040. },
  4041. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4042. yWidth,
  4043. llx,
  4044. lly,
  4045. urx,
  4046. ury) {
  4047. // TODO According to the spec we're also suppose to ignore any operators
  4048. // that set color or include images while processing this type3 font.
  4049. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4050. this.clip();
  4051. this.endPath();
  4052. },
  4053. // Color
  4054. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4055. var pattern;
  4056. if (IR[0] === 'TilingPattern') {
  4057. var color = IR[1];
  4058. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4059. this.commonObjs, this.baseTransform);
  4060. } else {
  4061. pattern = getShadingPatternFromIR(IR);
  4062. }
  4063. return pattern;
  4064. },
  4065. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4066. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4067. },
  4068. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4069. this.current.fillColor = this.getColorN_Pattern(arguments);
  4070. },
  4071. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4072. var color = Util.makeCssRgb(arguments);
  4073. this.ctx.strokeStyle = color;
  4074. this.current.strokeColor = color;
  4075. },
  4076. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4077. var color = Util.makeCssRgb(arguments);
  4078. this.ctx.fillStyle = color;
  4079. this.current.fillColor = color;
  4080. },
  4081. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4082. var ctx = this.ctx;
  4083. this.save();
  4084. var pattern = getShadingPatternFromIR(patternIR);
  4085. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4086. var inv = ctx.mozCurrentTransformInverse;
  4087. if (inv) {
  4088. var canvas = ctx.canvas;
  4089. var width = canvas.width;
  4090. var height = canvas.height;
  4091. var bl = Util.applyTransform([0, 0], inv);
  4092. var br = Util.applyTransform([0, height], inv);
  4093. var ul = Util.applyTransform([width, 0], inv);
  4094. var ur = Util.applyTransform([width, height], inv);
  4095. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4096. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4097. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4098. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4099. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4100. } else {
  4101. // HACK to draw the gradient onto an infinite rectangle.
  4102. // PDF gradients are drawn across the entire image while
  4103. // Canvas only allows gradients to be drawn in a rectangle
  4104. // The following bug should allow us to remove this.
  4105. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4106. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4107. }
  4108. this.restore();
  4109. },
  4110. // Images
  4111. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4112. error('Should not call beginInlineImage');
  4113. },
  4114. beginImageData: function CanvasGraphics_beginImageData() {
  4115. error('Should not call beginImageData');
  4116. },
  4117. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4118. bbox) {
  4119. this.save();
  4120. this.baseTransformStack.push(this.baseTransform);
  4121. if (isArray(matrix) && 6 === matrix.length) {
  4122. this.transform.apply(this, matrix);
  4123. }
  4124. this.baseTransform = this.ctx.mozCurrentTransform;
  4125. if (isArray(bbox) && 4 === bbox.length) {
  4126. var width = bbox[2] - bbox[0];
  4127. var height = bbox[3] - bbox[1];
  4128. this.ctx.rect(bbox[0], bbox[1], width, height);
  4129. this.clip();
  4130. this.endPath();
  4131. }
  4132. },
  4133. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4134. this.restore();
  4135. this.baseTransform = this.baseTransformStack.pop();
  4136. },
  4137. beginGroup: function CanvasGraphics_beginGroup(group) {
  4138. this.save();
  4139. var currentCtx = this.ctx;
  4140. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4141. // group results aren't usually that different and they even have tools
  4142. // that ignore this setting. Notes from Rik on implmenting:
  4143. // - When you encounter an transparency group, create a new canvas with
  4144. // the dimensions of the bbox
  4145. // - copy the content from the previous canvas to the new canvas
  4146. // - draw as usual
  4147. // - remove the backdrop alpha:
  4148. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4149. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4150. // backdrop
  4151. // - remove background color:
  4152. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4153. if (!group.isolated) {
  4154. info('TODO: Support non-isolated groups.');
  4155. }
  4156. // TODO knockout - supposedly possible with the clever use of compositing
  4157. // modes.
  4158. if (group.knockout) {
  4159. warn('Knockout groups not supported.');
  4160. }
  4161. var currentTransform = currentCtx.mozCurrentTransform;
  4162. if (group.matrix) {
  4163. currentCtx.transform.apply(currentCtx, group.matrix);
  4164. }
  4165. assert(group.bbox, 'Bounding box is required.');
  4166. // Based on the current transform figure out how big the bounding box
  4167. // will actually be.
  4168. var bounds = Util.getAxialAlignedBoundingBox(
  4169. group.bbox,
  4170. currentCtx.mozCurrentTransform);
  4171. // Clip the bounding box to the current canvas.
  4172. var canvasBounds = [0,
  4173. 0,
  4174. currentCtx.canvas.width,
  4175. currentCtx.canvas.height];
  4176. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4177. // Use ceil in case we're between sizes so we don't create canvas that is
  4178. // too small and make the canvas at least 1x1 pixels.
  4179. var offsetX = Math.floor(bounds[0]);
  4180. var offsetY = Math.floor(bounds[1]);
  4181. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4182. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4183. var scaleX = 1, scaleY = 1;
  4184. if (drawnWidth > MAX_GROUP_SIZE) {
  4185. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4186. drawnWidth = MAX_GROUP_SIZE;
  4187. }
  4188. if (drawnHeight > MAX_GROUP_SIZE) {
  4189. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4190. drawnHeight = MAX_GROUP_SIZE;
  4191. }
  4192. var cacheId = 'groupAt' + this.groupLevel;
  4193. if (group.smask) {
  4194. // Using two cache entries is case if masks are used one after another.
  4195. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4196. }
  4197. var scratchCanvas = CachedCanvases.getCanvas(
  4198. cacheId, drawnWidth, drawnHeight, true);
  4199. var groupCtx = scratchCanvas.context;
  4200. // Since we created a new canvas that is just the size of the bounding box
  4201. // we have to translate the group ctx.
  4202. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4203. groupCtx.translate(-offsetX, -offsetY);
  4204. groupCtx.transform.apply(groupCtx, currentTransform);
  4205. if (group.smask) {
  4206. // Saving state and cached mask to be used in setGState.
  4207. this.smaskStack.push({
  4208. canvas: scratchCanvas.canvas,
  4209. context: groupCtx,
  4210. offsetX: offsetX,
  4211. offsetY: offsetY,
  4212. scaleX: scaleX,
  4213. scaleY: scaleY,
  4214. subtype: group.smask.subtype,
  4215. backdrop: group.smask.backdrop
  4216. });
  4217. } else {
  4218. // Setup the current ctx so when the group is popped we draw it at the
  4219. // right location.
  4220. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4221. currentCtx.translate(offsetX, offsetY);
  4222. currentCtx.scale(scaleX, scaleY);
  4223. }
  4224. // The transparency group inherits all off the current graphics state
  4225. // except the blend mode, soft mask, and alpha constants.
  4226. copyCtxState(currentCtx, groupCtx);
  4227. this.ctx = groupCtx;
  4228. this.setGState([
  4229. ['BM', 'Normal'],
  4230. ['ca', 1],
  4231. ['CA', 1]
  4232. ]);
  4233. this.groupStack.push(currentCtx);
  4234. this.groupLevel++;
  4235. },
  4236. endGroup: function CanvasGraphics_endGroup(group) {
  4237. this.groupLevel--;
  4238. var groupCtx = this.ctx;
  4239. this.ctx = this.groupStack.pop();
  4240. // Turn off image smoothing to avoid sub pixel interpolation which can
  4241. // look kind of blurry for some pdfs.
  4242. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4243. this.ctx.imageSmoothingEnabled = false;
  4244. } else {
  4245. this.ctx.mozImageSmoothingEnabled = false;
  4246. }
  4247. if (group.smask) {
  4248. this.tempSMask = this.smaskStack.pop();
  4249. } else {
  4250. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4251. }
  4252. this.restore();
  4253. },
  4254. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4255. this.save();
  4256. this.current = new CanvasExtraState();
  4257. },
  4258. endAnnotations: function CanvasGraphics_endAnnotations() {
  4259. this.restore();
  4260. },
  4261. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4262. matrix) {
  4263. this.save();
  4264. if (isArray(rect) && 4 === rect.length) {
  4265. var width = rect[2] - rect[0];
  4266. var height = rect[3] - rect[1];
  4267. this.ctx.rect(rect[0], rect[1], width, height);
  4268. this.clip();
  4269. this.endPath();
  4270. }
  4271. this.transform.apply(this, transform);
  4272. this.transform.apply(this, matrix);
  4273. },
  4274. endAnnotation: function CanvasGraphics_endAnnotation() {
  4275. this.restore();
  4276. },
  4277. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4278. var domImage = this.objs.get(objId);
  4279. if (!domImage) {
  4280. warn('Dependent image isn\'t ready yet');
  4281. return;
  4282. }
  4283. this.save();
  4284. var ctx = this.ctx;
  4285. // scale the image to the unit square
  4286. ctx.scale(1 / w, -1 / h);
  4287. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4288. 0, -h, w, h);
  4289. if (this.imageLayer) {
  4290. var currentTransform = ctx.mozCurrentTransformInverse;
  4291. var position = this.getCanvasPosition(0, 0);
  4292. this.imageLayer.appendImage({
  4293. objId: objId,
  4294. left: position[0],
  4295. top: position[1],
  4296. width: w / currentTransform[0],
  4297. height: h / currentTransform[3]
  4298. });
  4299. }
  4300. this.restore();
  4301. },
  4302. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4303. var ctx = this.ctx;
  4304. var width = img.width, height = img.height;
  4305. var glyph = this.processingType3;
  4306. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4307. var MAX_SIZE_TO_COMPILE = 1000;
  4308. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4309. glyph.compiled =
  4310. compileType3Glyph({data: img.data, width: width, height: height});
  4311. } else {
  4312. glyph.compiled = null;
  4313. }
  4314. }
  4315. if (glyph && glyph.compiled) {
  4316. glyph.compiled(ctx);
  4317. return;
  4318. }
  4319. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4320. var maskCtx = maskCanvas.context;
  4321. maskCtx.save();
  4322. putBinaryImageMask(maskCtx, img);
  4323. maskCtx.globalCompositeOperation = 'source-in';
  4324. var fillColor = this.current.fillColor;
  4325. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4326. fillColor.type === 'Pattern') ?
  4327. fillColor.getPattern(maskCtx, this) : fillColor;
  4328. maskCtx.fillRect(0, 0, width, height);
  4329. maskCtx.restore();
  4330. this.paintInlineImageXObject(maskCanvas.canvas);
  4331. },
  4332. paintImageMaskXObjectRepeat:
  4333. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4334. scaleY, positions) {
  4335. var width = imgData.width;
  4336. var height = imgData.height;
  4337. var ctx = this.ctx;
  4338. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4339. var maskCtx = maskCanvas.context;
  4340. maskCtx.save();
  4341. putBinaryImageMask(maskCtx, imgData);
  4342. maskCtx.globalCompositeOperation = 'source-in';
  4343. var fillColor = this.current.fillColor;
  4344. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4345. fillColor.type === 'Pattern') ?
  4346. fillColor.getPattern(maskCtx, this) : fillColor;
  4347. maskCtx.fillRect(0, 0, width, height);
  4348. maskCtx.restore();
  4349. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4350. ctx.save();
  4351. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4352. ctx.scale(1, -1);
  4353. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4354. 0, -1, 1, 1);
  4355. ctx.restore();
  4356. }
  4357. },
  4358. paintImageMaskXObjectGroup:
  4359. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4360. var ctx = this.ctx;
  4361. for (var i = 0, ii = images.length; i < ii; i++) {
  4362. var image = images[i];
  4363. var width = image.width, height = image.height;
  4364. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4365. var maskCtx = maskCanvas.context;
  4366. maskCtx.save();
  4367. putBinaryImageMask(maskCtx, image);
  4368. maskCtx.globalCompositeOperation = 'source-in';
  4369. var fillColor = this.current.fillColor;
  4370. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4371. fillColor.type === 'Pattern') ?
  4372. fillColor.getPattern(maskCtx, this) : fillColor;
  4373. maskCtx.fillRect(0, 0, width, height);
  4374. maskCtx.restore();
  4375. ctx.save();
  4376. ctx.transform.apply(ctx, image.transform);
  4377. ctx.scale(1, -1);
  4378. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4379. 0, -1, 1, 1);
  4380. ctx.restore();
  4381. }
  4382. },
  4383. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4384. var imgData = this.objs.get(objId);
  4385. if (!imgData) {
  4386. warn('Dependent image isn\'t ready yet');
  4387. return;
  4388. }
  4389. this.paintInlineImageXObject(imgData);
  4390. },
  4391. paintImageXObjectRepeat:
  4392. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4393. positions) {
  4394. var imgData = this.objs.get(objId);
  4395. if (!imgData) {
  4396. warn('Dependent image isn\'t ready yet');
  4397. return;
  4398. }
  4399. var width = imgData.width;
  4400. var height = imgData.height;
  4401. var map = [];
  4402. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4403. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4404. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4405. }
  4406. this.paintInlineImageXObjectGroup(imgData, map);
  4407. },
  4408. paintInlineImageXObject:
  4409. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4410. var width = imgData.width;
  4411. var height = imgData.height;
  4412. var ctx = this.ctx;
  4413. this.save();
  4414. // scale the image to the unit square
  4415. ctx.scale(1 / width, -1 / height);
  4416. var currentTransform = ctx.mozCurrentTransformInverse;
  4417. var a = currentTransform[0], b = currentTransform[1];
  4418. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4419. var c = currentTransform[2], d = currentTransform[3];
  4420. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4421. var imgToPaint, tmpCanvas;
  4422. // instanceof HTMLElement does not work in jsdom node.js module
  4423. if (imgData instanceof HTMLElement || !imgData.data) {
  4424. imgToPaint = imgData;
  4425. } else {
  4426. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4427. var tmpCtx = tmpCanvas.context;
  4428. putBinaryImageData(tmpCtx, imgData);
  4429. imgToPaint = tmpCanvas.canvas;
  4430. }
  4431. var paintWidth = width, paintHeight = height;
  4432. var tmpCanvasId = 'prescale1';
  4433. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4434. // pixels during drawImage operation, painting on the temporary canvas(es)
  4435. // that are twice smaller in size
  4436. while ((widthScale > 2 && paintWidth > 1) ||
  4437. (heightScale > 2 && paintHeight > 1)) {
  4438. var newWidth = paintWidth, newHeight = paintHeight;
  4439. if (widthScale > 2 && paintWidth > 1) {
  4440. newWidth = Math.ceil(paintWidth / 2);
  4441. widthScale /= paintWidth / newWidth;
  4442. }
  4443. if (heightScale > 2 && paintHeight > 1) {
  4444. newHeight = Math.ceil(paintHeight / 2);
  4445. heightScale /= paintHeight / newHeight;
  4446. }
  4447. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4448. tmpCtx = tmpCanvas.context;
  4449. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4450. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4451. 0, 0, newWidth, newHeight);
  4452. imgToPaint = tmpCanvas.canvas;
  4453. paintWidth = newWidth;
  4454. paintHeight = newHeight;
  4455. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4456. }
  4457. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4458. 0, -height, width, height);
  4459. if (this.imageLayer) {
  4460. var position = this.getCanvasPosition(0, -height);
  4461. this.imageLayer.appendImage({
  4462. imgData: imgData,
  4463. left: position[0],
  4464. top: position[1],
  4465. width: width / currentTransform[0],
  4466. height: height / currentTransform[3]
  4467. });
  4468. }
  4469. this.restore();
  4470. },
  4471. paintInlineImageXObjectGroup:
  4472. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4473. var ctx = this.ctx;
  4474. var w = imgData.width;
  4475. var h = imgData.height;
  4476. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4477. var tmpCtx = tmpCanvas.context;
  4478. putBinaryImageData(tmpCtx, imgData);
  4479. for (var i = 0, ii = map.length; i < ii; i++) {
  4480. var entry = map[i];
  4481. ctx.save();
  4482. ctx.transform.apply(ctx, entry.transform);
  4483. ctx.scale(1, -1);
  4484. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4485. 0, -1, 1, 1);
  4486. if (this.imageLayer) {
  4487. var position = this.getCanvasPosition(entry.x, entry.y);
  4488. this.imageLayer.appendImage({
  4489. imgData: imgData,
  4490. left: position[0],
  4491. top: position[1],
  4492. width: w,
  4493. height: h
  4494. });
  4495. }
  4496. ctx.restore();
  4497. }
  4498. },
  4499. paintSolidColorImageMask:
  4500. function CanvasGraphics_paintSolidColorImageMask() {
  4501. this.ctx.fillRect(0, 0, 1, 1);
  4502. },
  4503. // Marked content
  4504. markPoint: function CanvasGraphics_markPoint(tag) {
  4505. // TODO Marked content.
  4506. },
  4507. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4508. // TODO Marked content.
  4509. },
  4510. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4511. // TODO Marked content.
  4512. },
  4513. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4514. tag, properties) {
  4515. // TODO Marked content.
  4516. },
  4517. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4518. // TODO Marked content.
  4519. },
  4520. // Compatibility
  4521. beginCompat: function CanvasGraphics_beginCompat() {
  4522. // TODO ignore undefined operators (should we do that anyway?)
  4523. },
  4524. endCompat: function CanvasGraphics_endCompat() {
  4525. // TODO stop ignoring undefined operators
  4526. },
  4527. // Helper functions
  4528. consumePath: function CanvasGraphics_consumePath() {
  4529. var ctx = this.ctx;
  4530. if (this.pendingClip) {
  4531. if (this.pendingClip === EO_CLIP) {
  4532. if (ctx.mozFillRule !== undefined) {
  4533. ctx.mozFillRule = 'evenodd';
  4534. ctx.clip();
  4535. ctx.mozFillRule = 'nonzero';
  4536. } else {
  4537. try {
  4538. ctx.clip('evenodd');
  4539. } catch (ex) {
  4540. // shouldn't really happen, but browsers might think differently
  4541. ctx.clip();
  4542. }
  4543. }
  4544. } else {
  4545. ctx.clip();
  4546. }
  4547. this.pendingClip = null;
  4548. }
  4549. ctx.beginPath();
  4550. },
  4551. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4552. var inverse = this.ctx.mozCurrentTransformInverse;
  4553. // max of the current horizontal and vertical scale
  4554. return Math.sqrt(Math.max(
  4555. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4556. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4557. },
  4558. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4559. var transform = this.ctx.mozCurrentTransform;
  4560. return [
  4561. transform[0] * x + transform[2] * y + transform[4],
  4562. transform[1] * x + transform[3] * y + transform[5]
  4563. ];
  4564. }
  4565. };
  4566. for (var op in OPS) {
  4567. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4568. }
  4569. return CanvasGraphics;
  4570. })();
  4571. var WebGLUtils = (function WebGLUtilsClosure() {
  4572. function loadShader(gl, code, shaderType) {
  4573. var shader = gl.createShader(shaderType);
  4574. gl.shaderSource(shader, code);
  4575. gl.compileShader(shader);
  4576. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4577. if (!compiled) {
  4578. var errorMsg = gl.getShaderInfoLog(shader);
  4579. throw new Error('Error during shader compilation: ' + errorMsg);
  4580. }
  4581. return shader;
  4582. }
  4583. function createVertexShader(gl, code) {
  4584. return loadShader(gl, code, gl.VERTEX_SHADER);
  4585. }
  4586. function createFragmentShader(gl, code) {
  4587. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4588. }
  4589. function createProgram(gl, shaders) {
  4590. var program = gl.createProgram();
  4591. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4592. gl.attachShader(program, shaders[i]);
  4593. }
  4594. gl.linkProgram(program);
  4595. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4596. if (!linked) {
  4597. var errorMsg = gl.getProgramInfoLog(program);
  4598. throw new Error('Error during program linking: ' + errorMsg);
  4599. }
  4600. return program;
  4601. }
  4602. function createTexture(gl, image, textureId) {
  4603. gl.activeTexture(textureId);
  4604. var texture = gl.createTexture();
  4605. gl.bindTexture(gl.TEXTURE_2D, texture);
  4606. // Set the parameters so we can render any size image.
  4607. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4608. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4609. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4610. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4611. // Upload the image into the texture.
  4612. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4613. return texture;
  4614. }
  4615. var currentGL, currentCanvas;
  4616. function generageGL() {
  4617. if (currentGL) {
  4618. return;
  4619. }
  4620. currentCanvas = document.createElement('canvas');
  4621. currentGL = currentCanvas.getContext('webgl',
  4622. { premultipliedalpha: false });
  4623. }
  4624. var smaskVertexShaderCode = '\
  4625. attribute vec2 a_position; \
  4626. attribute vec2 a_texCoord; \
  4627. \
  4628. uniform vec2 u_resolution; \
  4629. \
  4630. varying vec2 v_texCoord; \
  4631. \
  4632. void main() { \
  4633. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4634. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4635. \
  4636. v_texCoord = a_texCoord; \
  4637. } ';
  4638. var smaskFragmentShaderCode = '\
  4639. precision mediump float; \
  4640. \
  4641. uniform vec4 u_backdrop; \
  4642. uniform int u_subtype; \
  4643. uniform sampler2D u_image; \
  4644. uniform sampler2D u_mask; \
  4645. \
  4646. varying vec2 v_texCoord; \
  4647. \
  4648. void main() { \
  4649. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4650. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4651. if (u_backdrop.a > 0.0) { \
  4652. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4653. u_backdrop.rgb * (1.0 - maskColor.a); \
  4654. } \
  4655. float lum; \
  4656. if (u_subtype == 0) { \
  4657. lum = maskColor.a; \
  4658. } else { \
  4659. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4660. maskColor.b * 0.11; \
  4661. } \
  4662. imageColor.a *= lum; \
  4663. imageColor.rgb *= imageColor.a; \
  4664. gl_FragColor = imageColor; \
  4665. } ';
  4666. var smaskCache = null;
  4667. function initSmaskGL() {
  4668. var canvas, gl;
  4669. generageGL();
  4670. canvas = currentCanvas;
  4671. currentCanvas = null;
  4672. gl = currentGL;
  4673. currentGL = null;
  4674. // setup a GLSL program
  4675. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4676. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4677. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4678. gl.useProgram(program);
  4679. var cache = {};
  4680. cache.gl = gl;
  4681. cache.canvas = canvas;
  4682. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4683. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4684. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4685. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4686. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4687. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4688. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4689. // provide texture coordinates for the rectangle.
  4690. var texCoordBuffer = gl.createBuffer();
  4691. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4692. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4693. 0.0, 0.0,
  4694. 1.0, 0.0,
  4695. 0.0, 1.0,
  4696. 0.0, 1.0,
  4697. 1.0, 0.0,
  4698. 1.0, 1.0]), gl.STATIC_DRAW);
  4699. gl.enableVertexAttribArray(texCoordLocation);
  4700. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4701. gl.uniform1i(texLayerLocation, 0);
  4702. gl.uniform1i(texMaskLocation, 1);
  4703. smaskCache = cache;
  4704. }
  4705. function composeSMask(layer, mask, properties) {
  4706. var width = layer.width, height = layer.height;
  4707. if (!smaskCache) {
  4708. initSmaskGL();
  4709. }
  4710. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4711. canvas.width = width;
  4712. canvas.height = height;
  4713. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4714. gl.uniform2f(cache.resolutionLocation, width, height);
  4715. if (properties.backdrop) {
  4716. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4717. properties.backdrop[1], properties.backdrop[2], 1);
  4718. } else {
  4719. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4720. }
  4721. gl.uniform1i(cache.subtypeLocation,
  4722. properties.subtype === 'Luminosity' ? 1 : 0);
  4723. // Create a textures
  4724. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4725. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4726. // Create a buffer and put a single clipspace rectangle in
  4727. // it (2 triangles)
  4728. var buffer = gl.createBuffer();
  4729. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4730. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4731. 0, 0,
  4732. width, 0,
  4733. 0, height,
  4734. 0, height,
  4735. width, 0,
  4736. width, height]), gl.STATIC_DRAW);
  4737. gl.enableVertexAttribArray(cache.positionLocation);
  4738. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4739. // draw
  4740. gl.clearColor(0, 0, 0, 0);
  4741. gl.enable(gl.BLEND);
  4742. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4743. gl.clear(gl.COLOR_BUFFER_BIT);
  4744. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4745. gl.flush();
  4746. gl.deleteTexture(texture);
  4747. gl.deleteTexture(maskTexture);
  4748. gl.deleteBuffer(buffer);
  4749. return canvas;
  4750. }
  4751. var figuresVertexShaderCode = '\
  4752. attribute vec2 a_position; \
  4753. attribute vec3 a_color; \
  4754. \
  4755. uniform vec2 u_resolution; \
  4756. uniform vec2 u_scale; \
  4757. uniform vec2 u_offset; \
  4758. \
  4759. varying vec4 v_color; \
  4760. \
  4761. void main() { \
  4762. vec2 position = (a_position + u_offset) * u_scale; \
  4763. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4764. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4765. \
  4766. v_color = vec4(a_color / 255.0, 1.0); \
  4767. } ';
  4768. var figuresFragmentShaderCode = '\
  4769. precision mediump float; \
  4770. \
  4771. varying vec4 v_color; \
  4772. \
  4773. void main() { \
  4774. gl_FragColor = v_color; \
  4775. } ';
  4776. var figuresCache = null;
  4777. function initFiguresGL() {
  4778. var canvas, gl;
  4779. generageGL();
  4780. canvas = currentCanvas;
  4781. currentCanvas = null;
  4782. gl = currentGL;
  4783. currentGL = null;
  4784. // setup a GLSL program
  4785. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4786. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4787. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4788. gl.useProgram(program);
  4789. var cache = {};
  4790. cache.gl = gl;
  4791. cache.canvas = canvas;
  4792. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4793. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4794. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4795. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4796. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4797. figuresCache = cache;
  4798. }
  4799. function drawFigures(width, height, backgroundColor, figures, context) {
  4800. if (!figuresCache) {
  4801. initFiguresGL();
  4802. }
  4803. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4804. canvas.width = width;
  4805. canvas.height = height;
  4806. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4807. gl.uniform2f(cache.resolutionLocation, width, height);
  4808. // count triangle points
  4809. var count = 0;
  4810. var i, ii, rows;
  4811. for (i = 0, ii = figures.length; i < ii; i++) {
  4812. switch (figures[i].type) {
  4813. case 'lattice':
  4814. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4815. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4816. break;
  4817. case 'triangles':
  4818. count += figures[i].coords.length;
  4819. break;
  4820. }
  4821. }
  4822. // transfer data
  4823. var coords = new Float32Array(count * 2);
  4824. var colors = new Uint8Array(count * 3);
  4825. var coordsMap = context.coords, colorsMap = context.colors;
  4826. var pIndex = 0, cIndex = 0;
  4827. for (i = 0, ii = figures.length; i < ii; i++) {
  4828. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4829. switch (figure.type) {
  4830. case 'lattice':
  4831. var cols = figure.verticesPerRow;
  4832. rows = (ps.length / cols) | 0;
  4833. for (var row = 1; row < rows; row++) {
  4834. var offset = row * cols + 1;
  4835. for (var col = 1; col < cols; col++, offset++) {
  4836. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4837. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4838. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4839. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4840. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4841. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4842. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4843. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4844. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4845. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4846. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4847. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4848. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4849. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4850. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4851. coords[pIndex + 6] = coords[pIndex + 2];
  4852. coords[pIndex + 7] = coords[pIndex + 3];
  4853. coords[pIndex + 8] = coords[pIndex + 4];
  4854. coords[pIndex + 9] = coords[pIndex + 5];
  4855. coords[pIndex + 10] = coordsMap[ps[offset]];
  4856. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4857. colors[cIndex + 9] = colors[cIndex + 3];
  4858. colors[cIndex + 10] = colors[cIndex + 4];
  4859. colors[cIndex + 11] = colors[cIndex + 5];
  4860. colors[cIndex + 12] = colors[cIndex + 6];
  4861. colors[cIndex + 13] = colors[cIndex + 7];
  4862. colors[cIndex + 14] = colors[cIndex + 8];
  4863. colors[cIndex + 15] = colorsMap[cs[offset]];
  4864. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4865. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4866. pIndex += 12;
  4867. cIndex += 18;
  4868. }
  4869. }
  4870. break;
  4871. case 'triangles':
  4872. for (var j = 0, jj = ps.length; j < jj; j++) {
  4873. coords[pIndex] = coordsMap[ps[j]];
  4874. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4875. colors[cIndex] = colorsMap[cs[i]];
  4876. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4877. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4878. pIndex += 2;
  4879. cIndex += 3;
  4880. }
  4881. break;
  4882. }
  4883. }
  4884. // draw
  4885. if (backgroundColor) {
  4886. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4887. backgroundColor[2] / 255, 1.0);
  4888. } else {
  4889. gl.clearColor(0, 0, 0, 0);
  4890. }
  4891. gl.clear(gl.COLOR_BUFFER_BIT);
  4892. var coordsBuffer = gl.createBuffer();
  4893. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4894. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4895. gl.enableVertexAttribArray(cache.positionLocation);
  4896. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4897. var colorsBuffer = gl.createBuffer();
  4898. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4899. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4900. gl.enableVertexAttribArray(cache.colorLocation);
  4901. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4902. 0, 0);
  4903. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4904. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4905. gl.drawArrays(gl.TRIANGLES, 0, count);
  4906. gl.flush();
  4907. gl.deleteBuffer(coordsBuffer);
  4908. gl.deleteBuffer(colorsBuffer);
  4909. return canvas;
  4910. }
  4911. function cleanup() {
  4912. if (smaskCache && smaskCache.canvas) {
  4913. smaskCache.canvas.width = 0;
  4914. smaskCache.canvas.height = 0;
  4915. }
  4916. if (figuresCache && figuresCache.canvas) {
  4917. figuresCache.canvas.width = 0;
  4918. figuresCache.canvas.height = 0;
  4919. }
  4920. smaskCache = null;
  4921. figuresCache = null;
  4922. }
  4923. return {
  4924. get isEnabled() {
  4925. if (PDFJS.disableWebGL) {
  4926. return false;
  4927. }
  4928. var enabled = false;
  4929. try {
  4930. generageGL();
  4931. enabled = !!currentGL;
  4932. } catch (e) { }
  4933. return shadow(this, 'isEnabled', enabled);
  4934. },
  4935. composeSMask: composeSMask,
  4936. drawFigures: drawFigures,
  4937. clear: cleanup
  4938. };
  4939. })();
  4940. var ShadingIRs = {};
  4941. ShadingIRs.RadialAxial = {
  4942. fromIR: function RadialAxial_fromIR(raw) {
  4943. var type = raw[1];
  4944. var colorStops = raw[2];
  4945. var p0 = raw[3];
  4946. var p1 = raw[4];
  4947. var r0 = raw[5];
  4948. var r1 = raw[6];
  4949. return {
  4950. type: 'Pattern',
  4951. getPattern: function RadialAxial_getPattern(ctx) {
  4952. var grad;
  4953. if (type === 'axial') {
  4954. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  4955. } else if (type === 'radial') {
  4956. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  4957. }
  4958. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  4959. var c = colorStops[i];
  4960. grad.addColorStop(c[0], c[1]);
  4961. }
  4962. return grad;
  4963. }
  4964. };
  4965. }
  4966. };
  4967. var createMeshCanvas = (function createMeshCanvasClosure() {
  4968. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4969. // Very basic Gouraud-shaded triangle rasterization algorithm.
  4970. var coords = context.coords, colors = context.colors;
  4971. var bytes = data.data, rowSize = data.width * 4;
  4972. var tmp;
  4973. if (coords[p1 + 1] > coords[p2 + 1]) {
  4974. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4975. }
  4976. if (coords[p2 + 1] > coords[p3 + 1]) {
  4977. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  4978. }
  4979. if (coords[p1 + 1] > coords[p2 + 1]) {
  4980. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4981. }
  4982. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4983. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4984. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4985. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4986. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4987. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4988. if (y1 >= y3) {
  4989. return;
  4990. }
  4991. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  4992. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  4993. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  4994. var minY = Math.round(y1), maxY = Math.round(y3);
  4995. var xa, car, cag, cab;
  4996. var xb, cbr, cbg, cbb;
  4997. var k;
  4998. for (var y = minY; y <= maxY; y++) {
  4999. if (y < y2) {
  5000. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5001. xa = x1 - (x1 - x2) * k;
  5002. car = c1r - (c1r - c2r) * k;
  5003. cag = c1g - (c1g - c2g) * k;
  5004. cab = c1b - (c1b - c2b) * k;
  5005. } else {
  5006. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5007. xa = x2 - (x2 - x3) * k;
  5008. car = c2r - (c2r - c3r) * k;
  5009. cag = c2g - (c2g - c3g) * k;
  5010. cab = c2b - (c2b - c3b) * k;
  5011. }
  5012. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5013. xb = x1 - (x1 - x3) * k;
  5014. cbr = c1r - (c1r - c3r) * k;
  5015. cbg = c1g - (c1g - c3g) * k;
  5016. cbb = c1b - (c1b - c3b) * k;
  5017. var x1_ = Math.round(Math.min(xa, xb));
  5018. var x2_ = Math.round(Math.max(xa, xb));
  5019. var j = rowSize * y + x1_ * 4;
  5020. for (var x = x1_; x <= x2_; x++) {
  5021. k = (xa - x) / (xa - xb);
  5022. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5023. bytes[j++] = (car - (car - cbr) * k) | 0;
  5024. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5025. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5026. bytes[j++] = 255;
  5027. }
  5028. }
  5029. }
  5030. function drawFigure(data, figure, context) {
  5031. var ps = figure.coords;
  5032. var cs = figure.colors;
  5033. var i, ii;
  5034. switch (figure.type) {
  5035. case 'lattice':
  5036. var verticesPerRow = figure.verticesPerRow;
  5037. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5038. var cols = verticesPerRow - 1;
  5039. for (i = 0; i < rows; i++) {
  5040. var q = i * verticesPerRow;
  5041. for (var j = 0; j < cols; j++, q++) {
  5042. drawTriangle(data, context,
  5043. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5044. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5045. drawTriangle(data, context,
  5046. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5047. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5048. }
  5049. }
  5050. break;
  5051. case 'triangles':
  5052. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5053. drawTriangle(data, context,
  5054. ps[i], ps[i + 1], ps[i + 2],
  5055. cs[i], cs[i + 1], cs[i + 2]);
  5056. }
  5057. break;
  5058. default:
  5059. error('illigal figure');
  5060. break;
  5061. }
  5062. }
  5063. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5064. backgroundColor) {
  5065. // we will increase scale on some weird factor to let antialiasing take
  5066. // care of "rough" edges
  5067. var EXPECTED_SCALE = 1.1;
  5068. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5069. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5070. var offsetX = Math.floor(bounds[0]);
  5071. var offsetY = Math.floor(bounds[1]);
  5072. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5073. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5074. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5075. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5076. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5077. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5078. var scaleX = boundsWidth / width;
  5079. var scaleY = boundsHeight / height;
  5080. var context = {
  5081. coords: coords,
  5082. colors: colors,
  5083. offsetX: -offsetX,
  5084. offsetY: -offsetY,
  5085. scaleX: 1 / scaleX,
  5086. scaleY: 1 / scaleY
  5087. };
  5088. var canvas, tmpCanvas, i, ii;
  5089. if (WebGLUtils.isEnabled) {
  5090. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5091. figures, context);
  5092. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5093. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5094. tmpCanvas.context.drawImage(canvas, 0, 0);
  5095. canvas = tmpCanvas.canvas;
  5096. } else {
  5097. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5098. var tmpCtx = tmpCanvas.context;
  5099. var data = tmpCtx.createImageData(width, height);
  5100. if (backgroundColor) {
  5101. var bytes = data.data;
  5102. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5103. bytes[i] = backgroundColor[0];
  5104. bytes[i + 1] = backgroundColor[1];
  5105. bytes[i + 2] = backgroundColor[2];
  5106. bytes[i + 3] = 255;
  5107. }
  5108. }
  5109. for (i = 0; i < figures.length; i++) {
  5110. drawFigure(data, figures[i], context);
  5111. }
  5112. tmpCtx.putImageData(data, 0, 0);
  5113. canvas = tmpCanvas.canvas;
  5114. }
  5115. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5116. scaleX: scaleX, scaleY: scaleY};
  5117. }
  5118. return createMeshCanvas;
  5119. })();
  5120. ShadingIRs.Mesh = {
  5121. fromIR: function Mesh_fromIR(raw) {
  5122. //var type = raw[1];
  5123. var coords = raw[2];
  5124. var colors = raw[3];
  5125. var figures = raw[4];
  5126. var bounds = raw[5];
  5127. var matrix = raw[6];
  5128. //var bbox = raw[7];
  5129. var background = raw[8];
  5130. return {
  5131. type: 'Pattern',
  5132. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5133. var scale;
  5134. if (shadingFill) {
  5135. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5136. } else {
  5137. // Obtain scale from matrix and current transformation matrix.
  5138. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5139. if (matrix) {
  5140. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5141. scale = [scale[0] * matrixScale[0],
  5142. scale[1] * matrixScale[1]];
  5143. }
  5144. }
  5145. // Rasterizing on the main thread since sending/queue large canvases
  5146. // might cause OOM.
  5147. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5148. colors, figures, shadingFill ? null : background);
  5149. if (!shadingFill) {
  5150. ctx.setTransform.apply(ctx, owner.baseTransform);
  5151. if (matrix) {
  5152. ctx.transform.apply(ctx, matrix);
  5153. }
  5154. }
  5155. ctx.translate(temporaryPatternCanvas.offsetX,
  5156. temporaryPatternCanvas.offsetY);
  5157. ctx.scale(temporaryPatternCanvas.scaleX,
  5158. temporaryPatternCanvas.scaleY);
  5159. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5160. }
  5161. };
  5162. }
  5163. };
  5164. ShadingIRs.Dummy = {
  5165. fromIR: function Dummy_fromIR() {
  5166. return {
  5167. type: 'Pattern',
  5168. getPattern: function Dummy_fromIR_getPattern() {
  5169. return 'hotpink';
  5170. }
  5171. };
  5172. }
  5173. };
  5174. function getShadingPatternFromIR(raw) {
  5175. var shadingIR = ShadingIRs[raw[0]];
  5176. if (!shadingIR) {
  5177. error('Unknown IR type: ' + raw[0]);
  5178. }
  5179. return shadingIR.fromIR(raw);
  5180. }
  5181. var TilingPattern = (function TilingPatternClosure() {
  5182. var PaintType = {
  5183. COLORED: 1,
  5184. UNCOLORED: 2
  5185. };
  5186. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5187. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5188. this.operatorList = IR[2];
  5189. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5190. this.bbox = IR[4];
  5191. this.xstep = IR[5];
  5192. this.ystep = IR[6];
  5193. this.paintType = IR[7];
  5194. this.tilingType = IR[8];
  5195. this.color = color;
  5196. this.objs = objs;
  5197. this.commonObjs = commonObjs;
  5198. this.baseTransform = baseTransform;
  5199. this.type = 'Pattern';
  5200. this.ctx = ctx;
  5201. }
  5202. TilingPattern.prototype = {
  5203. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5204. var operatorList = this.operatorList;
  5205. var bbox = this.bbox;
  5206. var xstep = this.xstep;
  5207. var ystep = this.ystep;
  5208. var paintType = this.paintType;
  5209. var tilingType = this.tilingType;
  5210. var color = this.color;
  5211. var objs = this.objs;
  5212. var commonObjs = this.commonObjs;
  5213. info('TilingType: ' + tilingType);
  5214. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5215. var topLeft = [x0, y0];
  5216. // we want the canvas to be as large as the step size
  5217. var botRight = [x0 + xstep, y0 + ystep];
  5218. var width = botRight[0] - topLeft[0];
  5219. var height = botRight[1] - topLeft[1];
  5220. // Obtain scale from matrix and current transformation matrix.
  5221. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5222. var curMatrixScale = Util.singularValueDecompose2dScale(
  5223. this.baseTransform);
  5224. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5225. matrixScale[1] * curMatrixScale[1]];
  5226. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5227. // Use width and height values that are as close as possible to the end
  5228. // result when the pattern is used. Too low value makes the pattern look
  5229. // blurry. Too large value makes it look too crispy.
  5230. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5231. MAX_PATTERN_SIZE);
  5232. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5233. MAX_PATTERN_SIZE);
  5234. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5235. var tmpCtx = tmpCanvas.context;
  5236. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5237. graphics.groupLevel = owner.groupLevel;
  5238. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5239. this.setScale(width, height, xstep, ystep);
  5240. this.transformToScale(graphics);
  5241. // transform coordinates to pattern space
  5242. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5243. graphics.transform.apply(graphics, tmpTranslate);
  5244. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5245. graphics.executeOperatorList(operatorList);
  5246. return tmpCanvas.canvas;
  5247. },
  5248. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5249. this.scale = [width / xstep, height / ystep];
  5250. },
  5251. transformToScale: function TilingPattern_transformToScale(graphics) {
  5252. var scale = this.scale;
  5253. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5254. graphics.transform.apply(graphics, tmpScale);
  5255. },
  5256. scaleToContext: function TilingPattern_scaleToContext() {
  5257. var scale = this.scale;
  5258. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5259. },
  5260. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5261. if (bbox && isArray(bbox) && bbox.length === 4) {
  5262. var bboxWidth = x1 - x0;
  5263. var bboxHeight = y1 - y0;
  5264. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5265. graphics.clip();
  5266. graphics.endPath();
  5267. }
  5268. },
  5269. setFillAndStrokeStyleToContext:
  5270. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5271. switch (paintType) {
  5272. case PaintType.COLORED:
  5273. var ctx = this.ctx;
  5274. context.fillStyle = ctx.fillStyle;
  5275. context.strokeStyle = ctx.strokeStyle;
  5276. break;
  5277. case PaintType.UNCOLORED:
  5278. var cssColor = Util.makeCssRgb(color);
  5279. context.fillStyle = cssColor;
  5280. context.strokeStyle = cssColor;
  5281. break;
  5282. default:
  5283. error('Unsupported paint type: ' + paintType);
  5284. }
  5285. },
  5286. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5287. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5288. ctx = this.ctx;
  5289. ctx.setTransform.apply(ctx, this.baseTransform);
  5290. ctx.transform.apply(ctx, this.matrix);
  5291. this.scaleToContext();
  5292. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5293. }
  5294. };
  5295. return TilingPattern;
  5296. })();
  5297. PDFJS.disableFontFace = false;
  5298. var FontLoader = {
  5299. insertRule: function fontLoaderInsertRule(rule) {
  5300. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5301. if (!styleElement) {
  5302. styleElement = document.createElement('style');
  5303. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5304. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5305. styleElement);
  5306. }
  5307. var styleSheet = styleElement.sheet;
  5308. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5309. },
  5310. clear: function fontLoaderClear() {
  5311. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5312. if (styleElement) {
  5313. styleElement.parentNode.removeChild(styleElement);
  5314. }
  5315. },
  5316. get loadTestFont() {
  5317. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5318. // height.
  5319. return shadow(this, 'loadTestFont', atob(
  5320. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5321. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5322. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5323. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5324. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5325. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5326. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5327. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5328. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5329. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5330. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5331. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5332. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5333. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5334. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5335. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5336. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5337. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5338. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5339. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5340. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5341. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5342. ));
  5343. },
  5344. loadTestFontId: 0,
  5345. loadingContext: {
  5346. requests: [],
  5347. nextRequestId: 0
  5348. },
  5349. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5350. if (isWorker) {
  5351. return false;
  5352. }
  5353. // User agent string sniffing is bad, but there is no reliable way to tell
  5354. // if font is fully loaded and ready to be used with canvas.
  5355. var userAgent = window.navigator.userAgent;
  5356. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5357. if (m && m[1] >= 14) {
  5358. return true;
  5359. }
  5360. // TODO other browsers
  5361. return false;
  5362. })(),
  5363. bind: function fontLoaderBind(fonts, callback) {
  5364. assert(!isWorker, 'bind() shall be called from main thread');
  5365. var rules = [], fontsToLoad = [];
  5366. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5367. var font = fonts[i];
  5368. // Add the font to the DOM only once or skip if the font
  5369. // is already loaded.
  5370. if (font.attached || font.loading === false) {
  5371. continue;
  5372. }
  5373. font.attached = true;
  5374. var rule = font.bindDOM();
  5375. if (rule) {
  5376. rules.push(rule);
  5377. fontsToLoad.push(font);
  5378. }
  5379. }
  5380. var request = FontLoader.queueLoadingCallback(callback);
  5381. if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5382. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5383. } else {
  5384. request.complete();
  5385. }
  5386. },
  5387. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5388. function LoadLoader_completeRequest() {
  5389. assert(!request.end, 'completeRequest() cannot be called twice');
  5390. request.end = Date.now();
  5391. // sending all completed requests in order how they were queued
  5392. while (context.requests.length > 0 && context.requests[0].end) {
  5393. var otherRequest = context.requests.shift();
  5394. setTimeout(otherRequest.callback, 0);
  5395. }
  5396. }
  5397. var context = FontLoader.loadingContext;
  5398. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5399. var request = {
  5400. id: requestId,
  5401. complete: LoadLoader_completeRequest,
  5402. callback: callback,
  5403. started: Date.now()
  5404. };
  5405. context.requests.push(request);
  5406. return request;
  5407. },
  5408. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5409. fonts,
  5410. request) {
  5411. /** Hack begin */
  5412. // There's currently no event when a font has finished downloading so the
  5413. // following code is a dirty hack to 'guess' when a font is
  5414. // ready. It's assumed fonts are loaded in order, so add a known test
  5415. // font after the desired fonts and then test for the loading of that
  5416. // test font.
  5417. function int32(data, offset) {
  5418. return (data.charCodeAt(offset) << 24) |
  5419. (data.charCodeAt(offset + 1) << 16) |
  5420. (data.charCodeAt(offset + 2) << 8) |
  5421. (data.charCodeAt(offset + 3) & 0xff);
  5422. }
  5423. function spliceString(s, offset, remove, insert) {
  5424. var chunk1 = s.substr(0, offset);
  5425. var chunk2 = s.substr(offset + remove);
  5426. return chunk1 + insert + chunk2;
  5427. }
  5428. var i, ii;
  5429. var canvas = document.createElement('canvas');
  5430. canvas.width = 1;
  5431. canvas.height = 1;
  5432. var ctx = canvas.getContext('2d');
  5433. var called = 0;
  5434. function isFontReady(name, callback) {
  5435. called++;
  5436. // With setTimeout clamping this gives the font ~100ms to load.
  5437. if(called > 30) {
  5438. warn('Load test font never loaded.');
  5439. callback();
  5440. return;
  5441. }
  5442. ctx.font = '30px ' + name;
  5443. ctx.fillText('.', 0, 20);
  5444. var imageData = ctx.getImageData(0, 0, 1, 1);
  5445. if (imageData.data[3] > 0) {
  5446. callback();
  5447. return;
  5448. }
  5449. setTimeout(isFontReady.bind(null, name, callback));
  5450. }
  5451. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5452. // Chromium seems to cache fonts based on a hash of the actual font data,
  5453. // so the font must be modified for each load test else it will appear to
  5454. // be loaded already.
  5455. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5456. // font by splitting it in chunks before hand and padding the font id.
  5457. var data = this.loadTestFont;
  5458. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5459. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5460. loadTestFontId);
  5461. // CFF checksum is important for IE, adjusting it
  5462. var CFF_CHECKSUM_OFFSET = 16;
  5463. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5464. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5465. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5466. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5467. }
  5468. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5469. checksum = (checksum - XXXX_VALUE +
  5470. int32(loadTestFontId + 'XXX', i)) | 0;
  5471. }
  5472. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5473. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5474. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5475. url + '}';
  5476. FontLoader.insertRule(rule);
  5477. var names = [];
  5478. for (i = 0, ii = fonts.length; i < ii; i++) {
  5479. names.push(fonts[i].loadedName);
  5480. }
  5481. names.push(loadTestFontId);
  5482. var div = document.createElement('div');
  5483. div.setAttribute('style',
  5484. 'visibility: hidden;' +
  5485. 'width: 10px; height: 10px;' +
  5486. 'position: absolute; top: 0px; left: 0px;');
  5487. for (i = 0, ii = names.length; i < ii; ++i) {
  5488. var span = document.createElement('span');
  5489. span.textContent = 'Hi';
  5490. span.style.fontFamily = names[i];
  5491. div.appendChild(span);
  5492. }
  5493. document.body.appendChild(div);
  5494. isFontReady(loadTestFontId, function() {
  5495. document.body.removeChild(div);
  5496. request.complete();
  5497. });
  5498. /** Hack end */
  5499. }
  5500. };
  5501. var FontFace = (function FontFaceClosure() {
  5502. function FontFace(name, file, properties) {
  5503. this.compiledGlyphs = {};
  5504. if (arguments.length === 1) {
  5505. // importing translated data
  5506. var data = arguments[0];
  5507. for (var i in data) {
  5508. this[i] = data[i];
  5509. }
  5510. return;
  5511. }
  5512. }
  5513. FontFace.prototype = {
  5514. bindDOM: function FontFace_bindDOM() {
  5515. if (!this.data) {
  5516. return null;
  5517. }
  5518. if (PDFJS.disableFontFace) {
  5519. this.disableFontFace = true;
  5520. return null;
  5521. }
  5522. var data = bytesToString(new Uint8Array(this.data));
  5523. var fontName = this.loadedName;
  5524. // Add the font-face rule to the document
  5525. var url = ('url(data:' + this.mimetype + ';base64,' +
  5526. window.btoa(data) + ');');
  5527. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5528. FontLoader.insertRule(rule);
  5529. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5530. globalScope['FontInspector'].enabled) {
  5531. globalScope['FontInspector'].fontAdded(this, url);
  5532. }
  5533. return rule;
  5534. },
  5535. getPathGenerator: function (objs, character) {
  5536. if (!(character in this.compiledGlyphs)) {
  5537. var js = objs.get(this.loadedName + '_path_' + character);
  5538. /*jshint -W054 */
  5539. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5540. }
  5541. return this.compiledGlyphs[character];
  5542. }
  5543. };
  5544. return FontFace;
  5545. })();
  5546. var HIGHLIGHT_OFFSET = 4; // px
  5547. var ANNOT_MIN_SIZE = 10; // px
  5548. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5549. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5550. function setTextStyles(element, item, fontObj) {
  5551. var style = element.style;
  5552. style.fontSize = item.fontSize + 'px';
  5553. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5554. if (!fontObj) {
  5555. return;
  5556. }
  5557. style.fontWeight = fontObj.black ?
  5558. (fontObj.bold ? 'bolder' : 'bold') :
  5559. (fontObj.bold ? 'bold' : 'normal');
  5560. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5561. var fontName = fontObj.loadedName;
  5562. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5563. // Use a reasonable default font if the font doesn't specify a fallback
  5564. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5565. style.fontFamily = fontFamily + fallbackName;
  5566. }
  5567. // TODO(mack): Remove this, it's not really that helpful.
  5568. function getEmptyContainer(tagName, rect, borderWidth) {
  5569. var bWidth = borderWidth || 0;
  5570. var element = document.createElement(tagName);
  5571. element.style.borderWidth = bWidth + 'px';
  5572. var width = rect[2] - rect[0] - 2 * bWidth;
  5573. var height = rect[3] - rect[1] - 2 * bWidth;
  5574. element.style.width = width + 'px';
  5575. element.style.height = height + 'px';
  5576. return element;
  5577. }
  5578. function initContainer(item) {
  5579. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5580. container.style.backgroundColor = item.color;
  5581. var color = item.color;
  5582. var rgb = [];
  5583. for (var i = 0; i < 3; ++i) {
  5584. rgb[i] = Math.round(color[i] * 255);
  5585. }
  5586. item.colorCssRgb = Util.makeCssRgb(rgb);
  5587. var highlight = document.createElement('div');
  5588. highlight.className = 'annotationHighlight';
  5589. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5590. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5591. highlight.setAttribute('hidden', true);
  5592. item.highlightElement = highlight;
  5593. container.appendChild(item.highlightElement);
  5594. return container;
  5595. }
  5596. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5597. var element = getEmptyContainer('div', item.rect, 0);
  5598. element.style.display = 'table';
  5599. var content = document.createElement('div');
  5600. content.textContent = item.fieldValue;
  5601. var textAlignment = item.textAlignment;
  5602. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5603. content.style.verticalAlign = 'middle';
  5604. content.style.display = 'table-cell';
  5605. var fontObj = item.fontRefName ?
  5606. commonObjs.getData(item.fontRefName) : null;
  5607. setTextStyles(content, item, fontObj);
  5608. element.appendChild(content);
  5609. return element;
  5610. }
  5611. function getHtmlElementForTextAnnotation(item) {
  5612. var rect = item.rect;
  5613. // sanity check because of OOo-generated PDFs
  5614. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5615. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5616. }
  5617. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5618. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5619. }
  5620. var container = initContainer(item);
  5621. container.className = 'annotText';
  5622. var image = document.createElement('img');
  5623. image.style.height = container.style.height;
  5624. image.style.width = container.style.width;
  5625. var iconName = item.name;
  5626. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5627. iconName.toLowerCase() + '.svg';
  5628. image.alt = '[{{type}} Annotation]';
  5629. image.dataset.l10nId = 'text_annotation_type';
  5630. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5631. var contentWrapper = document.createElement('div');
  5632. contentWrapper.className = 'annotTextContentWrapper';
  5633. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5634. contentWrapper.style.top = '-10px';
  5635. var content = document.createElement('div');
  5636. content.className = 'annotTextContent';
  5637. content.setAttribute('hidden', true);
  5638. var i, ii;
  5639. if (item.hasBgColor) {
  5640. var color = item.color;
  5641. var rgb = [];
  5642. for (i = 0; i < 3; ++i) {
  5643. // Enlighten the color (70%)
  5644. var c = Math.round(color[i] * 255);
  5645. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5646. }
  5647. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5648. }
  5649. var title = document.createElement('h1');
  5650. var text = document.createElement('p');
  5651. title.textContent = item.title;
  5652. if (!item.content && !item.title) {
  5653. content.setAttribute('hidden', true);
  5654. } else {
  5655. var e = document.createElement('span');
  5656. var lines = item.content.split(/(?:\r\n?|\n)/);
  5657. for (i = 0, ii = lines.length; i < ii; ++i) {
  5658. var line = lines[i];
  5659. e.appendChild(document.createTextNode(line));
  5660. if (i < (ii - 1)) {
  5661. e.appendChild(document.createElement('br'));
  5662. }
  5663. }
  5664. text.appendChild(e);
  5665. var pinned = false;
  5666. var showAnnotation = function showAnnotation(pin) {
  5667. if (pin) {
  5668. pinned = true;
  5669. }
  5670. if (content.hasAttribute('hidden')) {
  5671. container.style.zIndex += 1;
  5672. content.removeAttribute('hidden');
  5673. }
  5674. };
  5675. var hideAnnotation = function hideAnnotation(unpin) {
  5676. if (unpin) {
  5677. pinned = false;
  5678. }
  5679. if (!content.hasAttribute('hidden') && !pinned) {
  5680. container.style.zIndex -= 1;
  5681. content.setAttribute('hidden', true);
  5682. }
  5683. };
  5684. var toggleAnnotation = function toggleAnnotation() {
  5685. if (pinned) {
  5686. hideAnnotation(true);
  5687. } else {
  5688. showAnnotation(true);
  5689. }
  5690. };
  5691. image.addEventListener('click', function image_clickHandler() {
  5692. toggleAnnotation();
  5693. }, false);
  5694. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5695. showAnnotation();
  5696. }, false);
  5697. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5698. hideAnnotation();
  5699. }, false);
  5700. content.addEventListener('click', function content_clickHandler() {
  5701. hideAnnotation(true);
  5702. }, false);
  5703. }
  5704. content.appendChild(title);
  5705. content.appendChild(text);
  5706. contentWrapper.appendChild(content);
  5707. container.appendChild(image);
  5708. container.appendChild(contentWrapper);
  5709. return container;
  5710. }
  5711. function getHtmlElementForLinkAnnotation(item) {
  5712. var container = initContainer(item);
  5713. container.className = 'annotLink';
  5714. container.style.borderColor = item.colorCssRgb;
  5715. container.style.borderStyle = 'solid';
  5716. var link = document.createElement('a');
  5717. link.href = link.title = item.url || '';
  5718. container.appendChild(link);
  5719. return container;
  5720. }
  5721. function getHtmlElement(data, objs) {
  5722. switch (data.annotationType) {
  5723. case AnnotationType.WIDGET:
  5724. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5725. case AnnotationType.TEXT:
  5726. return getHtmlElementForTextAnnotation(data);
  5727. case AnnotationType.LINK:
  5728. return getHtmlElementForLinkAnnotation(data);
  5729. default:
  5730. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5731. }
  5732. }
  5733. return {
  5734. getHtmlElement: getHtmlElement
  5735. };
  5736. })();
  5737. PDFJS.AnnotationUtils = AnnotationUtils;
  5738. var NetworkManager = (function NetworkManagerClosure() {
  5739. var OK_RESPONSE = 200;
  5740. var PARTIAL_CONTENT_RESPONSE = 206;
  5741. function NetworkManager(url, args) {
  5742. this.url = url;
  5743. args = args || {};
  5744. this.isHttp = /^https?:/i.test(url);
  5745. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  5746. this.withCredentials = args.withCredentials || false;
  5747. this.getXhr = args.getXhr ||
  5748. function NetworkManager_getXhr() {
  5749. return new XMLHttpRequest();
  5750. };
  5751. this.currXhrId = 0;
  5752. this.pendingRequests = {};
  5753. this.loadedRequests = {};
  5754. }
  5755. function getArrayBuffer(xhr) {
  5756. var data = xhr.response;
  5757. if (typeof data !== 'string') {
  5758. return data;
  5759. }
  5760. var length = data.length;
  5761. var buffer = new Uint8Array(length);
  5762. for (var i = 0; i < length; i++) {
  5763. buffer[i] = data.charCodeAt(i) & 0xFF;
  5764. }
  5765. return buffer;
  5766. }
  5767. NetworkManager.prototype = {
  5768. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  5769. var args = {
  5770. begin: begin,
  5771. end: end
  5772. };
  5773. for (var prop in listeners) {
  5774. args[prop] = listeners[prop];
  5775. }
  5776. return this.request(args);
  5777. },
  5778. requestFull: function NetworkManager_requestRange(listeners) {
  5779. return this.request(listeners);
  5780. },
  5781. request: function NetworkManager_requestRange(args) {
  5782. var xhr = this.getXhr();
  5783. var xhrId = this.currXhrId++;
  5784. var pendingRequest = this.pendingRequests[xhrId] = {
  5785. xhr: xhr
  5786. };
  5787. xhr.open('GET', this.url);
  5788. xhr.withCredentials = this.withCredentials;
  5789. for (var property in this.httpHeaders) {
  5790. var value = this.httpHeaders[property];
  5791. if (typeof value === 'undefined') {
  5792. continue;
  5793. }
  5794. xhr.setRequestHeader(property, value);
  5795. }
  5796. if (this.isHttp && 'begin' in args && 'end' in args) {
  5797. var rangeStr = args.begin + '-' + (args.end - 1);
  5798. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  5799. pendingRequest.expectedStatus = 206;
  5800. } else {
  5801. pendingRequest.expectedStatus = 200;
  5802. }
  5803. xhr.responseType = 'arraybuffer';
  5804. if (args.onProgress) {
  5805. xhr.onprogress = args.onProgress;
  5806. }
  5807. if (args.onError) {
  5808. xhr.onerror = function(evt) {
  5809. args.onError(xhr.status);
  5810. };
  5811. }
  5812. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  5813. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  5814. pendingRequest.onDone = args.onDone;
  5815. pendingRequest.onError = args.onError;
  5816. xhr.send(null);
  5817. return xhrId;
  5818. },
  5819. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  5820. var pendingRequest = this.pendingRequests[xhrId];
  5821. if (!pendingRequest) {
  5822. // Maybe abortRequest was called...
  5823. return;
  5824. }
  5825. var xhr = pendingRequest.xhr;
  5826. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  5827. pendingRequest.onHeadersReceived();
  5828. delete pendingRequest.onHeadersReceived;
  5829. }
  5830. if (xhr.readyState !== 4) {
  5831. return;
  5832. }
  5833. if (!(xhrId in this.pendingRequests)) {
  5834. // The XHR request might have been aborted in onHeadersReceived()
  5835. // callback, in which case we should abort request
  5836. return;
  5837. }
  5838. delete this.pendingRequests[xhrId];
  5839. // success status == 0 can be on ftp, file and other protocols
  5840. if (xhr.status === 0 && this.isHttp) {
  5841. if (pendingRequest.onError) {
  5842. pendingRequest.onError(xhr.status);
  5843. }
  5844. return;
  5845. }
  5846. var xhrStatus = xhr.status || OK_RESPONSE;
  5847. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  5848. // "A server MAY ignore the Range header". This means it's possible to
  5849. // get a 200 rather than a 206 response from a range request.
  5850. var ok_response_on_range_request =
  5851. xhrStatus === OK_RESPONSE &&
  5852. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  5853. if (!ok_response_on_range_request &&
  5854. xhrStatus !== pendingRequest.expectedStatus) {
  5855. if (pendingRequest.onError) {
  5856. pendingRequest.onError(xhr.status);
  5857. }
  5858. return;
  5859. }
  5860. this.loadedRequests[xhrId] = true;
  5861. var chunk = getArrayBuffer(xhr);
  5862. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  5863. var rangeHeader = xhr.getResponseHeader('Content-Range');
  5864. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  5865. var begin = parseInt(matches[1], 10);
  5866. pendingRequest.onDone({
  5867. begin: begin,
  5868. chunk: chunk
  5869. });
  5870. } else {
  5871. pendingRequest.onDone({
  5872. begin: 0,
  5873. chunk: chunk
  5874. });
  5875. }
  5876. },
  5877. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  5878. for (var xhrId in this.pendingRequests) {
  5879. return true;
  5880. }
  5881. return false;
  5882. },
  5883. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  5884. return this.pendingRequests[xhrId].xhr;
  5885. },
  5886. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  5887. return xhrId in this.pendingRequests;
  5888. },
  5889. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  5890. return xhrId in this.loadedRequests;
  5891. },
  5892. abortAllRequests: function NetworkManager_abortAllRequests() {
  5893. for (var xhrId in this.pendingRequests) {
  5894. this.abortRequest(xhrId | 0);
  5895. }
  5896. },
  5897. abortRequest: function NetworkManager_abortRequest(xhrId) {
  5898. var xhr = this.pendingRequests[xhrId].xhr;
  5899. delete this.pendingRequests[xhrId];
  5900. xhr.abort();
  5901. }
  5902. };
  5903. return NetworkManager;
  5904. })();
  5905. var ChunkedStream = (function ChunkedStreamClosure() {
  5906. function ChunkedStream(length, chunkSize, manager) {
  5907. this.bytes = new Uint8Array(length);
  5908. this.start = 0;
  5909. this.pos = 0;
  5910. this.end = length;
  5911. this.chunkSize = chunkSize;
  5912. this.loadedChunks = [];
  5913. this.numChunksLoaded = 0;
  5914. this.numChunks = Math.ceil(length / chunkSize);
  5915. this.manager = manager;
  5916. this.initialDataLength = 0;
  5917. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  5918. }
  5919. // required methods for a stream. if a particular stream does not
  5920. // implement these, an error should be thrown
  5921. ChunkedStream.prototype = {
  5922. getMissingChunks: function ChunkedStream_getMissingChunks() {
  5923. var chunks = [];
  5924. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  5925. if (!(chunk in this.loadedChunks)) {
  5926. chunks.push(chunk);
  5927. }
  5928. }
  5929. return chunks;
  5930. },
  5931. getBaseStreams: function ChunkedStream_getBaseStreams() {
  5932. return [this];
  5933. },
  5934. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  5935. return this.numChunksLoaded === this.numChunks;
  5936. },
  5937. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  5938. var end = begin + chunk.byteLength;
  5939. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  5940. // Using this.length is inaccurate here since this.start can be moved
  5941. // See ChunkedStream.moveStart()
  5942. var length = this.bytes.length;
  5943. assert(end % this.chunkSize === 0 || end === length,
  5944. 'Bad end offset: ' + end);
  5945. this.bytes.set(new Uint8Array(chunk), begin);
  5946. var chunkSize = this.chunkSize;
  5947. var beginChunk = Math.floor(begin / chunkSize);
  5948. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5949. var curChunk;
  5950. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5951. if (!(curChunk in this.loadedChunks)) {
  5952. this.loadedChunks[curChunk] = true;
  5953. ++this.numChunksLoaded;
  5954. }
  5955. }
  5956. },
  5957. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  5958. this.bytes.set(data);
  5959. this.initialDataLength = data.length;
  5960. var endChunk = (this.end === data.length ?
  5961. this.numChunks : Math.floor(data.length / this.chunkSize));
  5962. for (var i = 0; i < endChunk; i++) {
  5963. this.loadedChunks[i] = true;
  5964. ++this.numChunksLoaded;
  5965. }
  5966. },
  5967. ensureByte: function ChunkedStream_ensureRange(pos) {
  5968. var chunk = Math.floor(pos / this.chunkSize);
  5969. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  5970. return;
  5971. }
  5972. if (!(chunk in this.loadedChunks)) {
  5973. throw new MissingDataException(pos, pos + 1);
  5974. }
  5975. this.lastSuccessfulEnsureByteChunk = chunk;
  5976. },
  5977. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  5978. if (begin >= end) {
  5979. return;
  5980. }
  5981. if (end <= this.initialDataLength) {
  5982. return;
  5983. }
  5984. var chunkSize = this.chunkSize;
  5985. var beginChunk = Math.floor(begin / chunkSize);
  5986. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5987. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5988. if (!(chunk in this.loadedChunks)) {
  5989. throw new MissingDataException(begin, end);
  5990. }
  5991. }
  5992. },
  5993. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  5994. var chunk, n;
  5995. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  5996. if (!(chunk in this.loadedChunks)) {
  5997. return chunk;
  5998. }
  5999. }
  6000. // Wrap around to beginning
  6001. for (chunk = 0; chunk < beginChunk; ++chunk) {
  6002. if (!(chunk in this.loadedChunks)) {
  6003. return chunk;
  6004. }
  6005. }
  6006. return null;
  6007. },
  6008. hasChunk: function ChunkedStream_hasChunk(chunk) {
  6009. return chunk in this.loadedChunks;
  6010. },
  6011. get length() {
  6012. return this.end - this.start;
  6013. },
  6014. get isEmpty() {
  6015. return this.length === 0;
  6016. },
  6017. getByte: function ChunkedStream_getByte() {
  6018. var pos = this.pos;
  6019. if (pos >= this.end) {
  6020. return -1;
  6021. }
  6022. this.ensureByte(pos);
  6023. return this.bytes[this.pos++];
  6024. },
  6025. getUint16: function ChunkedStream_getUint16() {
  6026. var b0 = this.getByte();
  6027. var b1 = this.getByte();
  6028. return (b0 << 8) + b1;
  6029. },
  6030. getInt32: function ChunkedStream_getInt32() {
  6031. var b0 = this.getByte();
  6032. var b1 = this.getByte();
  6033. var b2 = this.getByte();
  6034. var b3 = this.getByte();
  6035. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  6036. },
  6037. // returns subarray of original buffer
  6038. // should only be read
  6039. getBytes: function ChunkedStream_getBytes(length) {
  6040. var bytes = this.bytes;
  6041. var pos = this.pos;
  6042. var strEnd = this.end;
  6043. if (!length) {
  6044. this.ensureRange(pos, strEnd);
  6045. return bytes.subarray(pos, strEnd);
  6046. }
  6047. var end = pos + length;
  6048. if (end > strEnd) {
  6049. end = strEnd;
  6050. }
  6051. this.ensureRange(pos, end);
  6052. this.pos = end;
  6053. return bytes.subarray(pos, end);
  6054. },
  6055. peekBytes: function ChunkedStream_peekBytes(length) {
  6056. var bytes = this.getBytes(length);
  6057. this.pos -= bytes.length;
  6058. return bytes;
  6059. },
  6060. getByteRange: function ChunkedStream_getBytes(begin, end) {
  6061. this.ensureRange(begin, end);
  6062. return this.bytes.subarray(begin, end);
  6063. },
  6064. skip: function ChunkedStream_skip(n) {
  6065. if (!n) {
  6066. n = 1;
  6067. }
  6068. this.pos += n;
  6069. },
  6070. reset: function ChunkedStream_reset() {
  6071. this.pos = this.start;
  6072. },
  6073. moveStart: function ChunkedStream_moveStart() {
  6074. this.start = this.pos;
  6075. },
  6076. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  6077. this.ensureRange(start, start + length);
  6078. function ChunkedStreamSubstream() {}
  6079. ChunkedStreamSubstream.prototype = Object.create(this);
  6080. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  6081. var chunkSize = this.chunkSize;
  6082. var beginChunk = Math.floor(this.start / chunkSize);
  6083. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  6084. var missingChunks = [];
  6085. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6086. if (!(chunk in this.loadedChunks)) {
  6087. missingChunks.push(chunk);
  6088. }
  6089. }
  6090. return missingChunks;
  6091. };
  6092. var subStream = new ChunkedStreamSubstream();
  6093. subStream.pos = subStream.start = start;
  6094. subStream.end = start + length || this.end;
  6095. subStream.dict = dict;
  6096. return subStream;
  6097. },
  6098. isStream: true
  6099. };
  6100. return ChunkedStream;
  6101. })();
  6102. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  6103. function ChunkedStreamManager(length, chunkSize, url, args) {
  6104. this.stream = new ChunkedStream(length, chunkSize, this);
  6105. this.length = length;
  6106. this.chunkSize = chunkSize;
  6107. this.url = url;
  6108. this.disableAutoFetch = args.disableAutoFetch;
  6109. var msgHandler = this.msgHandler = args.msgHandler;
  6110. if (args.chunkedViewerLoading) {
  6111. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  6112. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  6113. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6114. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  6115. };
  6116. } else {
  6117. var getXhr = function getXhr() {
  6118. return new XMLHttpRequest();
  6119. };
  6120. this.networkManager = new NetworkManager(this.url, {
  6121. getXhr: getXhr,
  6122. httpHeaders: args.httpHeaders,
  6123. withCredentials: args.withCredentials
  6124. });
  6125. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6126. this.networkManager.requestRange(begin, end, {
  6127. onDone: this.onReceiveData.bind(this),
  6128. onProgress: this.onProgress.bind(this)
  6129. });
  6130. };
  6131. }
  6132. this.currRequestId = 0;
  6133. this.chunksNeededByRequest = {};
  6134. this.requestsByChunk = {};
  6135. this.callbacksByRequest = {};
  6136. this._loadedStreamCapability = createPromiseCapability();
  6137. if (args.initialData) {
  6138. this.setInitialData(args.initialData);
  6139. }
  6140. }
  6141. ChunkedStreamManager.prototype = {
  6142. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  6143. this.stream.onReceiveInitialData(data);
  6144. if (this.stream.allChunksLoaded()) {
  6145. this._loadedStreamCapability.resolve(this.stream);
  6146. } else if (this.msgHandler) {
  6147. this.msgHandler.send('DocProgress', {
  6148. loaded: data.length,
  6149. total: this.length
  6150. });
  6151. }
  6152. },
  6153. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  6154. return this._loadedStreamCapability.promise;
  6155. },
  6156. // Get all the chunks that are not yet loaded and groups them into
  6157. // contiguous ranges to load in as few requests as possible
  6158. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  6159. var missingChunks = this.stream.getMissingChunks();
  6160. this.requestChunks(missingChunks);
  6161. return this._loadedStreamCapability.promise;
  6162. },
  6163. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  6164. callback) {
  6165. var requestId = this.currRequestId++;
  6166. var chunksNeeded;
  6167. var i, ii;
  6168. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  6169. for (i = 0, ii = chunks.length; i < ii; i++) {
  6170. if (!this.stream.hasChunk(chunks[i])) {
  6171. chunksNeeded[chunks[i]] = true;
  6172. }
  6173. }
  6174. if (isEmptyObj(chunksNeeded)) {
  6175. if (callback) {
  6176. callback();
  6177. }
  6178. return;
  6179. }
  6180. this.callbacksByRequest[requestId] = callback;
  6181. var chunksToRequest = [];
  6182. for (var chunk in chunksNeeded) {
  6183. chunk = chunk | 0;
  6184. if (!(chunk in this.requestsByChunk)) {
  6185. this.requestsByChunk[chunk] = [];
  6186. chunksToRequest.push(chunk);
  6187. }
  6188. this.requestsByChunk[chunk].push(requestId);
  6189. }
  6190. if (!chunksToRequest.length) {
  6191. return;
  6192. }
  6193. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  6194. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  6195. var groupedChunk = groupedChunksToRequest[i];
  6196. var begin = groupedChunk.beginChunk * this.chunkSize;
  6197. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  6198. this.sendRequest(begin, end);
  6199. }
  6200. },
  6201. getStream: function ChunkedStreamManager_getStream() {
  6202. return this.stream;
  6203. },
  6204. // Loads any chunks in the requested range that are not yet loaded
  6205. requestRange: function ChunkedStreamManager_requestRange(
  6206. begin, end, callback) {
  6207. end = Math.min(end, this.length);
  6208. var beginChunk = this.getBeginChunk(begin);
  6209. var endChunk = this.getEndChunk(end);
  6210. var chunks = [];
  6211. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6212. chunks.push(chunk);
  6213. }
  6214. this.requestChunks(chunks, callback);
  6215. },
  6216. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  6217. callback) {
  6218. ranges = ranges || [];
  6219. var chunksToRequest = [];
  6220. for (var i = 0; i < ranges.length; i++) {
  6221. var beginChunk = this.getBeginChunk(ranges[i].begin);
  6222. var endChunk = this.getEndChunk(ranges[i].end);
  6223. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6224. if (chunksToRequest.indexOf(chunk) < 0) {
  6225. chunksToRequest.push(chunk);
  6226. }
  6227. }
  6228. }
  6229. chunksToRequest.sort(function(a, b) { return a - b; });
  6230. this.requestChunks(chunksToRequest, callback);
  6231. },
  6232. // Groups a sorted array of chunks into as few continguous larger
  6233. // chunks as possible
  6234. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  6235. var groupedChunks = [];
  6236. var beginChunk = -1;
  6237. var prevChunk = -1;
  6238. for (var i = 0; i < chunks.length; ++i) {
  6239. var chunk = chunks[i];
  6240. if (beginChunk < 0) {
  6241. beginChunk = chunk;
  6242. }
  6243. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  6244. groupedChunks.push({ beginChunk: beginChunk,
  6245. endChunk: prevChunk + 1 });
  6246. beginChunk = chunk;
  6247. }
  6248. if (i + 1 === chunks.length) {
  6249. groupedChunks.push({ beginChunk: beginChunk,
  6250. endChunk: chunk + 1 });
  6251. }
  6252. prevChunk = chunk;
  6253. }
  6254. return groupedChunks;
  6255. },
  6256. onProgress: function ChunkedStreamManager_onProgress(args) {
  6257. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  6258. args.loaded);
  6259. this.msgHandler.send('DocProgress', {
  6260. loaded: bytesLoaded,
  6261. total: this.length
  6262. });
  6263. },
  6264. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  6265. var chunk = args.chunk;
  6266. var begin = args.begin;
  6267. var end = begin + chunk.byteLength;
  6268. var beginChunk = this.getBeginChunk(begin);
  6269. var endChunk = this.getEndChunk(end);
  6270. this.stream.onReceiveData(begin, chunk);
  6271. if (this.stream.allChunksLoaded()) {
  6272. this._loadedStreamCapability.resolve(this.stream);
  6273. }
  6274. var loadedRequests = [];
  6275. var i, requestId;
  6276. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  6277. // The server might return more chunks than requested
  6278. var requestIds = this.requestsByChunk[chunk] || [];
  6279. delete this.requestsByChunk[chunk];
  6280. for (i = 0; i < requestIds.length; ++i) {
  6281. requestId = requestIds[i];
  6282. var chunksNeeded = this.chunksNeededByRequest[requestId];
  6283. if (chunk in chunksNeeded) {
  6284. delete chunksNeeded[chunk];
  6285. }
  6286. if (!isEmptyObj(chunksNeeded)) {
  6287. continue;
  6288. }
  6289. loadedRequests.push(requestId);
  6290. }
  6291. }
  6292. // If there are no pending requests, automatically fetch the next
  6293. // unfetched chunk of the PDF
  6294. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  6295. var nextEmptyChunk;
  6296. if (this.stream.numChunksLoaded === 1) {
  6297. // This is a special optimization so that after fetching the first
  6298. // chunk, rather than fetching the second chunk, we fetch the last
  6299. // chunk.
  6300. var lastChunk = this.stream.numChunks - 1;
  6301. if (!this.stream.hasChunk(lastChunk)) {
  6302. nextEmptyChunk = lastChunk;
  6303. }
  6304. } else {
  6305. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  6306. }
  6307. if (isInt(nextEmptyChunk)) {
  6308. this.requestChunks([nextEmptyChunk]);
  6309. }
  6310. }
  6311. for (i = 0; i < loadedRequests.length; ++i) {
  6312. requestId = loadedRequests[i];
  6313. var callback = this.callbacksByRequest[requestId];
  6314. delete this.callbacksByRequest[requestId];
  6315. if (callback) {
  6316. callback();
  6317. }
  6318. }
  6319. this.msgHandler.send('DocProgress', {
  6320. loaded: this.stream.numChunksLoaded * this.chunkSize,
  6321. total: this.length
  6322. });
  6323. },
  6324. onError: function ChunkedStreamManager_onError(err) {
  6325. this._loadedStreamCapability.reject(err);
  6326. },
  6327. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  6328. var chunk = Math.floor(begin / this.chunkSize);
  6329. return chunk;
  6330. },
  6331. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  6332. if (end % this.chunkSize === 0) {
  6333. return end / this.chunkSize;
  6334. }
  6335. // 0 -> 0
  6336. // 1 -> 1
  6337. // 99 -> 1
  6338. // 100 -> 1
  6339. // 101 -> 2
  6340. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  6341. return chunk;
  6342. }
  6343. };
  6344. return ChunkedStreamManager;
  6345. })();
  6346. // The maximum number of bytes fetched per range request
  6347. var RANGE_CHUNK_SIZE = 65536;
  6348. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  6349. var BasePdfManager = (function BasePdfManagerClosure() {
  6350. function BasePdfManager() {
  6351. throw new Error('Cannot initialize BaseManagerManager');
  6352. }
  6353. BasePdfManager.prototype = {
  6354. onLoadedStream: function BasePdfManager_onLoadedStream() {
  6355. throw new NotImplementedException();
  6356. },
  6357. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  6358. return this.ensure(this.pdfDocument, prop, args);
  6359. },
  6360. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  6361. return this.ensure(this.pdfDocument.xref, prop, args);
  6362. },
  6363. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  6364. return this.ensure(this.pdfDocument.catalog, prop, args);
  6365. },
  6366. getPage: function BasePdfManager_pagePage(pageIndex) {
  6367. return this.pdfDocument.getPage(pageIndex);
  6368. },
  6369. cleanup: function BasePdfManager_cleanup() {
  6370. return this.pdfDocument.cleanup();
  6371. },
  6372. ensure: function BasePdfManager_ensure(obj, prop, args) {
  6373. return new NotImplementedException();
  6374. },
  6375. requestRange: function BasePdfManager_ensure(begin, end) {
  6376. return new NotImplementedException();
  6377. },
  6378. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  6379. return new NotImplementedException();
  6380. },
  6381. updatePassword: function BasePdfManager_updatePassword(password) {
  6382. this.pdfDocument.xref.password = this.password = password;
  6383. if (this._passwordChangedCapability) {
  6384. this._passwordChangedCapability.resolve();
  6385. }
  6386. },
  6387. passwordChanged: function BasePdfManager_passwordChanged() {
  6388. this._passwordChangedCapability = createPromiseCapability();
  6389. return this._passwordChangedCapability.promise;
  6390. },
  6391. terminate: function BasePdfManager_terminate() {
  6392. return new NotImplementedException();
  6393. }
  6394. };
  6395. return BasePdfManager;
  6396. })();
  6397. var LocalPdfManager = (function LocalPdfManagerClosure() {
  6398. function LocalPdfManager(data, password) {
  6399. var stream = new Stream(data);
  6400. this.pdfDocument = new PDFDocument(this, stream, password);
  6401. this._loadedStreamCapability = createPromiseCapability();
  6402. this._loadedStreamCapability.resolve(stream);
  6403. }
  6404. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6405. LocalPdfManager.prototype.constructor = LocalPdfManager;
  6406. LocalPdfManager.prototype.ensure =
  6407. function LocalPdfManager_ensure(obj, prop, args) {
  6408. return new Promise(function (resolve, reject) {
  6409. try {
  6410. var value = obj[prop];
  6411. var result;
  6412. if (typeof value === 'function') {
  6413. result = value.apply(obj, args);
  6414. } else {
  6415. result = value;
  6416. }
  6417. resolve(result);
  6418. } catch (e) {
  6419. reject(e);
  6420. }
  6421. });
  6422. };
  6423. LocalPdfManager.prototype.requestRange =
  6424. function LocalPdfManager_requestRange(begin, end) {
  6425. return Promise.resolve();
  6426. };
  6427. LocalPdfManager.prototype.requestLoadedStream =
  6428. function LocalPdfManager_requestLoadedStream() {
  6429. };
  6430. LocalPdfManager.prototype.onLoadedStream =
  6431. function LocalPdfManager_getLoadedStream() {
  6432. return this._loadedStreamCapability.promise;
  6433. };
  6434. LocalPdfManager.prototype.terminate =
  6435. function LocalPdfManager_terminate() {
  6436. return;
  6437. };
  6438. return LocalPdfManager;
  6439. })();
  6440. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  6441. function NetworkPdfManager(args, msgHandler) {
  6442. this.msgHandler = msgHandler;
  6443. var params = {
  6444. msgHandler: msgHandler,
  6445. httpHeaders: args.httpHeaders,
  6446. withCredentials: args.withCredentials,
  6447. chunkedViewerLoading: args.chunkedViewerLoading,
  6448. disableAutoFetch: args.disableAutoFetch,
  6449. initialData: args.initialData
  6450. };
  6451. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  6452. args.url, params);
  6453. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  6454. args.password);
  6455. }
  6456. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6457. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  6458. NetworkPdfManager.prototype.ensure =
  6459. function NetworkPdfManager_ensure(obj, prop, args) {
  6460. var pdfManager = this;
  6461. return new Promise(function (resolve, reject) {
  6462. function ensureHelper() {
  6463. try {
  6464. var result;
  6465. var value = obj[prop];
  6466. if (typeof value === 'function') {
  6467. result = value.apply(obj, args);
  6468. } else {
  6469. result = value;
  6470. }
  6471. resolve(result);
  6472. } catch(e) {
  6473. if (!(e instanceof MissingDataException)) {
  6474. reject(e);
  6475. return;
  6476. }
  6477. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  6478. }
  6479. }
  6480. ensureHelper();
  6481. });
  6482. };
  6483. NetworkPdfManager.prototype.requestRange =
  6484. function NetworkPdfManager_requestRange(begin, end) {
  6485. return new Promise(function (resolve) {
  6486. this.streamManager.requestRange(begin, end, function() {
  6487. resolve();
  6488. });
  6489. }.bind(this));
  6490. };
  6491. NetworkPdfManager.prototype.requestLoadedStream =
  6492. function NetworkPdfManager_requestLoadedStream() {
  6493. this.streamManager.requestAllChunks();
  6494. };
  6495. NetworkPdfManager.prototype.onLoadedStream =
  6496. function NetworkPdfManager_getLoadedStream() {
  6497. return this.streamManager.onLoadedStream();
  6498. };
  6499. NetworkPdfManager.prototype.terminate =
  6500. function NetworkPdfManager_terminate() {
  6501. this.streamManager.networkManager.abortAllRequests();
  6502. };
  6503. return NetworkPdfManager;
  6504. })();
  6505. var Page = (function PageClosure() {
  6506. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  6507. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  6508. this.pdfManager = pdfManager;
  6509. this.pageIndex = pageIndex;
  6510. this.pageDict = pageDict;
  6511. this.xref = xref;
  6512. this.ref = ref;
  6513. this.fontCache = fontCache;
  6514. this.idCounters = {
  6515. obj: 0
  6516. };
  6517. this.resourcesPromise = null;
  6518. }
  6519. Page.prototype = {
  6520. getPageProp: function Page_getPageProp(key) {
  6521. return this.pageDict.get(key);
  6522. },
  6523. getInheritedPageProp: function Page_inheritPageProp(key) {
  6524. var dict = this.pageDict;
  6525. var value = dict.get(key);
  6526. while (value === undefined) {
  6527. dict = dict.get('Parent');
  6528. if (!dict) {
  6529. break;
  6530. }
  6531. value = dict.get(key);
  6532. }
  6533. return value;
  6534. },
  6535. get content() {
  6536. return this.getPageProp('Contents');
  6537. },
  6538. get resources() {
  6539. var value = this.getInheritedPageProp('Resources');
  6540. // For robustness: The spec states that a \Resources entry has to be
  6541. // present, but can be empty. Some document omit it still. In this case
  6542. // return an empty dictionary:
  6543. if (value === undefined) {
  6544. value = Dict.empty;
  6545. }
  6546. return shadow(this, 'resources', value);
  6547. },
  6548. get mediaBox() {
  6549. var obj = this.getInheritedPageProp('MediaBox');
  6550. // Reset invalid media box to letter size.
  6551. if (!isArray(obj) || obj.length !== 4) {
  6552. obj = LETTER_SIZE_MEDIABOX;
  6553. }
  6554. return shadow(this, 'mediaBox', obj);
  6555. },
  6556. get view() {
  6557. var mediaBox = this.mediaBox;
  6558. var cropBox = this.getInheritedPageProp('CropBox');
  6559. if (!isArray(cropBox) || cropBox.length !== 4) {
  6560. return shadow(this, 'view', mediaBox);
  6561. }
  6562. // From the spec, 6th ed., p.963:
  6563. // "The crop, bleed, trim, and art boxes should not ordinarily
  6564. // extend beyond the boundaries of the media box. If they do, they are
  6565. // effectively reduced to their intersection with the media box."
  6566. cropBox = Util.intersect(cropBox, mediaBox);
  6567. if (!cropBox) {
  6568. return shadow(this, 'view', mediaBox);
  6569. }
  6570. return shadow(this, 'view', cropBox);
  6571. },
  6572. get annotationRefs() {
  6573. return shadow(this, 'annotationRefs',
  6574. this.getInheritedPageProp('Annots'));
  6575. },
  6576. get rotate() {
  6577. var rotate = this.getInheritedPageProp('Rotate') || 0;
  6578. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  6579. if (rotate % 90 !== 0) {
  6580. rotate = 0;
  6581. } else if (rotate >= 360) {
  6582. rotate = rotate % 360;
  6583. } else if (rotate < 0) {
  6584. // The spec doesn't cover negatives, assume its counterclockwise
  6585. // rotation. The following is the other implementation of modulo.
  6586. rotate = ((rotate % 360) + 360) % 360;
  6587. }
  6588. return shadow(this, 'rotate', rotate);
  6589. },
  6590. getContentStream: function Page_getContentStream() {
  6591. var content = this.content;
  6592. var stream;
  6593. if (isArray(content)) {
  6594. // fetching items
  6595. var xref = this.xref;
  6596. var i, n = content.length;
  6597. var streams = [];
  6598. for (i = 0; i < n; ++i) {
  6599. streams.push(xref.fetchIfRef(content[i]));
  6600. }
  6601. stream = new StreamsSequenceStream(streams);
  6602. } else if (isStream(content)) {
  6603. stream = content;
  6604. } else {
  6605. // replacing non-existent page content with empty one
  6606. stream = new NullStream();
  6607. }
  6608. return stream;
  6609. },
  6610. loadResources: function Page_loadResources(keys) {
  6611. if (!this.resourcesPromise) {
  6612. // TODO: add async getInheritedPageProp and remove this.
  6613. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  6614. }
  6615. return this.resourcesPromise.then(function resourceSuccess() {
  6616. var objectLoader = new ObjectLoader(this.resources.map,
  6617. keys,
  6618. this.xref);
  6619. return objectLoader.load();
  6620. }.bind(this));
  6621. },
  6622. getOperatorList: function Page_getOperatorList(handler, intent) {
  6623. var self = this;
  6624. var pdfManager = this.pdfManager;
  6625. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6626. []);
  6627. var resourcesPromise = this.loadResources([
  6628. 'ExtGState',
  6629. 'ColorSpace',
  6630. 'Pattern',
  6631. 'Shading',
  6632. 'XObject',
  6633. 'Font'
  6634. // ProcSet
  6635. // Properties
  6636. ]);
  6637. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  6638. handler, this.pageIndex,
  6639. 'p' + this.pageIndex + '_',
  6640. this.idCounters,
  6641. this.fontCache);
  6642. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  6643. var pageListPromise = dataPromises.then(function(data) {
  6644. var contentStream = data[0];
  6645. var opList = new OperatorList(intent, handler, self.pageIndex);
  6646. handler.send('StartRenderPage', {
  6647. transparency: partialEvaluator.hasBlendModes(self.resources),
  6648. pageIndex: self.pageIndex,
  6649. intent: intent
  6650. });
  6651. return partialEvaluator.getOperatorList(contentStream, self.resources,
  6652. opList).then(function () {
  6653. return opList;
  6654. });
  6655. });
  6656. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  6657. return Promise.all([pageListPromise, annotationsPromise]).then(
  6658. function(datas) {
  6659. var pageOpList = datas[0];
  6660. var annotations = datas[1];
  6661. if (annotations.length === 0) {
  6662. pageOpList.flush(true);
  6663. return pageOpList;
  6664. }
  6665. var annotationsReadyPromise = Annotation.appendToOperatorList(
  6666. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  6667. return annotationsReadyPromise.then(function () {
  6668. pageOpList.flush(true);
  6669. return pageOpList;
  6670. });
  6671. });
  6672. },
  6673. extractTextContent: function Page_extractTextContent() {
  6674. var handler = {
  6675. on: function nullHandlerOn() {},
  6676. send: function nullHandlerSend() {}
  6677. };
  6678. var self = this;
  6679. var pdfManager = this.pdfManager;
  6680. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6681. []);
  6682. var resourcesPromise = this.loadResources([
  6683. 'ExtGState',
  6684. 'XObject',
  6685. 'Font'
  6686. ]);
  6687. var dataPromises = Promise.all([contentStreamPromise,
  6688. resourcesPromise]);
  6689. return dataPromises.then(function(data) {
  6690. var contentStream = data[0];
  6691. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  6692. handler, self.pageIndex,
  6693. 'p' + self.pageIndex + '_',
  6694. self.idCounters,
  6695. self.fontCache);
  6696. return partialEvaluator.getTextContent(contentStream,
  6697. self.resources);
  6698. });
  6699. },
  6700. getAnnotationsData: function Page_getAnnotationsData() {
  6701. var annotations = this.annotations;
  6702. var annotationsData = [];
  6703. for (var i = 0, n = annotations.length; i < n; ++i) {
  6704. annotationsData.push(annotations[i].getData());
  6705. }
  6706. return annotationsData;
  6707. },
  6708. get annotations() {
  6709. var annotations = [];
  6710. var annotationRefs = (this.annotationRefs || []);
  6711. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  6712. var annotationRef = annotationRefs[i];
  6713. var annotation = Annotation.fromRef(this.xref, annotationRef);
  6714. if (annotation) {
  6715. annotations.push(annotation);
  6716. }
  6717. }
  6718. return shadow(this, 'annotations', annotations);
  6719. }
  6720. };
  6721. return Page;
  6722. })();
  6723. /**
  6724. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  6725. * `PDFDoc`, this one doesn't have any job management code.
  6726. * Right now there exists one PDFDocument on the main thread + one object
  6727. * for each worker. If there is no worker support enabled, there are two
  6728. * `PDFDocument` objects on the main thread created.
  6729. */
  6730. var PDFDocument = (function PDFDocumentClosure() {
  6731. function PDFDocument(pdfManager, arg, password) {
  6732. if (isStream(arg)) {
  6733. init.call(this, pdfManager, arg, password);
  6734. } else if (isArrayBuffer(arg)) {
  6735. init.call(this, pdfManager, new Stream(arg), password);
  6736. } else {
  6737. error('PDFDocument: Unknown argument type');
  6738. }
  6739. }
  6740. function init(pdfManager, stream, password) {
  6741. assert(stream.length > 0, 'stream must have data');
  6742. this.pdfManager = pdfManager;
  6743. this.stream = stream;
  6744. var xref = new XRef(this.stream, password, pdfManager);
  6745. this.xref = xref;
  6746. }
  6747. function find(stream, needle, limit, backwards) {
  6748. var pos = stream.pos;
  6749. var end = stream.end;
  6750. var strBuf = [];
  6751. if (pos + limit > end) {
  6752. limit = end - pos;
  6753. }
  6754. for (var n = 0; n < limit; ++n) {
  6755. strBuf.push(String.fromCharCode(stream.getByte()));
  6756. }
  6757. var str = strBuf.join('');
  6758. stream.pos = pos;
  6759. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  6760. if (index === -1) {
  6761. return false; /* not found */
  6762. }
  6763. stream.pos += index;
  6764. return true; /* found */
  6765. }
  6766. var DocumentInfoValidators = {
  6767. get entries() {
  6768. // Lazily build this since all the validation functions below are not
  6769. // defined until after this file loads.
  6770. return shadow(this, 'entries', {
  6771. Title: isString,
  6772. Author: isString,
  6773. Subject: isString,
  6774. Keywords: isString,
  6775. Creator: isString,
  6776. Producer: isString,
  6777. CreationDate: isString,
  6778. ModDate: isString,
  6779. Trapped: isName
  6780. });
  6781. }
  6782. };
  6783. PDFDocument.prototype = {
  6784. parse: function PDFDocument_parse(recoveryMode) {
  6785. this.setup(recoveryMode);
  6786. try {
  6787. // checking if AcroForm is present
  6788. this.acroForm = this.catalog.catDict.get('AcroForm');
  6789. if (this.acroForm) {
  6790. this.xfa = this.acroForm.get('XFA');
  6791. var fields = this.acroForm.get('Fields');
  6792. if ((!fields || !isArray(fields) || fields.length === 0) &&
  6793. !this.xfa) {
  6794. // no fields and no XFA -- not a form (?)
  6795. this.acroForm = null;
  6796. }
  6797. }
  6798. } catch (ex) {
  6799. info('Something wrong with AcroForm entry');
  6800. this.acroForm = null;
  6801. }
  6802. },
  6803. get linearization() {
  6804. var linearization = null;
  6805. if (this.stream.length) {
  6806. try {
  6807. linearization = Linearization.create(this.stream);
  6808. } catch (err) {
  6809. if (err instanceof MissingDataException) {
  6810. throw err;
  6811. }
  6812. info(err);
  6813. }
  6814. }
  6815. // shadow the prototype getter with a data property
  6816. return shadow(this, 'linearization', linearization);
  6817. },
  6818. get startXRef() {
  6819. var stream = this.stream;
  6820. var startXRef = 0;
  6821. var linearization = this.linearization;
  6822. if (linearization) {
  6823. // Find end of first obj.
  6824. stream.reset();
  6825. if (find(stream, 'endobj', 1024)) {
  6826. startXRef = stream.pos + 6;
  6827. }
  6828. } else {
  6829. // Find startxref by jumping backward from the end of the file.
  6830. var step = 1024;
  6831. var found = false, pos = stream.end;
  6832. while (!found && pos > 0) {
  6833. pos -= step - 'startxref'.length;
  6834. if (pos < 0) {
  6835. pos = 0;
  6836. }
  6837. stream.pos = pos;
  6838. found = find(stream, 'startxref', step, true);
  6839. }
  6840. if (found) {
  6841. stream.skip(9);
  6842. var ch;
  6843. do {
  6844. ch = stream.getByte();
  6845. } while (Lexer.isSpace(ch));
  6846. var str = '';
  6847. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  6848. str += String.fromCharCode(ch);
  6849. ch = stream.getByte();
  6850. }
  6851. startXRef = parseInt(str, 10);
  6852. if (isNaN(startXRef)) {
  6853. startXRef = 0;
  6854. }
  6855. }
  6856. }
  6857. // shadow the prototype getter with a data property
  6858. return shadow(this, 'startXRef', startXRef);
  6859. },
  6860. get mainXRefEntriesOffset() {
  6861. var mainXRefEntriesOffset = 0;
  6862. var linearization = this.linearization;
  6863. if (linearization) {
  6864. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  6865. }
  6866. // shadow the prototype getter with a data property
  6867. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  6868. },
  6869. // Find the header, remove leading garbage and setup the stream
  6870. // starting from the header.
  6871. checkHeader: function PDFDocument_checkHeader() {
  6872. var stream = this.stream;
  6873. stream.reset();
  6874. if (find(stream, '%PDF-', 1024)) {
  6875. // Found the header, trim off any garbage before it.
  6876. stream.moveStart();
  6877. // Reading file format version
  6878. var MAX_VERSION_LENGTH = 12;
  6879. var version = '', ch;
  6880. while ((ch = stream.getByte()) > 0x20) { // SPACE
  6881. if (version.length >= MAX_VERSION_LENGTH) {
  6882. break;
  6883. }
  6884. version += String.fromCharCode(ch);
  6885. }
  6886. // removing "%PDF-"-prefix
  6887. this.pdfFormatVersion = version.substring(5);
  6888. return;
  6889. }
  6890. // May not be a PDF file, continue anyway.
  6891. },
  6892. parseStartXRef: function PDFDocument_parseStartXRef() {
  6893. var startXRef = this.startXRef;
  6894. this.xref.setStartXRef(startXRef);
  6895. },
  6896. setup: function PDFDocument_setup(recoveryMode) {
  6897. this.xref.parse(recoveryMode);
  6898. this.catalog = new Catalog(this.pdfManager, this.xref);
  6899. },
  6900. get numPages() {
  6901. var linearization = this.linearization;
  6902. var num = linearization ? linearization.numPages : this.catalog.numPages;
  6903. // shadow the prototype getter
  6904. return shadow(this, 'numPages', num);
  6905. },
  6906. get documentInfo() {
  6907. var docInfo = {
  6908. PDFFormatVersion: this.pdfFormatVersion,
  6909. IsAcroFormPresent: !!this.acroForm,
  6910. IsXFAPresent: !!this.xfa
  6911. };
  6912. var infoDict;
  6913. try {
  6914. infoDict = this.xref.trailer.get('Info');
  6915. } catch (err) {
  6916. info('The document information dictionary is invalid.');
  6917. }
  6918. if (infoDict) {
  6919. var validEntries = DocumentInfoValidators.entries;
  6920. // Only fill the document info with valid entries from the spec.
  6921. for (var key in validEntries) {
  6922. if (infoDict.has(key)) {
  6923. var value = infoDict.get(key);
  6924. // Make sure the value conforms to the spec.
  6925. if (validEntries[key](value)) {
  6926. docInfo[key] = (typeof value !== 'string' ?
  6927. value : stringToPDFString(value));
  6928. } else {
  6929. info('Bad value in document info for "' + key + '"');
  6930. }
  6931. }
  6932. }
  6933. }
  6934. return shadow(this, 'documentInfo', docInfo);
  6935. },
  6936. get fingerprint() {
  6937. var xref = this.xref, hash, fileID = '';
  6938. if (xref.trailer.has('ID')) {
  6939. hash = stringToBytes(xref.trailer.get('ID')[0]);
  6940. } else {
  6941. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  6942. }
  6943. for (var i = 0, n = hash.length; i < n; i++) {
  6944. fileID += hash[i].toString(16);
  6945. }
  6946. return shadow(this, 'fingerprint', fileID);
  6947. },
  6948. getPage: function PDFDocument_getPage(pageIndex) {
  6949. return this.catalog.getPage(pageIndex);
  6950. },
  6951. cleanup: function PDFDocument_cleanup() {
  6952. return this.catalog.cleanup();
  6953. }
  6954. };
  6955. return PDFDocument;
  6956. })();
  6957. var Name = (function NameClosure() {
  6958. function Name(name) {
  6959. this.name = name;
  6960. }
  6961. Name.prototype = {};
  6962. var nameCache = {};
  6963. Name.get = function Name_get(name) {
  6964. var nameValue = nameCache[name];
  6965. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  6966. };
  6967. return Name;
  6968. })();
  6969. var Cmd = (function CmdClosure() {
  6970. function Cmd(cmd) {
  6971. this.cmd = cmd;
  6972. }
  6973. Cmd.prototype = {};
  6974. var cmdCache = {};
  6975. Cmd.get = function Cmd_get(cmd) {
  6976. var cmdValue = cmdCache[cmd];
  6977. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  6978. };
  6979. return Cmd;
  6980. })();
  6981. var Dict = (function DictClosure() {
  6982. var nonSerializable = function nonSerializableClosure() {
  6983. return nonSerializable; // creating closure on some variable
  6984. };
  6985. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  6986. 'Background': true,
  6987. 'ExtGState': true,
  6988. 'Halftone': true,
  6989. 'Layout': true,
  6990. 'Mask': true,
  6991. 'Pagination': true,
  6992. 'Printing': true
  6993. };
  6994. function isRecursionAllowedFor(dict) {
  6995. if (!isName(dict.Type)) {
  6996. return true;
  6997. }
  6998. var dictType = dict.Type.name;
  6999. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  7000. }
  7001. // xref is optional
  7002. function Dict(xref) {
  7003. // Map should only be used internally, use functions below to access.
  7004. this.map = Object.create(null);
  7005. this.xref = xref;
  7006. this.objId = null;
  7007. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  7008. }
  7009. Dict.prototype = {
  7010. assignXref: function Dict_assignXref(newXref) {
  7011. this.xref = newXref;
  7012. },
  7013. // automatically dereferences Ref objects
  7014. get: function Dict_get(key1, key2, key3) {
  7015. var value;
  7016. var xref = this.xref;
  7017. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7018. typeof key2 === 'undefined') {
  7019. return xref ? xref.fetchIfRef(value) : value;
  7020. }
  7021. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7022. typeof key3 === 'undefined') {
  7023. return xref ? xref.fetchIfRef(value) : value;
  7024. }
  7025. value = this.map[key3] || null;
  7026. return xref ? xref.fetchIfRef(value) : value;
  7027. },
  7028. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  7029. getAsync: function Dict_getAsync(key1, key2, key3) {
  7030. var value;
  7031. var xref = this.xref;
  7032. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7033. typeof key2 === 'undefined') {
  7034. if (xref) {
  7035. return xref.fetchIfRefAsync(value);
  7036. }
  7037. return Promise.resolve(value);
  7038. }
  7039. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7040. typeof key3 === 'undefined') {
  7041. if (xref) {
  7042. return xref.fetchIfRefAsync(value);
  7043. }
  7044. return Promise.resolve(value);
  7045. }
  7046. value = this.map[key3] || null;
  7047. if (xref) {
  7048. return xref.fetchIfRefAsync(value);
  7049. }
  7050. return Promise.resolve(value);
  7051. },
  7052. // no dereferencing
  7053. getRaw: function Dict_getRaw(key) {
  7054. return this.map[key];
  7055. },
  7056. // creates new map and dereferences all Refs
  7057. getAll: function Dict_getAll() {
  7058. var all = Object.create(null);
  7059. var queue = null;
  7060. var key, obj;
  7061. for (key in this.map) {
  7062. obj = this.get(key);
  7063. if (obj instanceof Dict) {
  7064. if (isRecursionAllowedFor(obj)) {
  7065. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  7066. } else {
  7067. all[key] = this.getRaw(key);
  7068. }
  7069. } else {
  7070. all[key] = obj;
  7071. }
  7072. }
  7073. if (!queue) {
  7074. return all;
  7075. }
  7076. // trying to take cyclic references into the account
  7077. var processed = Object.create(null);
  7078. while (queue.length > 0) {
  7079. var item = queue.shift();
  7080. var itemObj = item.obj;
  7081. var objId = itemObj.objId;
  7082. if (objId && objId in processed) {
  7083. item.target[item.key] = processed[objId];
  7084. continue;
  7085. }
  7086. var dereferenced = Object.create(null);
  7087. for (key in itemObj.map) {
  7088. obj = itemObj.get(key);
  7089. if (obj instanceof Dict) {
  7090. if (isRecursionAllowedFor(obj)) {
  7091. queue.push({target: dereferenced, key: key, obj: obj});
  7092. } else {
  7093. dereferenced[key] = itemObj.getRaw(key);
  7094. }
  7095. } else {
  7096. dereferenced[key] = obj;
  7097. }
  7098. }
  7099. if (objId) {
  7100. processed[objId] = dereferenced;
  7101. }
  7102. item.target[item.key] = dereferenced;
  7103. }
  7104. return all;
  7105. },
  7106. set: function Dict_set(key, value) {
  7107. this.map[key] = value;
  7108. },
  7109. has: function Dict_has(key) {
  7110. return key in this.map;
  7111. },
  7112. forEach: function Dict_forEach(callback) {
  7113. for (var key in this.map) {
  7114. callback(key, this.get(key));
  7115. }
  7116. }
  7117. };
  7118. Dict.empty = new Dict(null);
  7119. return Dict;
  7120. })();
  7121. var Ref = (function RefClosure() {
  7122. function Ref(num, gen) {
  7123. this.num = num;
  7124. this.gen = gen;
  7125. }
  7126. Ref.prototype = {
  7127. toString: function Ref_toString() {
  7128. // This function is hot, so we make the string as compact as possible.
  7129. // |this.gen| is almost always zero, so we treat that case specially.
  7130. var str = this.num + 'R';
  7131. if (this.gen !== 0) {
  7132. str += this.gen;
  7133. }
  7134. return str;
  7135. }
  7136. };
  7137. return Ref;
  7138. })();
  7139. // The reference is identified by number and generation.
  7140. // This structure stores only one instance of the reference.
  7141. var RefSet = (function RefSetClosure() {
  7142. function RefSet() {
  7143. this.dict = {};
  7144. }
  7145. RefSet.prototype = {
  7146. has: function RefSet_has(ref) {
  7147. return ref.toString() in this.dict;
  7148. },
  7149. put: function RefSet_put(ref) {
  7150. this.dict[ref.toString()] = true;
  7151. },
  7152. remove: function RefSet_remove(ref) {
  7153. delete this.dict[ref.toString()];
  7154. }
  7155. };
  7156. return RefSet;
  7157. })();
  7158. var RefSetCache = (function RefSetCacheClosure() {
  7159. function RefSetCache() {
  7160. this.dict = Object.create(null);
  7161. }
  7162. RefSetCache.prototype = {
  7163. get: function RefSetCache_get(ref) {
  7164. return this.dict[ref.toString()];
  7165. },
  7166. has: function RefSetCache_has(ref) {
  7167. return ref.toString() in this.dict;
  7168. },
  7169. put: function RefSetCache_put(ref, obj) {
  7170. this.dict[ref.toString()] = obj;
  7171. },
  7172. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  7173. this.dict[ref.toString()] = this.get(aliasRef);
  7174. },
  7175. forEach: function RefSetCache_forEach(fn, thisArg) {
  7176. for (var i in this.dict) {
  7177. fn.call(thisArg, this.dict[i]);
  7178. }
  7179. },
  7180. clear: function RefSetCache_clear() {
  7181. this.dict = Object.create(null);
  7182. }
  7183. };
  7184. return RefSetCache;
  7185. })();
  7186. var Catalog = (function CatalogClosure() {
  7187. function Catalog(pdfManager, xref) {
  7188. this.pdfManager = pdfManager;
  7189. this.xref = xref;
  7190. this.catDict = xref.getCatalogObj();
  7191. this.fontCache = new RefSetCache();
  7192. assert(isDict(this.catDict),
  7193. 'catalog object is not a dictionary');
  7194. this.pagePromises = [];
  7195. }
  7196. Catalog.prototype = {
  7197. get metadata() {
  7198. var streamRef = this.catDict.getRaw('Metadata');
  7199. if (!isRef(streamRef)) {
  7200. return shadow(this, 'metadata', null);
  7201. }
  7202. var encryptMetadata = (!this.xref.encrypt ? false :
  7203. this.xref.encrypt.encryptMetadata);
  7204. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  7205. var metadata;
  7206. if (stream && isDict(stream.dict)) {
  7207. var type = stream.dict.get('Type');
  7208. var subtype = stream.dict.get('Subtype');
  7209. if (isName(type) && isName(subtype) &&
  7210. type.name === 'Metadata' && subtype.name === 'XML') {
  7211. // XXX: This should examine the charset the XML document defines,
  7212. // however since there are currently no real means to decode
  7213. // arbitrary charsets, let's just hope that the author of the PDF
  7214. // was reasonable enough to stick with the XML default charset,
  7215. // which is UTF-8.
  7216. try {
  7217. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  7218. } catch (e) {
  7219. info('Skipping invalid metadata.');
  7220. }
  7221. }
  7222. }
  7223. return shadow(this, 'metadata', metadata);
  7224. },
  7225. get toplevelPagesDict() {
  7226. var pagesObj = this.catDict.get('Pages');
  7227. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  7228. // shadow the prototype getter
  7229. return shadow(this, 'toplevelPagesDict', pagesObj);
  7230. },
  7231. get documentOutline() {
  7232. var obj = null;
  7233. try {
  7234. obj = this.readDocumentOutline();
  7235. } catch (ex) {
  7236. if (ex instanceof MissingDataException) {
  7237. throw ex;
  7238. }
  7239. warn('Unable to read document outline');
  7240. }
  7241. return shadow(this, 'documentOutline', obj);
  7242. },
  7243. readDocumentOutline: function Catalog_readDocumentOutline() {
  7244. var xref = this.xref;
  7245. var obj = this.catDict.get('Outlines');
  7246. var root = { items: [] };
  7247. if (isDict(obj)) {
  7248. obj = obj.getRaw('First');
  7249. var processed = new RefSet();
  7250. if (isRef(obj)) {
  7251. var queue = [{obj: obj, parent: root}];
  7252. // to avoid recursion keeping track of the items
  7253. // in the processed dictionary
  7254. processed.put(obj);
  7255. while (queue.length > 0) {
  7256. var i = queue.shift();
  7257. var outlineDict = xref.fetchIfRef(i.obj);
  7258. if (outlineDict === null) {
  7259. continue;
  7260. }
  7261. if (!outlineDict.has('Title')) {
  7262. error('Invalid outline item');
  7263. }
  7264. var dest = outlineDict.get('A');
  7265. if (dest) {
  7266. dest = dest.get('D');
  7267. } else if (outlineDict.has('Dest')) {
  7268. dest = outlineDict.getRaw('Dest');
  7269. if (isName(dest)) {
  7270. dest = dest.name;
  7271. }
  7272. }
  7273. var title = outlineDict.get('Title');
  7274. var outlineItem = {
  7275. dest: dest,
  7276. title: stringToPDFString(title),
  7277. color: outlineDict.get('C') || [0, 0, 0],
  7278. count: outlineDict.get('Count'),
  7279. bold: !!(outlineDict.get('F') & 2),
  7280. italic: !!(outlineDict.get('F') & 1),
  7281. items: []
  7282. };
  7283. i.parent.items.push(outlineItem);
  7284. obj = outlineDict.getRaw('First');
  7285. if (isRef(obj) && !processed.has(obj)) {
  7286. queue.push({obj: obj, parent: outlineItem});
  7287. processed.put(obj);
  7288. }
  7289. obj = outlineDict.getRaw('Next');
  7290. if (isRef(obj) && !processed.has(obj)) {
  7291. queue.push({obj: obj, parent: i.parent});
  7292. processed.put(obj);
  7293. }
  7294. }
  7295. }
  7296. }
  7297. return (root.items.length > 0 ? root.items : null);
  7298. },
  7299. get numPages() {
  7300. var obj = this.toplevelPagesDict.get('Count');
  7301. assert(
  7302. isInt(obj),
  7303. 'page count in top level pages object is not an integer'
  7304. );
  7305. // shadow the prototype getter
  7306. return shadow(this, 'num', obj);
  7307. },
  7308. get destinations() {
  7309. function fetchDestination(dest) {
  7310. return isDict(dest) ? dest.get('D') : dest;
  7311. }
  7312. var xref = this.xref;
  7313. var dests = {}, nameTreeRef, nameDictionaryRef;
  7314. var obj = this.catDict.get('Names');
  7315. if (obj && obj.has('Dests')) {
  7316. nameTreeRef = obj.getRaw('Dests');
  7317. } else if (this.catDict.has('Dests')) {
  7318. nameDictionaryRef = this.catDict.get('Dests');
  7319. }
  7320. if (nameDictionaryRef) {
  7321. // reading simple destination dictionary
  7322. obj = nameDictionaryRef;
  7323. obj.forEach(function catalogForEach(key, value) {
  7324. if (!value) {
  7325. return;
  7326. }
  7327. dests[key] = fetchDestination(value);
  7328. });
  7329. }
  7330. if (nameTreeRef) {
  7331. var nameTree = new NameTree(nameTreeRef, xref);
  7332. var names = nameTree.getAll();
  7333. for (var name in names) {
  7334. if (!names.hasOwnProperty(name)) {
  7335. continue;
  7336. }
  7337. dests[name] = fetchDestination(names[name]);
  7338. }
  7339. }
  7340. return shadow(this, 'destinations', dests);
  7341. },
  7342. get attachments() {
  7343. var xref = this.xref;
  7344. var attachments = null, nameTreeRef;
  7345. var obj = this.catDict.get('Names');
  7346. if (obj) {
  7347. nameTreeRef = obj.getRaw('EmbeddedFiles');
  7348. }
  7349. if (nameTreeRef) {
  7350. var nameTree = new NameTree(nameTreeRef, xref);
  7351. var names = nameTree.getAll();
  7352. for (var name in names) {
  7353. if (!names.hasOwnProperty(name)) {
  7354. continue;
  7355. }
  7356. var fs = new FileSpec(names[name], xref);
  7357. if (!attachments) {
  7358. attachments = {};
  7359. }
  7360. attachments[stringToPDFString(name)] = fs.serializable;
  7361. }
  7362. }
  7363. return shadow(this, 'attachments', attachments);
  7364. },
  7365. get javaScript() {
  7366. var xref = this.xref;
  7367. var obj = this.catDict.get('Names');
  7368. var javaScript = [];
  7369. if (obj && obj.has('JavaScript')) {
  7370. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  7371. var names = nameTree.getAll();
  7372. for (var name in names) {
  7373. if (!names.hasOwnProperty(name)) {
  7374. continue;
  7375. }
  7376. // We don't really use the JavaScript right now. This code is
  7377. // defensive so we don't cause errors on document load.
  7378. var jsDict = names[name];
  7379. if (!isDict(jsDict)) {
  7380. continue;
  7381. }
  7382. var type = jsDict.get('S');
  7383. if (!isName(type) || type.name !== 'JavaScript') {
  7384. continue;
  7385. }
  7386. var js = jsDict.get('JS');
  7387. if (!isString(js) && !isStream(js)) {
  7388. continue;
  7389. }
  7390. if (isStream(js)) {
  7391. js = bytesToString(js.getBytes());
  7392. }
  7393. javaScript.push(stringToPDFString(js));
  7394. }
  7395. }
  7396. // Append OpenAction actions to javaScript array
  7397. var openactionDict = this.catDict.get('OpenAction');
  7398. if (isDict(openactionDict)) {
  7399. var objType = openactionDict.get('Type');
  7400. var actionType = openactionDict.get('S');
  7401. var action = openactionDict.get('N');
  7402. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  7403. isName(actionType) && actionType.name === 'Named' &&
  7404. isName(action) && action.name === 'Print');
  7405. if (isPrintAction) {
  7406. javaScript.push('print(true);');
  7407. }
  7408. }
  7409. return shadow(this, 'javaScript', javaScript);
  7410. },
  7411. cleanup: function Catalog_cleanup() {
  7412. var promises = [];
  7413. this.fontCache.forEach(function (promise) {
  7414. promises.push(promise);
  7415. });
  7416. return Promise.all(promises).then(function (translatedFonts) {
  7417. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  7418. var font = translatedFonts[i].dict;
  7419. delete font.translated;
  7420. }
  7421. this.fontCache.clear();
  7422. }.bind(this));
  7423. },
  7424. getPage: function Catalog_getPage(pageIndex) {
  7425. if (!(pageIndex in this.pagePromises)) {
  7426. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  7427. function (a) {
  7428. var dict = a[0];
  7429. var ref = a[1];
  7430. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  7431. this.fontCache);
  7432. }.bind(this)
  7433. );
  7434. }
  7435. return this.pagePromises[pageIndex];
  7436. },
  7437. getPageDict: function Catalog_getPageDict(pageIndex) {
  7438. var capability = createPromiseCapability();
  7439. var nodesToVisit = [this.catDict.getRaw('Pages')];
  7440. var currentPageIndex = 0;
  7441. var xref = this.xref;
  7442. function next() {
  7443. while (nodesToVisit.length) {
  7444. var currentNode = nodesToVisit.pop();
  7445. if (isRef(currentNode)) {
  7446. xref.fetchAsync(currentNode).then(function (obj) {
  7447. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  7448. if (pageIndex === currentPageIndex) {
  7449. capability.resolve([obj, currentNode]);
  7450. } else {
  7451. currentPageIndex++;
  7452. next();
  7453. }
  7454. return;
  7455. }
  7456. nodesToVisit.push(obj);
  7457. next();
  7458. }, capability.reject);
  7459. return;
  7460. }
  7461. // must be a child page dictionary
  7462. assert(
  7463. isDict(currentNode),
  7464. 'page dictionary kid reference points to wrong type of object'
  7465. );
  7466. var count = currentNode.get('Count');
  7467. // Skip nodes where the page can't be.
  7468. if (currentPageIndex + count <= pageIndex) {
  7469. currentPageIndex += count;
  7470. continue;
  7471. }
  7472. var kids = currentNode.get('Kids');
  7473. assert(isArray(kids), 'page dictionary kids object is not an array');
  7474. if (count === kids.length) {
  7475. // Nodes that don't have the page have been skipped and this is the
  7476. // bottom of the tree which means the page requested must be a
  7477. // descendant of this pages node. Ideally we would just resolve the
  7478. // promise with the page ref here, but there is the case where more
  7479. // pages nodes could link to single a page (see issue 3666 pdf). To
  7480. // handle this push it back on the queue so if it is a pages node it
  7481. // will be descended into.
  7482. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  7483. currentPageIndex = pageIndex;
  7484. continue;
  7485. } else {
  7486. for (var last = kids.length - 1; last >= 0; last--) {
  7487. nodesToVisit.push(kids[last]);
  7488. }
  7489. }
  7490. }
  7491. capability.reject('Page index ' + pageIndex + ' not found.');
  7492. }
  7493. next();
  7494. return capability.promise;
  7495. },
  7496. getPageIndex: function Catalog_getPageIndex(ref) {
  7497. // The page tree nodes have the count of all the leaves below them. To get
  7498. // how many pages are before we just have to walk up the tree and keep
  7499. // adding the count of siblings to the left of the node.
  7500. var xref = this.xref;
  7501. function pagesBeforeRef(kidRef) {
  7502. var total = 0;
  7503. var parentRef;
  7504. return xref.fetchAsync(kidRef).then(function (node) {
  7505. if (!node) {
  7506. return null;
  7507. }
  7508. parentRef = node.getRaw('Parent');
  7509. return node.getAsync('Parent');
  7510. }).then(function (parent) {
  7511. if (!parent) {
  7512. return null;
  7513. }
  7514. return parent.getAsync('Kids');
  7515. }).then(function (kids) {
  7516. if (!kids) {
  7517. return null;
  7518. }
  7519. var kidPromises = [];
  7520. var found = false;
  7521. for (var i = 0; i < kids.length; i++) {
  7522. var kid = kids[i];
  7523. assert(isRef(kid), 'kids must be a ref');
  7524. if (kid.num === kidRef.num) {
  7525. found = true;
  7526. break;
  7527. }
  7528. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  7529. if (kid.has('Count')) {
  7530. var count = kid.get('Count');
  7531. total += count;
  7532. } else { // page leaf node
  7533. total++;
  7534. }
  7535. }));
  7536. }
  7537. if (!found) {
  7538. error('kid ref not found in parents kids');
  7539. }
  7540. return Promise.all(kidPromises).then(function () {
  7541. return [total, parentRef];
  7542. });
  7543. });
  7544. }
  7545. var total = 0;
  7546. function next(ref) {
  7547. return pagesBeforeRef(ref).then(function (args) {
  7548. if (!args) {
  7549. return total;
  7550. }
  7551. var count = args[0];
  7552. var parentRef = args[1];
  7553. total += count;
  7554. return next(parentRef);
  7555. });
  7556. }
  7557. return next(ref);
  7558. }
  7559. };
  7560. return Catalog;
  7561. })();
  7562. var XRef = (function XRefClosure() {
  7563. function XRef(stream, password) {
  7564. this.stream = stream;
  7565. this.entries = [];
  7566. this.xrefstms = {};
  7567. // prepare the XRef cache
  7568. this.cache = [];
  7569. this.password = password;
  7570. this.stats = {
  7571. streamTypes: [],
  7572. fontTypes: []
  7573. };
  7574. }
  7575. XRef.prototype = {
  7576. setStartXRef: function XRef_setStartXRef(startXRef) {
  7577. // Store the starting positions of xref tables as we process them
  7578. // so we can recover from missing data errors
  7579. this.startXRefQueue = [startXRef];
  7580. },
  7581. parse: function XRef_parse(recoveryMode) {
  7582. var trailerDict;
  7583. if (!recoveryMode) {
  7584. trailerDict = this.readXRef();
  7585. } else {
  7586. warn('Indexing all PDF objects');
  7587. trailerDict = this.indexObjects();
  7588. }
  7589. trailerDict.assignXref(this);
  7590. this.trailer = trailerDict;
  7591. var encrypt = trailerDict.get('Encrypt');
  7592. if (encrypt) {
  7593. var ids = trailerDict.get('ID');
  7594. var fileId = (ids && ids.length) ? ids[0] : '';
  7595. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  7596. this.password);
  7597. }
  7598. // get the root dictionary (catalog) object
  7599. if (!(this.root = trailerDict.get('Root'))) {
  7600. error('Invalid root reference');
  7601. }
  7602. },
  7603. processXRefTable: function XRef_processXRefTable(parser) {
  7604. if (!('tableState' in this)) {
  7605. // Stores state of the table as we process it so we can resume
  7606. // from middle of table in case of missing data error
  7607. this.tableState = {
  7608. entryNum: 0,
  7609. streamPos: parser.lexer.stream.pos,
  7610. parserBuf1: parser.buf1,
  7611. parserBuf2: parser.buf2
  7612. };
  7613. }
  7614. var obj = this.readXRefTable(parser);
  7615. // Sanity check
  7616. if (!isCmd(obj, 'trailer')) {
  7617. error('Invalid XRef table: could not find trailer dictionary');
  7618. }
  7619. // Read trailer dictionary, e.g.
  7620. // trailer
  7621. // << /Size 22
  7622. // /Root 20R
  7623. // /Info 10R
  7624. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  7625. // >>
  7626. // The parser goes through the entire stream << ... >> and provides
  7627. // a getter interface for the key-value table
  7628. var dict = parser.getObj();
  7629. // The pdflib PDF generator can generate a nested trailer dictionary
  7630. if (!isDict(dict) && dict.dict) {
  7631. dict = dict.dict;
  7632. }
  7633. if (!isDict(dict)) {
  7634. error('Invalid XRef table: could not parse trailer dictionary');
  7635. }
  7636. delete this.tableState;
  7637. return dict;
  7638. },
  7639. readXRefTable: function XRef_readXRefTable(parser) {
  7640. // Example of cross-reference table:
  7641. // xref
  7642. // 0 1 <-- subsection header (first obj #, obj count)
  7643. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  7644. // 23 2 <-- subsection header ... and so on ...
  7645. // 0000025518 00002 n
  7646. // 0000025635 00000 n
  7647. // trailer
  7648. // ...
  7649. var stream = parser.lexer.stream;
  7650. var tableState = this.tableState;
  7651. stream.pos = tableState.streamPos;
  7652. parser.buf1 = tableState.parserBuf1;
  7653. parser.buf2 = tableState.parserBuf2;
  7654. // Outer loop is over subsection headers
  7655. var obj;
  7656. while (true) {
  7657. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  7658. if (isCmd(obj = parser.getObj(), 'trailer')) {
  7659. break;
  7660. }
  7661. tableState.firstEntryNum = obj;
  7662. tableState.entryCount = parser.getObj();
  7663. }
  7664. var first = tableState.firstEntryNum;
  7665. var count = tableState.entryCount;
  7666. if (!isInt(first) || !isInt(count)) {
  7667. error('Invalid XRef table: wrong types in subsection header');
  7668. }
  7669. // Inner loop is over objects themselves
  7670. for (var i = tableState.entryNum; i < count; i++) {
  7671. tableState.streamPos = stream.pos;
  7672. tableState.entryNum = i;
  7673. tableState.parserBuf1 = parser.buf1;
  7674. tableState.parserBuf2 = parser.buf2;
  7675. var entry = {};
  7676. entry.offset = parser.getObj();
  7677. entry.gen = parser.getObj();
  7678. var type = parser.getObj();
  7679. if (isCmd(type, 'f')) {
  7680. entry.free = true;
  7681. } else if (isCmd(type, 'n')) {
  7682. entry.uncompressed = true;
  7683. }
  7684. // Validate entry obj
  7685. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  7686. !(entry.free || entry.uncompressed)) {
  7687. console.log(entry.offset, entry.gen, entry.free,
  7688. entry.uncompressed);
  7689. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  7690. }
  7691. if (!this.entries[i + first]) {
  7692. this.entries[i + first] = entry;
  7693. }
  7694. }
  7695. tableState.entryNum = 0;
  7696. tableState.streamPos = stream.pos;
  7697. tableState.parserBuf1 = parser.buf1;
  7698. tableState.parserBuf2 = parser.buf2;
  7699. delete tableState.firstEntryNum;
  7700. delete tableState.entryCount;
  7701. }
  7702. // Per issue 3248: hp scanners generate bad XRef
  7703. if (first === 1 && this.entries[1] && this.entries[1].free) {
  7704. // shifting the entries
  7705. this.entries.shift();
  7706. }
  7707. // Sanity check: as per spec, first object must be free
  7708. if (this.entries[0] && !this.entries[0].free) {
  7709. error('Invalid XRef table: unexpected first object');
  7710. }
  7711. return obj;
  7712. },
  7713. processXRefStream: function XRef_processXRefStream(stream) {
  7714. if (!('streamState' in this)) {
  7715. // Stores state of the stream as we process it so we can resume
  7716. // from middle of stream in case of missing data error
  7717. var streamParameters = stream.dict;
  7718. var byteWidths = streamParameters.get('W');
  7719. var range = streamParameters.get('Index');
  7720. if (!range) {
  7721. range = [0, streamParameters.get('Size')];
  7722. }
  7723. this.streamState = {
  7724. entryRanges: range,
  7725. byteWidths: byteWidths,
  7726. entryNum: 0,
  7727. streamPos: stream.pos
  7728. };
  7729. }
  7730. this.readXRefStream(stream);
  7731. delete this.streamState;
  7732. return stream.dict;
  7733. },
  7734. readXRefStream: function XRef_readXRefStream(stream) {
  7735. var i, j;
  7736. var streamState = this.streamState;
  7737. stream.pos = streamState.streamPos;
  7738. var byteWidths = streamState.byteWidths;
  7739. var typeFieldWidth = byteWidths[0];
  7740. var offsetFieldWidth = byteWidths[1];
  7741. var generationFieldWidth = byteWidths[2];
  7742. var entryRanges = streamState.entryRanges;
  7743. while (entryRanges.length > 0) {
  7744. var first = entryRanges[0];
  7745. var n = entryRanges[1];
  7746. if (!isInt(first) || !isInt(n)) {
  7747. error('Invalid XRef range fields: ' + first + ', ' + n);
  7748. }
  7749. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  7750. !isInt(generationFieldWidth)) {
  7751. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  7752. }
  7753. for (i = streamState.entryNum; i < n; ++i) {
  7754. streamState.entryNum = i;
  7755. streamState.streamPos = stream.pos;
  7756. var type = 0, offset = 0, generation = 0;
  7757. for (j = 0; j < typeFieldWidth; ++j) {
  7758. type = (type << 8) | stream.getByte();
  7759. }
  7760. // if type field is absent, its default value is 1
  7761. if (typeFieldWidth === 0) {
  7762. type = 1;
  7763. }
  7764. for (j = 0; j < offsetFieldWidth; ++j) {
  7765. offset = (offset << 8) | stream.getByte();
  7766. }
  7767. for (j = 0; j < generationFieldWidth; ++j) {
  7768. generation = (generation << 8) | stream.getByte();
  7769. }
  7770. var entry = {};
  7771. entry.offset = offset;
  7772. entry.gen = generation;
  7773. switch (type) {
  7774. case 0:
  7775. entry.free = true;
  7776. break;
  7777. case 1:
  7778. entry.uncompressed = true;
  7779. break;
  7780. case 2:
  7781. break;
  7782. default:
  7783. error('Invalid XRef entry type: ' + type);
  7784. }
  7785. if (!this.entries[first + i]) {
  7786. this.entries[first + i] = entry;
  7787. }
  7788. }
  7789. streamState.entryNum = 0;
  7790. streamState.streamPos = stream.pos;
  7791. entryRanges.splice(0, 2);
  7792. }
  7793. },
  7794. indexObjects: function XRef_indexObjects() {
  7795. // Simple scan through the PDF content to find objects,
  7796. // trailers and XRef streams.
  7797. function readToken(data, offset) {
  7798. var token = '', ch = data[offset];
  7799. while (ch !== 13 && ch !== 10) {
  7800. if (++offset >= data.length) {
  7801. break;
  7802. }
  7803. token += String.fromCharCode(ch);
  7804. ch = data[offset];
  7805. }
  7806. return token;
  7807. }
  7808. function skipUntil(data, offset, what) {
  7809. var length = what.length, dataLength = data.length;
  7810. var skipped = 0;
  7811. // finding byte sequence
  7812. while (offset < dataLength) {
  7813. var i = 0;
  7814. while (i < length && data[offset + i] === what[i]) {
  7815. ++i;
  7816. }
  7817. if (i >= length) {
  7818. break; // sequence found
  7819. }
  7820. offset++;
  7821. skipped++;
  7822. }
  7823. return skipped;
  7824. }
  7825. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  7826. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  7827. 101, 102]);
  7828. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  7829. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  7830. var stream = this.stream;
  7831. stream.pos = 0;
  7832. var buffer = stream.getBytes();
  7833. var position = stream.start, length = buffer.length;
  7834. var trailers = [], xrefStms = [];
  7835. while (position < length) {
  7836. var ch = buffer[position];
  7837. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  7838. ++position;
  7839. continue;
  7840. }
  7841. if (ch === 37) { // %-comment
  7842. do {
  7843. ++position;
  7844. if (position >= length) {
  7845. break;
  7846. }
  7847. ch = buffer[position];
  7848. } while (ch !== 13 && ch !== 10);
  7849. continue;
  7850. }
  7851. var token = readToken(buffer, position);
  7852. var m;
  7853. if (token === 'xref') {
  7854. position += skipUntil(buffer, position, trailerBytes);
  7855. trailers.push(position);
  7856. position += skipUntil(buffer, position, startxrefBytes);
  7857. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  7858. this.entries[m[1]] = {
  7859. offset: position,
  7860. gen: m[2] | 0,
  7861. uncompressed: true
  7862. };
  7863. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  7864. var content = buffer.subarray(position, position + contentLength);
  7865. // checking XRef stream suspect
  7866. // (it shall have '/XRef' and next char is not a letter)
  7867. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  7868. if (xrefTagOffset < contentLength &&
  7869. content[xrefTagOffset + 5] < 64) {
  7870. xrefStms.push(position);
  7871. this.xrefstms[position] = 1; // don't read it recursively
  7872. }
  7873. position += contentLength;
  7874. } else {
  7875. position += token.length + 1;
  7876. }
  7877. }
  7878. // reading XRef streams
  7879. var i, ii;
  7880. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  7881. this.startXRefQueue.push(xrefStms[i]);
  7882. this.readXRef(/* recoveryMode */ true);
  7883. }
  7884. // finding main trailer
  7885. var dict;
  7886. for (i = 0, ii = trailers.length; i < ii; ++i) {
  7887. stream.pos = trailers[i];
  7888. var parser = new Parser(new Lexer(stream), true, this);
  7889. var obj = parser.getObj();
  7890. if (!isCmd(obj, 'trailer')) {
  7891. continue;
  7892. }
  7893. // read the trailer dictionary
  7894. if (!isDict(dict = parser.getObj())) {
  7895. continue;
  7896. }
  7897. // taking the first one with 'ID'
  7898. if (dict.has('ID')) {
  7899. return dict;
  7900. }
  7901. }
  7902. // no tailer with 'ID', taking last one (if exists)
  7903. if (dict) {
  7904. return dict;
  7905. }
  7906. // nothing helps
  7907. // calling error() would reject worker with an UnknownErrorException.
  7908. throw new InvalidPDFException('Invalid PDF structure');
  7909. },
  7910. readXRef: function XRef_readXRef(recoveryMode) {
  7911. var stream = this.stream;
  7912. try {
  7913. while (this.startXRefQueue.length) {
  7914. var startXRef = this.startXRefQueue[0];
  7915. stream.pos = startXRef + stream.start;
  7916. var parser = new Parser(new Lexer(stream), true, this);
  7917. var obj = parser.getObj();
  7918. var dict;
  7919. // Get dictionary
  7920. if (isCmd(obj, 'xref')) {
  7921. // Parse end-of-file XRef
  7922. dict = this.processXRefTable(parser);
  7923. if (!this.topDict) {
  7924. this.topDict = dict;
  7925. }
  7926. // Recursively get other XRefs 'XRefStm', if any
  7927. obj = dict.get('XRefStm');
  7928. if (isInt(obj)) {
  7929. var pos = obj;
  7930. // ignore previously loaded xref streams
  7931. // (possible infinite recursion)
  7932. if (!(pos in this.xrefstms)) {
  7933. this.xrefstms[pos] = 1;
  7934. this.startXRefQueue.push(pos);
  7935. }
  7936. }
  7937. } else if (isInt(obj)) {
  7938. // Parse in-stream XRef
  7939. if (!isInt(parser.getObj()) ||
  7940. !isCmd(parser.getObj(), 'obj') ||
  7941. !isStream(obj = parser.getObj())) {
  7942. error('Invalid XRef stream');
  7943. }
  7944. dict = this.processXRefStream(obj);
  7945. if (!this.topDict) {
  7946. this.topDict = dict;
  7947. }
  7948. if (!dict) {
  7949. error('Failed to read XRef stream');
  7950. }
  7951. } else {
  7952. error('Invalid XRef stream header');
  7953. }
  7954. // Recursively get previous dictionary, if any
  7955. obj = dict.get('Prev');
  7956. if (isInt(obj)) {
  7957. this.startXRefQueue.push(obj);
  7958. } else if (isRef(obj)) {
  7959. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  7960. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  7961. this.startXRefQueue.push(obj.num);
  7962. }
  7963. this.startXRefQueue.shift();
  7964. }
  7965. return this.topDict;
  7966. } catch (e) {
  7967. if (e instanceof MissingDataException) {
  7968. throw e;
  7969. }
  7970. info('(while reading XRef): ' + e);
  7971. }
  7972. if (recoveryMode) {
  7973. return;
  7974. }
  7975. throw new XRefParseException();
  7976. },
  7977. getEntry: function XRef_getEntry(i) {
  7978. var xrefEntry = this.entries[i];
  7979. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  7980. return xrefEntry;
  7981. }
  7982. return null;
  7983. },
  7984. fetchIfRef: function XRef_fetchIfRef(obj) {
  7985. if (!isRef(obj)) {
  7986. return obj;
  7987. }
  7988. return this.fetch(obj);
  7989. },
  7990. fetch: function XRef_fetch(ref, suppressEncryption) {
  7991. assert(isRef(ref), 'ref object is not a reference');
  7992. var num = ref.num;
  7993. if (num in this.cache) {
  7994. var cacheEntry = this.cache[num];
  7995. return cacheEntry;
  7996. }
  7997. var xrefEntry = this.getEntry(num);
  7998. // the referenced entry can be free
  7999. if (xrefEntry === null) {
  8000. return (this.cache[num] = null);
  8001. }
  8002. if (xrefEntry.uncompressed) {
  8003. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  8004. } else {
  8005. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  8006. }
  8007. if (isDict(xrefEntry)){
  8008. xrefEntry.objId = ref.toString();
  8009. } else if (isStream(xrefEntry)) {
  8010. xrefEntry.dict.objId = ref.toString();
  8011. }
  8012. return xrefEntry;
  8013. },
  8014. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  8015. suppressEncryption) {
  8016. var gen = ref.gen;
  8017. var num = ref.num;
  8018. if (xrefEntry.gen !== gen) {
  8019. error('inconsistent generation in XRef');
  8020. }
  8021. var stream = this.stream.makeSubStream(xrefEntry.offset +
  8022. this.stream.start);
  8023. var parser = new Parser(new Lexer(stream), true, this);
  8024. var obj1 = parser.getObj();
  8025. var obj2 = parser.getObj();
  8026. var obj3 = parser.getObj();
  8027. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  8028. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  8029. !isCmd(obj3)) {
  8030. error('bad XRef entry');
  8031. }
  8032. if (!isCmd(obj3, 'obj')) {
  8033. // some bad PDFs use "obj1234" and really mean 1234
  8034. if (obj3.cmd.indexOf('obj') === 0) {
  8035. num = parseInt(obj3.cmd.substring(3), 10);
  8036. if (!isNaN(num)) {
  8037. return num;
  8038. }
  8039. }
  8040. error('bad XRef entry');
  8041. }
  8042. if (this.encrypt && !suppressEncryption) {
  8043. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  8044. } else {
  8045. xrefEntry = parser.getObj();
  8046. }
  8047. if (!isStream(xrefEntry)) {
  8048. this.cache[num] = xrefEntry;
  8049. }
  8050. return xrefEntry;
  8051. },
  8052. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  8053. suppressEncryption) {
  8054. var tableOffset = xrefEntry.offset;
  8055. var stream = this.fetch(new Ref(tableOffset, 0));
  8056. if (!isStream(stream)) {
  8057. error('bad ObjStm stream');
  8058. }
  8059. var first = stream.dict.get('First');
  8060. var n = stream.dict.get('N');
  8061. if (!isInt(first) || !isInt(n)) {
  8062. error('invalid first and n parameters for ObjStm stream');
  8063. }
  8064. var parser = new Parser(new Lexer(stream), false, this);
  8065. parser.allowStreams = true;
  8066. var i, entries = [], num, nums = [];
  8067. // read the object numbers to populate cache
  8068. for (i = 0; i < n; ++i) {
  8069. num = parser.getObj();
  8070. if (!isInt(num)) {
  8071. error('invalid object number in the ObjStm stream: ' + num);
  8072. }
  8073. nums.push(num);
  8074. var offset = parser.getObj();
  8075. if (!isInt(offset)) {
  8076. error('invalid object offset in the ObjStm stream: ' + offset);
  8077. }
  8078. }
  8079. // read stream objects for cache
  8080. for (i = 0; i < n; ++i) {
  8081. entries.push(parser.getObj());
  8082. num = nums[i];
  8083. var entry = this.entries[num];
  8084. if (entry && entry.offset === tableOffset && entry.gen === i) {
  8085. this.cache[num] = entries[i];
  8086. }
  8087. }
  8088. xrefEntry = entries[xrefEntry.gen];
  8089. if (xrefEntry === undefined) {
  8090. error('bad XRef entry for compressed object');
  8091. }
  8092. return xrefEntry;
  8093. },
  8094. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  8095. if (!isRef(obj)) {
  8096. return Promise.resolve(obj);
  8097. }
  8098. return this.fetchAsync(obj);
  8099. },
  8100. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  8101. var streamManager = this.stream.manager;
  8102. var xref = this;
  8103. return new Promise(function tryFetch(resolve, reject) {
  8104. try {
  8105. resolve(xref.fetch(ref, suppressEncryption));
  8106. } catch (e) {
  8107. if (e instanceof MissingDataException) {
  8108. streamManager.requestRange(e.begin, e.end, function () {
  8109. tryFetch(resolve, reject);
  8110. });
  8111. return;
  8112. }
  8113. reject(e);
  8114. }
  8115. });
  8116. },
  8117. getCatalogObj: function XRef_getCatalogObj() {
  8118. return this.root;
  8119. }
  8120. };
  8121. return XRef;
  8122. })();
  8123. /**
  8124. * A NameTree is like a Dict but has some advantageous properties, see the
  8125. * spec (7.9.6) for more details.
  8126. * TODO: implement all the Dict functions and make this more efficent.
  8127. */
  8128. var NameTree = (function NameTreeClosure() {
  8129. function NameTree(root, xref) {
  8130. this.root = root;
  8131. this.xref = xref;
  8132. }
  8133. NameTree.prototype = {
  8134. getAll: function NameTree_getAll() {
  8135. var dict = {};
  8136. if (!this.root) {
  8137. return dict;
  8138. }
  8139. var xref = this.xref;
  8140. // reading name tree
  8141. var processed = new RefSet();
  8142. processed.put(this.root);
  8143. var queue = [this.root];
  8144. while (queue.length > 0) {
  8145. var i, n;
  8146. var obj = xref.fetchIfRef(queue.shift());
  8147. if (!isDict(obj)) {
  8148. continue;
  8149. }
  8150. if (obj.has('Kids')) {
  8151. var kids = obj.get('Kids');
  8152. for (i = 0, n = kids.length; i < n; i++) {
  8153. var kid = kids[i];
  8154. if (processed.has(kid)) {
  8155. error('invalid destinations');
  8156. }
  8157. queue.push(kid);
  8158. processed.put(kid);
  8159. }
  8160. continue;
  8161. }
  8162. var names = obj.get('Names');
  8163. if (names) {
  8164. for (i = 0, n = names.length; i < n; i += 2) {
  8165. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  8166. }
  8167. }
  8168. }
  8169. return dict;
  8170. }
  8171. };
  8172. return NameTree;
  8173. })();
  8174. /**
  8175. * "A PDF file can refer to the contents of another file by using a File
  8176. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  8177. * NOTE: Only embedded files are supported (as part of the attachments support)
  8178. * TODO: support the 'URL' file system (with caching if !/V), portable
  8179. * collections attributes and related files (/RF)
  8180. */
  8181. var FileSpec = (function FileSpecClosure() {
  8182. function FileSpec(root, xref) {
  8183. if (!root || !isDict(root)) {
  8184. return;
  8185. }
  8186. this.xref = xref;
  8187. this.root = root;
  8188. if (root.has('FS')) {
  8189. this.fs = root.get('FS');
  8190. }
  8191. this.description = root.has('Desc') ?
  8192. stringToPDFString(root.get('Desc')) :
  8193. '';
  8194. if (root.has('RF')) {
  8195. warn('Related file specifications are not supported');
  8196. }
  8197. this.contentAvailable = true;
  8198. if (!root.has('EF')) {
  8199. this.contentAvailable = false;
  8200. warn('Non-embedded file specifications are not supported');
  8201. }
  8202. }
  8203. function pickPlatformItem(dict) {
  8204. // Look for the filename in this order:
  8205. // UF, F, Unix, Mac, DOS
  8206. if (dict.has('UF')) {
  8207. return dict.get('UF');
  8208. } else if (dict.has('F')) {
  8209. return dict.get('F');
  8210. } else if (dict.has('Unix')) {
  8211. return dict.get('Unix');
  8212. } else if (dict.has('Mac')) {
  8213. return dict.get('Mac');
  8214. } else if (dict.has('DOS')) {
  8215. return dict.get('DOS');
  8216. } else {
  8217. return null;
  8218. }
  8219. }
  8220. FileSpec.prototype = {
  8221. get filename() {
  8222. if (!this._filename && this.root) {
  8223. var filename = pickPlatformItem(this.root) || 'unnamed';
  8224. this._filename = stringToPDFString(filename).
  8225. replace(/\\\\/g, '\\').
  8226. replace(/\\\//g, '/').
  8227. replace(/\\/g, '/');
  8228. }
  8229. return this._filename;
  8230. },
  8231. get content() {
  8232. if (!this.contentAvailable) {
  8233. return null;
  8234. }
  8235. if (!this.contentRef && this.root) {
  8236. this.contentRef = pickPlatformItem(this.root.get('EF'));
  8237. }
  8238. var content = null;
  8239. if (this.contentRef) {
  8240. var xref = this.xref;
  8241. var fileObj = xref.fetchIfRef(this.contentRef);
  8242. if (fileObj && isStream(fileObj)) {
  8243. content = fileObj.getBytes();
  8244. } else {
  8245. warn('Embedded file specification points to non-existing/invalid ' +
  8246. 'content');
  8247. }
  8248. } else {
  8249. warn('Embedded file specification does not have a content');
  8250. }
  8251. return content;
  8252. },
  8253. get serializable() {
  8254. return {
  8255. filename: this.filename,
  8256. content: this.content
  8257. };
  8258. }
  8259. };
  8260. return FileSpec;
  8261. })();
  8262. /**
  8263. * A helper for loading missing data in object graphs. It traverses the graph
  8264. * depth first and queues up any objects that have missing data. Once it has
  8265. * has traversed as many objects that are available it attempts to bundle the
  8266. * missing data requests and then resume from the nodes that weren't ready.
  8267. *
  8268. * NOTE: It provides protection from circular references by keeping track of
  8269. * of loaded references. However, you must be careful not to load any graphs
  8270. * that have references to the catalog or other pages since that will cause the
  8271. * entire PDF document object graph to be traversed.
  8272. */
  8273. var ObjectLoader = (function() {
  8274. function mayHaveChildren(value) {
  8275. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  8276. }
  8277. function addChildren(node, nodesToVisit) {
  8278. var value;
  8279. if (isDict(node) || isStream(node)) {
  8280. var map;
  8281. if (isDict(node)) {
  8282. map = node.map;
  8283. } else {
  8284. map = node.dict.map;
  8285. }
  8286. for (var key in map) {
  8287. value = map[key];
  8288. if (mayHaveChildren(value)) {
  8289. nodesToVisit.push(value);
  8290. }
  8291. }
  8292. } else if (isArray(node)) {
  8293. for (var i = 0, ii = node.length; i < ii; i++) {
  8294. value = node[i];
  8295. if (mayHaveChildren(value)) {
  8296. nodesToVisit.push(value);
  8297. }
  8298. }
  8299. }
  8300. }
  8301. function ObjectLoader(obj, keys, xref) {
  8302. this.obj = obj;
  8303. this.keys = keys;
  8304. this.xref = xref;
  8305. this.refSet = null;
  8306. }
  8307. ObjectLoader.prototype = {
  8308. load: function ObjectLoader_load() {
  8309. var keys = this.keys;
  8310. this.capability = createPromiseCapability();
  8311. // Don't walk the graph if all the data is already loaded.
  8312. if (!(this.xref.stream instanceof ChunkedStream) ||
  8313. this.xref.stream.getMissingChunks().length === 0) {
  8314. this.capability.resolve();
  8315. return this.capability.promise;
  8316. }
  8317. this.refSet = new RefSet();
  8318. // Setup the initial nodes to visit.
  8319. var nodesToVisit = [];
  8320. for (var i = 0; i < keys.length; i++) {
  8321. nodesToVisit.push(this.obj[keys[i]]);
  8322. }
  8323. this.walk(nodesToVisit);
  8324. return this.capability.promise;
  8325. },
  8326. walk: function ObjectLoader_walk(nodesToVisit) {
  8327. var nodesToRevisit = [];
  8328. var pendingRequests = [];
  8329. // DFS walk of the object graph.
  8330. while (nodesToVisit.length) {
  8331. var currentNode = nodesToVisit.pop();
  8332. // Only references or chunked streams can cause missing data exceptions.
  8333. if (isRef(currentNode)) {
  8334. // Skip nodes that have already been visited.
  8335. if (this.refSet.has(currentNode)) {
  8336. continue;
  8337. }
  8338. try {
  8339. var ref = currentNode;
  8340. this.refSet.put(ref);
  8341. currentNode = this.xref.fetch(currentNode);
  8342. } catch (e) {
  8343. if (!(e instanceof MissingDataException)) {
  8344. throw e;
  8345. }
  8346. nodesToRevisit.push(currentNode);
  8347. pendingRequests.push({ begin: e.begin, end: e.end });
  8348. }
  8349. }
  8350. if (currentNode && currentNode.getBaseStreams) {
  8351. var baseStreams = currentNode.getBaseStreams();
  8352. var foundMissingData = false;
  8353. for (var i = 0; i < baseStreams.length; i++) {
  8354. var stream = baseStreams[i];
  8355. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  8356. foundMissingData = true;
  8357. pendingRequests.push({
  8358. begin: stream.start,
  8359. end: stream.end
  8360. });
  8361. }
  8362. }
  8363. if (foundMissingData) {
  8364. nodesToRevisit.push(currentNode);
  8365. }
  8366. }
  8367. addChildren(currentNode, nodesToVisit);
  8368. }
  8369. if (pendingRequests.length) {
  8370. this.xref.stream.manager.requestRanges(pendingRequests,
  8371. function pendingRequestCallback() {
  8372. nodesToVisit = nodesToRevisit;
  8373. for (var i = 0; i < nodesToRevisit.length; i++) {
  8374. var node = nodesToRevisit[i];
  8375. // Remove any reference nodes from the currrent refset so they
  8376. // aren't skipped when we revist them.
  8377. if (isRef(node)) {
  8378. this.refSet.remove(node);
  8379. }
  8380. }
  8381. this.walk(nodesToVisit);
  8382. }.bind(this));
  8383. return;
  8384. }
  8385. // Everything is loaded.
  8386. this.refSet = null;
  8387. this.capability.resolve();
  8388. }
  8389. };
  8390. return ObjectLoader;
  8391. })();
  8392. var ISOAdobeCharset = [
  8393. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8394. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8395. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8396. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8397. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8398. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8399. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8400. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8401. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8402. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8403. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8404. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8405. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8406. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8407. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8408. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8409. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8410. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8411. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8412. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8413. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8414. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8415. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8416. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8417. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8418. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8419. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8420. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8421. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8422. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8423. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8424. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8425. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8426. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8427. ];
  8428. var ExpertCharset = [
  8429. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8430. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8431. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8432. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8433. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8434. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8435. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8436. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8437. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8438. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8439. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8440. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8441. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8442. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8443. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8444. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8445. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8446. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8447. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8448. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8449. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8450. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8451. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8452. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8453. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8454. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8455. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8456. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8457. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8458. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8459. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8460. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8461. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8462. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8463. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8464. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8465. 'Ydieresissmall'
  8466. ];
  8467. var ExpertSubsetCharset = [
  8468. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8469. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8470. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8471. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8472. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8473. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8474. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8475. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8476. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8477. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8478. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8479. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8480. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8481. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8482. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8483. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8484. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8485. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8486. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8487. 'periodinferior', 'commainferior'
  8488. ];
  8489. var DEFAULT_ICON_SIZE = 22; // px
  8490. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  8491. var Annotation = (function AnnotationClosure() {
  8492. // 12.5.5: Algorithm: Appearance streams
  8493. function getTransformMatrix(rect, bbox, matrix) {
  8494. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  8495. var minX = bounds[0];
  8496. var minY = bounds[1];
  8497. var maxX = bounds[2];
  8498. var maxY = bounds[3];
  8499. if (minX === maxX || minY === maxY) {
  8500. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  8501. // just apply the transform for rect
  8502. return [1, 0, 0, 1, rect[0], rect[1]];
  8503. }
  8504. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  8505. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  8506. return [
  8507. xRatio,
  8508. 0,
  8509. 0,
  8510. yRatio,
  8511. rect[0] - minX * xRatio,
  8512. rect[1] - minY * yRatio
  8513. ];
  8514. }
  8515. function getDefaultAppearance(dict) {
  8516. var appearanceState = dict.get('AP');
  8517. if (!isDict(appearanceState)) {
  8518. return;
  8519. }
  8520. var appearance;
  8521. var appearances = appearanceState.get('N');
  8522. if (isDict(appearances)) {
  8523. var as = dict.get('AS');
  8524. if (as && appearances.has(as.name)) {
  8525. appearance = appearances.get(as.name);
  8526. }
  8527. } else {
  8528. appearance = appearances;
  8529. }
  8530. return appearance;
  8531. }
  8532. function Annotation(params) {
  8533. var dict = params.dict;
  8534. var data = this.data = {};
  8535. data.subtype = dict.get('Subtype').name;
  8536. var rect = dict.get('Rect') || [0, 0, 0, 0];
  8537. data.rect = Util.normalizeRect(rect);
  8538. data.annotationFlags = dict.get('F');
  8539. var color = dict.get('C');
  8540. if (isArray(color) && color.length === 3) {
  8541. // TODO(mack): currently only supporting rgb; need support different
  8542. // colorspaces
  8543. data.color = color;
  8544. } else {
  8545. data.color = [0, 0, 0];
  8546. }
  8547. // Some types of annotations have border style dict which has more
  8548. // info than the border array
  8549. if (dict.has('BS')) {
  8550. var borderStyle = dict.get('BS');
  8551. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  8552. } else {
  8553. var borderArray = dict.get('Border') || [0, 0, 1];
  8554. data.borderWidth = borderArray[2] || 0;
  8555. // TODO: implement proper support for annotations with line dash patterns.
  8556. var dashArray = borderArray[3];
  8557. if (data.borderWidth > 0 && dashArray) {
  8558. if (!isArray(dashArray)) {
  8559. // Ignore the border if dashArray is not actually an array,
  8560. // this is consistent with the behaviour in Adobe Reader.
  8561. data.borderWidth = 0;
  8562. } else {
  8563. var dashArrayLength = dashArray.length;
  8564. if (dashArrayLength > 0) {
  8565. // According to the PDF specification: the elements in a dashArray
  8566. // shall be numbers that are nonnegative and not all equal to zero.
  8567. var isInvalid = false;
  8568. var numPositive = 0;
  8569. for (var i = 0; i < dashArrayLength; i++) {
  8570. var validNumber = (+dashArray[i] >= 0);
  8571. if (!validNumber) {
  8572. isInvalid = true;
  8573. break;
  8574. } else if (dashArray[i] > 0) {
  8575. numPositive++;
  8576. }
  8577. }
  8578. if (isInvalid || numPositive === 0) {
  8579. data.borderWidth = 0;
  8580. }
  8581. }
  8582. }
  8583. }
  8584. }
  8585. this.appearance = getDefaultAppearance(dict);
  8586. data.hasAppearance = !!this.appearance;
  8587. data.id = params.ref.num;
  8588. }
  8589. Annotation.prototype = {
  8590. getData: function Annotation_getData() {
  8591. return this.data;
  8592. },
  8593. isInvisible: function Annotation_isInvisible() {
  8594. var data = this.data;
  8595. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  8596. return false;
  8597. } else {
  8598. return !!(data &&
  8599. data.annotationFlags && // Default: not invisible
  8600. data.annotationFlags & 0x1); // Invisible
  8601. }
  8602. },
  8603. isViewable: function Annotation_isViewable() {
  8604. var data = this.data;
  8605. return !!(!this.isInvisible() &&
  8606. data &&
  8607. (!data.annotationFlags ||
  8608. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  8609. data.rect); // rectangle is necessary
  8610. },
  8611. isPrintable: function Annotation_isPrintable() {
  8612. var data = this.data;
  8613. return !!(!this.isInvisible() &&
  8614. data &&
  8615. data.annotationFlags && // Default: not printable
  8616. data.annotationFlags & 0x4 && // Print
  8617. !(data.annotationFlags & 0x2) && // Hidden
  8618. data.rect); // rectangle is necessary
  8619. },
  8620. loadResources: function Annotation_loadResources(keys) {
  8621. return new Promise(function (resolve, reject) {
  8622. this.appearance.dict.getAsync('Resources').then(function (resources) {
  8623. if (!resources) {
  8624. resolve();
  8625. return;
  8626. }
  8627. var objectLoader = new ObjectLoader(resources.map,
  8628. keys,
  8629. resources.xref);
  8630. objectLoader.load().then(function() {
  8631. resolve(resources);
  8632. }, reject);
  8633. }, reject);
  8634. }.bind(this));
  8635. },
  8636. getOperatorList: function Annotation_getOperatorList(evaluator) {
  8637. if (!this.appearance) {
  8638. return Promise.resolve(new OperatorList());
  8639. }
  8640. var data = this.data;
  8641. var appearanceDict = this.appearance.dict;
  8642. var resourcesPromise = this.loadResources([
  8643. 'ExtGState',
  8644. 'ColorSpace',
  8645. 'Pattern',
  8646. 'Shading',
  8647. 'XObject',
  8648. 'Font'
  8649. // ProcSet
  8650. // Properties
  8651. ]);
  8652. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  8653. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  8654. var transform = getTransformMatrix(data.rect, bbox, matrix);
  8655. var self = this;
  8656. return resourcesPromise.then(function(resources) {
  8657. var opList = new OperatorList();
  8658. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  8659. return evaluator.getOperatorList(self.appearance, resources, opList).
  8660. then(function () {
  8661. opList.addOp(OPS.endAnnotation, []);
  8662. self.appearance.reset();
  8663. return opList;
  8664. });
  8665. });
  8666. }
  8667. };
  8668. Annotation.getConstructor =
  8669. function Annotation_getConstructor(subtype, fieldType) {
  8670. if (!subtype) {
  8671. return;
  8672. }
  8673. // TODO(mack): Implement FreeText annotations
  8674. if (subtype === 'Link') {
  8675. return LinkAnnotation;
  8676. } else if (subtype === 'Text') {
  8677. return TextAnnotation;
  8678. } else if (subtype === 'Widget') {
  8679. if (!fieldType) {
  8680. return;
  8681. }
  8682. if (fieldType === 'Tx') {
  8683. return TextWidgetAnnotation;
  8684. } else {
  8685. return WidgetAnnotation;
  8686. }
  8687. } else {
  8688. return Annotation;
  8689. }
  8690. };
  8691. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  8692. var dict = xref.fetchIfRef(ref);
  8693. if (!isDict(dict)) {
  8694. return;
  8695. }
  8696. var subtype = dict.get('Subtype');
  8697. subtype = isName(subtype) ? subtype.name : '';
  8698. if (!subtype) {
  8699. return;
  8700. }
  8701. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8702. fieldType = isName(fieldType) ? fieldType.name : '';
  8703. var Constructor = Annotation.getConstructor(subtype, fieldType);
  8704. if (!Constructor) {
  8705. return;
  8706. }
  8707. var params = {
  8708. dict: dict,
  8709. ref: ref,
  8710. };
  8711. var annotation = new Constructor(params);
  8712. if (annotation.isViewable() || annotation.isPrintable()) {
  8713. return annotation;
  8714. } else {
  8715. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  8716. warn('unimplemented annotation type: ' + subtype);
  8717. }
  8718. }
  8719. };
  8720. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  8721. annotations, opList, pdfManager, partialEvaluator, intent) {
  8722. function reject(e) {
  8723. annotationsReadyCapability.reject(e);
  8724. }
  8725. var annotationsReadyCapability = createPromiseCapability();
  8726. var annotationPromises = [];
  8727. for (var i = 0, n = annotations.length; i < n; ++i) {
  8728. if (intent === 'display' && annotations[i].isViewable() ||
  8729. intent === 'print' && annotations[i].isPrintable()) {
  8730. annotationPromises.push(
  8731. annotations[i].getOperatorList(partialEvaluator));
  8732. }
  8733. }
  8734. Promise.all(annotationPromises).then(function(datas) {
  8735. opList.addOp(OPS.beginAnnotations, []);
  8736. for (var i = 0, n = datas.length; i < n; ++i) {
  8737. var annotOpList = datas[i];
  8738. opList.addOpList(annotOpList);
  8739. }
  8740. opList.addOp(OPS.endAnnotations, []);
  8741. annotationsReadyCapability.resolve();
  8742. }, reject);
  8743. return annotationsReadyCapability.promise;
  8744. };
  8745. return Annotation;
  8746. })();
  8747. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  8748. function WidgetAnnotation(params) {
  8749. Annotation.call(this, params);
  8750. var dict = params.dict;
  8751. var data = this.data;
  8752. data.fieldValue = stringToPDFString(
  8753. Util.getInheritableProperty(dict, 'V') || '');
  8754. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  8755. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  8756. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8757. data.fieldType = isName(fieldType) ? fieldType.name : '';
  8758. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  8759. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  8760. // Building the full field name by collecting the field and
  8761. // its ancestors 'T' data and joining them using '.'.
  8762. var fieldName = [];
  8763. var namedItem = dict;
  8764. var ref = params.ref;
  8765. while (namedItem) {
  8766. var parent = namedItem.get('Parent');
  8767. var parentRef = namedItem.getRaw('Parent');
  8768. var name = namedItem.get('T');
  8769. if (name) {
  8770. fieldName.unshift(stringToPDFString(name));
  8771. } else {
  8772. // The field name is absent, that means more than one field
  8773. // with the same name may exist. Replacing the empty name
  8774. // with the '`' plus index in the parent's 'Kids' array.
  8775. // This is not in the PDF spec but necessary to id the
  8776. // the input controls.
  8777. var kids = parent.get('Kids');
  8778. var j, jj;
  8779. for (j = 0, jj = kids.length; j < jj; j++) {
  8780. var kidRef = kids[j];
  8781. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  8782. break;
  8783. }
  8784. }
  8785. fieldName.unshift('`' + j);
  8786. }
  8787. namedItem = parent;
  8788. ref = parentRef;
  8789. }
  8790. data.fullName = fieldName.join('.');
  8791. }
  8792. var parent = Annotation.prototype;
  8793. Util.inherit(WidgetAnnotation, Annotation, {
  8794. isViewable: function WidgetAnnotation_isViewable() {
  8795. if (this.data.fieldType === 'Sig') {
  8796. warn('unimplemented annotation type: Widget signature');
  8797. return false;
  8798. }
  8799. return parent.isViewable.call(this);
  8800. }
  8801. });
  8802. return WidgetAnnotation;
  8803. })();
  8804. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  8805. function TextWidgetAnnotation(params) {
  8806. WidgetAnnotation.call(this, params);
  8807. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  8808. this.data.annotationType = AnnotationType.WIDGET;
  8809. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  8810. }
  8811. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  8812. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  8813. if (this.appearance) {
  8814. return Annotation.prototype.getOperatorList.call(this, evaluator);
  8815. }
  8816. var opList = new OperatorList();
  8817. var data = this.data;
  8818. // Even if there is an appearance stream, ignore it. This is the
  8819. // behaviour used by Adobe Reader.
  8820. if (!data.defaultAppearance) {
  8821. return Promise.resolve(opList);
  8822. }
  8823. var stream = new Stream(stringToBytes(data.defaultAppearance));
  8824. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  8825. then(function () {
  8826. return opList;
  8827. });
  8828. }
  8829. });
  8830. return TextWidgetAnnotation;
  8831. })();
  8832. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  8833. function InteractiveAnnotation(params) {
  8834. Annotation.call(this, params);
  8835. this.data.hasHtml = true;
  8836. }
  8837. Util.inherit(InteractiveAnnotation, Annotation, { });
  8838. return InteractiveAnnotation;
  8839. })();
  8840. var TextAnnotation = (function TextAnnotationClosure() {
  8841. function TextAnnotation(params) {
  8842. InteractiveAnnotation.call(this, params);
  8843. var dict = params.dict;
  8844. var data = this.data;
  8845. var content = dict.get('Contents');
  8846. var title = dict.get('T');
  8847. data.annotationType = AnnotationType.TEXT;
  8848. data.content = stringToPDFString(content || '');
  8849. data.title = stringToPDFString(title || '');
  8850. if (data.hasAppearance) {
  8851. data.name = 'NoIcon';
  8852. } else {
  8853. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  8854. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  8855. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  8856. }
  8857. if (dict.has('C')) {
  8858. data.hasBgColor = true;
  8859. }
  8860. }
  8861. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  8862. return TextAnnotation;
  8863. })();
  8864. var LinkAnnotation = (function LinkAnnotationClosure() {
  8865. function LinkAnnotation(params) {
  8866. InteractiveAnnotation.call(this, params);
  8867. var dict = params.dict;
  8868. var data = this.data;
  8869. data.annotationType = AnnotationType.LINK;
  8870. var action = dict.get('A');
  8871. if (action) {
  8872. var linkType = action.get('S').name;
  8873. if (linkType === 'URI') {
  8874. var url = action.get('URI');
  8875. if (isName(url)) {
  8876. // Some bad PDFs do not put parentheses around relative URLs.
  8877. url = '/' + url.name;
  8878. } else if (url) {
  8879. url = addDefaultProtocolToUrl(url);
  8880. }
  8881. // TODO: pdf spec mentions urls can be relative to a Base
  8882. // entry in the dictionary.
  8883. if (!isValidUrl(url, false)) {
  8884. url = '';
  8885. }
  8886. data.url = url;
  8887. } else if (linkType === 'GoTo') {
  8888. data.dest = action.get('D');
  8889. } else if (linkType === 'GoToR') {
  8890. var urlDict = action.get('F');
  8891. if (isDict(urlDict)) {
  8892. // We assume that the 'url' is a Filspec dictionary
  8893. // and fetch the url without checking any further
  8894. url = urlDict.get('F') || '';
  8895. }
  8896. // TODO: pdf reference says that GoToR
  8897. // can also have 'NewWindow' attribute
  8898. if (!isValidUrl(url, false)) {
  8899. url = '';
  8900. }
  8901. data.url = url;
  8902. data.dest = action.get('D');
  8903. } else if (linkType === 'Named') {
  8904. data.action = action.get('N').name;
  8905. } else {
  8906. warn('unrecognized link type: ' + linkType);
  8907. }
  8908. } else if (dict.has('Dest')) {
  8909. // simple destination link
  8910. var dest = dict.get('Dest');
  8911. data.dest = isName(dest) ? dest.name : dest;
  8912. }
  8913. }
  8914. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  8915. function addDefaultProtocolToUrl(url) {
  8916. if (url && url.indexOf('www.') === 0) {
  8917. return ('http://' + url);
  8918. }
  8919. return url;
  8920. }
  8921. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  8922. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  8923. return false;
  8924. }
  8925. });
  8926. return LinkAnnotation;
  8927. })();
  8928. var PDFFunction = (function PDFFunctionClosure() {
  8929. var CONSTRUCT_SAMPLED = 0;
  8930. var CONSTRUCT_INTERPOLATED = 2;
  8931. var CONSTRUCT_STICHED = 3;
  8932. var CONSTRUCT_POSTSCRIPT = 4;
  8933. return {
  8934. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  8935. str) {
  8936. var i, ii;
  8937. var length = 1;
  8938. for (i = 0, ii = size.length; i < ii; i++) {
  8939. length *= size[i];
  8940. }
  8941. length *= outputSize;
  8942. var array = [];
  8943. var codeSize = 0;
  8944. var codeBuf = 0;
  8945. // 32 is a valid bps so shifting won't work
  8946. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  8947. var strBytes = str.getBytes((length * bps + 7) / 8);
  8948. var strIdx = 0;
  8949. for (i = 0; i < length; i++) {
  8950. while (codeSize < bps) {
  8951. codeBuf <<= 8;
  8952. codeBuf |= strBytes[strIdx++];
  8953. codeSize += 8;
  8954. }
  8955. codeSize -= bps;
  8956. array.push((codeBuf >> codeSize) * sampleMul);
  8957. codeBuf &= (1 << codeSize) - 1;
  8958. }
  8959. return array;
  8960. },
  8961. getIR: function PDFFunction_getIR(xref, fn) {
  8962. var dict = fn.dict;
  8963. if (!dict) {
  8964. dict = fn;
  8965. }
  8966. var types = [this.constructSampled,
  8967. null,
  8968. this.constructInterpolated,
  8969. this.constructStiched,
  8970. this.constructPostScript];
  8971. var typeNum = dict.get('FunctionType');
  8972. var typeFn = types[typeNum];
  8973. if (!typeFn) {
  8974. error('Unknown type of function');
  8975. }
  8976. return typeFn.call(this, fn, dict, xref);
  8977. },
  8978. fromIR: function PDFFunction_fromIR(IR) {
  8979. var type = IR[0];
  8980. switch (type) {
  8981. case CONSTRUCT_SAMPLED:
  8982. return this.constructSampledFromIR(IR);
  8983. case CONSTRUCT_INTERPOLATED:
  8984. return this.constructInterpolatedFromIR(IR);
  8985. case CONSTRUCT_STICHED:
  8986. return this.constructStichedFromIR(IR);
  8987. //case CONSTRUCT_POSTSCRIPT:
  8988. default:
  8989. return this.constructPostScriptFromIR(IR);
  8990. }
  8991. },
  8992. parse: function PDFFunction_parse(xref, fn) {
  8993. var IR = this.getIR(xref, fn);
  8994. return this.fromIR(IR);
  8995. },
  8996. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  8997. if (!isArray(fnObj)) {
  8998. // not an array -- parsing as regular function
  8999. return this.parse(xref, fnObj);
  9000. }
  9001. var fnArray = [];
  9002. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  9003. var obj = xref.fetchIfRef(fnObj[j]);
  9004. fnArray.push(PDFFunction.parse(xref, obj));
  9005. }
  9006. return function (src, srcOffset, dest, destOffset) {
  9007. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  9008. fnArray[i](src, srcOffset, dest, destOffset + i);
  9009. }
  9010. };
  9011. },
  9012. constructSampled: function PDFFunction_constructSampled(str, dict) {
  9013. function toMultiArray(arr) {
  9014. var inputLength = arr.length;
  9015. var out = [];
  9016. var index = 0;
  9017. for (var i = 0; i < inputLength; i += 2) {
  9018. out[index] = [arr[i], arr[i + 1]];
  9019. ++index;
  9020. }
  9021. return out;
  9022. }
  9023. var domain = dict.get('Domain');
  9024. var range = dict.get('Range');
  9025. if (!domain || !range) {
  9026. error('No domain or range');
  9027. }
  9028. var inputSize = domain.length / 2;
  9029. var outputSize = range.length / 2;
  9030. domain = toMultiArray(domain);
  9031. range = toMultiArray(range);
  9032. var size = dict.get('Size');
  9033. var bps = dict.get('BitsPerSample');
  9034. var order = dict.get('Order') || 1;
  9035. if (order !== 1) {
  9036. // No description how cubic spline interpolation works in PDF32000:2008
  9037. // As in poppler, ignoring order, linear interpolation may work as good
  9038. info('No support for cubic spline interpolation: ' + order);
  9039. }
  9040. var encode = dict.get('Encode');
  9041. if (!encode) {
  9042. encode = [];
  9043. for (var i = 0; i < inputSize; ++i) {
  9044. encode.push(0);
  9045. encode.push(size[i] - 1);
  9046. }
  9047. }
  9048. encode = toMultiArray(encode);
  9049. var decode = dict.get('Decode');
  9050. if (!decode) {
  9051. decode = range;
  9052. } else {
  9053. decode = toMultiArray(decode);
  9054. }
  9055. var samples = this.getSampleArray(size, outputSize, bps, str);
  9056. return [
  9057. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  9058. outputSize, Math.pow(2, bps) - 1, range
  9059. ];
  9060. },
  9061. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  9062. // See chapter 3, page 109 of the PDF reference
  9063. function interpolate(x, xmin, xmax, ymin, ymax) {
  9064. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  9065. }
  9066. return function constructSampledFromIRResult(src, srcOffset,
  9067. dest, destOffset) {
  9068. // See chapter 3, page 110 of the PDF reference.
  9069. var m = IR[1];
  9070. var domain = IR[2];
  9071. var encode = IR[3];
  9072. var decode = IR[4];
  9073. var samples = IR[5];
  9074. var size = IR[6];
  9075. var n = IR[7];
  9076. //var mask = IR[8];
  9077. var range = IR[9];
  9078. // Building the cube vertices: its part and sample index
  9079. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  9080. var cubeVertices = 1 << m;
  9081. var cubeN = new Float64Array(cubeVertices);
  9082. var cubeVertex = new Uint32Array(cubeVertices);
  9083. var i, j;
  9084. for (j = 0; j < cubeVertices; j++) {
  9085. cubeN[j] = 1;
  9086. }
  9087. var k = n, pos = 1;
  9088. // Map x_i to y_j for 0 <= i < m using the sampled function.
  9089. for (i = 0; i < m; ++i) {
  9090. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  9091. var domain_2i = domain[i][0];
  9092. var domain_2i_1 = domain[i][1];
  9093. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  9094. domain_2i_1);
  9095. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  9096. // Encode_2i, Encode_2i+1)
  9097. var e = interpolate(xi, domain_2i, domain_2i_1,
  9098. encode[i][0], encode[i][1]);
  9099. // e_i' = min(max(e_i, 0), Size_i - 1)
  9100. var size_i = size[i];
  9101. e = Math.min(Math.max(e, 0), size_i - 1);
  9102. // Adjusting the cube: N and vertex sample index
  9103. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  9104. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  9105. var n1 = e - e0; // (e - e0) / (e1 - e0);
  9106. var offset0 = e0 * k;
  9107. var offset1 = offset0 + k; // e1 * k
  9108. for (j = 0; j < cubeVertices; j++) {
  9109. if (j & pos) {
  9110. cubeN[j] *= n1;
  9111. cubeVertex[j] += offset1;
  9112. } else {
  9113. cubeN[j] *= n0;
  9114. cubeVertex[j] += offset0;
  9115. }
  9116. }
  9117. k *= size_i;
  9118. pos <<= 1;
  9119. }
  9120. for (j = 0; j < n; ++j) {
  9121. // Sum all cube vertices' samples portions
  9122. var rj = 0;
  9123. for (i = 0; i < cubeVertices; i++) {
  9124. rj += samples[cubeVertex[i] + j] * cubeN[i];
  9125. }
  9126. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  9127. // Decode_2j, Decode_2j+1)
  9128. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  9129. // y_j = min(max(r_j, range_2j), range_2j+1)
  9130. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  9131. range[j][1]);
  9132. }
  9133. };
  9134. },
  9135. constructInterpolated: function PDFFunction_constructInterpolated(str,
  9136. dict) {
  9137. var c0 = dict.get('C0') || [0];
  9138. var c1 = dict.get('C1') || [1];
  9139. var n = dict.get('N');
  9140. if (!isArray(c0) || !isArray(c1)) {
  9141. error('Illegal dictionary for interpolated function');
  9142. }
  9143. var length = c0.length;
  9144. var diff = [];
  9145. for (var i = 0; i < length; ++i) {
  9146. diff.push(c1[i] - c0[i]);
  9147. }
  9148. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  9149. },
  9150. constructInterpolatedFromIR:
  9151. function PDFFunction_constructInterpolatedFromIR(IR) {
  9152. var c0 = IR[1];
  9153. var diff = IR[2];
  9154. var n = IR[3];
  9155. var length = diff.length;
  9156. return function constructInterpolatedFromIRResult(src, srcOffset,
  9157. dest, destOffset) {
  9158. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  9159. for (var j = 0; j < length; ++j) {
  9160. dest[destOffset + j] = c0[j] + (x * diff[j]);
  9161. }
  9162. };
  9163. },
  9164. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  9165. var domain = dict.get('Domain');
  9166. if (!domain) {
  9167. error('No domain');
  9168. }
  9169. var inputSize = domain.length / 2;
  9170. if (inputSize !== 1) {
  9171. error('Bad domain for stiched function');
  9172. }
  9173. var fnRefs = dict.get('Functions');
  9174. var fns = [];
  9175. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  9176. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  9177. }
  9178. var bounds = dict.get('Bounds');
  9179. var encode = dict.get('Encode');
  9180. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  9181. },
  9182. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  9183. var domain = IR[1];
  9184. var bounds = IR[2];
  9185. var encode = IR[3];
  9186. var fnsIR = IR[4];
  9187. var fns = [];
  9188. var tmpBuf = new Float32Array(1);
  9189. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  9190. fns.push(PDFFunction.fromIR(fnsIR[i]));
  9191. }
  9192. return function constructStichedFromIRResult(src, srcOffset,
  9193. dest, destOffset) {
  9194. var clip = function constructStichedFromIRClip(v, min, max) {
  9195. if (v > max) {
  9196. v = max;
  9197. } else if (v < min) {
  9198. v = min;
  9199. }
  9200. return v;
  9201. };
  9202. // clip to domain
  9203. var v = clip(src[srcOffset], domain[0], domain[1]);
  9204. // calulate which bound the value is in
  9205. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  9206. if (v < bounds[i]) {
  9207. break;
  9208. }
  9209. }
  9210. // encode value into domain of function
  9211. var dmin = domain[0];
  9212. if (i > 0) {
  9213. dmin = bounds[i - 1];
  9214. }
  9215. var dmax = domain[1];
  9216. if (i < bounds.length) {
  9217. dmax = bounds[i];
  9218. }
  9219. var rmin = encode[2 * i];
  9220. var rmax = encode[2 * i + 1];
  9221. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  9222. // call the appropriate function
  9223. fns[i](tmpBuf, 0, dest, destOffset);
  9224. };
  9225. },
  9226. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  9227. xref) {
  9228. var domain = dict.get('Domain');
  9229. var range = dict.get('Range');
  9230. if (!domain) {
  9231. error('No domain.');
  9232. }
  9233. if (!range) {
  9234. error('No range.');
  9235. }
  9236. var lexer = new PostScriptLexer(fn);
  9237. var parser = new PostScriptParser(lexer);
  9238. var code = parser.parse();
  9239. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  9240. },
  9241. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  9242. IR) {
  9243. var domain = IR[1];
  9244. var range = IR[2];
  9245. var code = IR[3];
  9246. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  9247. if (compiled) {
  9248. // Compiled function consists of simple expressions such as addition,
  9249. // subtraction, Math.max, and also contains 'var' and 'return'
  9250. // statements. See the generation in the PostScriptCompiler below.
  9251. /*jshint -W054 */
  9252. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  9253. }
  9254. info('Unable to compile PS function');
  9255. var numOutputs = range.length >> 1;
  9256. var numInputs = domain.length >> 1;
  9257. var evaluator = new PostScriptEvaluator(code);
  9258. // Cache the values for a big speed up, the cache size is limited though
  9259. // since the number of possible values can be huge from a PS function.
  9260. var cache = {};
  9261. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  9262. // seen in our tests.
  9263. var MAX_CACHE_SIZE = 2048 * 4;
  9264. var cache_available = MAX_CACHE_SIZE;
  9265. var tmpBuf = new Float32Array(numInputs);
  9266. return function constructPostScriptFromIRResult(src, srcOffset,
  9267. dest, destOffset) {
  9268. var i, value;
  9269. var key = '';
  9270. var input = tmpBuf;
  9271. for (i = 0; i < numInputs; i++) {
  9272. value = src[srcOffset + i];
  9273. input[i] = value;
  9274. key += value + '_';
  9275. }
  9276. var cachedValue = cache[key];
  9277. if (cachedValue !== undefined) {
  9278. cachedValue.set(dest, destOffset);
  9279. return;
  9280. }
  9281. var output = new Float32Array(numOutputs);
  9282. var stack = evaluator.execute(input);
  9283. var stackIndex = stack.length - numOutputs;
  9284. for (i = 0; i < numOutputs; i++) {
  9285. value = stack[stackIndex + i];
  9286. var bound = range[i * 2];
  9287. if (value < bound) {
  9288. value = bound;
  9289. } else {
  9290. bound = range[i * 2 +1];
  9291. if (value > bound) {
  9292. value = bound;
  9293. }
  9294. }
  9295. output[i] = value;
  9296. }
  9297. if (cache_available > 0) {
  9298. cache_available--;
  9299. cache[key] = output;
  9300. }
  9301. output.set(dest, destOffset);
  9302. };
  9303. }
  9304. };
  9305. })();
  9306. function isPDFFunction(v) {
  9307. var fnDict;
  9308. if (typeof v !== 'object') {
  9309. return false;
  9310. } else if (isDict(v)) {
  9311. fnDict = v;
  9312. } else if (isStream(v)) {
  9313. fnDict = v.dict;
  9314. } else {
  9315. return false;
  9316. }
  9317. return fnDict.has('FunctionType');
  9318. }
  9319. var PostScriptStack = (function PostScriptStackClosure() {
  9320. var MAX_STACK_SIZE = 100;
  9321. function PostScriptStack(initialStack) {
  9322. this.stack = !initialStack ? [] :
  9323. Array.prototype.slice.call(initialStack, 0);
  9324. }
  9325. PostScriptStack.prototype = {
  9326. push: function PostScriptStack_push(value) {
  9327. if (this.stack.length >= MAX_STACK_SIZE) {
  9328. error('PostScript function stack overflow.');
  9329. }
  9330. this.stack.push(value);
  9331. },
  9332. pop: function PostScriptStack_pop() {
  9333. if (this.stack.length <= 0) {
  9334. error('PostScript function stack underflow.');
  9335. }
  9336. return this.stack.pop();
  9337. },
  9338. copy: function PostScriptStack_copy(n) {
  9339. if (this.stack.length + n >= MAX_STACK_SIZE) {
  9340. error('PostScript function stack overflow.');
  9341. }
  9342. var stack = this.stack;
  9343. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  9344. stack.push(stack[i]);
  9345. }
  9346. },
  9347. index: function PostScriptStack_index(n) {
  9348. this.push(this.stack[this.stack.length - n - 1]);
  9349. },
  9350. // rotate the last n stack elements p times
  9351. roll: function PostScriptStack_roll(n, p) {
  9352. var stack = this.stack;
  9353. var l = stack.length - n;
  9354. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  9355. for (i = l, j = r; i < j; i++, j--) {
  9356. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9357. }
  9358. for (i = l, j = c - 1; i < j; i++, j--) {
  9359. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9360. }
  9361. for (i = c, j = r; i < j; i++, j--) {
  9362. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9363. }
  9364. }
  9365. };
  9366. return PostScriptStack;
  9367. })();
  9368. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  9369. function PostScriptEvaluator(operators) {
  9370. this.operators = operators;
  9371. }
  9372. PostScriptEvaluator.prototype = {
  9373. execute: function PostScriptEvaluator_execute(initialStack) {
  9374. var stack = new PostScriptStack(initialStack);
  9375. var counter = 0;
  9376. var operators = this.operators;
  9377. var length = operators.length;
  9378. var operator, a, b;
  9379. while (counter < length) {
  9380. operator = operators[counter++];
  9381. if (typeof operator === 'number') {
  9382. // Operator is really an operand and should be pushed to the stack.
  9383. stack.push(operator);
  9384. continue;
  9385. }
  9386. switch (operator) {
  9387. // non standard ps operators
  9388. case 'jz': // jump if false
  9389. b = stack.pop();
  9390. a = stack.pop();
  9391. if (!a) {
  9392. counter = b;
  9393. }
  9394. break;
  9395. case 'j': // jump
  9396. a = stack.pop();
  9397. counter = a;
  9398. break;
  9399. // all ps operators in alphabetical order (excluding if/ifelse)
  9400. case 'abs':
  9401. a = stack.pop();
  9402. stack.push(Math.abs(a));
  9403. break;
  9404. case 'add':
  9405. b = stack.pop();
  9406. a = stack.pop();
  9407. stack.push(a + b);
  9408. break;
  9409. case 'and':
  9410. b = stack.pop();
  9411. a = stack.pop();
  9412. if (isBool(a) && isBool(b)) {
  9413. stack.push(a && b);
  9414. } else {
  9415. stack.push(a & b);
  9416. }
  9417. break;
  9418. case 'atan':
  9419. a = stack.pop();
  9420. stack.push(Math.atan(a));
  9421. break;
  9422. case 'bitshift':
  9423. b = stack.pop();
  9424. a = stack.pop();
  9425. if (a > 0) {
  9426. stack.push(a << b);
  9427. } else {
  9428. stack.push(a >> b);
  9429. }
  9430. break;
  9431. case 'ceiling':
  9432. a = stack.pop();
  9433. stack.push(Math.ceil(a));
  9434. break;
  9435. case 'copy':
  9436. a = stack.pop();
  9437. stack.copy(a);
  9438. break;
  9439. case 'cos':
  9440. a = stack.pop();
  9441. stack.push(Math.cos(a));
  9442. break;
  9443. case 'cvi':
  9444. a = stack.pop() | 0;
  9445. stack.push(a);
  9446. break;
  9447. case 'cvr':
  9448. // noop
  9449. break;
  9450. case 'div':
  9451. b = stack.pop();
  9452. a = stack.pop();
  9453. stack.push(a / b);
  9454. break;
  9455. case 'dup':
  9456. stack.copy(1);
  9457. break;
  9458. case 'eq':
  9459. b = stack.pop();
  9460. a = stack.pop();
  9461. stack.push(a === b);
  9462. break;
  9463. case 'exch':
  9464. stack.roll(2, 1);
  9465. break;
  9466. case 'exp':
  9467. b = stack.pop();
  9468. a = stack.pop();
  9469. stack.push(Math.pow(a, b));
  9470. break;
  9471. case 'false':
  9472. stack.push(false);
  9473. break;
  9474. case 'floor':
  9475. a = stack.pop();
  9476. stack.push(Math.floor(a));
  9477. break;
  9478. case 'ge':
  9479. b = stack.pop();
  9480. a = stack.pop();
  9481. stack.push(a >= b);
  9482. break;
  9483. case 'gt':
  9484. b = stack.pop();
  9485. a = stack.pop();
  9486. stack.push(a > b);
  9487. break;
  9488. case 'idiv':
  9489. b = stack.pop();
  9490. a = stack.pop();
  9491. stack.push((a / b) | 0);
  9492. break;
  9493. case 'index':
  9494. a = stack.pop();
  9495. stack.index(a);
  9496. break;
  9497. case 'le':
  9498. b = stack.pop();
  9499. a = stack.pop();
  9500. stack.push(a <= b);
  9501. break;
  9502. case 'ln':
  9503. a = stack.pop();
  9504. stack.push(Math.log(a));
  9505. break;
  9506. case 'log':
  9507. a = stack.pop();
  9508. stack.push(Math.log(a) / Math.LN10);
  9509. break;
  9510. case 'lt':
  9511. b = stack.pop();
  9512. a = stack.pop();
  9513. stack.push(a < b);
  9514. break;
  9515. case 'mod':
  9516. b = stack.pop();
  9517. a = stack.pop();
  9518. stack.push(a % b);
  9519. break;
  9520. case 'mul':
  9521. b = stack.pop();
  9522. a = stack.pop();
  9523. stack.push(a * b);
  9524. break;
  9525. case 'ne':
  9526. b = stack.pop();
  9527. a = stack.pop();
  9528. stack.push(a !== b);
  9529. break;
  9530. case 'neg':
  9531. a = stack.pop();
  9532. stack.push(-a);
  9533. break;
  9534. case 'not':
  9535. a = stack.pop();
  9536. if (isBool(a)) {
  9537. stack.push(!a);
  9538. } else {
  9539. stack.push(~a);
  9540. }
  9541. break;
  9542. case 'or':
  9543. b = stack.pop();
  9544. a = stack.pop();
  9545. if (isBool(a) && isBool(b)) {
  9546. stack.push(a || b);
  9547. } else {
  9548. stack.push(a | b);
  9549. }
  9550. break;
  9551. case 'pop':
  9552. stack.pop();
  9553. break;
  9554. case 'roll':
  9555. b = stack.pop();
  9556. a = stack.pop();
  9557. stack.roll(a, b);
  9558. break;
  9559. case 'round':
  9560. a = stack.pop();
  9561. stack.push(Math.round(a));
  9562. break;
  9563. case 'sin':
  9564. a = stack.pop();
  9565. stack.push(Math.sin(a));
  9566. break;
  9567. case 'sqrt':
  9568. a = stack.pop();
  9569. stack.push(Math.sqrt(a));
  9570. break;
  9571. case 'sub':
  9572. b = stack.pop();
  9573. a = stack.pop();
  9574. stack.push(a - b);
  9575. break;
  9576. case 'true':
  9577. stack.push(true);
  9578. break;
  9579. case 'truncate':
  9580. a = stack.pop();
  9581. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  9582. stack.push(a);
  9583. break;
  9584. case 'xor':
  9585. b = stack.pop();
  9586. a = stack.pop();
  9587. if (isBool(a) && isBool(b)) {
  9588. stack.push(a !== b);
  9589. } else {
  9590. stack.push(a ^ b);
  9591. }
  9592. break;
  9593. default:
  9594. error('Unknown operator ' + operator);
  9595. break;
  9596. }
  9597. }
  9598. return stack.stack;
  9599. }
  9600. };
  9601. return PostScriptEvaluator;
  9602. })();
  9603. // Most of the PDFs functions consist of simple operations such as:
  9604. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  9605. //
  9606. // We can compile most of such programs, and at the same moment, we can
  9607. // optimize some expressions using basic math properties. Keeping track of
  9608. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  9609. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  9610. function AstNode(type) {
  9611. this.type = type;
  9612. }
  9613. AstNode.prototype.visit = function (visitor) {
  9614. throw new Error('abstract method');
  9615. };
  9616. function AstArgument(index, min, max) {
  9617. AstNode.call(this, 'args');
  9618. this.index = index;
  9619. this.min = min;
  9620. this.max = max;
  9621. }
  9622. AstArgument.prototype = Object.create(AstNode.prototype);
  9623. AstArgument.prototype.visit = function (visitor) {
  9624. visitor.visitArgument(this);
  9625. };
  9626. function AstLiteral(number) {
  9627. AstNode.call(this, 'literal');
  9628. this.number = number;
  9629. this.min = number;
  9630. this.max = number;
  9631. }
  9632. AstLiteral.prototype = Object.create(AstNode.prototype);
  9633. AstLiteral.prototype.visit = function (visitor) {
  9634. visitor.visitLiteral(this);
  9635. };
  9636. function AstBinaryOperation(op, arg1, arg2, min, max) {
  9637. AstNode.call(this, 'binary');
  9638. this.op = op;
  9639. this.arg1 = arg1;
  9640. this.arg2 = arg2;
  9641. this.min = min;
  9642. this.max = max;
  9643. }
  9644. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  9645. AstBinaryOperation.prototype.visit = function (visitor) {
  9646. visitor.visitBinaryOperation(this);
  9647. };
  9648. function AstMin(arg, max) {
  9649. AstNode.call(this, 'max');
  9650. this.arg = arg;
  9651. this.min = arg.min;
  9652. this.max = max;
  9653. }
  9654. AstMin.prototype = Object.create(AstNode.prototype);
  9655. AstMin.prototype.visit = function (visitor) {
  9656. visitor.visitMin(this);
  9657. };
  9658. function AstVariable(index, min, max) {
  9659. AstNode.call(this, 'var');
  9660. this.index = index;
  9661. this.min = min;
  9662. this.max = max;
  9663. }
  9664. AstVariable.prototype = Object.create(AstNode.prototype);
  9665. AstVariable.prototype.visit = function (visitor) {
  9666. visitor.visitVariable(this);
  9667. };
  9668. function AstVariableDefinition(variable, arg) {
  9669. AstNode.call(this, 'definition');
  9670. this.variable = variable;
  9671. this.arg = arg;
  9672. }
  9673. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  9674. AstVariableDefinition.prototype.visit = function (visitor) {
  9675. visitor.visitVariableDefinition(this);
  9676. };
  9677. function ExpressionBuilderVisitor() {
  9678. this.parts = [];
  9679. }
  9680. ExpressionBuilderVisitor.prototype = {
  9681. visitArgument: function (arg) {
  9682. this.parts.push('Math.max(', arg.min, ', Math.min(',
  9683. arg.max, ', src[srcOffset + ', arg.index, ']))');
  9684. },
  9685. visitVariable: function (variable) {
  9686. this.parts.push('v', variable.index);
  9687. },
  9688. visitLiteral: function (literal) {
  9689. this.parts.push(literal.number);
  9690. },
  9691. visitBinaryOperation: function (operation) {
  9692. this.parts.push('(');
  9693. operation.arg1.visit(this);
  9694. this.parts.push(' ', operation.op, ' ');
  9695. operation.arg2.visit(this);
  9696. this.parts.push(')');
  9697. },
  9698. visitVariableDefinition: function (definition) {
  9699. this.parts.push('var ');
  9700. definition.variable.visit(this);
  9701. this.parts.push(' = ');
  9702. definition.arg.visit(this);
  9703. this.parts.push(';');
  9704. },
  9705. visitMin: function (max) {
  9706. this.parts.push('Math.min(');
  9707. max.arg.visit(this);
  9708. this.parts.push(', ', max.max, ')');
  9709. },
  9710. toString: function () {
  9711. return this.parts.join('');
  9712. }
  9713. };
  9714. function buildAddOperation(num1, num2) {
  9715. if (num2.type === 'literal' && num2.number === 0) {
  9716. // optimization: second operand is 0
  9717. return num1;
  9718. }
  9719. if (num1.type === 'literal' && num1.number === 0) {
  9720. // optimization: first operand is 0
  9721. return num2;
  9722. }
  9723. if (num2.type === 'literal' && num1.type === 'literal') {
  9724. // optimization: operands operand are literals
  9725. return new AstLiteral(num1.number + num2.number);
  9726. }
  9727. return new AstBinaryOperation('+', num1, num2,
  9728. num1.min + num2.min, num1.max + num2.max);
  9729. }
  9730. function buildMulOperation(num1, num2) {
  9731. if (num2.type === 'literal') {
  9732. // optimization: second operands is a literal...
  9733. if (num2.number === 0) {
  9734. return new AstLiteral(0); // and it's 0
  9735. } else if (num2.number === 1) {
  9736. return num1; // and it's 1
  9737. } else if (num1.type === 'literal') {
  9738. // ... and first operands is a literal too
  9739. return new AstLiteral(num1.number * num2.number);
  9740. }
  9741. }
  9742. if (num1.type === 'literal') {
  9743. // optimization: first operands is a literal...
  9744. if (num1.number === 0) {
  9745. return new AstLiteral(0); // and it's 0
  9746. } else if (num1.number === 1) {
  9747. return num2; // and it's 1
  9748. }
  9749. }
  9750. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  9751. num1.max * num2.min, num1.max * num2.max);
  9752. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  9753. num1.max * num2.min, num1.max * num2.max);
  9754. return new AstBinaryOperation('*', num1, num2, min, max);
  9755. }
  9756. function buildSubOperation(num1, num2) {
  9757. if (num2.type === 'literal') {
  9758. // optimization: second operands is a literal...
  9759. if (num2.number === 0) {
  9760. return num1; // ... and it's 0
  9761. } else if (num1.type === 'literal') {
  9762. // ... and first operands is a literal too
  9763. return new AstLiteral(num1.number - num2.number);
  9764. }
  9765. }
  9766. if (num2.type === 'binary' && num2.op === '-' &&
  9767. num1.type === 'literal' && num1.number === 1 &&
  9768. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  9769. // optimization for case: 1 - (1 - x)
  9770. return num2.arg2;
  9771. }
  9772. return new AstBinaryOperation('-', num1, num2,
  9773. num1.min - num2.max, num1.max - num2.min);
  9774. }
  9775. function buildMinOperation(num1, max) {
  9776. if (num1.min >= max) {
  9777. // optimization: num1 min value is not less than required max
  9778. return new AstLiteral(max); // just returning max
  9779. } else if (num1.max <= max) {
  9780. // optimization: num1 max value is not greater than required max
  9781. return num1; // just returning an argument
  9782. }
  9783. return new AstMin(num1, max);
  9784. }
  9785. function PostScriptCompiler() {}
  9786. PostScriptCompiler.prototype = {
  9787. compile: function PostScriptCompiler_compile(code, domain, range) {
  9788. var stack = [];
  9789. var i, ii;
  9790. var instructions = [];
  9791. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  9792. var lastRegister = 0;
  9793. var n, j, min, max;
  9794. var num1, num2, ast1, ast2, tmpVar, item;
  9795. for (i = 0; i < inputSize; i++) {
  9796. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  9797. }
  9798. for (i = 0, ii = code.length; i < ii; i++) {
  9799. item = code[i];
  9800. if (typeof item === 'number') {
  9801. stack.push(new AstLiteral(item));
  9802. continue;
  9803. }
  9804. switch (item) {
  9805. case 'add':
  9806. if (stack.length < 2) {
  9807. return null;
  9808. }
  9809. num2 = stack.pop();
  9810. num1 = stack.pop();
  9811. stack.push(buildAddOperation(num1, num2));
  9812. break;
  9813. case 'cvr':
  9814. if (stack.length < 1) {
  9815. return null;
  9816. }
  9817. break;
  9818. case 'mul':
  9819. if (stack.length < 2) {
  9820. return null;
  9821. }
  9822. num2 = stack.pop();
  9823. num1 = stack.pop();
  9824. stack.push(buildMulOperation(num1, num2));
  9825. break;
  9826. case 'sub':
  9827. if (stack.length < 2) {
  9828. return null;
  9829. }
  9830. num2 = stack.pop();
  9831. num1 = stack.pop();
  9832. stack.push(buildSubOperation(num1, num2));
  9833. break;
  9834. case 'exch':
  9835. if (stack.length < 2) {
  9836. return null;
  9837. }
  9838. ast1 = stack.pop(); ast2 = stack.pop();
  9839. stack.push(ast1, ast2);
  9840. break;
  9841. case 'pop':
  9842. if (stack.length < 1) {
  9843. return null;
  9844. }
  9845. stack.pop();
  9846. break;
  9847. case 'index':
  9848. if (stack.length < 1) {
  9849. return null;
  9850. }
  9851. num1 = stack.pop();
  9852. if (num1.type !== 'literal') {
  9853. return null;
  9854. }
  9855. n = num1.number;
  9856. if (n < 0 || (n|0) !== n || stack.length < n) {
  9857. return null;
  9858. }
  9859. ast1 = stack[stack.length - n - 1];
  9860. if (ast1.type === 'literal' || ast1.type === 'var') {
  9861. stack.push(ast1);
  9862. break;
  9863. }
  9864. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9865. stack[stack.length - n - 1] = tmpVar;
  9866. stack.push(tmpVar);
  9867. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9868. break;
  9869. case 'dup':
  9870. if (stack.length < 1) {
  9871. return null;
  9872. }
  9873. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  9874. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  9875. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  9876. // special case of the commands sequence for the min operation
  9877. num1 = stack.pop();
  9878. stack.push(buildMinOperation(num1, code[i + 1]));
  9879. i += 6;
  9880. break;
  9881. }
  9882. ast1 = stack[stack.length - 1];
  9883. if (ast1.type === 'literal' || ast1.type === 'var') {
  9884. // we don't have to save into intermediate variable a literal or
  9885. // variable.
  9886. stack.push(ast1);
  9887. break;
  9888. }
  9889. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9890. stack[stack.length - 1] = tmpVar;
  9891. stack.push(tmpVar);
  9892. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9893. break;
  9894. case 'roll':
  9895. if (stack.length < 2) {
  9896. return null;
  9897. }
  9898. num2 = stack.pop();
  9899. num1 = stack.pop();
  9900. if (num2.type !== 'literal' || num1.type !== 'literal') {
  9901. // both roll operands must be numbers
  9902. return null;
  9903. }
  9904. j = num2.number;
  9905. n = num1.number;
  9906. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  9907. // ... and integers
  9908. return null;
  9909. }
  9910. j = ((j % n) + n) % n;
  9911. if (j === 0) {
  9912. break; // just skipping -- there are nothing to rotate
  9913. }
  9914. Array.prototype.push.apply(stack,
  9915. stack.splice(stack.length - n, n - j));
  9916. break;
  9917. default:
  9918. return null; // unsupported operator
  9919. }
  9920. }
  9921. if (stack.length !== outputSize) {
  9922. return null;
  9923. }
  9924. var result = [];
  9925. instructions.forEach(function (instruction) {
  9926. var statementBuilder = new ExpressionBuilderVisitor();
  9927. instruction.visit(statementBuilder);
  9928. result.push(statementBuilder.toString());
  9929. });
  9930. stack.forEach(function (expr, i) {
  9931. var statementBuilder = new ExpressionBuilderVisitor();
  9932. expr.visit(statementBuilder);
  9933. var min = range[i * 2], max = range[i * 2 + 1];
  9934. var out = [statementBuilder.toString()];
  9935. if (min > expr.min) {
  9936. out.unshift('Math.max(', min, ', ');
  9937. out.push(')');
  9938. }
  9939. if (max < expr.max) {
  9940. out.unshift('Math.min(', max, ', ');
  9941. out.push(')');
  9942. }
  9943. out.unshift('dest[destOffset + ', i, '] = ');
  9944. out.push(';');
  9945. result.push(out.join(''));
  9946. });
  9947. return result.join('\n');
  9948. }
  9949. };
  9950. return PostScriptCompiler;
  9951. })();
  9952. var ColorSpace = (function ColorSpaceClosure() {
  9953. // Constructor should define this.numComps, this.defaultColor, this.name
  9954. function ColorSpace() {
  9955. error('should not call ColorSpace constructor');
  9956. }
  9957. ColorSpace.prototype = {
  9958. /**
  9959. * Converts the color value to the RGB color. The color components are
  9960. * located in the src array starting from the srcOffset. Returns the array
  9961. * of the rgb components, each value ranging from [0,255].
  9962. */
  9963. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  9964. var rgb = new Uint8Array(3);
  9965. this.getRgbItem(src, srcOffset, rgb, 0);
  9966. return rgb;
  9967. },
  9968. /**
  9969. * Converts the color value to the RGB color, similar to the getRgb method.
  9970. * The result placed into the dest array starting from the destOffset.
  9971. */
  9972. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  9973. dest, destOffset) {
  9974. error('Should not call ColorSpace.getRgbItem');
  9975. },
  9976. /**
  9977. * Converts the specified number of the color values to the RGB colors.
  9978. * The colors are located in the src array starting from the srcOffset.
  9979. * The result is placed into the dest array starting from the destOffset.
  9980. * The src array items shall be in [0,2^bits) range, the dest array items
  9981. * will be in [0,255] range. alpha01 indicates how many alpha components
  9982. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  9983. * array).
  9984. */
  9985. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  9986. dest, destOffset, bits,
  9987. alpha01) {
  9988. error('Should not call ColorSpace.getRgbBuffer');
  9989. },
  9990. /**
  9991. * Determines the number of bytes required to store the result of the
  9992. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  9993. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  9994. */
  9995. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  9996. alpha01) {
  9997. error('Should not call ColorSpace.getOutputLength');
  9998. },
  9999. /**
  10000. * Returns true if source data will be equal the result/output data.
  10001. */
  10002. isPassthrough: function ColorSpace_isPassthrough(bits) {
  10003. return false;
  10004. },
  10005. /**
  10006. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  10007. * how many alpha components there are in the dest array; it will be either
  10008. * 0 (RGB array) or 1 (RGBA array).
  10009. */
  10010. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  10011. originalHeight, width, height,
  10012. actualHeight, bpc, comps, alpha01) {
  10013. var count = originalWidth * originalHeight;
  10014. var rgbBuf = null;
  10015. var numComponentColors = 1 << bpc;
  10016. var needsResizing = originalHeight !== height || originalWidth !== width;
  10017. var i, ii;
  10018. if (this.isPassthrough(bpc)) {
  10019. rgbBuf = comps;
  10020. } else if (this.numComps === 1 && count > numComponentColors &&
  10021. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  10022. // Optimization: create a color map when there is just one component and
  10023. // we are converting more colors than the size of the color map. We
  10024. // don't build the map if the colorspace is gray or rgb since those
  10025. // methods are faster than building a map. This mainly offers big speed
  10026. // ups for indexed and alternate colorspaces.
  10027. //
  10028. // TODO it may be worth while to cache the color map. While running
  10029. // testing I never hit a cache so I will leave that out for now (perhaps
  10030. // we are reparsing colorspaces too much?).
  10031. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  10032. new Uint16Array(numComponentColors);
  10033. var key;
  10034. for (i = 0; i < numComponentColors; i++) {
  10035. allColors[i] = i;
  10036. }
  10037. var colorMap = new Uint8Array(numComponentColors * 3);
  10038. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  10039. /* alpha01 = */ 0);
  10040. var destPos, rgbPos;
  10041. if (!needsResizing) {
  10042. // Fill in the RGB values directly into |dest|.
  10043. destPos = 0;
  10044. for (i = 0; i < count; ++i) {
  10045. key = comps[i] * 3;
  10046. dest[destPos++] = colorMap[key];
  10047. dest[destPos++] = colorMap[key + 1];
  10048. dest[destPos++] = colorMap[key + 2];
  10049. destPos += alpha01;
  10050. }
  10051. } else {
  10052. rgbBuf = new Uint8Array(count * 3);
  10053. rgbPos = 0;
  10054. for (i = 0; i < count; ++i) {
  10055. key = comps[i] * 3;
  10056. rgbBuf[rgbPos++] = colorMap[key];
  10057. rgbBuf[rgbPos++] = colorMap[key + 1];
  10058. rgbBuf[rgbPos++] = colorMap[key + 2];
  10059. }
  10060. }
  10061. } else {
  10062. if (!needsResizing) {
  10063. // Fill in the RGB values directly into |dest|.
  10064. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  10065. alpha01);
  10066. } else {
  10067. rgbBuf = new Uint8Array(count * 3);
  10068. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  10069. /* alpha01 = */ 0);
  10070. }
  10071. }
  10072. if (rgbBuf) {
  10073. if (needsResizing) {
  10074. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  10075. height, dest, alpha01);
  10076. } else {
  10077. rgbPos = 0;
  10078. destPos = 0;
  10079. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  10080. dest[destPos++] = rgbBuf[rgbPos++];
  10081. dest[destPos++] = rgbBuf[rgbPos++];
  10082. dest[destPos++] = rgbBuf[rgbPos++];
  10083. destPos += alpha01;
  10084. }
  10085. }
  10086. }
  10087. },
  10088. /**
  10089. * True if the colorspace has components in the default range of [0, 1].
  10090. * This should be true for all colorspaces except for lab color spaces
  10091. * which are [0,100], [-128, 127], [-128, 127].
  10092. */
  10093. usesZeroToOneRange: true
  10094. };
  10095. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  10096. var IR = ColorSpace.parseToIR(cs, xref, res);
  10097. if (IR instanceof AlternateCS) {
  10098. return IR;
  10099. }
  10100. return ColorSpace.fromIR(IR);
  10101. };
  10102. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  10103. var name = isArray(IR) ? IR[0] : IR;
  10104. var whitePoint, blackPoint;
  10105. switch (name) {
  10106. case 'DeviceGrayCS':
  10107. return this.singletons.gray;
  10108. case 'DeviceRgbCS':
  10109. return this.singletons.rgb;
  10110. case 'DeviceCmykCS':
  10111. return this.singletons.cmyk;
  10112. case 'CalGrayCS':
  10113. whitePoint = IR[1].WhitePoint;
  10114. blackPoint = IR[1].BlackPoint;
  10115. var gamma = IR[1].Gamma;
  10116. return new CalGrayCS(whitePoint, blackPoint, gamma);
  10117. case 'PatternCS':
  10118. var basePatternCS = IR[1];
  10119. if (basePatternCS) {
  10120. basePatternCS = ColorSpace.fromIR(basePatternCS);
  10121. }
  10122. return new PatternCS(basePatternCS);
  10123. case 'IndexedCS':
  10124. var baseIndexedCS = IR[1];
  10125. var hiVal = IR[2];
  10126. var lookup = IR[3];
  10127. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  10128. case 'AlternateCS':
  10129. var numComps = IR[1];
  10130. var alt = IR[2];
  10131. var tintFnIR = IR[3];
  10132. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  10133. PDFFunction.fromIR(tintFnIR));
  10134. case 'LabCS':
  10135. whitePoint = IR[1].WhitePoint;
  10136. blackPoint = IR[1].BlackPoint;
  10137. var range = IR[1].Range;
  10138. return new LabCS(whitePoint, blackPoint, range);
  10139. default:
  10140. error('Unkown name ' + name);
  10141. }
  10142. return null;
  10143. };
  10144. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  10145. if (isName(cs)) {
  10146. var colorSpaces = res.get('ColorSpace');
  10147. if (isDict(colorSpaces)) {
  10148. var refcs = colorSpaces.get(cs.name);
  10149. if (refcs) {
  10150. cs = refcs;
  10151. }
  10152. }
  10153. }
  10154. cs = xref.fetchIfRef(cs);
  10155. var mode;
  10156. if (isName(cs)) {
  10157. mode = cs.name;
  10158. this.mode = mode;
  10159. switch (mode) {
  10160. case 'DeviceGray':
  10161. case 'G':
  10162. return 'DeviceGrayCS';
  10163. case 'DeviceRGB':
  10164. case 'RGB':
  10165. return 'DeviceRgbCS';
  10166. case 'DeviceCMYK':
  10167. case 'CMYK':
  10168. return 'DeviceCmykCS';
  10169. case 'Pattern':
  10170. return ['PatternCS', null];
  10171. default:
  10172. error('unrecognized colorspace ' + mode);
  10173. }
  10174. } else if (isArray(cs)) {
  10175. mode = cs[0].name;
  10176. this.mode = mode;
  10177. var numComps, params;
  10178. switch (mode) {
  10179. case 'DeviceGray':
  10180. case 'G':
  10181. return 'DeviceGrayCS';
  10182. case 'DeviceRGB':
  10183. case 'RGB':
  10184. return 'DeviceRgbCS';
  10185. case 'DeviceCMYK':
  10186. case 'CMYK':
  10187. return 'DeviceCmykCS';
  10188. case 'CalGray':
  10189. params = cs[1].getAll();
  10190. return ['CalGrayCS', params];
  10191. case 'CalRGB':
  10192. return 'DeviceRgbCS';
  10193. case 'ICCBased':
  10194. var stream = xref.fetchIfRef(cs[1]);
  10195. var dict = stream.dict;
  10196. numComps = dict.get('N');
  10197. if (numComps === 1) {
  10198. return 'DeviceGrayCS';
  10199. } else if (numComps === 3) {
  10200. return 'DeviceRgbCS';
  10201. } else if (numComps === 4) {
  10202. return 'DeviceCmykCS';
  10203. }
  10204. break;
  10205. case 'Pattern':
  10206. var basePatternCS = cs[1];
  10207. if (basePatternCS) {
  10208. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  10209. }
  10210. return ['PatternCS', basePatternCS];
  10211. case 'Indexed':
  10212. case 'I':
  10213. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  10214. var hiVal = cs[2] + 1;
  10215. var lookup = xref.fetchIfRef(cs[3]);
  10216. if (isStream(lookup)) {
  10217. lookup = lookup.getBytes();
  10218. }
  10219. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  10220. case 'Separation':
  10221. case 'DeviceN':
  10222. var name = cs[1];
  10223. numComps = 1;
  10224. if (isName(name)) {
  10225. numComps = 1;
  10226. } else if (isArray(name)) {
  10227. numComps = name.length;
  10228. }
  10229. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  10230. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  10231. return ['AlternateCS', numComps, alt, tintFnIR];
  10232. case 'Lab':
  10233. params = cs[1].getAll();
  10234. return ['LabCS', params];
  10235. default:
  10236. error('unimplemented color space object "' + mode + '"');
  10237. }
  10238. } else {
  10239. error('unrecognized color space object: "' + cs + '"');
  10240. }
  10241. return null;
  10242. };
  10243. /**
  10244. * Checks if a decode map matches the default decode map for a color space.
  10245. * This handles the general decode maps where there are two values per
  10246. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  10247. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  10248. * slightly different.
  10249. * @param {Array} decode Decode map (usually from an image).
  10250. * @param {Number} n Number of components the color space has.
  10251. */
  10252. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  10253. if (!decode) {
  10254. return true;
  10255. }
  10256. if (n * 2 !== decode.length) {
  10257. warn('The decode map is not the correct length');
  10258. return true;
  10259. }
  10260. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  10261. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  10262. return false;
  10263. }
  10264. }
  10265. return true;
  10266. };
  10267. ColorSpace.singletons = {
  10268. get gray() {
  10269. return shadow(this, 'gray', new DeviceGrayCS());
  10270. },
  10271. get rgb() {
  10272. return shadow(this, 'rgb', new DeviceRgbCS());
  10273. },
  10274. get cmyk() {
  10275. return shadow(this, 'cmyk', new DeviceCmykCS());
  10276. }
  10277. };
  10278. return ColorSpace;
  10279. })();
  10280. /**
  10281. * Alternate color space handles both Separation and DeviceN color spaces. A
  10282. * Separation color space is actually just a DeviceN with one color component.
  10283. * Both color spaces use a tinting function to convert colors to a base color
  10284. * space.
  10285. */
  10286. var AlternateCS = (function AlternateCSClosure() {
  10287. function AlternateCS(numComps, base, tintFn) {
  10288. this.name = 'Alternate';
  10289. this.numComps = numComps;
  10290. this.defaultColor = new Float32Array(numComps);
  10291. for (var i = 0; i < numComps; ++i) {
  10292. this.defaultColor[i] = 1;
  10293. }
  10294. this.base = base;
  10295. this.tintFn = tintFn;
  10296. this.tmpBuf = new Float32Array(base.numComps);
  10297. }
  10298. AlternateCS.prototype = {
  10299. getRgb: ColorSpace.prototype.getRgb,
  10300. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  10301. dest, destOffset) {
  10302. var tmpBuf = this.tmpBuf;
  10303. this.tintFn(src, srcOffset, tmpBuf, 0);
  10304. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  10305. },
  10306. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  10307. dest, destOffset, bits,
  10308. alpha01) {
  10309. var tintFn = this.tintFn;
  10310. var base = this.base;
  10311. var scale = 1 / ((1 << bits) - 1);
  10312. var baseNumComps = base.numComps;
  10313. var usesZeroToOneRange = base.usesZeroToOneRange;
  10314. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  10315. alpha01 === 0;
  10316. var pos = isPassthrough ? destOffset : 0;
  10317. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  10318. var numComps = this.numComps;
  10319. var scaled = new Float32Array(numComps);
  10320. var tinted = new Float32Array(baseNumComps);
  10321. var i, j;
  10322. if (usesZeroToOneRange) {
  10323. for (i = 0; i < count; i++) {
  10324. for (j = 0; j < numComps; j++) {
  10325. scaled[j] = src[srcOffset++] * scale;
  10326. }
  10327. tintFn(scaled, 0, tinted, 0);
  10328. for (j = 0; j < baseNumComps; j++) {
  10329. baseBuf[pos++] = tinted[j] * 255;
  10330. }
  10331. }
  10332. } else {
  10333. for (i = 0; i < count; i++) {
  10334. for (j = 0; j < numComps; j++) {
  10335. scaled[j] = src[srcOffset++] * scale;
  10336. }
  10337. tintFn(scaled, 0, tinted, 0);
  10338. base.getRgbItem(tinted, 0, baseBuf, pos);
  10339. pos += baseNumComps;
  10340. }
  10341. }
  10342. if (!isPassthrough) {
  10343. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  10344. }
  10345. },
  10346. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  10347. alpha01) {
  10348. return this.base.getOutputLength(inputLength *
  10349. this.base.numComps / this.numComps,
  10350. alpha01);
  10351. },
  10352. isPassthrough: ColorSpace.prototype.isPassthrough,
  10353. fillRgb: ColorSpace.prototype.fillRgb,
  10354. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  10355. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10356. },
  10357. usesZeroToOneRange: true
  10358. };
  10359. return AlternateCS;
  10360. })();
  10361. var PatternCS = (function PatternCSClosure() {
  10362. function PatternCS(baseCS) {
  10363. this.name = 'Pattern';
  10364. this.base = baseCS;
  10365. }
  10366. PatternCS.prototype = {};
  10367. return PatternCS;
  10368. })();
  10369. var IndexedCS = (function IndexedCSClosure() {
  10370. function IndexedCS(base, highVal, lookup) {
  10371. this.name = 'Indexed';
  10372. this.numComps = 1;
  10373. this.defaultColor = new Uint8Array([0]);
  10374. this.base = base;
  10375. this.highVal = highVal;
  10376. var baseNumComps = base.numComps;
  10377. var length = baseNumComps * highVal;
  10378. var lookupArray;
  10379. if (isStream(lookup)) {
  10380. lookupArray = new Uint8Array(length);
  10381. var bytes = lookup.getBytes(length);
  10382. lookupArray.set(bytes);
  10383. } else if (isString(lookup)) {
  10384. lookupArray = new Uint8Array(length);
  10385. for (var i = 0; i < length; ++i) {
  10386. lookupArray[i] = lookup.charCodeAt(i);
  10387. }
  10388. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  10389. lookupArray = lookup;
  10390. } else {
  10391. error('Unrecognized lookup table: ' + lookup);
  10392. }
  10393. this.lookup = lookupArray;
  10394. }
  10395. IndexedCS.prototype = {
  10396. getRgb: ColorSpace.prototype.getRgb,
  10397. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  10398. dest, destOffset) {
  10399. var numComps = this.base.numComps;
  10400. var start = src[srcOffset] * numComps;
  10401. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  10402. },
  10403. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  10404. dest, destOffset, bits,
  10405. alpha01) {
  10406. var base = this.base;
  10407. var numComps = base.numComps;
  10408. var outputDelta = base.getOutputLength(numComps, alpha01);
  10409. var lookup = this.lookup;
  10410. for (var i = 0; i < count; ++i) {
  10411. var lookupPos = src[srcOffset++] * numComps;
  10412. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  10413. destOffset += outputDelta;
  10414. }
  10415. },
  10416. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  10417. return this.base.getOutputLength(inputLength * this.base.numComps,
  10418. alpha01);
  10419. },
  10420. isPassthrough: ColorSpace.prototype.isPassthrough,
  10421. fillRgb: ColorSpace.prototype.fillRgb,
  10422. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  10423. // indexed color maps shouldn't be changed
  10424. return true;
  10425. },
  10426. usesZeroToOneRange: true
  10427. };
  10428. return IndexedCS;
  10429. })();
  10430. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  10431. function DeviceGrayCS() {
  10432. this.name = 'DeviceGray';
  10433. this.numComps = 1;
  10434. this.defaultColor = new Float32Array([0]);
  10435. }
  10436. DeviceGrayCS.prototype = {
  10437. getRgb: ColorSpace.prototype.getRgb,
  10438. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  10439. dest, destOffset) {
  10440. var c = (src[srcOffset] * 255) | 0;
  10441. c = c < 0 ? 0 : c > 255 ? 255 : c;
  10442. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  10443. },
  10444. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  10445. dest, destOffset, bits,
  10446. alpha01) {
  10447. var scale = 255 / ((1 << bits) - 1);
  10448. var j = srcOffset, q = destOffset;
  10449. for (var i = 0; i < count; ++i) {
  10450. var c = (scale * src[j++]) | 0;
  10451. dest[q++] = c;
  10452. dest[q++] = c;
  10453. dest[q++] = c;
  10454. q += alpha01;
  10455. }
  10456. },
  10457. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  10458. alpha01) {
  10459. return inputLength * (3 + alpha01);
  10460. },
  10461. isPassthrough: ColorSpace.prototype.isPassthrough,
  10462. fillRgb: ColorSpace.prototype.fillRgb,
  10463. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  10464. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10465. },
  10466. usesZeroToOneRange: true
  10467. };
  10468. return DeviceGrayCS;
  10469. })();
  10470. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  10471. function DeviceRgbCS() {
  10472. this.name = 'DeviceRGB';
  10473. this.numComps = 3;
  10474. this.defaultColor = new Float32Array([0, 0, 0]);
  10475. }
  10476. DeviceRgbCS.prototype = {
  10477. getRgb: ColorSpace.prototype.getRgb,
  10478. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  10479. dest, destOffset) {
  10480. var r = (src[srcOffset] * 255) | 0;
  10481. var g = (src[srcOffset + 1] * 255) | 0;
  10482. var b = (src[srcOffset + 2] * 255) | 0;
  10483. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  10484. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  10485. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  10486. },
  10487. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  10488. dest, destOffset, bits,
  10489. alpha01) {
  10490. if (bits === 8 && alpha01 === 0) {
  10491. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  10492. return;
  10493. }
  10494. var scale = 255 / ((1 << bits) - 1);
  10495. var j = srcOffset, q = destOffset;
  10496. for (var i = 0; i < count; ++i) {
  10497. dest[q++] = (scale * src[j++]) | 0;
  10498. dest[q++] = (scale * src[j++]) | 0;
  10499. dest[q++] = (scale * src[j++]) | 0;
  10500. q += alpha01;
  10501. }
  10502. },
  10503. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  10504. alpha01) {
  10505. return (inputLength * (3 + alpha01) / 3) | 0;
  10506. },
  10507. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  10508. return bits === 8;
  10509. },
  10510. fillRgb: ColorSpace.prototype.fillRgb,
  10511. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  10512. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10513. },
  10514. usesZeroToOneRange: true
  10515. };
  10516. return DeviceRgbCS;
  10517. })();
  10518. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  10519. // The coefficients below was found using numerical analysis: the method of
  10520. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  10521. // where color_value is the tabular value from the table of sampled RGB colors
  10522. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  10523. // CMYK color conversion using the estimation below:
  10524. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  10525. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  10526. var c = src[srcOffset + 0] * srcScale;
  10527. var m = src[srcOffset + 1] * srcScale;
  10528. var y = src[srcOffset + 2] * srcScale;
  10529. var k = src[srcOffset + 3] * srcScale;
  10530. var r =
  10531. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  10532. 18.82290502165302 * y + 212.25662451639585 * k +
  10533. -285.2331026137004) +
  10534. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  10535. -17.873870861415444 * k - 5.497006427196366) +
  10536. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  10537. 17.5119270841813) +
  10538. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  10539. var g =
  10540. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  10541. 6.871425592049007 * y + 31.159100130055922 * k +
  10542. -79.2970844816548) +
  10543. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  10544. 131.35250912493976 * k - 190.9453302588951) +
  10545. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  10546. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  10547. var b =
  10548. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  10549. 30.89978309703729 * y - 0.23883238689178934 * k +
  10550. -14.183576799673286) +
  10551. m * (10.49593273432072 * m + 63.02378494754052 * y +
  10552. 50.606957656360734 * k - 112.23884253719248) +
  10553. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  10554. -193.58209356861505) +
  10555. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  10556. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  10557. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  10558. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  10559. }
  10560. function DeviceCmykCS() {
  10561. this.name = 'DeviceCMYK';
  10562. this.numComps = 4;
  10563. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  10564. }
  10565. DeviceCmykCS.prototype = {
  10566. getRgb: ColorSpace.prototype.getRgb,
  10567. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  10568. dest, destOffset) {
  10569. convertToRgb(src, srcOffset, 1, dest, destOffset);
  10570. },
  10571. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  10572. dest, destOffset, bits,
  10573. alpha01) {
  10574. var scale = 1 / ((1 << bits) - 1);
  10575. for (var i = 0; i < count; i++) {
  10576. convertToRgb(src, srcOffset, scale, dest, destOffset);
  10577. srcOffset += 4;
  10578. destOffset += 3 + alpha01;
  10579. }
  10580. },
  10581. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  10582. alpha01) {
  10583. return (inputLength / 4 * (3 + alpha01)) | 0;
  10584. },
  10585. isPassthrough: ColorSpace.prototype.isPassthrough,
  10586. fillRgb: ColorSpace.prototype.fillRgb,
  10587. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  10588. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10589. },
  10590. usesZeroToOneRange: true
  10591. };
  10592. return DeviceCmykCS;
  10593. })();
  10594. //
  10595. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  10596. //
  10597. var CalGrayCS = (function CalGrayCSClosure() {
  10598. function CalGrayCS(whitePoint, blackPoint, gamma) {
  10599. this.name = 'CalGray';
  10600. this.numComps = 1;
  10601. this.defaultColor = new Float32Array([0]);
  10602. if (!whitePoint) {
  10603. error('WhitePoint missing - required for color space CalGray');
  10604. }
  10605. blackPoint = blackPoint || [0, 0, 0];
  10606. gamma = gamma || 1;
  10607. // Translate arguments to spec variables.
  10608. this.XW = whitePoint[0];
  10609. this.YW = whitePoint[1];
  10610. this.ZW = whitePoint[2];
  10611. this.XB = blackPoint[0];
  10612. this.YB = blackPoint[1];
  10613. this.ZB = blackPoint[2];
  10614. this.G = gamma;
  10615. // Validate variables as per spec.
  10616. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10617. error('Invalid WhitePoint components for ' + this.name +
  10618. ', no fallback available');
  10619. }
  10620. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10621. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  10622. this.XB = this.YB = this.ZB = 0;
  10623. }
  10624. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  10625. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  10626. ', ZB: ' + this.ZB + ', only default values are supported.');
  10627. }
  10628. if (this.G < 1) {
  10629. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  10630. ', falling back to default');
  10631. this.G = 1;
  10632. }
  10633. }
  10634. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  10635. // A represents a gray component of a calibrated gray space.
  10636. // A <---> AG in the spec
  10637. var A = src[srcOffset] * scale;
  10638. var AG = Math.pow(A, cs.G);
  10639. // Computes L as per spec. ( = cs.YW * AG )
  10640. // Except if other than default BlackPoint values are used.
  10641. var L = cs.YW * AG;
  10642. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  10643. // Convert values to rgb range [0, 255].
  10644. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  10645. dest[destOffset] = val;
  10646. dest[destOffset + 1] = val;
  10647. dest[destOffset + 2] = val;
  10648. }
  10649. CalGrayCS.prototype = {
  10650. getRgb: ColorSpace.prototype.getRgb,
  10651. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  10652. dest, destOffset) {
  10653. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  10654. },
  10655. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  10656. dest, destOffset, bits,
  10657. alpha01) {
  10658. var scale = 1 / ((1 << bits) - 1);
  10659. for (var i = 0; i < count; ++i) {
  10660. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  10661. srcOffset += 1;
  10662. destOffset += 3 + alpha01;
  10663. }
  10664. },
  10665. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  10666. return inputLength * (3 + alpha01);
  10667. },
  10668. isPassthrough: ColorSpace.prototype.isPassthrough,
  10669. fillRgb: ColorSpace.prototype.fillRgb,
  10670. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  10671. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10672. },
  10673. usesZeroToOneRange: true
  10674. };
  10675. return CalGrayCS;
  10676. })();
  10677. //
  10678. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  10679. //
  10680. var LabCS = (function LabCSClosure() {
  10681. function LabCS(whitePoint, blackPoint, range) {
  10682. this.name = 'Lab';
  10683. this.numComps = 3;
  10684. this.defaultColor = new Float32Array([0, 0, 0]);
  10685. if (!whitePoint) {
  10686. error('WhitePoint missing - required for color space Lab');
  10687. }
  10688. blackPoint = blackPoint || [0, 0, 0];
  10689. range = range || [-100, 100, -100, 100];
  10690. // Translate args to spec variables
  10691. this.XW = whitePoint[0];
  10692. this.YW = whitePoint[1];
  10693. this.ZW = whitePoint[2];
  10694. this.amin = range[0];
  10695. this.amax = range[1];
  10696. this.bmin = range[2];
  10697. this.bmax = range[3];
  10698. // These are here just for completeness - the spec doesn't offer any
  10699. // formulas that use BlackPoint in Lab
  10700. this.XB = blackPoint[0];
  10701. this.YB = blackPoint[1];
  10702. this.ZB = blackPoint[2];
  10703. // Validate vars as per spec
  10704. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10705. error('Invalid WhitePoint components, no fallback available');
  10706. }
  10707. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10708. info('Invalid BlackPoint, falling back to default');
  10709. this.XB = this.YB = this.ZB = 0;
  10710. }
  10711. if (this.amin > this.amax || this.bmin > this.bmax) {
  10712. info('Invalid Range, falling back to defaults');
  10713. this.amin = -100;
  10714. this.amax = 100;
  10715. this.bmin = -100;
  10716. this.bmax = 100;
  10717. }
  10718. }
  10719. // Function g(x) from spec
  10720. function fn_g(x) {
  10721. if (x >= 6 / 29) {
  10722. return x * x * x;
  10723. } else {
  10724. return (108 / 841) * (x - 4 / 29);
  10725. }
  10726. }
  10727. function decode(value, high1, low2, high2) {
  10728. return low2 + (value) * (high2 - low2) / (high1);
  10729. }
  10730. // If decoding is needed maxVal should be 2^bits per component - 1.
  10731. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  10732. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  10733. // not the usual [0, 1]. If a command like setFillColor is used the src
  10734. // values will already be within the correct range. However, if we are
  10735. // converting an image we have to map the values to the correct range given
  10736. // above.
  10737. // Ls,as,bs <---> L*,a*,b* in the spec
  10738. var Ls = src[srcOffset];
  10739. var as = src[srcOffset + 1];
  10740. var bs = src[srcOffset + 2];
  10741. if (maxVal !== false) {
  10742. Ls = decode(Ls, maxVal, 0, 100);
  10743. as = decode(as, maxVal, cs.amin, cs.amax);
  10744. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  10745. }
  10746. // Adjust limits of 'as' and 'bs'
  10747. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  10748. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  10749. // Computes intermediate variables X,Y,Z as per spec
  10750. var M = (Ls + 16) / 116;
  10751. var L = M + (as / 500);
  10752. var N = M - (bs / 200);
  10753. var X = cs.XW * fn_g(L);
  10754. var Y = cs.YW * fn_g(M);
  10755. var Z = cs.ZW * fn_g(N);
  10756. var r, g, b;
  10757. // Using different conversions for D50 and D65 white points,
  10758. // per http://www.color.org/srgb.pdf
  10759. if (cs.ZW < 1) {
  10760. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  10761. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  10762. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  10763. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  10764. } else {
  10765. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  10766. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  10767. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  10768. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  10769. }
  10770. // clamp color values to [0,1] range then convert to [0,255] range.
  10771. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  10772. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  10773. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  10774. }
  10775. LabCS.prototype = {
  10776. getRgb: ColorSpace.prototype.getRgb,
  10777. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  10778. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  10779. },
  10780. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  10781. dest, destOffset, bits,
  10782. alpha01) {
  10783. var maxVal = (1 << bits) - 1;
  10784. for (var i = 0; i < count; i++) {
  10785. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  10786. srcOffset += 3;
  10787. destOffset += 3 + alpha01;
  10788. }
  10789. },
  10790. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  10791. return (inputLength * (3 + alpha01) / 3) | 0;
  10792. },
  10793. isPassthrough: ColorSpace.prototype.isPassthrough,
  10794. fillRgb: ColorSpace.prototype.fillRgb,
  10795. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  10796. // XXX: Decoding is handled with the lab conversion because of the strange
  10797. // ranges that are used.
  10798. return true;
  10799. },
  10800. usesZeroToOneRange: false
  10801. };
  10802. return LabCS;
  10803. })();
  10804. var ARCFourCipher = (function ARCFourCipherClosure() {
  10805. function ARCFourCipher(key) {
  10806. this.a = 0;
  10807. this.b = 0;
  10808. var s = new Uint8Array(256);
  10809. var i, j = 0, tmp, keyLength = key.length;
  10810. for (i = 0; i < 256; ++i) {
  10811. s[i] = i;
  10812. }
  10813. for (i = 0; i < 256; ++i) {
  10814. tmp = s[i];
  10815. j = (j + tmp + key[i % keyLength]) & 0xFF;
  10816. s[i] = s[j];
  10817. s[j] = tmp;
  10818. }
  10819. this.s = s;
  10820. }
  10821. ARCFourCipher.prototype = {
  10822. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  10823. var i, n = data.length, tmp, tmp2;
  10824. var a = this.a, b = this.b, s = this.s;
  10825. var output = new Uint8Array(n);
  10826. for (i = 0; i < n; ++i) {
  10827. a = (a + 1) & 0xFF;
  10828. tmp = s[a];
  10829. b = (b + tmp) & 0xFF;
  10830. tmp2 = s[b];
  10831. s[a] = tmp2;
  10832. s[b] = tmp;
  10833. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  10834. }
  10835. this.a = a;
  10836. this.b = b;
  10837. return output;
  10838. }
  10839. };
  10840. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  10841. return ARCFourCipher;
  10842. })();
  10843. var calculateMD5 = (function calculateMD5Closure() {
  10844. var r = new Uint8Array([
  10845. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  10846. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  10847. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  10848. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  10849. var k = new Int32Array([
  10850. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  10851. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  10852. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  10853. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  10854. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  10855. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  10856. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  10857. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  10858. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  10859. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  10860. -145523070, -1120210379, 718787259, -343485551]);
  10861. function hash(data, offset, length) {
  10862. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  10863. // pre-processing
  10864. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  10865. var padded = new Uint8Array(paddedLength);
  10866. var i, j, n;
  10867. for (i = 0; i < length; ++i) {
  10868. padded[i] = data[offset++];
  10869. }
  10870. padded[i++] = 0x80;
  10871. n = paddedLength - 8;
  10872. while (i < n) {
  10873. padded[i++] = 0;
  10874. }
  10875. padded[i++] = (length << 3) & 0xFF;
  10876. padded[i++] = (length >> 5) & 0xFF;
  10877. padded[i++] = (length >> 13) & 0xFF;
  10878. padded[i++] = (length >> 21) & 0xFF;
  10879. padded[i++] = (length >>> 29) & 0xFF;
  10880. padded[i++] = 0;
  10881. padded[i++] = 0;
  10882. padded[i++] = 0;
  10883. var w = new Int32Array(16);
  10884. for (i = 0; i < paddedLength;) {
  10885. for (j = 0; j < 16; ++j, i += 4) {
  10886. w[j] = (padded[i] | (padded[i + 1] << 8) |
  10887. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  10888. }
  10889. var a = h0, b = h1, c = h2, d = h3, f, g;
  10890. for (j = 0; j < 64; ++j) {
  10891. if (j < 16) {
  10892. f = (b & c) | ((~b) & d);
  10893. g = j;
  10894. } else if (j < 32) {
  10895. f = (d & b) | ((~d) & c);
  10896. g = (5 * j + 1) & 15;
  10897. } else if (j < 48) {
  10898. f = b ^ c ^ d;
  10899. g = (3 * j + 5) & 15;
  10900. } else {
  10901. f = c ^ (b | (~d));
  10902. g = (7 * j) & 15;
  10903. }
  10904. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  10905. d = c;
  10906. c = b;
  10907. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  10908. a = tmp;
  10909. }
  10910. h0 = (h0 + a) | 0;
  10911. h1 = (h1 + b) | 0;
  10912. h2 = (h2 + c) | 0;
  10913. h3 = (h3 + d) | 0;
  10914. }
  10915. return new Uint8Array([
  10916. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  10917. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  10918. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  10919. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  10920. ]);
  10921. }
  10922. return hash;
  10923. })();
  10924. var Word64 = (function Word64Closure() {
  10925. function Word64(highInteger, lowInteger) {
  10926. this.high = highInteger | 0;
  10927. this.low = lowInteger | 0;
  10928. }
  10929. Word64.prototype = {
  10930. and: function Word64_and(word) {
  10931. this.high &= word.high;
  10932. this.low &= word.low;
  10933. },
  10934. xor: function Word64_xor(word) {
  10935. this.high ^= word.high;
  10936. this.low ^= word.low;
  10937. },
  10938. or: function Word64_or(word) {
  10939. this.high |= word.high;
  10940. this.low |= word.low;
  10941. },
  10942. shiftRight: function Word64_shiftRight(places) {
  10943. if (places >= 32) {
  10944. this.low = (this.high >>> (places - 32)) | 0;
  10945. this.high = 0;
  10946. } else {
  10947. this.low = (this.low >>> places) | (this.high << (32 - places));
  10948. this.high = (this.high >>> places) | 0;
  10949. }
  10950. },
  10951. shiftLeft: function Word64_shiftLeft(places) {
  10952. if (places >= 32) {
  10953. this.high = this.low << (places - 32);
  10954. this.low = 0;
  10955. } else {
  10956. this.high = (this.high << places) | (this.low >>> (32 - places));
  10957. this.low = this.low << places;
  10958. }
  10959. },
  10960. rotateRight: function Word64_rotateRight(places) {
  10961. var low, high;
  10962. if (places & 32) {
  10963. high = this.low;
  10964. low = this.high;
  10965. } else {
  10966. low = this.low;
  10967. high = this.high;
  10968. }
  10969. places &= 31;
  10970. this.low = (low >>> places) | (high << (32 - places));
  10971. this.high = (high >>> places) | (low << (32 - places));
  10972. },
  10973. not: function Word64_not() {
  10974. this.high = ~this.high;
  10975. this.low = ~this.low;
  10976. },
  10977. add: function Word64_add(word) {
  10978. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  10979. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  10980. if (lowAdd > 0xFFFFFFFF) {
  10981. highAdd += 1;
  10982. }
  10983. this.low = lowAdd | 0;
  10984. this.high = highAdd | 0;
  10985. },
  10986. copyTo: function Word64_copyTo(bytes, offset) {
  10987. bytes[offset] = (this.high >>> 24) & 0xFF;
  10988. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  10989. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  10990. bytes[offset + 3] = this.high & 0xFF;
  10991. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  10992. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  10993. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  10994. bytes[offset + 7] = this.low & 0xFF;
  10995. },
  10996. assign: function Word64_assign(word) {
  10997. this.high = word.high;
  10998. this.low = word.low;
  10999. }
  11000. };
  11001. return Word64;
  11002. })();
  11003. var calculateSHA256 = (function calculateSHA256Closure() {
  11004. function rotr(x, n) {
  11005. return (x >>> n) | (x << 32 - n);
  11006. }
  11007. function ch(x, y, z) {
  11008. return (x & y) ^ (~x & z);
  11009. }
  11010. function maj(x, y, z) {
  11011. return (x & y) ^ (x & z) ^ (y & z);
  11012. }
  11013. function sigma(x) {
  11014. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  11015. }
  11016. function sigmaPrime(x) {
  11017. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  11018. }
  11019. function littleSigma(x) {
  11020. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  11021. }
  11022. function littleSigmaPrime(x) {
  11023. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  11024. }
  11025. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  11026. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  11027. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  11028. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  11029. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  11030. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  11031. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  11032. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  11033. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  11034. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  11035. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  11036. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  11037. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  11038. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  11039. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  11040. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  11041. function hash(data, offset, length) {
  11042. // initial hash values
  11043. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  11044. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  11045. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  11046. // pre-processing
  11047. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  11048. var padded = new Uint8Array(paddedLength);
  11049. var i, j, n;
  11050. for (i = 0; i < length; ++i) {
  11051. padded[i] = data[offset++];
  11052. }
  11053. padded[i++] = 0x80;
  11054. n = paddedLength - 8;
  11055. while (i < n) {
  11056. padded[i++] = 0;
  11057. }
  11058. padded[i++] = 0;
  11059. padded[i++] = 0;
  11060. padded[i++] = 0;
  11061. padded[i++] = (length >>> 29) & 0xFF;
  11062. padded[i++] = (length >> 21) & 0xFF;
  11063. padded[i++] = (length >> 13) & 0xFF;
  11064. padded[i++] = (length >> 5) & 0xFF;
  11065. padded[i++] = (length << 3) & 0xFF;
  11066. var w = new Uint32Array(64);
  11067. // for each 512 bit block
  11068. for (i = 0; i < paddedLength;) {
  11069. for (j = 0; j < 16; ++j) {
  11070. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  11071. (padded[i + 2] << 8) | (padded[i + 3]));
  11072. i += 4;
  11073. }
  11074. for (j = 16; j < 64; ++j) {
  11075. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  11076. littleSigma(w[j - 15]) + w[j - 16] | 0;
  11077. }
  11078. var a = h0, b = h1, c = h2, d = h3, e = h4,
  11079. f = h5, g = h6, h = h7, t1, t2;
  11080. for (j = 0; j < 64; ++j) {
  11081. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  11082. t2 = sigma(a) + maj(a, b, c);
  11083. h = g;
  11084. g = f;
  11085. f = e;
  11086. e = (d + t1) | 0;
  11087. d = c;
  11088. c = b;
  11089. b = a;
  11090. a = (t1 + t2) | 0;
  11091. }
  11092. h0 = (h0 + a) | 0;
  11093. h1 = (h1 + b) | 0;
  11094. h2 = (h2 + c) | 0;
  11095. h3 = (h3 + d) | 0;
  11096. h4 = (h4 + e) | 0;
  11097. h5 = (h5 + f) | 0;
  11098. h6 = (h6 + g) | 0;
  11099. h7 = (h7 + h) | 0;
  11100. }
  11101. return new Uint8Array([
  11102. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  11103. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  11104. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  11105. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  11106. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  11107. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  11108. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  11109. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  11110. ]);
  11111. }
  11112. return hash;
  11113. })();
  11114. var calculateSHA512 = (function calculateSHA512Closure() {
  11115. function ch(result, x, y, z, tmp) {
  11116. result.assign(x);
  11117. result.and(y);
  11118. tmp.assign(x);
  11119. tmp.not();
  11120. tmp.and(z);
  11121. result.xor(tmp);
  11122. }
  11123. function maj(result, x, y, z, tmp) {
  11124. result.assign(x);
  11125. result.and(y);
  11126. tmp.assign(x);
  11127. tmp.and(z);
  11128. result.xor(tmp);
  11129. tmp.assign(y);
  11130. tmp.and(z);
  11131. result.xor(tmp);
  11132. }
  11133. function sigma(result, x, tmp) {
  11134. result.assign(x);
  11135. result.rotateRight(28);
  11136. tmp.assign(x);
  11137. tmp.rotateRight(34);
  11138. result.xor(tmp);
  11139. tmp.assign(x);
  11140. tmp.rotateRight(39);
  11141. result.xor(tmp);
  11142. }
  11143. function sigmaPrime(result, x, tmp) {
  11144. result.assign(x);
  11145. result.rotateRight(14);
  11146. tmp.assign(x);
  11147. tmp.rotateRight(18);
  11148. result.xor(tmp);
  11149. tmp.assign(x);
  11150. tmp.rotateRight(41);
  11151. result.xor(tmp);
  11152. }
  11153. function littleSigma(result, x, tmp) {
  11154. result.assign(x);
  11155. result.rotateRight(1);
  11156. tmp.assign(x);
  11157. tmp.rotateRight(8);
  11158. result.xor(tmp);
  11159. tmp.assign(x);
  11160. tmp.shiftRight(7);
  11161. result.xor(tmp);
  11162. }
  11163. function littleSigmaPrime(result, x, tmp) {
  11164. result.assign(x);
  11165. result.rotateRight(19);
  11166. tmp.assign(x);
  11167. tmp.rotateRight(61);
  11168. result.xor(tmp);
  11169. tmp.assign(x);
  11170. tmp.shiftRight(6);
  11171. result.xor(tmp);
  11172. }
  11173. var k = [
  11174. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  11175. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  11176. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  11177. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  11178. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  11179. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  11180. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  11181. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  11182. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  11183. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  11184. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  11185. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  11186. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  11187. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  11188. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  11189. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  11190. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  11191. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  11192. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  11193. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  11194. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  11195. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  11196. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  11197. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  11198. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  11199. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  11200. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  11201. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  11202. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  11203. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  11204. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  11205. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  11206. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  11207. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  11208. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  11209. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  11210. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  11211. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  11212. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  11213. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  11214. function hash(data, offset, length, mode384) {
  11215. mode384 = !!mode384;
  11216. // initial hash values
  11217. var h0, h1, h2, h3, h4, h5, h6, h7;
  11218. if (!mode384) {
  11219. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  11220. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  11221. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  11222. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  11223. h4 = new Word64(0x510e527f, 0xade682d1);
  11224. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  11225. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  11226. h7 = new Word64(0x5be0cd19, 0x137e2179);
  11227. }
  11228. else {
  11229. // SHA384 is exactly the same
  11230. // except with different starting values and a trimmed result
  11231. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  11232. h1 = new Word64(0x629a292a, 0x367cd507);
  11233. h2 = new Word64(0x9159015a, 0x3070dd17);
  11234. h3 = new Word64(0x152fecd8, 0xf70e5939);
  11235. h4 = new Word64(0x67332667, 0xffc00b31);
  11236. h5 = new Word64(0x8eb44a87, 0x68581511);
  11237. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  11238. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  11239. }
  11240. // pre-processing
  11241. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  11242. var padded = new Uint8Array(paddedLength);
  11243. var i, j, n;
  11244. for (i = 0; i < length; ++i) {
  11245. padded[i] = data[offset++];
  11246. }
  11247. padded[i++] = 0x80;
  11248. n = paddedLength - 16;
  11249. while (i < n) {
  11250. padded[i++] = 0;
  11251. }
  11252. padded[i++] = 0;
  11253. padded[i++] = 0;
  11254. padded[i++] = 0;
  11255. padded[i++] = 0;
  11256. padded[i++] = 0;
  11257. padded[i++] = 0;
  11258. padded[i++] = 0;
  11259. padded[i++] = 0;
  11260. padded[i++] = 0;
  11261. padded[i++] = 0;
  11262. padded[i++] = 0;
  11263. padded[i++] = (length >>> 29) & 0xFF;
  11264. padded[i++] = (length >> 21) & 0xFF;
  11265. padded[i++] = (length >> 13) & 0xFF;
  11266. padded[i++] = (length >> 5) & 0xFF;
  11267. padded[i++] = (length << 3) & 0xFF;
  11268. var w = new Array(80);
  11269. for (i = 0; i < 80; i++) {
  11270. w[i] = new Word64(0, 0);
  11271. }
  11272. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  11273. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  11274. var g = new Word64(0, 0), h = new Word64(0, 0);
  11275. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  11276. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  11277. // for each 1024 bit block
  11278. for (i = 0; i < paddedLength;) {
  11279. for (j = 0; j < 16; ++j) {
  11280. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  11281. (padded[i + 2] << 8) | (padded[i + 3]);
  11282. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  11283. (padded[i + 6]) << 8 | (padded[i + 7]);
  11284. i += 8;
  11285. }
  11286. for (j = 16; j < 80; ++j) {
  11287. tmp3 = w[j];
  11288. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  11289. tmp3.add(w[j - 7]);
  11290. littleSigma(tmp1, w[j - 15], tmp2);
  11291. tmp3.add(tmp1);
  11292. tmp3.add(w[j - 16]);
  11293. }
  11294. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  11295. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  11296. for (j = 0; j < 80; ++j) {
  11297. t1.assign(h);
  11298. sigmaPrime(tmp1, e, tmp2);
  11299. t1.add(tmp1);
  11300. ch(tmp1, e, f, g, tmp2);
  11301. t1.add(tmp1);
  11302. t1.add(k[j]);
  11303. t1.add(w[j]);
  11304. sigma(t2, a, tmp2);
  11305. maj(tmp1, a, b, c, tmp2);
  11306. t2.add(tmp1);
  11307. tmp3 = h;
  11308. h = g;
  11309. g = f;
  11310. f = e;
  11311. d.add(t1);
  11312. e = d;
  11313. d = c;
  11314. c = b;
  11315. b = a;
  11316. tmp3.assign(t1);
  11317. tmp3.add(t2);
  11318. a = tmp3;
  11319. }
  11320. h0.add(a);
  11321. h1.add(b);
  11322. h2.add(c);
  11323. h3.add(d);
  11324. h4.add(e);
  11325. h5.add(f);
  11326. h6.add(g);
  11327. h7.add(h);
  11328. }
  11329. var result;
  11330. if (!mode384) {
  11331. result = new Uint8Array(64);
  11332. h0.copyTo(result,0);
  11333. h1.copyTo(result,8);
  11334. h2.copyTo(result,16);
  11335. h3.copyTo(result,24);
  11336. h4.copyTo(result,32);
  11337. h5.copyTo(result,40);
  11338. h6.copyTo(result,48);
  11339. h7.copyTo(result,56);
  11340. }
  11341. else {
  11342. result = new Uint8Array(48);
  11343. h0.copyTo(result,0);
  11344. h1.copyTo(result,8);
  11345. h2.copyTo(result,16);
  11346. h3.copyTo(result,24);
  11347. h4.copyTo(result,32);
  11348. h5.copyTo(result,40);
  11349. }
  11350. return result;
  11351. }
  11352. return hash;
  11353. })();
  11354. var calculateSHA384 = (function calculateSHA384Closure() {
  11355. function hash(data, offset, length) {
  11356. return calculateSHA512(data, offset, length, true);
  11357. }
  11358. return hash;
  11359. })();
  11360. var NullCipher = (function NullCipherClosure() {
  11361. function NullCipher() {
  11362. }
  11363. NullCipher.prototype = {
  11364. decryptBlock: function NullCipher_decryptBlock(data) {
  11365. return data;
  11366. }
  11367. };
  11368. return NullCipher;
  11369. })();
  11370. var AES128Cipher = (function AES128CipherClosure() {
  11371. var rcon = new Uint8Array([
  11372. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11373. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11374. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11375. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11376. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11377. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11378. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11379. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11380. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11381. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11382. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11383. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11384. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11385. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11386. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11387. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11388. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11389. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11390. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11391. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11392. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11393. 0x74, 0xe8, 0xcb, 0x8d]);
  11394. var s = new Uint8Array([
  11395. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11396. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11397. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11398. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11399. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11400. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11401. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11402. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11403. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11404. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11405. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11406. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11407. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11408. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11409. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11410. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11411. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11412. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11413. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11414. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11415. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11416. 0xb0, 0x54, 0xbb, 0x16]);
  11417. var inv_s = new Uint8Array([
  11418. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11419. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11420. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11421. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11422. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11423. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11424. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11425. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11426. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11427. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11428. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11429. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11430. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11431. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11432. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11433. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11434. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11435. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11436. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11437. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11438. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11439. 0x55, 0x21, 0x0c, 0x7d]);
  11440. var mixCol = new Uint8Array(256);
  11441. for (var i = 0; i < 256; i++) {
  11442. if (i < 128) {
  11443. mixCol[i] = i << 1;
  11444. } else {
  11445. mixCol[i] = (i << 1) ^ 0x1b;
  11446. }
  11447. }
  11448. var mix = new Uint32Array([
  11449. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11450. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11451. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11452. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11453. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11454. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11455. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11456. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11457. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11458. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11459. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11460. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11461. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11462. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11463. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11464. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11465. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11466. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11467. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11468. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11469. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11470. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11471. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11472. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11473. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11474. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11475. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11476. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11477. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11478. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11479. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11480. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11481. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11482. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11483. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11484. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11485. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11486. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11487. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11488. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11489. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11490. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11491. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11492. function expandKey128(cipherKey) {
  11493. var b = 176, result = new Uint8Array(b);
  11494. result.set(cipherKey);
  11495. for (var j = 16, i = 1; j < b; ++i) {
  11496. // RotWord
  11497. var t1 = result[j - 3], t2 = result[j - 2],
  11498. t3 = result[j - 1], t4 = result[j - 4];
  11499. // SubWord
  11500. t1 = s[t1];
  11501. t2 = s[t2];
  11502. t3 = s[t3];
  11503. t4 = s[t4];
  11504. // Rcon
  11505. t1 = t1 ^ rcon[i];
  11506. for (var n = 0; n < 4; ++n) {
  11507. result[j] = (t1 ^= result[j - 16]);
  11508. j++;
  11509. result[j] = (t2 ^= result[j - 16]);
  11510. j++;
  11511. result[j] = (t3 ^= result[j - 16]);
  11512. j++;
  11513. result[j] = (t4 ^= result[j - 16]);
  11514. j++;
  11515. }
  11516. }
  11517. return result;
  11518. }
  11519. function decrypt128(input, key) {
  11520. var state = new Uint8Array(16);
  11521. state.set(input);
  11522. var i, j, k;
  11523. var t, u, v;
  11524. // AddRoundKey
  11525. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11526. state[j] ^= key[k];
  11527. }
  11528. for (i = 9; i >= 1; --i) {
  11529. // InvShiftRows
  11530. t = state[13];
  11531. state[13] = state[9];
  11532. state[9] = state[5];
  11533. state[5] = state[1];
  11534. state[1] = t;
  11535. t = state[14];
  11536. u = state[10];
  11537. state[14] = state[6];
  11538. state[10] = state[2];
  11539. state[6] = t;
  11540. state[2] = u;
  11541. t = state[15];
  11542. u = state[11];
  11543. v = state[7];
  11544. state[15] = state[3];
  11545. state[11] = t;
  11546. state[7] = u;
  11547. state[3] = v;
  11548. // InvSubBytes
  11549. for (j = 0; j < 16; ++j) {
  11550. state[j] = inv_s[state[j]];
  11551. }
  11552. // AddRoundKey
  11553. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11554. state[j] ^= key[k];
  11555. }
  11556. // InvMixColumns
  11557. for (j = 0; j < 16; j += 4) {
  11558. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11559. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11560. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11561. (s3 >>> 24) ^ (s3 << 8));
  11562. state[j] = (t >>> 24) & 0xFF;
  11563. state[j + 1] = (t >> 16) & 0xFF;
  11564. state[j + 2] = (t >> 8) & 0xFF;
  11565. state[j + 3] = t & 0xFF;
  11566. }
  11567. }
  11568. // InvShiftRows
  11569. t = state[13];
  11570. state[13] = state[9];
  11571. state[9] = state[5];
  11572. state[5] = state[1];
  11573. state[1] = t;
  11574. t = state[14];
  11575. u = state[10];
  11576. state[14] = state[6];
  11577. state[10] = state[2];
  11578. state[6] = t;
  11579. state[2] = u;
  11580. t = state[15];
  11581. u = state[11];
  11582. v = state[7];
  11583. state[15] = state[3];
  11584. state[11] = t;
  11585. state[7] = u;
  11586. state[3] = v;
  11587. for (j = 0; j < 16; ++j) {
  11588. // InvSubBytes
  11589. state[j] = inv_s[state[j]];
  11590. // AddRoundKey
  11591. state[j] ^= key[j];
  11592. }
  11593. return state;
  11594. }
  11595. function encrypt128(input, key) {
  11596. var t, u, v, k;
  11597. var state = new Uint8Array(16);
  11598. state.set(input);
  11599. for (j = 0; j < 16; ++j) {
  11600. // AddRoundKey
  11601. state[j] ^= key[j];
  11602. }
  11603. for (i = 1; i < 10; i++) {
  11604. //SubBytes
  11605. for (j = 0; j < 16; ++j) {
  11606. state[j] = s[state[j]];
  11607. }
  11608. //ShiftRows
  11609. v = state[1];
  11610. state[1] = state[5];
  11611. state[5] = state[9];
  11612. state[9] = state[13];
  11613. state[13] = v;
  11614. v = state[2];
  11615. u = state[6];
  11616. state[2] = state[10];
  11617. state[6] = state[14];
  11618. state[10] = v;
  11619. state[14] = u;
  11620. v = state[3];
  11621. u = state[7];
  11622. t = state[11];
  11623. state[3] = state[15];
  11624. state[7] = v;
  11625. state[11] = u;
  11626. state[15] = t;
  11627. //MixColumns
  11628. for (var j = 0; j < 16; j += 4) {
  11629. var s0 = state[j + 0], s1 = state[j + 1];
  11630. var s2 = state[j + 2], s3 = state[j + 3];
  11631. t = s0 ^ s1 ^ s2 ^ s3;
  11632. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  11633. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  11634. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  11635. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  11636. }
  11637. //AddRoundKey
  11638. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11639. state[j] ^= key[k];
  11640. }
  11641. }
  11642. //SubBytes
  11643. for (j = 0; j < 16; ++j) {
  11644. state[j] = s[state[j]];
  11645. }
  11646. //ShiftRows
  11647. v = state[1];
  11648. state[1] = state[5];
  11649. state[5] = state[9];
  11650. state[9] = state[13];
  11651. state[13] = v;
  11652. v = state[2];
  11653. u = state[6];
  11654. state[2] = state[10];
  11655. state[6] = state[14];
  11656. state[10] = v;
  11657. state[14] = u;
  11658. v = state[3];
  11659. u = state[7];
  11660. t = state[11];
  11661. state[3] = state[15];
  11662. state[7] = v;
  11663. state[11] = u;
  11664. state[15] = t;
  11665. //AddRoundKey
  11666. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11667. state[j] ^= key[k];
  11668. }
  11669. return state;
  11670. }
  11671. function AES128Cipher(key) {
  11672. this.key = expandKey128(key);
  11673. this.buffer = new Uint8Array(16);
  11674. this.bufferPosition = 0;
  11675. }
  11676. function decryptBlock2(data, finalize) {
  11677. var i, j, ii, sourceLength = data.length,
  11678. buffer = this.buffer, bufferLength = this.bufferPosition,
  11679. result = [], iv = this.iv;
  11680. for (i = 0; i < sourceLength; ++i) {
  11681. buffer[bufferLength] = data[i];
  11682. ++bufferLength;
  11683. if (bufferLength < 16) {
  11684. continue;
  11685. }
  11686. // buffer is full, decrypting
  11687. var plain = decrypt128(buffer, this.key);
  11688. // xor-ing the IV vector to get plain text
  11689. for (j = 0; j < 16; ++j) {
  11690. plain[j] ^= iv[j];
  11691. }
  11692. iv = buffer;
  11693. result.push(plain);
  11694. buffer = new Uint8Array(16);
  11695. bufferLength = 0;
  11696. }
  11697. // saving incomplete buffer
  11698. this.buffer = buffer;
  11699. this.bufferLength = bufferLength;
  11700. this.iv = iv;
  11701. if (result.length === 0) {
  11702. return new Uint8Array([]);
  11703. }
  11704. // combining plain text blocks into one
  11705. var outputLength = 16 * result.length;
  11706. if (finalize) {
  11707. // undo a padding that is described in RFC 2898
  11708. var lastBlock = result[result.length - 1];
  11709. var psLen = lastBlock[15];
  11710. if (psLen <= 16) {
  11711. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  11712. if (lastBlock[i] !== psLen) {
  11713. // Invalid padding, assume that the block has no padding.
  11714. psLen = 0;
  11715. break;
  11716. }
  11717. }
  11718. outputLength -= psLen;
  11719. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  11720. }
  11721. }
  11722. var output = new Uint8Array(outputLength);
  11723. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11724. output.set(result[i], j);
  11725. }
  11726. return output;
  11727. }
  11728. AES128Cipher.prototype = {
  11729. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  11730. var i, sourceLength = data.length;
  11731. var buffer = this.buffer, bufferLength = this.bufferPosition;
  11732. // waiting for IV values -- they are at the start of the stream
  11733. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  11734. buffer[bufferLength] = data[i];
  11735. }
  11736. if (bufferLength < 16) {
  11737. // need more data
  11738. this.bufferLength = bufferLength;
  11739. return new Uint8Array([]);
  11740. }
  11741. this.iv = buffer;
  11742. this.buffer = new Uint8Array(16);
  11743. this.bufferLength = 0;
  11744. // starting decryption
  11745. this.decryptBlock = decryptBlock2;
  11746. return this.decryptBlock(data.subarray(16), finalize);
  11747. },
  11748. encrypt: function AES128Cipher_encrypt(data, iv) {
  11749. var i, j, ii, sourceLength = data.length,
  11750. buffer = this.buffer, bufferLength = this.bufferPosition,
  11751. result = [];
  11752. if (!iv) {
  11753. iv = new Uint8Array(16);
  11754. }
  11755. for (i = 0; i < sourceLength; ++i) {
  11756. buffer[bufferLength] = data[i];
  11757. ++bufferLength;
  11758. if (bufferLength < 16) {
  11759. continue;
  11760. }
  11761. for (j = 0; j < 16; ++j) {
  11762. buffer[j] ^= iv[j];
  11763. }
  11764. // buffer is full, encrypting
  11765. var cipher = encrypt128(buffer, this.key);
  11766. iv = cipher;
  11767. result.push(cipher);
  11768. buffer = new Uint8Array(16);
  11769. bufferLength = 0;
  11770. }
  11771. // saving incomplete buffer
  11772. this.buffer = buffer;
  11773. this.bufferLength = bufferLength;
  11774. this.iv = iv;
  11775. if (result.length === 0) {
  11776. return new Uint8Array([]);
  11777. }
  11778. // combining plain text blocks into one
  11779. var outputLength = 16 * result.length;
  11780. var output = new Uint8Array(outputLength);
  11781. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11782. output.set(result[i], j);
  11783. }
  11784. return output;
  11785. }
  11786. };
  11787. return AES128Cipher;
  11788. })();
  11789. var AES256Cipher = (function AES256CipherClosure() {
  11790. var rcon = new Uint8Array([
  11791. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11792. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11793. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11794. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11795. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11796. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11797. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11798. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11799. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11800. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11801. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11802. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11803. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11804. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11805. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11806. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11807. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11808. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11809. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11810. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11811. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11812. 0x74, 0xe8, 0xcb, 0x8d]);
  11813. var s = new Uint8Array([
  11814. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11815. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11816. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11817. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11818. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11819. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11820. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11821. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11822. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11823. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11824. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11825. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11826. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11827. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11828. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11829. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11830. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11831. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11832. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11833. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11834. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11835. 0xb0, 0x54, 0xbb, 0x16]);
  11836. var inv_s = new Uint8Array([
  11837. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11838. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11839. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11840. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11841. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11842. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11843. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11844. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11845. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11846. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11847. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11848. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11849. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11850. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11851. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11852. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11853. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11854. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11855. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11856. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11857. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11858. 0x55, 0x21, 0x0c, 0x7d]);
  11859. var mixCol = new Uint8Array(256);
  11860. for (var i = 0; i < 256; i++) {
  11861. if (i < 128) {
  11862. mixCol[i] = i << 1;
  11863. } else {
  11864. mixCol[i] = (i << 1) ^ 0x1b;
  11865. }
  11866. }
  11867. var mix = new Uint32Array([
  11868. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11869. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11870. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11871. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11872. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11873. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11874. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11875. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11876. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11877. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11878. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11879. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11880. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11881. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11882. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11883. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11884. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11885. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11886. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11887. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11888. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11889. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11890. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11891. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11892. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11893. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11894. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11895. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11896. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11897. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11898. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11899. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11900. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11901. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11902. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11903. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11904. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11905. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11906. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11907. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11908. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11909. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11910. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11911. function expandKey256(cipherKey) {
  11912. var b = 240, result = new Uint8Array(b);
  11913. var r = 1;
  11914. result.set(cipherKey);
  11915. for (var j = 32, i = 1; j < b; ++i) {
  11916. if (j % 32 === 16) {
  11917. t1 = s[t1];
  11918. t2 = s[t2];
  11919. t3 = s[t3];
  11920. t4 = s[t4];
  11921. } else if (j % 32 === 0) {
  11922. // RotWord
  11923. var t1 = result[j - 3], t2 = result[j - 2],
  11924. t3 = result[j - 1], t4 = result[j - 4];
  11925. // SubWord
  11926. t1 = s[t1];
  11927. t2 = s[t2];
  11928. t3 = s[t3];
  11929. t4 = s[t4];
  11930. // Rcon
  11931. t1 = t1 ^ r;
  11932. if ((r <<= 1) >= 256) {
  11933. r = (r ^ 0x1b) & 0xFF;
  11934. }
  11935. }
  11936. for (var n = 0; n < 4; ++n) {
  11937. result[j] = (t1 ^= result[j - 32]);
  11938. j++;
  11939. result[j] = (t2 ^= result[j - 32]);
  11940. j++;
  11941. result[j] = (t3 ^= result[j - 32]);
  11942. j++;
  11943. result[j] = (t4 ^= result[j - 32]);
  11944. j++;
  11945. }
  11946. }
  11947. return result;
  11948. }
  11949. function decrypt256(input, key) {
  11950. var state = new Uint8Array(16);
  11951. state.set(input);
  11952. var i, j, k;
  11953. var t, u, v;
  11954. // AddRoundKey
  11955. for (j = 0, k = 224; j < 16; ++j, ++k) {
  11956. state[j] ^= key[k];
  11957. }
  11958. for (i = 13; i >= 1; --i) {
  11959. // InvShiftRows
  11960. t = state[13];
  11961. state[13] = state[9];
  11962. state[9] = state[5];
  11963. state[5] = state[1];
  11964. state[1] = t;
  11965. t = state[14];
  11966. u = state[10];
  11967. state[14] = state[6];
  11968. state[10] = state[2];
  11969. state[6] = t;
  11970. state[2] = u;
  11971. t = state[15];
  11972. u = state[11];
  11973. v = state[7];
  11974. state[15] = state[3];
  11975. state[11] = t;
  11976. state[7] = u;
  11977. state[3] = v;
  11978. // InvSubBytes
  11979. for (j = 0; j < 16; ++j) {
  11980. state[j] = inv_s[state[j]];
  11981. }
  11982. // AddRoundKey
  11983. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11984. state[j] ^= key[k];
  11985. }
  11986. // InvMixColumns
  11987. for (j = 0; j < 16; j += 4) {
  11988. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11989. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11990. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11991. (s3 >>> 24) ^ (s3 << 8));
  11992. state[j] = (t >>> 24) & 0xFF;
  11993. state[j + 1] = (t >> 16) & 0xFF;
  11994. state[j + 2] = (t >> 8) & 0xFF;
  11995. state[j + 3] = t & 0xFF;
  11996. }
  11997. }
  11998. // InvShiftRows
  11999. t = state[13];
  12000. state[13] = state[9];
  12001. state[9] = state[5];
  12002. state[5] = state[1];
  12003. state[1] = t;
  12004. t = state[14];
  12005. u = state[10];
  12006. state[14] = state[6];
  12007. state[10] = state[2];
  12008. state[6] = t;
  12009. state[2] = u;
  12010. t = state[15];
  12011. u = state[11];
  12012. v = state[7];
  12013. state[15] = state[3];
  12014. state[11] = t;
  12015. state[7] = u;
  12016. state[3] = v;
  12017. for (j = 0; j < 16; ++j) {
  12018. // InvSubBytes
  12019. state[j] = inv_s[state[j]];
  12020. // AddRoundKey
  12021. state[j] ^= key[j];
  12022. }
  12023. return state;
  12024. }
  12025. function encrypt256(input, key) {
  12026. var t, u, v, k;
  12027. var state = new Uint8Array(16);
  12028. state.set(input);
  12029. for (j = 0; j < 16; ++j) {
  12030. // AddRoundKey
  12031. state[j] ^= key[j];
  12032. }
  12033. for (i = 1; i < 14; i++) {
  12034. //SubBytes
  12035. for (j = 0; j < 16; ++j) {
  12036. state[j] = s[state[j]];
  12037. }
  12038. //ShiftRows
  12039. v = state[1];
  12040. state[1] = state[5];
  12041. state[5] = state[9];
  12042. state[9] = state[13];
  12043. state[13] = v;
  12044. v = state[2];
  12045. u = state[6];
  12046. state[2] = state[10];
  12047. state[6] = state[14];
  12048. state[10] = v;
  12049. state[14] = u;
  12050. v = state[3];
  12051. u = state[7];
  12052. t = state[11];
  12053. state[3] = state[15];
  12054. state[7] = v;
  12055. state[11] = u;
  12056. state[15] = t;
  12057. //MixColumns
  12058. for (var j = 0; j < 16; j += 4) {
  12059. var s0 = state[j + 0], s1 = state[j + 1];
  12060. var s2 = state[j + 2], s3 = state[j + 3];
  12061. t = s0 ^ s1 ^ s2 ^ s3;
  12062. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  12063. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  12064. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  12065. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  12066. }
  12067. //AddRoundKey
  12068. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12069. state[j] ^= key[k];
  12070. }
  12071. }
  12072. //SubBytes
  12073. for (j = 0; j < 16; ++j) {
  12074. state[j] = s[state[j]];
  12075. }
  12076. //ShiftRows
  12077. v = state[1];
  12078. state[1] = state[5];
  12079. state[5] = state[9];
  12080. state[9] = state[13];
  12081. state[13] = v;
  12082. v = state[2];
  12083. u = state[6];
  12084. state[2] = state[10];
  12085. state[6] = state[14];
  12086. state[10] = v;
  12087. state[14] = u;
  12088. v = state[3];
  12089. u = state[7];
  12090. t = state[11];
  12091. state[3] = state[15];
  12092. state[7] = v;
  12093. state[11] = u;
  12094. state[15] = t;
  12095. //AddRoundKey
  12096. for (j = 0, k = 224; j < 16; ++j, ++k) {
  12097. state[j] ^= key[k];
  12098. }
  12099. return state;
  12100. }
  12101. function AES256Cipher(key) {
  12102. this.key = expandKey256(key);
  12103. this.buffer = new Uint8Array(16);
  12104. this.bufferPosition = 0;
  12105. }
  12106. function decryptBlock2(data, finalize) {
  12107. var i, j, ii, sourceLength = data.length,
  12108. buffer = this.buffer, bufferLength = this.bufferPosition,
  12109. result = [], iv = this.iv;
  12110. for (i = 0; i < sourceLength; ++i) {
  12111. buffer[bufferLength] = data[i];
  12112. ++bufferLength;
  12113. if (bufferLength < 16) {
  12114. continue;
  12115. }
  12116. // buffer is full, decrypting
  12117. var plain = decrypt256(buffer, this.key);
  12118. // xor-ing the IV vector to get plain text
  12119. for (j = 0; j < 16; ++j) {
  12120. plain[j] ^= iv[j];
  12121. }
  12122. iv = buffer;
  12123. result.push(plain);
  12124. buffer = new Uint8Array(16);
  12125. bufferLength = 0;
  12126. }
  12127. // saving incomplete buffer
  12128. this.buffer = buffer;
  12129. this.bufferLength = bufferLength;
  12130. this.iv = iv;
  12131. if (result.length === 0) {
  12132. return new Uint8Array([]);
  12133. }
  12134. // combining plain text blocks into one
  12135. var outputLength = 16 * result.length;
  12136. if (finalize) {
  12137. // undo a padding that is described in RFC 2898
  12138. var lastBlock = result[result.length - 1];
  12139. var psLen = lastBlock[15];
  12140. if (psLen <= 16) {
  12141. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  12142. if (lastBlock[i] !== psLen) {
  12143. // Invalid padding, assume that the block has no padding.
  12144. psLen = 0;
  12145. break;
  12146. }
  12147. }
  12148. outputLength -= psLen;
  12149. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  12150. }
  12151. }
  12152. var output = new Uint8Array(outputLength);
  12153. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12154. output.set(result[i], j);
  12155. }
  12156. return output;
  12157. }
  12158. AES256Cipher.prototype = {
  12159. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  12160. var i, sourceLength = data.length;
  12161. var buffer = this.buffer, bufferLength = this.bufferPosition;
  12162. // if not supplied an IV wait for IV values
  12163. // they are at the start of the stream
  12164. if (iv) {
  12165. this.iv = iv;
  12166. } else {
  12167. for (i = 0; bufferLength < 16 &&
  12168. i < sourceLength; ++i, ++bufferLength) {
  12169. buffer[bufferLength] = data[i];
  12170. }
  12171. if (bufferLength < 16) {
  12172. //need more data
  12173. this.bufferLength = bufferLength;
  12174. return new Uint8Array([]);
  12175. }
  12176. this.iv = buffer;
  12177. data = data.subarray(16);
  12178. }
  12179. this.buffer = new Uint8Array(16);
  12180. this.bufferLength = 0;
  12181. // starting decryption
  12182. this.decryptBlock = decryptBlock2;
  12183. return this.decryptBlock(data, finalize);
  12184. },
  12185. encrypt: function AES256Cipher_encrypt(data, iv) {
  12186. var i, j, ii, sourceLength = data.length,
  12187. buffer = this.buffer, bufferLength = this.bufferPosition,
  12188. result = [];
  12189. if (!iv) {
  12190. iv = new Uint8Array(16);
  12191. }
  12192. for (i = 0; i < sourceLength; ++i) {
  12193. buffer[bufferLength] = data[i];
  12194. ++bufferLength;
  12195. if (bufferLength < 16) {
  12196. continue;
  12197. }
  12198. for (j = 0; j < 16; ++j) {
  12199. buffer[j] ^= iv[j];
  12200. }
  12201. // buffer is full, encrypting
  12202. var cipher = encrypt256(buffer, this.key);
  12203. this.iv = cipher;
  12204. result.push(cipher);
  12205. buffer = new Uint8Array(16);
  12206. bufferLength = 0;
  12207. }
  12208. // saving incomplete buffer
  12209. this.buffer = buffer;
  12210. this.bufferLength = bufferLength;
  12211. this.iv = iv;
  12212. if (result.length === 0) {
  12213. return new Uint8Array([]);
  12214. }
  12215. // combining plain text blocks into one
  12216. var outputLength = 16 * result.length;
  12217. var output = new Uint8Array(outputLength);
  12218. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12219. output.set(result[i], j);
  12220. }
  12221. return output;
  12222. }
  12223. };
  12224. return AES256Cipher;
  12225. })();
  12226. var PDF17 = (function PDF17Closure() {
  12227. function compareByteArrays(array1, array2) {
  12228. if (array1.length !== array2.length) {
  12229. return false;
  12230. }
  12231. for (var i = 0; i < array1.length; i++) {
  12232. if (array1[i] !== array2[i]) {
  12233. return false;
  12234. }
  12235. }
  12236. return true;
  12237. }
  12238. function PDF17() {
  12239. }
  12240. PDF17.prototype = {
  12241. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  12242. ownerValidationSalt,
  12243. userBytes,
  12244. ownerPassword) {
  12245. var hashData = new Uint8Array(password.length + 56);
  12246. hashData.set(password, 0);
  12247. hashData.set(ownerValidationSalt, password.length);
  12248. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12249. var result = calculateSHA256(hashData, 0, hashData.length);
  12250. return compareByteArrays(result, ownerPassword);
  12251. },
  12252. checkUserPassword: function PDF17_checkUserPassword(password,
  12253. userValidationSalt,
  12254. userPassword) {
  12255. var hashData = new Uint8Array(password.length + 8);
  12256. hashData.set(password, 0);
  12257. hashData.set(userValidationSalt, password.length);
  12258. var result = calculateSHA256(hashData, 0, hashData.length);
  12259. return compareByteArrays(result, userPassword);
  12260. },
  12261. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  12262. ownerEncryption) {
  12263. var hashData = new Uint8Array(password.length + 56);
  12264. hashData.set(password, 0);
  12265. hashData.set(ownerKeySalt, password.length);
  12266. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12267. var key = calculateSHA256(hashData, 0, hashData.length);
  12268. var cipher = new AES256Cipher(key);
  12269. return cipher.decryptBlock(ownerEncryption,
  12270. false,
  12271. new Uint8Array(16));
  12272. },
  12273. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  12274. userEncryption) {
  12275. var hashData = new Uint8Array(password.length + 8);
  12276. hashData.set(password, 0);
  12277. hashData.set(userKeySalt, password.length);
  12278. //key is the decryption key for the UE string
  12279. var key = calculateSHA256(hashData, 0, hashData.length);
  12280. var cipher = new AES256Cipher(key);
  12281. return cipher.decryptBlock(userEncryption,
  12282. false,
  12283. new Uint8Array(16));
  12284. }
  12285. };
  12286. return PDF17;
  12287. })();
  12288. var PDF20 = (function PDF20Closure() {
  12289. function concatArrays(array1, array2) {
  12290. var t = new Uint8Array(array1.length + array2.length);
  12291. t.set(array1, 0);
  12292. t.set(array2, array1.length);
  12293. return t;
  12294. }
  12295. function calculatePDF20Hash(password, input, userBytes) {
  12296. //This refers to Algorithm 2.B as defined in ISO 32000-2
  12297. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  12298. var e = [0];
  12299. var i = 0;
  12300. while (i < 64 || e[e.length - 1] > i - 32) {
  12301. var arrayLength = password.length + k.length + userBytes.length;
  12302. var k1 = new Uint8Array(arrayLength * 64);
  12303. var array = concatArrays(password, k);
  12304. array = concatArrays(array, userBytes);
  12305. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  12306. k1.set(array, pos);
  12307. }
  12308. //AES128 CBC NO PADDING with
  12309. //first 16 bytes of k as the key and the second 16 as the iv.
  12310. var cipher = new AES128Cipher(k.subarray(0, 16));
  12311. e = cipher.encrypt(k1, k.subarray(16, 32));
  12312. //Now we have to take the first 16 bytes of an unsigned
  12313. //big endian integer... and compute the remainder
  12314. //modulo 3.... That is a fairly large number and
  12315. //JavaScript isn't going to handle that well...
  12316. //So we're using a trick that allows us to perform
  12317. //modulo math byte by byte
  12318. var remainder = 0;
  12319. for (var z = 0; z < 16; z++) {
  12320. remainder *= (256 % 3);
  12321. remainder %= 3;
  12322. remainder += ((e[z] >>> 0) % 3);
  12323. remainder %= 3;
  12324. }
  12325. if (remainder === 0) {
  12326. k = calculateSHA256(e, 0, e.length);
  12327. }
  12328. else if (remainder === 1) {
  12329. k = calculateSHA384(e, 0, e.length);
  12330. }
  12331. else if (remainder === 2) {
  12332. k = calculateSHA512(e, 0, e.length);
  12333. }
  12334. i++;
  12335. }
  12336. return k.subarray(0, 32);
  12337. }
  12338. function PDF20() {
  12339. }
  12340. function compareByteArrays(array1, array2) {
  12341. if (array1.length !== array2.length) {
  12342. return false;
  12343. }
  12344. for (var i = 0; i < array1.length; i++) {
  12345. if (array1[i] !== array2[i]) {
  12346. return false;
  12347. }
  12348. }
  12349. return true;
  12350. }
  12351. PDF20.prototype = {
  12352. hash: function PDF20_hash(password, concatBytes, userBytes) {
  12353. return calculatePDF20Hash(password, concatBytes, userBytes);
  12354. },
  12355. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  12356. ownerValidationSalt,
  12357. userBytes,
  12358. ownerPassword) {
  12359. var hashData = new Uint8Array(password.length + 56);
  12360. hashData.set(password, 0);
  12361. hashData.set(ownerValidationSalt, password.length);
  12362. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12363. var result = calculatePDF20Hash(password, hashData, userBytes);
  12364. return compareByteArrays(result, ownerPassword);
  12365. },
  12366. checkUserPassword: function PDF20_checkUserPassword(password,
  12367. userValidationSalt,
  12368. userPassword) {
  12369. var hashData = new Uint8Array(password.length + 8);
  12370. hashData.set(password, 0);
  12371. hashData.set(userValidationSalt, password.length);
  12372. var result = calculatePDF20Hash(password, hashData, []);
  12373. return compareByteArrays(result, userPassword);
  12374. },
  12375. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  12376. ownerEncryption) {
  12377. var hashData = new Uint8Array(password.length + 56);
  12378. hashData.set(password, 0);
  12379. hashData.set(ownerKeySalt, password.length);
  12380. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12381. var key = calculatePDF20Hash(password, hashData, userBytes);
  12382. var cipher = new AES256Cipher(key);
  12383. return cipher.decryptBlock(ownerEncryption,
  12384. false,
  12385. new Uint8Array(16));
  12386. },
  12387. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  12388. userEncryption) {
  12389. var hashData = new Uint8Array(password.length + 8);
  12390. hashData.set(password, 0);
  12391. hashData.set(userKeySalt, password.length);
  12392. //key is the decryption key for the UE string
  12393. var key = calculatePDF20Hash(password, hashData, []);
  12394. var cipher = new AES256Cipher(key);
  12395. return cipher.decryptBlock(userEncryption,
  12396. false,
  12397. new Uint8Array(16));
  12398. }
  12399. };
  12400. return PDF20;
  12401. })();
  12402. var CipherTransform = (function CipherTransformClosure() {
  12403. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  12404. this.stringCipherConstructor = stringCipherConstructor;
  12405. this.streamCipherConstructor = streamCipherConstructor;
  12406. }
  12407. CipherTransform.prototype = {
  12408. createStream: function CipherTransform_createStream(stream, length) {
  12409. var cipher = new this.streamCipherConstructor();
  12410. return new DecryptStream(stream, length,
  12411. function cipherTransformDecryptStream(data, finalize) {
  12412. return cipher.decryptBlock(data, finalize);
  12413. }
  12414. );
  12415. },
  12416. decryptString: function CipherTransform_decryptString(s) {
  12417. var cipher = new this.stringCipherConstructor();
  12418. var data = stringToBytes(s);
  12419. data = cipher.decryptBlock(data, true);
  12420. return bytesToString(data);
  12421. }
  12422. };
  12423. return CipherTransform;
  12424. })();
  12425. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  12426. var defaultPasswordBytes = new Uint8Array([
  12427. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  12428. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  12429. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  12430. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  12431. function createEncryptionKey20(revision, password, ownerPassword,
  12432. ownerValidationSalt, ownerKeySalt, uBytes,
  12433. userPassword, userValidationSalt, userKeySalt,
  12434. ownerEncryption, userEncryption, perms) {
  12435. if (password) {
  12436. var passwordLength = Math.min(127, password.length);
  12437. password = password.subarray(0, passwordLength);
  12438. } else {
  12439. password = [];
  12440. }
  12441. var pdfAlgorithm;
  12442. if (revision === 6) {
  12443. pdfAlgorithm = new PDF20();
  12444. } else {
  12445. pdfAlgorithm = new PDF17();
  12446. }
  12447. if (pdfAlgorithm) {
  12448. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  12449. userPassword)) {
  12450. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  12451. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  12452. uBytes,
  12453. ownerPassword)) {
  12454. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  12455. ownerEncryption);
  12456. }
  12457. }
  12458. return null;
  12459. }
  12460. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  12461. flags, revision, keyLength, encryptMetadata) {
  12462. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  12463. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  12464. if (password) {
  12465. n = Math.min(32, password.length);
  12466. for (; i < n; ++i) {
  12467. hashData[i] = password[i];
  12468. }
  12469. }
  12470. j = 0;
  12471. while (i < 32) {
  12472. hashData[i++] = defaultPasswordBytes[j++];
  12473. }
  12474. // as now the padded password in the hashData[0..i]
  12475. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  12476. hashData[i++] = ownerPassword[j];
  12477. }
  12478. hashData[i++] = flags & 0xFF;
  12479. hashData[i++] = (flags >> 8) & 0xFF;
  12480. hashData[i++] = (flags >> 16) & 0xFF;
  12481. hashData[i++] = (flags >>> 24) & 0xFF;
  12482. for (j = 0, n = fileId.length; j < n; ++j) {
  12483. hashData[i++] = fileId[j];
  12484. }
  12485. if (revision >= 4 && !encryptMetadata) {
  12486. hashData[i++] = 0xFF;
  12487. hashData[i++] = 0xFF;
  12488. hashData[i++] = 0xFF;
  12489. hashData[i++] = 0xFF;
  12490. }
  12491. var hash = calculateMD5(hashData, 0, i);
  12492. var keyLengthInBytes = keyLength >> 3;
  12493. if (revision >= 3) {
  12494. for (j = 0; j < 50; ++j) {
  12495. hash = calculateMD5(hash, 0, keyLengthInBytes);
  12496. }
  12497. }
  12498. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  12499. var cipher, checkData;
  12500. if (revision >= 3) {
  12501. for (i = 0; i < 32; ++i) {
  12502. hashData[i] = defaultPasswordBytes[i];
  12503. }
  12504. for (j = 0, n = fileId.length; j < n; ++j) {
  12505. hashData[i++] = fileId[j];
  12506. }
  12507. cipher = new ARCFourCipher(encryptionKey);
  12508. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  12509. n = encryptionKey.length;
  12510. var derivedKey = new Uint8Array(n), k;
  12511. for (j = 1; j <= 19; ++j) {
  12512. for (k = 0; k < n; ++k) {
  12513. derivedKey[k] = encryptionKey[k] ^ j;
  12514. }
  12515. cipher = new ARCFourCipher(derivedKey);
  12516. checkData = cipher.encryptBlock(checkData);
  12517. }
  12518. for (j = 0, n = checkData.length; j < n; ++j) {
  12519. if (userPassword[j] !== checkData[j]) {
  12520. return null;
  12521. }
  12522. }
  12523. } else {
  12524. cipher = new ARCFourCipher(encryptionKey);
  12525. checkData = cipher.encryptBlock(defaultPasswordBytes);
  12526. for (j = 0, n = checkData.length; j < n; ++j) {
  12527. if (userPassword[j] !== checkData[j]) {
  12528. return null;
  12529. }
  12530. }
  12531. }
  12532. return encryptionKey;
  12533. }
  12534. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  12535. var hashData = new Uint8Array(32), i = 0, j, n;
  12536. n = Math.min(32, password.length);
  12537. for (; i < n; ++i) {
  12538. hashData[i] = password[i];
  12539. }
  12540. j = 0;
  12541. while (i < 32) {
  12542. hashData[i++] = defaultPasswordBytes[j++];
  12543. }
  12544. var hash = calculateMD5(hashData, 0, i);
  12545. var keyLengthInBytes = keyLength >> 3;
  12546. if (revision >= 3) {
  12547. for (j = 0; j < 50; ++j) {
  12548. hash = calculateMD5(hash, 0, hash.length);
  12549. }
  12550. }
  12551. var cipher, userPassword;
  12552. if (revision >= 3) {
  12553. userPassword = ownerPassword;
  12554. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  12555. for (j = 19; j >= 0; j--) {
  12556. for (k = 0; k < keyLengthInBytes; ++k) {
  12557. derivedKey[k] = hash[k] ^ j;
  12558. }
  12559. cipher = new ARCFourCipher(derivedKey);
  12560. userPassword = cipher.encryptBlock(userPassword);
  12561. }
  12562. } else {
  12563. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  12564. userPassword = cipher.encryptBlock(ownerPassword);
  12565. }
  12566. return userPassword;
  12567. }
  12568. var identityName = Name.get('Identity');
  12569. function CipherTransformFactory(dict, fileId, password) {
  12570. var filter = dict.get('Filter');
  12571. if (!isName(filter) || filter.name !== 'Standard') {
  12572. error('unknown encryption method');
  12573. }
  12574. this.dict = dict;
  12575. var algorithm = dict.get('V');
  12576. if (!isInt(algorithm) ||
  12577. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  12578. algorithm !== 5)) {
  12579. error('unsupported encryption algorithm');
  12580. }
  12581. this.algorithm = algorithm;
  12582. var keyLength = dict.get('Length') || 40;
  12583. if (!isInt(keyLength) ||
  12584. keyLength < 40 || (keyLength % 8) !== 0) {
  12585. error('invalid key length');
  12586. }
  12587. // prepare keys
  12588. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  12589. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  12590. var flags = dict.get('P');
  12591. var revision = dict.get('R');
  12592. // meaningful when V is 4 or 5
  12593. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  12594. dict.get('EncryptMetadata') !== false);
  12595. this.encryptMetadata = encryptMetadata;
  12596. var fileIdBytes = stringToBytes(fileId);
  12597. var passwordBytes;
  12598. if (password) {
  12599. passwordBytes = stringToBytes(password);
  12600. }
  12601. var encryptionKey;
  12602. if (algorithm !== 5) {
  12603. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  12604. ownerPassword, userPassword, flags,
  12605. revision, keyLength, encryptMetadata);
  12606. }
  12607. else {
  12608. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  12609. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  12610. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  12611. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  12612. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  12613. var ownerEncryption = stringToBytes(dict.get('OE'));
  12614. var userEncryption = stringToBytes(dict.get('UE'));
  12615. var perms = stringToBytes(dict.get('Perms'));
  12616. encryptionKey =
  12617. createEncryptionKey20(revision, passwordBytes,
  12618. ownerPassword, ownerValidationSalt,
  12619. ownerKeySalt, uBytes,
  12620. userPassword, userValidationSalt,
  12621. userKeySalt, ownerEncryption,
  12622. userEncryption, perms);
  12623. }
  12624. if (!encryptionKey && !password) {
  12625. throw new PasswordException('No password given',
  12626. PasswordResponses.NEED_PASSWORD);
  12627. } else if (!encryptionKey && password) {
  12628. // Attempting use the password as an owner password
  12629. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  12630. revision, keyLength);
  12631. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  12632. ownerPassword, userPassword, flags,
  12633. revision, keyLength, encryptMetadata);
  12634. }
  12635. if (!encryptionKey) {
  12636. throw new PasswordException('Incorrect Password',
  12637. PasswordResponses.INCORRECT_PASSWORD);
  12638. }
  12639. this.encryptionKey = encryptionKey;
  12640. if (algorithm >= 4) {
  12641. this.cf = dict.get('CF');
  12642. this.stmf = dict.get('StmF') || identityName;
  12643. this.strf = dict.get('StrF') || identityName;
  12644. this.eff = dict.get('EFF') || this.strf;
  12645. }
  12646. }
  12647. function buildObjectKey(num, gen, encryptionKey, isAes) {
  12648. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  12649. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  12650. key[i] = encryptionKey[i];
  12651. }
  12652. key[i++] = num & 0xFF;
  12653. key[i++] = (num >> 8) & 0xFF;
  12654. key[i++] = (num >> 16) & 0xFF;
  12655. key[i++] = gen & 0xFF;
  12656. key[i++] = (gen >> 8) & 0xFF;
  12657. if (isAes) {
  12658. key[i++] = 0x73;
  12659. key[i++] = 0x41;
  12660. key[i++] = 0x6C;
  12661. key[i++] = 0x54;
  12662. }
  12663. var hash = calculateMD5(key, 0, i);
  12664. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  12665. }
  12666. function buildCipherConstructor(cf, name, num, gen, key) {
  12667. var cryptFilter = cf.get(name.name);
  12668. var cfm;
  12669. if (cryptFilter !== null && cryptFilter !== undefined) {
  12670. cfm = cryptFilter.get('CFM');
  12671. }
  12672. if (!cfm || cfm.name === 'None') {
  12673. return function cipherTransformFactoryBuildCipherConstructorNone() {
  12674. return new NullCipher();
  12675. };
  12676. }
  12677. if ('V2' === cfm.name) {
  12678. return function cipherTransformFactoryBuildCipherConstructorV2() {
  12679. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  12680. };
  12681. }
  12682. if ('AESV2' === cfm.name) {
  12683. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  12684. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  12685. };
  12686. }
  12687. if ('AESV3' === cfm.name) {
  12688. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  12689. return new AES256Cipher(key);
  12690. };
  12691. }
  12692. error('Unknown crypto method');
  12693. }
  12694. CipherTransformFactory.prototype = {
  12695. createCipherTransform:
  12696. function CipherTransformFactory_createCipherTransform(num, gen) {
  12697. if (this.algorithm === 4 || this.algorithm === 5) {
  12698. return new CipherTransform(
  12699. buildCipherConstructor(this.cf, this.stmf,
  12700. num, gen, this.encryptionKey),
  12701. buildCipherConstructor(this.cf, this.strf,
  12702. num, gen, this.encryptionKey));
  12703. }
  12704. // algorithms 1 and 2
  12705. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  12706. var cipherConstructor = function buildCipherCipherConstructor() {
  12707. return new ARCFourCipher(key);
  12708. };
  12709. return new CipherTransform(cipherConstructor, cipherConstructor);
  12710. }
  12711. };
  12712. return CipherTransformFactory;
  12713. })();
  12714. var PatternType = {
  12715. FUNCTION_BASED: 1,
  12716. AXIAL: 2,
  12717. RADIAL: 3,
  12718. FREE_FORM_MESH: 4,
  12719. LATTICE_FORM_MESH: 5,
  12720. COONS_PATCH_MESH: 6,
  12721. TENSOR_PATCH_MESH: 7
  12722. };
  12723. var Pattern = (function PatternClosure() {
  12724. // Constructor should define this.getPattern
  12725. function Pattern() {
  12726. error('should not call Pattern constructor');
  12727. }
  12728. Pattern.prototype = {
  12729. // Input: current Canvas context
  12730. // Output: the appropriate fillStyle or strokeStyle
  12731. getPattern: function Pattern_getPattern(ctx) {
  12732. error('Should not call Pattern.getStyle: ' + ctx);
  12733. }
  12734. };
  12735. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  12736. res) {
  12737. var dict = isStream(shading) ? shading.dict : shading;
  12738. var type = dict.get('ShadingType');
  12739. switch (type) {
  12740. case PatternType.AXIAL:
  12741. case PatternType.RADIAL:
  12742. // Both radial and axial shadings are handled by RadialAxial shading.
  12743. return new Shadings.RadialAxial(dict, matrix, xref, res);
  12744. case PatternType.FREE_FORM_MESH:
  12745. case PatternType.LATTICE_FORM_MESH:
  12746. case PatternType.COONS_PATCH_MESH:
  12747. case PatternType.TENSOR_PATCH_MESH:
  12748. return new Shadings.Mesh(shading, matrix, xref, res);
  12749. default:
  12750. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  12751. return new Shadings.Dummy();
  12752. }
  12753. };
  12754. return Pattern;
  12755. })();
  12756. var Shadings = {};
  12757. // A small number to offset the first/last color stops so we can insert ones to
  12758. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  12759. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  12760. // internally so we have to go bigger.
  12761. Shadings.SMALL_NUMBER = 1e-2;
  12762. // Radial and axial shading have very similar implementations
  12763. // If needed, the implementations can be broken into two classes
  12764. Shadings.RadialAxial = (function RadialAxialClosure() {
  12765. function RadialAxial(dict, matrix, xref, res) {
  12766. this.matrix = matrix;
  12767. this.coordsArr = dict.get('Coords');
  12768. this.shadingType = dict.get('ShadingType');
  12769. this.type = 'Pattern';
  12770. var cs = dict.get('ColorSpace', 'CS');
  12771. cs = ColorSpace.parse(cs, xref, res);
  12772. this.cs = cs;
  12773. var t0 = 0.0, t1 = 1.0;
  12774. if (dict.has('Domain')) {
  12775. var domainArr = dict.get('Domain');
  12776. t0 = domainArr[0];
  12777. t1 = domainArr[1];
  12778. }
  12779. var extendStart = false, extendEnd = false;
  12780. if (dict.has('Extend')) {
  12781. var extendArr = dict.get('Extend');
  12782. extendStart = extendArr[0];
  12783. extendEnd = extendArr[1];
  12784. }
  12785. if (this.shadingType === PatternType.RADIAL &&
  12786. (!extendStart || !extendEnd)) {
  12787. // Radial gradient only currently works if either circle is fully within
  12788. // the other circle.
  12789. var x1 = this.coordsArr[0];
  12790. var y1 = this.coordsArr[1];
  12791. var r1 = this.coordsArr[2];
  12792. var x2 = this.coordsArr[3];
  12793. var y2 = this.coordsArr[4];
  12794. var r2 = this.coordsArr[5];
  12795. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  12796. if (r1 <= r2 + distance &&
  12797. r2 <= r1 + distance) {
  12798. warn('Unsupported radial gradient.');
  12799. }
  12800. }
  12801. this.extendStart = extendStart;
  12802. this.extendEnd = extendEnd;
  12803. var fnObj = dict.get('Function');
  12804. var fn = PDFFunction.parseArray(xref, fnObj);
  12805. // 10 samples seems good enough for now, but probably won't work
  12806. // if there are sharp color changes. Ideally, we would implement
  12807. // the spec faithfully and add lossless optimizations.
  12808. var diff = t1 - t0;
  12809. var step = diff / 10;
  12810. var colorStops = this.colorStops = [];
  12811. // Protect against bad domains so we don't end up in an infinte loop below.
  12812. if (t0 >= t1 || step <= 0) {
  12813. // Acrobat doesn't seem to handle these cases so we'll ignore for
  12814. // now.
  12815. info('Bad shading domain.');
  12816. return;
  12817. }
  12818. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  12819. var rgbColor;
  12820. for (var i = t0; i <= t1; i += step) {
  12821. ratio[0] = i;
  12822. fn(ratio, 0, color, 0);
  12823. rgbColor = cs.getRgb(color, 0);
  12824. var cssColor = Util.makeCssRgb(rgbColor);
  12825. colorStops.push([(i - t0) / diff, cssColor]);
  12826. }
  12827. var background = 'transparent';
  12828. if (dict.has('Background')) {
  12829. rgbColor = cs.getRgb(dict.get('Background'), 0);
  12830. background = Util.makeCssRgb(rgbColor);
  12831. }
  12832. if (!extendStart) {
  12833. // Insert a color stop at the front and offset the first real color stop
  12834. // so it doesn't conflict with the one we insert.
  12835. colorStops.unshift([0, background]);
  12836. colorStops[1][0] += Shadings.SMALL_NUMBER;
  12837. }
  12838. if (!extendEnd) {
  12839. // Same idea as above in extendStart but for the end.
  12840. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  12841. colorStops.push([1, background]);
  12842. }
  12843. this.colorStops = colorStops;
  12844. }
  12845. RadialAxial.prototype = {
  12846. getIR: function RadialAxial_getIR() {
  12847. var coordsArr = this.coordsArr;
  12848. var shadingType = this.shadingType;
  12849. var type, p0, p1, r0, r1;
  12850. if (shadingType === PatternType.AXIAL) {
  12851. p0 = [coordsArr[0], coordsArr[1]];
  12852. p1 = [coordsArr[2], coordsArr[3]];
  12853. r0 = null;
  12854. r1 = null;
  12855. type = 'axial';
  12856. } else if (shadingType === PatternType.RADIAL) {
  12857. p0 = [coordsArr[0], coordsArr[1]];
  12858. p1 = [coordsArr[3], coordsArr[4]];
  12859. r0 = coordsArr[2];
  12860. r1 = coordsArr[5];
  12861. type = 'radial';
  12862. } else {
  12863. error('getPattern type unknown: ' + shadingType);
  12864. }
  12865. var matrix = this.matrix;
  12866. if (matrix) {
  12867. p0 = Util.applyTransform(p0, matrix);
  12868. p1 = Util.applyTransform(p1, matrix);
  12869. }
  12870. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  12871. }
  12872. };
  12873. return RadialAxial;
  12874. })();
  12875. // All mesh shading. For now, they will be presented as set of the triangles
  12876. // to be drawn on the canvas and rgb color for each vertex.
  12877. Shadings.Mesh = (function MeshClosure() {
  12878. function MeshStreamReader(stream, context) {
  12879. this.stream = stream;
  12880. this.context = context;
  12881. this.buffer = 0;
  12882. this.bufferLength = 0;
  12883. var numComps = context.numComps;
  12884. this.tmpCompsBuf = new Float32Array(numComps);
  12885. var csNumComps = context.colorSpace;
  12886. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  12887. this.tmpCompsBuf;
  12888. }
  12889. MeshStreamReader.prototype = {
  12890. get hasData() {
  12891. if (this.stream.end) {
  12892. return this.stream.pos < this.stream.end;
  12893. }
  12894. if (this.bufferLength > 0) {
  12895. return true;
  12896. }
  12897. var nextByte = this.stream.getByte();
  12898. if (nextByte < 0) {
  12899. return false;
  12900. }
  12901. this.buffer = nextByte;
  12902. this.bufferLength = 8;
  12903. return true;
  12904. },
  12905. readBits: function MeshStreamReader_readBits(n) {
  12906. var buffer = this.buffer;
  12907. var bufferLength = this.bufferLength;
  12908. if (n === 32) {
  12909. if (bufferLength === 0) {
  12910. return ((this.stream.getByte() << 24) |
  12911. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  12912. this.stream.getByte()) >>> 0;
  12913. }
  12914. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  12915. (this.stream.getByte() << 8) | this.stream.getByte();
  12916. var nextByte = this.stream.getByte();
  12917. this.buffer = nextByte & ((1 << bufferLength) - 1);
  12918. return ((buffer << (8 - bufferLength)) |
  12919. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  12920. }
  12921. if (n === 8 && bufferLength === 0) {
  12922. return this.stream.getByte();
  12923. }
  12924. while (bufferLength < n) {
  12925. buffer = (buffer << 8) | this.stream.getByte();
  12926. bufferLength += 8;
  12927. }
  12928. bufferLength -= n;
  12929. this.bufferLength = bufferLength;
  12930. this.buffer = buffer & ((1 << bufferLength) - 1);
  12931. return buffer >> bufferLength;
  12932. },
  12933. align: function MeshStreamReader_align() {
  12934. this.buffer = 0;
  12935. this.bufferLength = 0;
  12936. },
  12937. readFlag: function MeshStreamReader_readFlag() {
  12938. return this.readBits(this.context.bitsPerFlag);
  12939. },
  12940. readCoordinate: function MeshStreamReader_readCoordinate() {
  12941. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  12942. var xi = this.readBits(bitsPerCoordinate);
  12943. var yi = this.readBits(bitsPerCoordinate);
  12944. var decode = this.context.decode;
  12945. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  12946. 2.3283064365386963e-10; // 2 ^ -32
  12947. return [
  12948. xi * scale * (decode[1] - decode[0]) + decode[0],
  12949. yi * scale * (decode[3] - decode[2]) + decode[2]
  12950. ];
  12951. },
  12952. readComponents: function MeshStreamReader_readComponents() {
  12953. var numComps = this.context.numComps;
  12954. var bitsPerComponent = this.context.bitsPerComponent;
  12955. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  12956. 2.3283064365386963e-10; // 2 ^ -32
  12957. var decode = this.context.decode;
  12958. var components = this.tmpCompsBuf;
  12959. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  12960. var ci = this.readBits(bitsPerComponent);
  12961. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  12962. }
  12963. var color = this.tmpCsCompsBuf;
  12964. if (this.context.colorFn) {
  12965. this.context.colorFn(components, 0, color, 0);
  12966. }
  12967. return this.context.colorSpace.getRgb(color, 0);
  12968. }
  12969. };
  12970. function decodeType4Shading(mesh, reader) {
  12971. var coords = mesh.coords;
  12972. var colors = mesh.colors;
  12973. var operators = [];
  12974. var ps = []; // not maintaining cs since that will match ps
  12975. var verticesLeft = 0; // assuming we have all data to start a new triangle
  12976. while (reader.hasData) {
  12977. var f = reader.readFlag();
  12978. var coord = reader.readCoordinate();
  12979. var color = reader.readComponents();
  12980. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  12981. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  12982. switch (f) {
  12983. case 0:
  12984. verticesLeft = 3;
  12985. break;
  12986. case 1:
  12987. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  12988. verticesLeft = 1;
  12989. break;
  12990. case 2:
  12991. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  12992. verticesLeft = 1;
  12993. break;
  12994. }
  12995. operators.push(f);
  12996. }
  12997. ps.push(coords.length);
  12998. coords.push(coord);
  12999. colors.push(color);
  13000. verticesLeft--;
  13001. reader.align();
  13002. }
  13003. var psPacked = new Int32Array(ps);
  13004. mesh.figures.push({
  13005. type: 'triangles',
  13006. coords: psPacked,
  13007. colors: psPacked
  13008. });
  13009. }
  13010. function decodeType5Shading(mesh, reader, verticesPerRow) {
  13011. var coords = mesh.coords;
  13012. var colors = mesh.colors;
  13013. var ps = []; // not maintaining cs since that will match ps
  13014. while (reader.hasData) {
  13015. var coord = reader.readCoordinate();
  13016. var color = reader.readComponents();
  13017. ps.push(coords.length);
  13018. coords.push(coord);
  13019. colors.push(color);
  13020. }
  13021. var psPacked = new Int32Array(ps);
  13022. mesh.figures.push({
  13023. type: 'lattice',
  13024. coords: psPacked,
  13025. colors: psPacked,
  13026. verticesPerRow: verticesPerRow
  13027. });
  13028. }
  13029. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  13030. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  13031. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  13032. var getB = (function getBClosure() {
  13033. function buildB(count) {
  13034. var lut = [];
  13035. for (var i = 0; i <= count; i++) {
  13036. var t = i / count, t_ = 1 - t;
  13037. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  13038. 3 * t * t * t_, t * t * t]));
  13039. }
  13040. return lut;
  13041. }
  13042. var cache = [];
  13043. return function getB(count) {
  13044. if (!cache[count]) {
  13045. cache[count] = buildB(count);
  13046. }
  13047. return cache[count];
  13048. };
  13049. })();
  13050. function buildFigureFromPatch(mesh, index) {
  13051. var figure = mesh.figures[index];
  13052. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  13053. var coords = mesh.coords, colors = mesh.colors;
  13054. var pi = figure.coords;
  13055. var ci = figure.colors;
  13056. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  13057. coords[pi[12]][0], coords[pi[15]][0]);
  13058. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  13059. coords[pi[12]][1], coords[pi[15]][1]);
  13060. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  13061. coords[pi[12]][0], coords[pi[15]][0]);
  13062. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  13063. coords[pi[12]][1], coords[pi[15]][1]);
  13064. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  13065. (mesh.bounds[2] - mesh.bounds[0]));
  13066. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13067. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  13068. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  13069. (mesh.bounds[3] - mesh.bounds[1]));
  13070. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13071. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  13072. var verticesPerRow = splitXBy + 1;
  13073. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  13074. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  13075. var k = 0;
  13076. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  13077. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  13078. c2 = colors[ci[2]], c3 = colors[ci[3]];
  13079. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  13080. for (var row = 0; row <= splitYBy; row++) {
  13081. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  13082. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  13083. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  13084. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  13085. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  13086. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  13087. for (var col = 0; col <= splitXBy; col++, k++) {
  13088. if ((row === 0 || row === splitYBy) &&
  13089. (col === 0 || col === splitXBy)) {
  13090. continue;
  13091. }
  13092. var x = 0, y = 0;
  13093. var q = 0;
  13094. for (var i = 0; i <= 3; i++) {
  13095. for (var j = 0; j <= 3; j++, q++) {
  13096. var m = bRow[row][i] * bCol[col][j];
  13097. x += coords[pi[q]][0] * m;
  13098. y += coords[pi[q]][1] * m;
  13099. }
  13100. }
  13101. figureCoords[k] = coords.length;
  13102. coords.push([x, y]);
  13103. figureColors[k] = colors.length;
  13104. var newColor = new Uint8Array(3);
  13105. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  13106. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  13107. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  13108. colors.push(newColor);
  13109. }
  13110. }
  13111. figureCoords[0] = pi[0];
  13112. figureColors[0] = ci[0];
  13113. figureCoords[splitXBy] = pi[3];
  13114. figureColors[splitXBy] = ci[1];
  13115. figureCoords[verticesPerRow * splitYBy] = pi[12];
  13116. figureColors[verticesPerRow * splitYBy] = ci[2];
  13117. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  13118. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  13119. mesh.figures[index] = {
  13120. type: 'lattice',
  13121. coords: figureCoords,
  13122. colors: figureColors,
  13123. verticesPerRow: verticesPerRow
  13124. };
  13125. }
  13126. function decodeType6Shading(mesh, reader) {
  13127. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  13128. var coords = mesh.coords;
  13129. var colors = mesh.colors;
  13130. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13131. var cs = new Int32Array(4); // c00, c30, c03, c33
  13132. while (reader.hasData) {
  13133. var f = reader.readFlag();
  13134. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  13135. var i, ii;
  13136. var pi = coords.length;
  13137. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  13138. coords.push(reader.readCoordinate());
  13139. }
  13140. var ci = colors.length;
  13141. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13142. colors.push(reader.readComponents());
  13143. }
  13144. var tmp1, tmp2, tmp3, tmp4;
  13145. switch (f) {
  13146. case 0:
  13147. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13148. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13149. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  13150. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13151. cs[2] = ci + 1; cs[3] = ci + 2;
  13152. cs[0] = ci; cs[1] = ci + 3;
  13153. break;
  13154. case 1:
  13155. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13156. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13157. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  13158. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  13159. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13160. tmp1 = cs[2]; tmp2 = cs[3];
  13161. cs[2] = ci + 1; cs[3] = ci;
  13162. cs[0] = tmp1; cs[1] = tmp2;
  13163. break;
  13164. case 2:
  13165. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13166. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  13167. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  13168. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13169. cs[2] = cs[3]; cs[3] = ci + 1;
  13170. cs[0] = cs[1]; cs[1] = ci;
  13171. break;
  13172. case 3:
  13173. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13174. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13175. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  13176. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13177. cs[2] = cs[0]; cs[3] = cs[1];
  13178. cs[0] = ci; cs[1] = ci + 1;
  13179. break;
  13180. }
  13181. // set p11, p12, p21, p22
  13182. ps[5] = coords.length;
  13183. coords.push([
  13184. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  13185. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  13186. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13187. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  13188. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  13189. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  13190. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13191. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  13192. ]);
  13193. ps[6] = coords.length;
  13194. coords.push([
  13195. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  13196. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  13197. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13198. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  13199. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  13200. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  13201. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13202. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  13203. ]);
  13204. ps[9] = coords.length;
  13205. coords.push([
  13206. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  13207. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  13208. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13209. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  13210. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  13211. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  13212. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13213. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  13214. ]);
  13215. ps[10] = coords.length;
  13216. coords.push([
  13217. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  13218. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  13219. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13220. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  13221. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  13222. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  13223. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13224. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  13225. ]);
  13226. mesh.figures.push({
  13227. type: 'patch',
  13228. coords: new Int32Array(ps), // making copies of ps and cs
  13229. colors: new Int32Array(cs)
  13230. });
  13231. }
  13232. }
  13233. function decodeType7Shading(mesh, reader) {
  13234. var coords = mesh.coords;
  13235. var colors = mesh.colors;
  13236. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13237. var cs = new Int32Array(4); // c00, c30, c03, c33
  13238. while (reader.hasData) {
  13239. var f = reader.readFlag();
  13240. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  13241. var i, ii;
  13242. var pi = coords.length;
  13243. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  13244. coords.push(reader.readCoordinate());
  13245. }
  13246. var ci = colors.length;
  13247. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13248. colors.push(reader.readComponents());
  13249. }
  13250. var tmp1, tmp2, tmp3, tmp4;
  13251. switch (f) {
  13252. case 0:
  13253. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13254. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  13255. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  13256. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13257. cs[2] = ci + 1; cs[3] = ci + 2;
  13258. cs[0] = ci; cs[1] = ci + 3;
  13259. break;
  13260. case 1:
  13261. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13262. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13263. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  13264. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  13265. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13266. tmp1 = cs[2]; tmp2 = cs[3];
  13267. cs[2] = ci + 1; cs[3] = ci;
  13268. cs[0] = tmp1; cs[1] = tmp2;
  13269. break;
  13270. case 2:
  13271. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13272. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  13273. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  13274. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13275. cs[2] = cs[3]; cs[3] = ci + 1;
  13276. cs[0] = cs[1]; cs[1] = ci;
  13277. break;
  13278. case 3:
  13279. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13280. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  13281. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  13282. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13283. cs[2] = cs[0]; cs[3] = cs[1];
  13284. cs[0] = ci; cs[1] = ci + 1;
  13285. break;
  13286. }
  13287. mesh.figures.push({
  13288. type: 'patch',
  13289. coords: new Int32Array(ps), // making copies of ps and cs
  13290. colors: new Int32Array(cs)
  13291. });
  13292. }
  13293. }
  13294. function updateBounds(mesh) {
  13295. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  13296. maxX = minX, maxY = minY;
  13297. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  13298. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  13299. minX = minX > x ? x : minX;
  13300. minY = minY > y ? y : minY;
  13301. maxX = maxX < x ? x : maxX;
  13302. maxY = maxY < y ? y : maxY;
  13303. }
  13304. mesh.bounds = [minX, minY, maxX, maxY];
  13305. }
  13306. function packData(mesh) {
  13307. var i, ii, j, jj;
  13308. var coords = mesh.coords;
  13309. var coordsPacked = new Float32Array(coords.length * 2);
  13310. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  13311. var xy = coords[i];
  13312. coordsPacked[j++] = xy[0];
  13313. coordsPacked[j++] = xy[1];
  13314. }
  13315. mesh.coords = coordsPacked;
  13316. var colors = mesh.colors;
  13317. var colorsPacked = new Uint8Array(colors.length * 3);
  13318. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  13319. var c = colors[i];
  13320. colorsPacked[j++] = c[0];
  13321. colorsPacked[j++] = c[1];
  13322. colorsPacked[j++] = c[2];
  13323. }
  13324. mesh.colors = colorsPacked;
  13325. var figures = mesh.figures;
  13326. for (i = 0, ii = figures.length; i < ii; i++) {
  13327. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  13328. for (j = 0, jj = ps.length; j < jj; j++) {
  13329. ps[j] *= 2;
  13330. cs[j] *= 3;
  13331. }
  13332. }
  13333. }
  13334. function Mesh(stream, matrix, xref, res) {
  13335. assert(isStream(stream), 'Mesh data is not a stream');
  13336. var dict = stream.dict;
  13337. this.matrix = matrix;
  13338. this.shadingType = dict.get('ShadingType');
  13339. this.type = 'Pattern';
  13340. this.bbox = dict.get('BBox');
  13341. var cs = dict.get('ColorSpace', 'CS');
  13342. cs = ColorSpace.parse(cs, xref, res);
  13343. this.cs = cs;
  13344. this.background = dict.has('Background') ?
  13345. cs.getRgb(dict.get('Background'), 0) : null;
  13346. var fnObj = dict.get('Function');
  13347. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  13348. this.coords = [];
  13349. this.colors = [];
  13350. this.figures = [];
  13351. var decodeContext = {
  13352. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  13353. bitsPerComponent: dict.get('BitsPerComponent'),
  13354. bitsPerFlag: dict.get('BitsPerFlag'),
  13355. decode: dict.get('Decode'),
  13356. colorFn: fn,
  13357. colorSpace: cs,
  13358. numComps: fn ? 1 : cs.numComps
  13359. };
  13360. var reader = new MeshStreamReader(stream, decodeContext);
  13361. var patchMesh = false;
  13362. switch (this.shadingType) {
  13363. case PatternType.FREE_FORM_MESH:
  13364. decodeType4Shading(this, reader);
  13365. break;
  13366. case PatternType.LATTICE_FORM_MESH:
  13367. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  13368. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  13369. decodeType5Shading(this, reader, verticesPerRow);
  13370. break;
  13371. case PatternType.COONS_PATCH_MESH:
  13372. decodeType6Shading(this, reader);
  13373. patchMesh = true;
  13374. break;
  13375. case PatternType.TENSOR_PATCH_MESH:
  13376. decodeType7Shading(this, reader);
  13377. patchMesh = true;
  13378. break;
  13379. default:
  13380. error('Unsupported mesh type.');
  13381. break;
  13382. }
  13383. if (patchMesh) {
  13384. // dirty bounds calculation for determining, how dense shall be triangles
  13385. updateBounds(this);
  13386. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  13387. buildFigureFromPatch(this, i);
  13388. }
  13389. }
  13390. // calculate bounds
  13391. updateBounds(this);
  13392. packData(this);
  13393. }
  13394. Mesh.prototype = {
  13395. getIR: function Mesh_getIR() {
  13396. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  13397. this.bounds, this.matrix, this.bbox, this.background];
  13398. }
  13399. };
  13400. return Mesh;
  13401. })();
  13402. Shadings.Dummy = (function DummyClosure() {
  13403. function Dummy() {
  13404. this.type = 'Pattern';
  13405. }
  13406. Dummy.prototype = {
  13407. getIR: function Dummy_getIR() {
  13408. return ['Dummy'];
  13409. }
  13410. };
  13411. return Dummy;
  13412. })();
  13413. function getTilingPatternIR(operatorList, dict, args) {
  13414. var matrix = dict.get('Matrix');
  13415. var bbox = dict.get('BBox');
  13416. var xstep = dict.get('XStep');
  13417. var ystep = dict.get('YStep');
  13418. var paintType = dict.get('PaintType');
  13419. var tilingType = dict.get('TilingType');
  13420. return [
  13421. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  13422. paintType, tilingType
  13423. ];
  13424. }
  13425. var PartialEvaluator = (function PartialEvaluatorClosure() {
  13426. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  13427. uniquePrefix, idCounters, fontCache) {
  13428. this.pdfManager = pdfManager;
  13429. this.xref = xref;
  13430. this.handler = handler;
  13431. this.pageIndex = pageIndex;
  13432. this.uniquePrefix = uniquePrefix;
  13433. this.idCounters = idCounters;
  13434. this.fontCache = fontCache;
  13435. }
  13436. // Trying to minimize Date.now() usage and check every 100 time
  13437. var TIME_SLOT_DURATION_MS = 20;
  13438. var CHECK_TIME_EVERY = 100;
  13439. function TimeSlotManager() {
  13440. this.reset();
  13441. }
  13442. TimeSlotManager.prototype = {
  13443. check: function TimeSlotManager_check() {
  13444. if (++this.checked < CHECK_TIME_EVERY) {
  13445. return false;
  13446. }
  13447. this.checked = 0;
  13448. return this.endTime <= Date.now();
  13449. },
  13450. reset: function TimeSlotManager_reset() {
  13451. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  13452. this.checked = 0;
  13453. }
  13454. };
  13455. var deferred = Promise.resolve();
  13456. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  13457. PartialEvaluator.prototype = {
  13458. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  13459. if (!isDict(resources)) {
  13460. return false;
  13461. }
  13462. var processed = Object.create(null);
  13463. if (resources.objId) {
  13464. processed[resources.objId] = true;
  13465. }
  13466. var nodes = [resources];
  13467. while (nodes.length) {
  13468. var key;
  13469. var node = nodes.shift();
  13470. // First check the current resources for blend modes.
  13471. var graphicStates = node.get('ExtGState');
  13472. if (isDict(graphicStates)) {
  13473. graphicStates = graphicStates.getAll();
  13474. for (key in graphicStates) {
  13475. var graphicState = graphicStates[key];
  13476. var bm = graphicState['BM'];
  13477. if (isName(bm) && bm.name !== 'Normal') {
  13478. return true;
  13479. }
  13480. }
  13481. }
  13482. // Descend into the XObjects to look for more resources and blend modes.
  13483. var xObjects = node.get('XObject');
  13484. if (!isDict(xObjects)) {
  13485. continue;
  13486. }
  13487. xObjects = xObjects.getAll();
  13488. for (key in xObjects) {
  13489. var xObject = xObjects[key];
  13490. if (!isStream(xObject)) {
  13491. continue;
  13492. }
  13493. if (xObject.dict.objId) {
  13494. if (processed[xObject.dict.objId]) {
  13495. // stream has objId and is processed already
  13496. continue;
  13497. }
  13498. processed[xObject.dict.objId] = true;
  13499. }
  13500. var xResources = xObject.dict.get('Resources');
  13501. // Checking objId to detect an infinite loop.
  13502. if (isDict(xResources) &&
  13503. (!xResources.objId || !processed[xResources.objId])) {
  13504. nodes.push(xResources);
  13505. if (xResources.objId) {
  13506. processed[xResources.objId] = true;
  13507. }
  13508. }
  13509. }
  13510. }
  13511. return false;
  13512. },
  13513. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  13514. xobj, smask,
  13515. operatorList,
  13516. initialState) {
  13517. var matrix = xobj.dict.get('Matrix');
  13518. var bbox = xobj.dict.get('BBox');
  13519. var group = xobj.dict.get('Group');
  13520. if (group) {
  13521. var groupOptions = {
  13522. matrix: matrix,
  13523. bbox: bbox,
  13524. smask: smask,
  13525. isolated: false,
  13526. knockout: false
  13527. };
  13528. var groupSubtype = group.get('S');
  13529. var colorSpace;
  13530. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  13531. groupOptions.isolated = (group.get('I') || false);
  13532. groupOptions.knockout = (group.get('K') || false);
  13533. colorSpace = (group.has('CS') ?
  13534. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  13535. }
  13536. if (smask && smask.backdrop) {
  13537. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  13538. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  13539. }
  13540. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  13541. }
  13542. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  13543. return this.getOperatorList(xobj,
  13544. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  13545. then(function () {
  13546. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  13547. if (group) {
  13548. operatorList.addOp(OPS.endGroup, [groupOptions]);
  13549. }
  13550. });
  13551. },
  13552. buildPaintImageXObject:
  13553. function PartialEvaluator_buildPaintImageXObject(resources, image,
  13554. inline, operatorList,
  13555. cacheKey, cache) {
  13556. var self = this;
  13557. var dict = image.dict;
  13558. var w = dict.get('Width', 'W');
  13559. var h = dict.get('Height', 'H');
  13560. if (!(w && isNum(w)) || !(h && isNum(h))) {
  13561. warn('Image dimensions are missing, or not numbers.');
  13562. return;
  13563. }
  13564. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  13565. warn('Image exceeded maximum allowed size and was removed.');
  13566. return;
  13567. }
  13568. var imageMask = (dict.get('ImageMask', 'IM') || false);
  13569. var imgData, args;
  13570. if (imageMask) {
  13571. // This depends on a tmpCanvas being filled with the
  13572. // current fillStyle, such that processing the pixel
  13573. // data can't be done here. Instead of creating a
  13574. // complete PDFImage, only read the information needed
  13575. // for later.
  13576. var width = dict.get('Width', 'W');
  13577. var height = dict.get('Height', 'H');
  13578. var bitStrideLength = (width + 7) >> 3;
  13579. var imgArray = image.getBytes(bitStrideLength * height);
  13580. var decode = dict.get('Decode', 'D');
  13581. var inverseDecode = (!!decode && decode[0] > 0);
  13582. imgData = PDFImage.createMask(imgArray, width, height,
  13583. image instanceof DecodeStream,
  13584. inverseDecode);
  13585. imgData.cached = true;
  13586. args = [imgData];
  13587. operatorList.addOp(OPS.paintImageMaskXObject, args);
  13588. if (cacheKey) {
  13589. cache.key = cacheKey;
  13590. cache.fn = OPS.paintImageMaskXObject;
  13591. cache.args = args;
  13592. }
  13593. return;
  13594. }
  13595. var softMask = (dict.get('SMask', 'SM') || false);
  13596. var mask = (dict.get('Mask') || false);
  13597. var SMALL_IMAGE_DIMENSIONS = 200;
  13598. // Inlining small images into the queue as RGB data
  13599. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  13600. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  13601. var imageObj = new PDFImage(this.xref, resources, image,
  13602. inline, null, null);
  13603. // We force the use of RGBA_32BPP images here, because we can't handle
  13604. // any other kind.
  13605. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  13606. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  13607. return;
  13608. }
  13609. // If there is no imageMask, create the PDFImage and a lot
  13610. // of image processing can be done here.
  13611. var uniquePrefix = (this.uniquePrefix || '');
  13612. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  13613. operatorList.addDependency(objId);
  13614. args = [objId, w, h];
  13615. if (!softMask && !mask && image instanceof JpegStream &&
  13616. image.isNativelySupported(this.xref, resources)) {
  13617. // These JPEGs don't need any more processing so we can just send it.
  13618. operatorList.addOp(OPS.paintJpegXObject, args);
  13619. this.handler.send('obj',
  13620. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  13621. return;
  13622. }
  13623. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  13624. then(function(imageObj) {
  13625. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  13626. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  13627. [imgData.data.buffer]);
  13628. }).then(null, function (reason) {
  13629. warn('Unable to decode image: ' + reason);
  13630. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  13631. });
  13632. operatorList.addOp(OPS.paintImageXObject, args);
  13633. if (cacheKey) {
  13634. cache.key = cacheKey;
  13635. cache.fn = OPS.paintImageXObject;
  13636. cache.args = args;
  13637. }
  13638. },
  13639. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  13640. operatorList,
  13641. stateManager) {
  13642. var smaskContent = smask.get('G');
  13643. var smaskOptions = {
  13644. subtype: smask.get('S').name,
  13645. backdrop: smask.get('BC')
  13646. };
  13647. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  13648. operatorList, stateManager.state.clone());
  13649. },
  13650. handleTilingType:
  13651. function PartialEvaluator_handleTilingType(fn, args, resources,
  13652. pattern, patternDict,
  13653. operatorList) {
  13654. // Create an IR of the pattern code.
  13655. var tilingOpList = new OperatorList();
  13656. return this.getOperatorList(pattern,
  13657. (patternDict.get('Resources') || resources), tilingOpList).
  13658. then(function () {
  13659. // Add the dependencies to the parent operator list so they are
  13660. // resolved before sub operator list is executed synchronously.
  13661. operatorList.addDependencies(tilingOpList.dependencies);
  13662. operatorList.addOp(fn, getTilingPatternIR({
  13663. fnArray: tilingOpList.fnArray,
  13664. argsArray: tilingOpList.argsArray
  13665. }, patternDict, args));
  13666. });
  13667. },
  13668. handleSetFont:
  13669. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  13670. operatorList, state) {
  13671. // TODO(mack): Not needed?
  13672. var fontName;
  13673. if (fontArgs) {
  13674. fontArgs = fontArgs.slice();
  13675. fontName = fontArgs[0].name;
  13676. }
  13677. var self = this;
  13678. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  13679. function (translated) {
  13680. if (!translated.font.isType3Font) {
  13681. return translated;
  13682. }
  13683. return translated.loadType3Data(self, resources, operatorList).then(
  13684. function () {
  13685. return translated;
  13686. });
  13687. }).then(function (translated) {
  13688. state.font = translated.font;
  13689. translated.send(self.handler);
  13690. return translated.loadedName;
  13691. });
  13692. },
  13693. handleText: function PartialEvaluator_handleText(chars, state) {
  13694. var font = state.font;
  13695. var glyphs = font.charsToGlyphs(chars);
  13696. var isAddToPathSet = !!(state.textRenderingMode &
  13697. TextRenderingMode.ADD_TO_PATH_FLAG);
  13698. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  13699. var buildPath = function (fontChar) {
  13700. if (!font.renderer.hasBuiltPath(fontChar)) {
  13701. var path = font.renderer.getPathJs(fontChar);
  13702. this.handler.send('commonobj', [
  13703. font.loadedName + '_path_' + fontChar,
  13704. 'FontPath',
  13705. path
  13706. ]);
  13707. }
  13708. }.bind(this);
  13709. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  13710. var glyph = glyphs[i];
  13711. if (glyph === null) {
  13712. continue;
  13713. }
  13714. buildPath(glyph.fontChar);
  13715. // If the glyph has an accent we need to build a path for its
  13716. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  13717. var accent = glyph.accent;
  13718. if (accent && accent.fontChar) {
  13719. buildPath(accent.fontChar);
  13720. }
  13721. }
  13722. }
  13723. return glyphs;
  13724. },
  13725. setGState: function PartialEvaluator_setGState(resources, gState,
  13726. operatorList, xref,
  13727. stateManager) {
  13728. // TODO(mack): This should be rewritten so that this function returns
  13729. // what should be added to the queue during each iteration
  13730. function setGStateForKey(gStateObj, key, value) {
  13731. switch (key) {
  13732. case 'Type':
  13733. break;
  13734. case 'LW':
  13735. case 'LC':
  13736. case 'LJ':
  13737. case 'ML':
  13738. case 'D':
  13739. case 'RI':
  13740. case 'FL':
  13741. case 'CA':
  13742. case 'ca':
  13743. gStateObj.push([key, value]);
  13744. break;
  13745. case 'Font':
  13746. promise = promise.then(function () {
  13747. return self.handleSetFont(resources, null, value[0],
  13748. operatorList, stateManager.state).
  13749. then(function (loadedName) {
  13750. operatorList.addDependency(loadedName);
  13751. gStateObj.push([key, [loadedName, value[1]]]);
  13752. });
  13753. });
  13754. break;
  13755. case 'BM':
  13756. gStateObj.push([key, value]);
  13757. break;
  13758. case 'SMask':
  13759. if (isName(value) && value.name === 'None') {
  13760. gStateObj.push([key, false]);
  13761. break;
  13762. }
  13763. var dict = xref.fetchIfRef(value);
  13764. if (isDict(dict)) {
  13765. promise = promise.then(function () {
  13766. return self.handleSMask(dict, resources, operatorList,
  13767. stateManager);
  13768. });
  13769. gStateObj.push([key, true]);
  13770. } else {
  13771. warn('Unsupported SMask type');
  13772. }
  13773. break;
  13774. // Only generate info log messages for the following since
  13775. // they are unlikey to have a big impact on the rendering.
  13776. case 'OP':
  13777. case 'op':
  13778. case 'OPM':
  13779. case 'BG':
  13780. case 'BG2':
  13781. case 'UCR':
  13782. case 'UCR2':
  13783. case 'TR':
  13784. case 'TR2':
  13785. case 'HT':
  13786. case 'SM':
  13787. case 'SA':
  13788. case 'AIS':
  13789. case 'TK':
  13790. // TODO implement these operators.
  13791. info('graphic state operator ' + key);
  13792. break;
  13793. default:
  13794. info('Unknown graphic state operator ' + key);
  13795. break;
  13796. }
  13797. }
  13798. // This array holds the converted/processed state data.
  13799. var gStateObj = [];
  13800. var gStateMap = gState.map;
  13801. var self = this;
  13802. var promise = Promise.resolve();
  13803. for (var key in gStateMap) {
  13804. var value = gStateMap[key];
  13805. setGStateForKey(gStateObj, key, value);
  13806. }
  13807. return promise.then(function () {
  13808. operatorList.addOp(OPS.setGState, [gStateObj]);
  13809. });
  13810. },
  13811. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  13812. resources) {
  13813. function errorFont() {
  13814. return Promise.resolve(new TranslatedFont('g_font_error',
  13815. new ErrorFont('Font ' + fontName + ' is not available'), font));
  13816. }
  13817. var fontRef;
  13818. if (font) { // Loading by ref.
  13819. assert(isRef(font));
  13820. fontRef = font;
  13821. } else { // Loading by name.
  13822. var fontRes = resources.get('Font');
  13823. if (fontRes) {
  13824. fontRef = fontRes.getRaw(fontName);
  13825. } else {
  13826. warn('fontRes not available');
  13827. return errorFont();
  13828. }
  13829. }
  13830. if (!fontRef) {
  13831. warn('fontRef not available');
  13832. return errorFont();
  13833. }
  13834. if (this.fontCache.has(fontRef)) {
  13835. return this.fontCache.get(fontRef);
  13836. }
  13837. font = xref.fetchIfRef(fontRef);
  13838. if (!isDict(font)) {
  13839. return errorFont();
  13840. }
  13841. // We are holding font.translated references just for fontRef that are not
  13842. // dictionaries (Dict). See explanation below.
  13843. if (font.translated) {
  13844. return font.translated;
  13845. }
  13846. var fontCapability = createPromiseCapability();
  13847. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  13848. var descriptor = preEvaluatedFont.descriptor;
  13849. var fontID = fontRef.num + '_' + fontRef.gen;
  13850. if (isDict(descriptor)) {
  13851. if (!descriptor.fontAliases) {
  13852. descriptor.fontAliases = Object.create(null);
  13853. }
  13854. var fontAliases = descriptor.fontAliases;
  13855. var hash = preEvaluatedFont.hash;
  13856. if (fontAliases[hash]) {
  13857. var aliasFontRef = fontAliases[hash].aliasRef;
  13858. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  13859. this.fontCache.putAlias(fontRef, aliasFontRef);
  13860. return this.fontCache.get(fontRef);
  13861. }
  13862. }
  13863. if (!fontAliases[hash]) {
  13864. fontAliases[hash] = {
  13865. fontID: Font.getFontID()
  13866. };
  13867. }
  13868. fontAliases[hash].aliasRef = fontRef;
  13869. fontID = fontAliases[hash].fontID;
  13870. }
  13871. // Workaround for bad PDF generators that don't reference fonts
  13872. // properly, i.e. by not using an object identifier.
  13873. // Check if the fontRef is a Dict (as opposed to a standard object),
  13874. // in which case we don't cache the font and instead reference it by
  13875. // fontName in font.loadedName below.
  13876. var fontRefIsDict = isDict(fontRef);
  13877. if (!fontRefIsDict) {
  13878. this.fontCache.put(fontRef, fontCapability.promise);
  13879. }
  13880. // Keep track of each font we translated so the caller can
  13881. // load them asynchronously before calling display on a page.
  13882. font.loadedName = 'g_font_' + (fontRefIsDict ?
  13883. fontName.replace(/\W/g, '') : fontID);
  13884. font.translated = fontCapability.promise;
  13885. // TODO move promises into translate font
  13886. var translatedPromise;
  13887. try {
  13888. translatedPromise = Promise.resolve(
  13889. this.translateFont(preEvaluatedFont, xref));
  13890. } catch (e) {
  13891. translatedPromise = Promise.reject(e);
  13892. }
  13893. translatedPromise.then(function (translatedFont) {
  13894. if (translatedFont.fontType !== undefined) {
  13895. var xrefFontStats = xref.stats.fontTypes;
  13896. xrefFontStats[translatedFont.fontType] = true;
  13897. }
  13898. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13899. translatedFont, font));
  13900. }, function (reason) {
  13901. // TODO fontCapability.reject?
  13902. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  13903. try {
  13904. // error, but it's still nice to have font type reported
  13905. var descriptor = preEvaluatedFont.descriptor;
  13906. var fontFile3 = descriptor && descriptor.get('FontFile3');
  13907. var subtype = fontFile3 && fontFile3.get('Subtype');
  13908. var fontType = getFontType(preEvaluatedFont.type,
  13909. subtype && subtype.name);
  13910. var xrefFontStats = xref.stats.fontTypes;
  13911. xrefFontStats[fontType] = true;
  13912. } catch (ex) { }
  13913. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13914. new ErrorFont(reason instanceof Error ? reason.message : reason),
  13915. font));
  13916. });
  13917. return fontCapability.promise;
  13918. },
  13919. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  13920. var lastIndex = operatorList.length - 1;
  13921. if (!args) {
  13922. args = [];
  13923. }
  13924. if (lastIndex < 0 ||
  13925. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  13926. operatorList.addOp(OPS.constructPath, [[fn], args]);
  13927. } else {
  13928. var opArgs = operatorList.argsArray[lastIndex];
  13929. opArgs[0].push(fn);
  13930. Array.prototype.push.apply(opArgs[1], args);
  13931. }
  13932. },
  13933. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  13934. cs, patterns, resources, xref) {
  13935. // compile tiling patterns
  13936. var patternName = args[args.length - 1];
  13937. // SCN/scn applies patterns along with normal colors
  13938. var pattern;
  13939. if (isName(patternName) &&
  13940. (pattern = patterns.get(patternName.name))) {
  13941. var dict = (isStream(pattern) ? pattern.dict : pattern);
  13942. var typeNum = dict.get('PatternType');
  13943. if (typeNum === TILING_PATTERN) {
  13944. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  13945. return this.handleTilingType(fn, color, resources, pattern,
  13946. dict, operatorList);
  13947. } else if (typeNum === SHADING_PATTERN) {
  13948. var shading = dict.get('Shading');
  13949. var matrix = dict.get('Matrix');
  13950. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  13951. operatorList.addOp(fn, pattern.getIR());
  13952. return Promise.resolve();
  13953. } else {
  13954. return Promise.reject('Unknown PatternType: ' + typeNum);
  13955. }
  13956. }
  13957. // TODO shall we fail here?
  13958. operatorList.addOp(fn, args);
  13959. return Promise.resolve();
  13960. },
  13961. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  13962. resources,
  13963. operatorList,
  13964. initialState) {
  13965. var self = this;
  13966. var xref = this.xref;
  13967. var imageCache = {};
  13968. assert(operatorList);
  13969. resources = (resources || Dict.empty);
  13970. var xobjs = (resources.get('XObject') || Dict.empty);
  13971. var patterns = (resources.get('Pattern') || Dict.empty);
  13972. var stateManager = new StateManager(initialState || new EvalState());
  13973. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  13974. var timeSlotManager = new TimeSlotManager();
  13975. return new Promise(function next(resolve, reject) {
  13976. timeSlotManager.reset();
  13977. var stop, operation = {}, i, ii, cs;
  13978. while (!(stop = timeSlotManager.check()) &&
  13979. preprocessor.read(operation)) {
  13980. var args = operation.args;
  13981. var fn = operation.fn;
  13982. switch (fn | 0) {
  13983. case OPS.paintXObject:
  13984. if (args[0].code) {
  13985. break;
  13986. }
  13987. // eagerly compile XForm objects
  13988. var name = args[0].name;
  13989. if (imageCache.key === name) {
  13990. operatorList.addOp(imageCache.fn, imageCache.args);
  13991. args = null;
  13992. continue;
  13993. }
  13994. var xobj = xobjs.get(name);
  13995. if (xobj) {
  13996. assert(isStream(xobj), 'XObject should be a stream');
  13997. var type = xobj.dict.get('Subtype');
  13998. assert(isName(type),
  13999. 'XObject should have a Name subtype');
  14000. if (type.name === 'Form') {
  14001. stateManager.save();
  14002. return self.buildFormXObject(resources, xobj, null,
  14003. operatorList,
  14004. stateManager.state.clone()).
  14005. then(function () {
  14006. stateManager.restore();
  14007. next(resolve, reject);
  14008. }, reject);
  14009. } else if (type.name === 'Image') {
  14010. self.buildPaintImageXObject(resources, xobj, false,
  14011. operatorList, name, imageCache);
  14012. args = null;
  14013. continue;
  14014. } else if (type.name === 'PS') {
  14015. // PostScript XObjects are unused when viewing documents.
  14016. // See section 4.7.1 of Adobe's PDF reference.
  14017. info('Ignored XObject subtype PS');
  14018. continue;
  14019. } else {
  14020. error('Unhandled XObject subtype ' + type.name);
  14021. }
  14022. }
  14023. break;
  14024. case OPS.setFont:
  14025. var fontSize = args[1];
  14026. // eagerly collect all fonts
  14027. return self.handleSetFont(resources, args, null,
  14028. operatorList, stateManager.state).
  14029. then(function (loadedName) {
  14030. operatorList.addDependency(loadedName);
  14031. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  14032. next(resolve, reject);
  14033. }, reject);
  14034. case OPS.endInlineImage:
  14035. var cacheKey = args[0].cacheKey;
  14036. if (cacheKey && imageCache.key === cacheKey) {
  14037. operatorList.addOp(imageCache.fn, imageCache.args);
  14038. args = null;
  14039. continue;
  14040. }
  14041. self.buildPaintImageXObject(resources, args[0], true,
  14042. operatorList, cacheKey, imageCache);
  14043. args = null;
  14044. continue;
  14045. case OPS.showText:
  14046. args[0] = self.handleText(args[0], stateManager.state);
  14047. break;
  14048. case OPS.showSpacedText:
  14049. var arr = args[0];
  14050. var combinedGlyphs = [];
  14051. var arrLength = arr.length;
  14052. for (i = 0; i < arrLength; ++i) {
  14053. var arrItem = arr[i];
  14054. if (isString(arrItem)) {
  14055. Array.prototype.push.apply(combinedGlyphs,
  14056. self.handleText(arrItem, stateManager.state));
  14057. } else if (isNum(arrItem)) {
  14058. combinedGlyphs.push(arrItem);
  14059. }
  14060. }
  14061. args[0] = combinedGlyphs;
  14062. fn = OPS.showText;
  14063. break;
  14064. case OPS.nextLineShowText:
  14065. operatorList.addOp(OPS.nextLine);
  14066. args[0] = self.handleText(args[0], stateManager.state);
  14067. fn = OPS.showText;
  14068. break;
  14069. case OPS.nextLineSetSpacingShowText:
  14070. operatorList.addOp(OPS.nextLine);
  14071. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  14072. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  14073. args[0] = self.handleText(args[0], stateManager.state);
  14074. fn = OPS.showText;
  14075. break;
  14076. case OPS.setTextRenderingMode:
  14077. stateManager.state.textRenderingMode = args[0];
  14078. break;
  14079. case OPS.setFillColorSpace:
  14080. stateManager.state.fillColorSpace =
  14081. ColorSpace.parse(args[0], xref, resources);
  14082. continue;
  14083. case OPS.setStrokeColorSpace:
  14084. stateManager.state.strokeColorSpace =
  14085. ColorSpace.parse(args[0], xref, resources);
  14086. continue;
  14087. case OPS.setFillColor:
  14088. cs = stateManager.state.fillColorSpace;
  14089. args = cs.getRgb(args, 0);
  14090. fn = OPS.setFillRGBColor;
  14091. break;
  14092. case OPS.setStrokeColor:
  14093. cs = stateManager.state.strokeColorSpace;
  14094. args = cs.getRgb(args, 0);
  14095. fn = OPS.setStrokeRGBColor;
  14096. break;
  14097. case OPS.setFillGray:
  14098. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  14099. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14100. fn = OPS.setFillRGBColor;
  14101. break;
  14102. case OPS.setStrokeGray:
  14103. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  14104. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14105. fn = OPS.setStrokeRGBColor;
  14106. break;
  14107. case OPS.setFillCMYKColor:
  14108. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  14109. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14110. fn = OPS.setFillRGBColor;
  14111. break;
  14112. case OPS.setStrokeCMYKColor:
  14113. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  14114. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14115. fn = OPS.setStrokeRGBColor;
  14116. break;
  14117. case OPS.setFillRGBColor:
  14118. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  14119. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14120. break;
  14121. case OPS.setStrokeRGBColor:
  14122. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  14123. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14124. break;
  14125. case OPS.setFillColorN:
  14126. cs = stateManager.state.fillColorSpace;
  14127. if (cs.name === 'Pattern') {
  14128. return self.handleColorN(operatorList, OPS.setFillColorN,
  14129. args, cs, patterns, resources, xref).then(function() {
  14130. next(resolve, reject);
  14131. }, reject);
  14132. }
  14133. args = cs.getRgb(args, 0);
  14134. fn = OPS.setFillRGBColor;
  14135. break;
  14136. case OPS.setStrokeColorN:
  14137. cs = stateManager.state.strokeColorSpace;
  14138. if (cs.name === 'Pattern') {
  14139. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  14140. args, cs, patterns, resources, xref).then(function() {
  14141. next(resolve, reject);
  14142. }, reject);
  14143. }
  14144. args = cs.getRgb(args, 0);
  14145. fn = OPS.setStrokeRGBColor;
  14146. break;
  14147. case OPS.shadingFill:
  14148. var shadingRes = resources.get('Shading');
  14149. if (!shadingRes) {
  14150. error('No shading resource found');
  14151. }
  14152. var shading = shadingRes.get(args[0].name);
  14153. if (!shading) {
  14154. error('No shading object found');
  14155. }
  14156. var shadingFill = Pattern.parseShading(shading, null, xref,
  14157. resources);
  14158. var patternIR = shadingFill.getIR();
  14159. args = [patternIR];
  14160. fn = OPS.shadingFill;
  14161. break;
  14162. case OPS.setGState:
  14163. var dictName = args[0];
  14164. var extGState = resources.get('ExtGState');
  14165. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14166. break;
  14167. }
  14168. var gState = extGState.get(dictName.name);
  14169. return self.setGState(resources, gState, operatorList, xref,
  14170. stateManager).then(function() {
  14171. next(resolve, reject);
  14172. }, reject);
  14173. case OPS.moveTo:
  14174. case OPS.lineTo:
  14175. case OPS.curveTo:
  14176. case OPS.curveTo2:
  14177. case OPS.curveTo3:
  14178. case OPS.closePath:
  14179. self.buildPath(operatorList, fn, args);
  14180. continue;
  14181. case OPS.rectangle:
  14182. self.buildPath(operatorList, fn, args);
  14183. continue;
  14184. }
  14185. operatorList.addOp(fn, args);
  14186. }
  14187. if (stop) {
  14188. deferred.then(function () {
  14189. next(resolve, reject);
  14190. });
  14191. return;
  14192. }
  14193. // Some PDFs don't close all restores inside object/form.
  14194. // Closing those for them.
  14195. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  14196. operatorList.addOp(OPS.restore, []);
  14197. }
  14198. resolve();
  14199. });
  14200. },
  14201. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  14202. stateManager) {
  14203. stateManager = (stateManager || new StateManager(new TextState()));
  14204. var textContent = {
  14205. items: [],
  14206. styles: Object.create(null)
  14207. };
  14208. var bidiTexts = textContent.items;
  14209. var SPACE_FACTOR = 0.35;
  14210. var MULTI_SPACE_FACTOR = 1.5;
  14211. var self = this;
  14212. var xref = this.xref;
  14213. resources = (xref.fetchIfRef(resources) || Dict.empty);
  14214. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  14215. var xobjs = null;
  14216. var xobjsCache = {};
  14217. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  14218. var textState;
  14219. function newTextChunk() {
  14220. var font = textState.font;
  14221. if (!(font.loadedName in textContent.styles)) {
  14222. textContent.styles[font.loadedName] = {
  14223. fontFamily: font.fallbackName,
  14224. ascent: font.ascent,
  14225. descent: font.descent,
  14226. vertical: font.vertical
  14227. };
  14228. }
  14229. return {
  14230. // |str| is initially an array which we push individual chars to, and
  14231. // then runBidi() overwrites it with the final string.
  14232. str: [],
  14233. dir: null,
  14234. width: 0,
  14235. height: 0,
  14236. transform: null,
  14237. fontName: font.loadedName
  14238. };
  14239. }
  14240. function runBidi(textChunk) {
  14241. var str = textChunk.str.join('');
  14242. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  14243. textChunk.str = bidiResult.str;
  14244. textChunk.dir = bidiResult.dir;
  14245. return textChunk;
  14246. }
  14247. function handleSetFont(fontName, fontRef) {
  14248. return self.loadFont(fontName, fontRef, xref, resources).
  14249. then(function (translated) {
  14250. textState.font = translated.font;
  14251. textState.fontMatrix = translated.font.fontMatrix ||
  14252. FONT_IDENTITY_MATRIX;
  14253. });
  14254. }
  14255. function buildTextGeometry(chars, textChunk) {
  14256. var font = textState.font;
  14257. textChunk = textChunk || newTextChunk();
  14258. if (!textChunk.transform) {
  14259. // 9.4.4 Text Space Details
  14260. var tsm = [textState.fontSize * textState.textHScale, 0,
  14261. 0, textState.fontSize,
  14262. 0, textState.textRise];
  14263. var trm = textChunk.transform = Util.transform(textState.ctm,
  14264. Util.transform(textState.textMatrix, tsm));
  14265. if (!font.vertical) {
  14266. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  14267. } else {
  14268. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  14269. }
  14270. }
  14271. var width = 0;
  14272. var height = 0;
  14273. var glyphs = font.charsToGlyphs(chars);
  14274. var defaultVMetrics = font.defaultVMetrics;
  14275. for (var i = 0; i < glyphs.length; i++) {
  14276. var glyph = glyphs[i];
  14277. if (!glyph) { // Previous glyph was a space.
  14278. width += textState.wordSpacing * textState.textHScale;
  14279. continue;
  14280. }
  14281. var vMetricX = null;
  14282. var vMetricY = null;
  14283. var glyphWidth = null;
  14284. if (font.vertical) {
  14285. if (glyph.vmetric) {
  14286. glyphWidth = glyph.vmetric[0];
  14287. vMetricX = glyph.vmetric[1];
  14288. vMetricY = glyph.vmetric[2];
  14289. } else {
  14290. glyphWidth = glyph.width;
  14291. vMetricX = glyph.width * 0.5;
  14292. vMetricY = defaultVMetrics[2];
  14293. }
  14294. } else {
  14295. glyphWidth = glyph.width;
  14296. }
  14297. var glyphUnicode = glyph.unicode;
  14298. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  14299. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  14300. }
  14301. glyphUnicode = reverseIfRtl(glyphUnicode);
  14302. // The following will calculate the x and y of the individual glyphs.
  14303. // if (font.vertical) {
  14304. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  14305. // textState.fontMatrix[0];
  14306. // tsm[5] -= vMetricY * textState.fontSize *
  14307. // textState.fontMatrix[0];
  14308. // }
  14309. // var trm = Util.transform(textState.textMatrix, tsm);
  14310. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  14311. // var x = pt[0];
  14312. // var y = pt[1];
  14313. var tx = 0;
  14314. var ty = 0;
  14315. if (!font.vertical) {
  14316. var w0 = glyphWidth * textState.fontMatrix[0];
  14317. tx = (w0 * textState.fontSize + textState.charSpacing) *
  14318. textState.textHScale;
  14319. width += tx;
  14320. } else {
  14321. var w1 = glyphWidth * textState.fontMatrix[0];
  14322. ty = w1 * textState.fontSize + textState.charSpacing;
  14323. height += ty;
  14324. }
  14325. textState.translateTextMatrix(tx, ty);
  14326. textChunk.str.push(glyphUnicode);
  14327. }
  14328. var a = textState.textLineMatrix[0];
  14329. var b = textState.textLineMatrix[1];
  14330. var scaleLineX = Math.sqrt(a * a + b * b);
  14331. a = textState.ctm[0];
  14332. b = textState.ctm[1];
  14333. var scaleCtmX = Math.sqrt(a * a + b * b);
  14334. if (!font.vertical) {
  14335. textChunk.width += width * scaleCtmX * scaleLineX;
  14336. } else {
  14337. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  14338. }
  14339. return textChunk;
  14340. }
  14341. var timeSlotManager = new TimeSlotManager();
  14342. return new Promise(function next(resolve, reject) {
  14343. timeSlotManager.reset();
  14344. var stop, operation = {};
  14345. while (!(stop = timeSlotManager.check()) &&
  14346. (preprocessor.read(operation))) {
  14347. textState = stateManager.state;
  14348. var fn = operation.fn;
  14349. var args = operation.args;
  14350. switch (fn | 0) {
  14351. case OPS.setFont:
  14352. textState.fontSize = args[1];
  14353. return handleSetFont(args[0].name).then(function() {
  14354. next(resolve, reject);
  14355. }, reject);
  14356. case OPS.setTextRise:
  14357. textState.textRise = args[0];
  14358. break;
  14359. case OPS.setHScale:
  14360. textState.textHScale = args[0] / 100;
  14361. break;
  14362. case OPS.setLeading:
  14363. textState.leading = args[0];
  14364. break;
  14365. case OPS.moveText:
  14366. textState.translateTextLineMatrix(args[0], args[1]);
  14367. textState.textMatrix = textState.textLineMatrix.slice();
  14368. break;
  14369. case OPS.setLeadingMoveText:
  14370. textState.leading = -args[1];
  14371. textState.translateTextLineMatrix(args[0], args[1]);
  14372. textState.textMatrix = textState.textLineMatrix.slice();
  14373. break;
  14374. case OPS.nextLine:
  14375. textState.carriageReturn();
  14376. break;
  14377. case OPS.setTextMatrix:
  14378. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  14379. args[4], args[5]);
  14380. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  14381. args[4], args[5]);
  14382. break;
  14383. case OPS.setCharSpacing:
  14384. textState.charSpacing = args[0];
  14385. break;
  14386. case OPS.setWordSpacing:
  14387. textState.wordSpacing = args[0];
  14388. break;
  14389. case OPS.beginText:
  14390. textState.textMatrix = IDENTITY_MATRIX.slice();
  14391. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  14392. break;
  14393. case OPS.showSpacedText:
  14394. var items = args[0];
  14395. var textChunk = newTextChunk();
  14396. var offset;
  14397. for (var j = 0, jj = items.length; j < jj; j++) {
  14398. if (typeof items[j] === 'string') {
  14399. buildTextGeometry(items[j], textChunk);
  14400. } else {
  14401. var val = items[j] / 1000;
  14402. if (!textState.font.vertical) {
  14403. offset = -val * textState.fontSize * textState.textHScale *
  14404. textState.textMatrix[0];
  14405. textState.translateTextMatrix(offset, 0);
  14406. textChunk.width += offset;
  14407. } else {
  14408. offset = -val * textState.fontSize *
  14409. textState.textMatrix[3];
  14410. textState.translateTextMatrix(0, offset);
  14411. textChunk.height += offset;
  14412. }
  14413. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  14414. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  14415. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  14416. fakeSpaces = Math.round(fakeSpaces);
  14417. while (fakeSpaces--) {
  14418. textChunk.str.push(' ');
  14419. }
  14420. } else if (fakeSpaces > SPACE_FACTOR) {
  14421. textChunk.str.push(' ');
  14422. }
  14423. }
  14424. }
  14425. }
  14426. bidiTexts.push(runBidi(textChunk));
  14427. break;
  14428. case OPS.showText:
  14429. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14430. break;
  14431. case OPS.nextLineShowText:
  14432. textState.carriageReturn();
  14433. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14434. break;
  14435. case OPS.nextLineSetSpacingShowText:
  14436. textState.wordSpacing = args[0];
  14437. textState.charSpacing = args[1];
  14438. textState.carriageReturn();
  14439. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  14440. break;
  14441. case OPS.paintXObject:
  14442. if (args[0].code) {
  14443. break;
  14444. }
  14445. if (!xobjs) {
  14446. xobjs = (resources.get('XObject') || Dict.empty);
  14447. }
  14448. var name = args[0].name;
  14449. if (xobjsCache.key === name) {
  14450. if (xobjsCache.texts) {
  14451. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  14452. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  14453. }
  14454. break;
  14455. }
  14456. var xobj = xobjs.get(name);
  14457. if (!xobj) {
  14458. break;
  14459. }
  14460. assert(isStream(xobj), 'XObject should be a stream');
  14461. var type = xobj.dict.get('Subtype');
  14462. assert(isName(type),
  14463. 'XObject should have a Name subtype');
  14464. if ('Form' !== type.name) {
  14465. xobjsCache.key = name;
  14466. xobjsCache.texts = null;
  14467. break;
  14468. }
  14469. stateManager.save();
  14470. var matrix = xobj.dict.get('Matrix');
  14471. if (isArray(matrix) && matrix.length === 6) {
  14472. stateManager.transform(matrix);
  14473. }
  14474. return self.getTextContent(xobj,
  14475. xobj.dict.get('Resources') || resources, stateManager).
  14476. then(function (formTextContent) {
  14477. Util.appendToArray(bidiTexts, formTextContent.items);
  14478. Util.extendObj(textContent.styles, formTextContent.styles);
  14479. stateManager.restore();
  14480. xobjsCache.key = name;
  14481. xobjsCache.texts = formTextContent;
  14482. next(resolve, reject);
  14483. }, reject);
  14484. case OPS.setGState:
  14485. var dictName = args[0];
  14486. var extGState = resources.get('ExtGState');
  14487. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14488. break;
  14489. }
  14490. var gsStateMap = extGState.get(dictName.name);
  14491. var gsStateFont = null;
  14492. for (var key in gsStateMap) {
  14493. if (key === 'Font') {
  14494. assert(!gsStateFont);
  14495. gsStateFont = gsStateMap[key];
  14496. }
  14497. }
  14498. if (gsStateFont) {
  14499. textState.fontSize = gsStateFont[1];
  14500. return handleSetFont(gsStateFont[0]).then(function() {
  14501. next(resolve, reject);
  14502. }, reject);
  14503. }
  14504. break;
  14505. } // switch
  14506. } // while
  14507. if (stop) {
  14508. deferred.then(function () {
  14509. next(resolve, reject);
  14510. });
  14511. return;
  14512. }
  14513. resolve(textContent);
  14514. });
  14515. },
  14516. extractDataStructures: function
  14517. partialEvaluatorExtractDataStructures(dict, baseDict,
  14518. xref, properties) {
  14519. // 9.10.2
  14520. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  14521. if (toUnicode) {
  14522. properties.toUnicode = this.readToUnicode(toUnicode);
  14523. }
  14524. if (properties.composite) {
  14525. // CIDSystemInfo helps to match CID to glyphs
  14526. var cidSystemInfo = dict.get('CIDSystemInfo');
  14527. if (isDict(cidSystemInfo)) {
  14528. properties.cidSystemInfo = {
  14529. registry: cidSystemInfo.get('Registry'),
  14530. ordering: cidSystemInfo.get('Ordering'),
  14531. supplement: cidSystemInfo.get('Supplement')
  14532. };
  14533. }
  14534. var cidToGidMap = dict.get('CIDToGIDMap');
  14535. if (isStream(cidToGidMap)) {
  14536. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  14537. }
  14538. }
  14539. // Based on 9.6.6 of the spec the encoding can come from multiple places
  14540. // and depends on the font type. The base encoding and differences are
  14541. // read here, but the encoding that is actually used is chosen during
  14542. // glyph mapping in the font.
  14543. // TODO: Loading the built in encoding in the font would allow the
  14544. // differences to be merged in here not require us to hold on to it.
  14545. var differences = [];
  14546. var baseEncodingName = null;
  14547. var encoding;
  14548. if (dict.has('Encoding')) {
  14549. encoding = dict.get('Encoding');
  14550. if (isDict(encoding)) {
  14551. baseEncodingName = encoding.get('BaseEncoding');
  14552. baseEncodingName = (isName(baseEncodingName) ?
  14553. baseEncodingName.name : null);
  14554. // Load the differences between the base and original
  14555. if (encoding.has('Differences')) {
  14556. var diffEncoding = encoding.get('Differences');
  14557. var index = 0;
  14558. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  14559. var data = diffEncoding[j];
  14560. if (isNum(data)) {
  14561. index = data;
  14562. } else {
  14563. differences[index++] = data.name;
  14564. }
  14565. }
  14566. }
  14567. } else if (isName(encoding)) {
  14568. baseEncodingName = encoding.name;
  14569. } else {
  14570. error('Encoding is not a Name nor a Dict');
  14571. }
  14572. // According to table 114 if the encoding is a named encoding it must be
  14573. // one of these predefined encodings.
  14574. if ((baseEncodingName !== 'MacRomanEncoding' &&
  14575. baseEncodingName !== 'MacExpertEncoding' &&
  14576. baseEncodingName !== 'WinAnsiEncoding')) {
  14577. baseEncodingName = null;
  14578. }
  14579. }
  14580. if (baseEncodingName) {
  14581. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  14582. } else {
  14583. encoding = (properties.type === 'TrueType' ?
  14584. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  14585. // The Symbolic attribute can be misused for regular fonts
  14586. // Heuristic: we have to check if the font is a standard one also
  14587. if (!!(properties.flags & FontFlags.Symbolic)) {
  14588. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  14589. Encodings.SymbolSetEncoding :
  14590. Encodings.MacRomanEncoding);
  14591. }
  14592. properties.defaultEncoding = encoding;
  14593. }
  14594. properties.differences = differences;
  14595. properties.baseEncodingName = baseEncodingName;
  14596. properties.dict = dict;
  14597. },
  14598. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  14599. var cmap, cmapObj = toUnicode;
  14600. if (isName(cmapObj)) {
  14601. cmap = CMapFactory.create(cmapObj,
  14602. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14603. return new ToUnicodeMap(cmap);
  14604. } else if (isStream(cmapObj)) {
  14605. cmap = CMapFactory.create(cmapObj,
  14606. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14607. // Convert UTF-16BE
  14608. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  14609. // to iterate over all keys.
  14610. cmap.forEach(function(token, i) {
  14611. var str = [];
  14612. for (var k = 0; k < token.length; k += 2) {
  14613. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14614. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  14615. str.push(w1);
  14616. continue;
  14617. }
  14618. k += 2;
  14619. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14620. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  14621. }
  14622. cmap[i] = String.fromCharCode.apply(String, str);
  14623. });
  14624. return new ToUnicodeMap(cmap);
  14625. }
  14626. return null;
  14627. },
  14628. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  14629. // Extract the encoding from the CIDToGIDMap
  14630. var glyphsData = cidToGidStream.getBytes();
  14631. // Set encoding 0 to later verify the font has an encoding
  14632. var result = [];
  14633. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  14634. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  14635. if (glyphID === 0) {
  14636. continue;
  14637. }
  14638. var code = j >> 1;
  14639. result[code] = glyphID;
  14640. }
  14641. return result;
  14642. },
  14643. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  14644. descriptor,
  14645. properties) {
  14646. var glyphsWidths = [];
  14647. var defaultWidth = 0;
  14648. var glyphsVMetrics = [];
  14649. var defaultVMetrics;
  14650. var i, ii, j, jj, start, code, widths;
  14651. if (properties.composite) {
  14652. defaultWidth = dict.get('DW') || 1000;
  14653. widths = dict.get('W');
  14654. if (widths) {
  14655. for (i = 0, ii = widths.length; i < ii; i++) {
  14656. start = widths[i++];
  14657. code = xref.fetchIfRef(widths[i]);
  14658. if (isArray(code)) {
  14659. for (j = 0, jj = code.length; j < jj; j++) {
  14660. glyphsWidths[start++] = code[j];
  14661. }
  14662. } else {
  14663. var width = widths[++i];
  14664. for (j = start; j <= code; j++) {
  14665. glyphsWidths[j] = width;
  14666. }
  14667. }
  14668. }
  14669. }
  14670. if (properties.vertical) {
  14671. var vmetrics = (dict.get('DW2') || [880, -1000]);
  14672. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  14673. vmetrics = dict.get('W2');
  14674. if (vmetrics) {
  14675. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  14676. start = vmetrics[i++];
  14677. code = xref.fetchIfRef(vmetrics[i]);
  14678. if (isArray(code)) {
  14679. for (j = 0, jj = code.length; j < jj; j++) {
  14680. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  14681. }
  14682. } else {
  14683. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  14684. for (j = start; j <= code; j++) {
  14685. glyphsVMetrics[j] = vmetric;
  14686. }
  14687. }
  14688. }
  14689. }
  14690. }
  14691. } else {
  14692. var firstChar = properties.firstChar;
  14693. widths = dict.get('Widths');
  14694. if (widths) {
  14695. j = firstChar;
  14696. for (i = 0, ii = widths.length; i < ii; i++) {
  14697. glyphsWidths[j++] = widths[i];
  14698. }
  14699. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  14700. } else {
  14701. // Trying get the BaseFont metrics (see comment above).
  14702. var baseFontName = dict.get('BaseFont');
  14703. if (isName(baseFontName)) {
  14704. var metrics = this.getBaseFontMetrics(baseFontName.name);
  14705. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  14706. properties);
  14707. defaultWidth = metrics.defaultWidth;
  14708. }
  14709. }
  14710. }
  14711. // Heuristic: detection of monospace font by checking all non-zero widths
  14712. var isMonospace = true;
  14713. var firstWidth = defaultWidth;
  14714. for (var glyph in glyphsWidths) {
  14715. var glyphWidth = glyphsWidths[glyph];
  14716. if (!glyphWidth) {
  14717. continue;
  14718. }
  14719. if (!firstWidth) {
  14720. firstWidth = glyphWidth;
  14721. continue;
  14722. }
  14723. if (firstWidth !== glyphWidth) {
  14724. isMonospace = false;
  14725. break;
  14726. }
  14727. }
  14728. if (isMonospace) {
  14729. properties.flags |= FontFlags.FixedPitch;
  14730. }
  14731. properties.defaultWidth = defaultWidth;
  14732. properties.widths = glyphsWidths;
  14733. properties.defaultVMetrics = defaultVMetrics;
  14734. properties.vmetrics = glyphsVMetrics;
  14735. },
  14736. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  14737. // Simulating descriptor flags attribute
  14738. var fontNameWoStyle = baseFontName.split('-')[0];
  14739. return (fontNameWoStyle in serifFonts) ||
  14740. (fontNameWoStyle.search(/serif/gi) !== -1);
  14741. },
  14742. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  14743. var defaultWidth = 0;
  14744. var widths = [];
  14745. var monospace = false;
  14746. var lookupName = (stdFontMap[name] || name);
  14747. if (!(lookupName in Metrics)) {
  14748. // Use default fonts for looking up font metrics if the passed
  14749. // font is not a base font
  14750. if (this.isSerifFont(name)) {
  14751. lookupName = 'Times-Roman';
  14752. } else {
  14753. lookupName = 'Helvetica';
  14754. }
  14755. }
  14756. var glyphWidths = Metrics[lookupName];
  14757. if (isNum(glyphWidths)) {
  14758. defaultWidth = glyphWidths;
  14759. monospace = true;
  14760. } else {
  14761. widths = glyphWidths;
  14762. }
  14763. return {
  14764. defaultWidth: defaultWidth,
  14765. monospace: monospace,
  14766. widths: widths
  14767. };
  14768. },
  14769. buildCharCodeToWidth:
  14770. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  14771. properties) {
  14772. var widths = Object.create(null);
  14773. var differences = properties.differences;
  14774. var encoding = properties.defaultEncoding;
  14775. for (var charCode = 0; charCode < 256; charCode++) {
  14776. if (charCode in differences &&
  14777. widthsByGlyphName[differences[charCode]]) {
  14778. widths[charCode] = widthsByGlyphName[differences[charCode]];
  14779. continue;
  14780. }
  14781. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  14782. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  14783. continue;
  14784. }
  14785. }
  14786. return widths;
  14787. },
  14788. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  14789. var baseDict = dict;
  14790. var type = dict.get('Subtype');
  14791. assert(isName(type), 'invalid font Subtype');
  14792. var composite = false;
  14793. var uint8array;
  14794. if (type.name === 'Type0') {
  14795. // If font is a composite
  14796. // - get the descendant font
  14797. // - set the type according to the descendant font
  14798. // - get the FontDescriptor from the descendant font
  14799. var df = dict.get('DescendantFonts');
  14800. if (!df) {
  14801. error('Descendant fonts are not specified');
  14802. }
  14803. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  14804. type = dict.get('Subtype');
  14805. assert(isName(type), 'invalid font Subtype');
  14806. composite = true;
  14807. }
  14808. var descriptor = dict.get('FontDescriptor');
  14809. if (descriptor) {
  14810. var hash = new MurmurHash3_64();
  14811. var encoding = baseDict.getRaw('Encoding');
  14812. if (isName(encoding)) {
  14813. hash.update(encoding.name);
  14814. } else if (isRef(encoding)) {
  14815. hash.update(encoding.num + '_' + encoding.gen);
  14816. }
  14817. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  14818. if (isStream(toUnicode)) {
  14819. var stream = toUnicode.str || toUnicode;
  14820. uint8array = stream.buffer ?
  14821. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  14822. new Uint8Array(stream.bytes.buffer,
  14823. stream.start, stream.end - stream.start);
  14824. hash.update(uint8array);
  14825. } else if (isName(toUnicode)) {
  14826. hash.update(toUnicode.name);
  14827. }
  14828. var widths = dict.get('Widths') || baseDict.get('Widths');
  14829. if (widths) {
  14830. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  14831. hash.update(uint8array);
  14832. }
  14833. }
  14834. return {
  14835. descriptor: descriptor,
  14836. dict: dict,
  14837. baseDict: baseDict,
  14838. composite: composite,
  14839. type: type.name,
  14840. hash: hash ? hash.hexdigest() : ''
  14841. };
  14842. },
  14843. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  14844. xref) {
  14845. var baseDict = preEvaluatedFont.baseDict;
  14846. var dict = preEvaluatedFont.dict;
  14847. var composite = preEvaluatedFont.composite;
  14848. var descriptor = preEvaluatedFont.descriptor;
  14849. var type = preEvaluatedFont.type;
  14850. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  14851. var properties;
  14852. if (!descriptor) {
  14853. if (type === 'Type3') {
  14854. // FontDescriptor is only required for Type3 fonts when the document
  14855. // is a tagged pdf. Create a barbebones one to get by.
  14856. descriptor = new Dict(null);
  14857. descriptor.set('FontName', Name.get(type));
  14858. } else {
  14859. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  14860. // FontDescriptor was not required.
  14861. // This case is here for compatibility.
  14862. var baseFontName = dict.get('BaseFont');
  14863. if (!isName(baseFontName)) {
  14864. error('Base font is not specified');
  14865. }
  14866. // Using base font name as a font name.
  14867. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  14868. var metrics = this.getBaseFontMetrics(baseFontName);
  14869. // Simulating descriptor flags attribute
  14870. var fontNameWoStyle = baseFontName.split('-')[0];
  14871. var flags =
  14872. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  14873. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  14874. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  14875. FontFlags.Nonsymbolic);
  14876. properties = {
  14877. type: type,
  14878. name: baseFontName,
  14879. widths: metrics.widths,
  14880. defaultWidth: metrics.defaultWidth,
  14881. flags: flags,
  14882. firstChar: 0,
  14883. lastChar: maxCharIndex
  14884. };
  14885. this.extractDataStructures(dict, dict, xref, properties);
  14886. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  14887. properties);
  14888. return new Font(baseFontName, null, properties);
  14889. }
  14890. }
  14891. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  14892. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  14893. // to ignore this rule when a variant of a standart font is used.
  14894. // TODO Fill the width array depending on which of the base font this is
  14895. // a variant.
  14896. var firstChar = (dict.get('FirstChar') || 0);
  14897. var lastChar = (dict.get('LastChar') || maxCharIndex);
  14898. var fontName = descriptor.get('FontName');
  14899. var baseFont = dict.get('BaseFont');
  14900. // Some bad PDFs have a string as the font name.
  14901. if (isString(fontName)) {
  14902. fontName = Name.get(fontName);
  14903. }
  14904. if (isString(baseFont)) {
  14905. baseFont = Name.get(baseFont);
  14906. }
  14907. if (type !== 'Type3') {
  14908. var fontNameStr = fontName && fontName.name;
  14909. var baseFontStr = baseFont && baseFont.name;
  14910. if (fontNameStr !== baseFontStr) {
  14911. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  14912. '" but should be the same as the Font\'s BaseFont "' +
  14913. baseFontStr + '"');
  14914. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  14915. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  14916. if (fontNameStr && baseFontStr &&
  14917. baseFontStr.indexOf(fontNameStr) === 0) {
  14918. fontName = baseFont;
  14919. }
  14920. }
  14921. }
  14922. fontName = (fontName || baseFont);
  14923. assert(isName(fontName), 'invalid font name');
  14924. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  14925. if (fontFile) {
  14926. if (fontFile.dict) {
  14927. var subtype = fontFile.dict.get('Subtype');
  14928. if (subtype) {
  14929. subtype = subtype.name;
  14930. }
  14931. var length1 = fontFile.dict.get('Length1');
  14932. var length2 = fontFile.dict.get('Length2');
  14933. }
  14934. }
  14935. properties = {
  14936. type: type,
  14937. name: fontName.name,
  14938. subtype: subtype,
  14939. file: fontFile,
  14940. length1: length1,
  14941. length2: length2,
  14942. loadedName: baseDict.loadedName,
  14943. composite: composite,
  14944. wideChars: composite,
  14945. fixedPitch: false,
  14946. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  14947. firstChar: firstChar || 0,
  14948. lastChar: (lastChar || maxCharIndex),
  14949. bbox: descriptor.get('FontBBox'),
  14950. ascent: descriptor.get('Ascent'),
  14951. descent: descriptor.get('Descent'),
  14952. xHeight: descriptor.get('XHeight'),
  14953. capHeight: descriptor.get('CapHeight'),
  14954. flags: descriptor.get('Flags'),
  14955. italicAngle: descriptor.get('ItalicAngle'),
  14956. coded: false
  14957. };
  14958. if (composite) {
  14959. var cidEncoding = baseDict.get('Encoding');
  14960. if (isName(cidEncoding)) {
  14961. properties.cidEncoding = cidEncoding.name;
  14962. }
  14963. properties.cMap = CMapFactory.create(cidEncoding,
  14964. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  14965. properties.vertical = properties.cMap.vertical;
  14966. }
  14967. this.extractDataStructures(dict, baseDict, xref, properties);
  14968. this.extractWidths(dict, xref, descriptor, properties);
  14969. if (type === 'Type3') {
  14970. properties.isType3Font = true;
  14971. }
  14972. return new Font(fontName.name, fontFile, properties);
  14973. }
  14974. };
  14975. return PartialEvaluator;
  14976. })();
  14977. var TranslatedFont = (function TranslatedFontClosure() {
  14978. function TranslatedFont(loadedName, font, dict) {
  14979. this.loadedName = loadedName;
  14980. this.font = font;
  14981. this.dict = dict;
  14982. this.type3Loaded = null;
  14983. this.sent = false;
  14984. }
  14985. TranslatedFont.prototype = {
  14986. send: function (handler) {
  14987. if (this.sent) {
  14988. return;
  14989. }
  14990. var fontData = this.font.exportData();
  14991. handler.send('commonobj', [
  14992. this.loadedName,
  14993. 'Font',
  14994. fontData
  14995. ]);
  14996. this.sent = true;
  14997. },
  14998. loadType3Data: function (evaluator, resources, parentOperatorList) {
  14999. assert(this.font.isType3Font);
  15000. if (this.type3Loaded) {
  15001. return this.type3Loaded;
  15002. }
  15003. var translatedFont = this.font;
  15004. var loadCharProcsPromise = Promise.resolve();
  15005. var charProcs = this.dict.get('CharProcs').getAll();
  15006. var fontResources = this.dict.get('Resources') || resources;
  15007. var charProcKeys = Object.keys(charProcs);
  15008. var charProcOperatorList = {};
  15009. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  15010. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  15011. var glyphStream = charProcs[key];
  15012. var operatorList = new OperatorList();
  15013. return evaluator.getOperatorList(glyphStream, fontResources,
  15014. operatorList).then(function () {
  15015. charProcOperatorList[key] = operatorList.getIR();
  15016. // Add the dependencies to the parent operator list so they are
  15017. // resolved before sub operator list is executed synchronously.
  15018. parentOperatorList.addDependencies(operatorList.dependencies);
  15019. }, function (reason) {
  15020. warn('Type3 font resource \"' + key + '\" is not available');
  15021. var operatorList = new OperatorList();
  15022. charProcOperatorList[key] = operatorList.getIR();
  15023. });
  15024. }.bind(this, charProcKeys[i]));
  15025. }
  15026. this.type3Loaded = loadCharProcsPromise.then(function () {
  15027. translatedFont.charProcOperatorList = charProcOperatorList;
  15028. });
  15029. return this.type3Loaded;
  15030. }
  15031. };
  15032. return TranslatedFont;
  15033. })();
  15034. var OperatorList = (function OperatorListClosure() {
  15035. var CHUNK_SIZE = 1000;
  15036. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  15037. function getTransfers(queue) {
  15038. var transfers = [];
  15039. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15040. for (var i = 0, ii = queue.length; i < ii; i++) {
  15041. switch (fnArray[i]) {
  15042. case OPS.paintInlineImageXObject:
  15043. case OPS.paintInlineImageXObjectGroup:
  15044. case OPS.paintImageMaskXObject:
  15045. var arg = argsArray[i][0]; // first param in imgData
  15046. if (!arg.cached) {
  15047. transfers.push(arg.data.buffer);
  15048. }
  15049. break;
  15050. }
  15051. }
  15052. return transfers;
  15053. }
  15054. function OperatorList(intent, messageHandler, pageIndex) {
  15055. this.messageHandler = messageHandler;
  15056. this.fnArray = [];
  15057. this.argsArray = [];
  15058. this.dependencies = {};
  15059. this.pageIndex = pageIndex;
  15060. this.intent = intent;
  15061. }
  15062. OperatorList.prototype = {
  15063. get length() {
  15064. return this.argsArray.length;
  15065. },
  15066. addOp: function(fn, args) {
  15067. this.fnArray.push(fn);
  15068. this.argsArray.push(args);
  15069. if (this.messageHandler) {
  15070. if (this.fnArray.length >= CHUNK_SIZE) {
  15071. this.flush();
  15072. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  15073. (fn === OPS.restore || fn === OPS.endText)) {
  15074. // heuristic to flush on boundary of restore or endText
  15075. this.flush();
  15076. }
  15077. }
  15078. },
  15079. addDependency: function(dependency) {
  15080. if (dependency in this.dependencies) {
  15081. return;
  15082. }
  15083. this.dependencies[dependency] = true;
  15084. this.addOp(OPS.dependency, [dependency]);
  15085. },
  15086. addDependencies: function(dependencies) {
  15087. for (var key in dependencies) {
  15088. this.addDependency(key);
  15089. }
  15090. },
  15091. addOpList: function(opList) {
  15092. Util.extendObj(this.dependencies, opList.dependencies);
  15093. for (var i = 0, ii = opList.length; i < ii; i++) {
  15094. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  15095. }
  15096. },
  15097. getIR: function() {
  15098. return {
  15099. fnArray: this.fnArray,
  15100. argsArray: this.argsArray,
  15101. length: this.length
  15102. };
  15103. },
  15104. flush: function(lastChunk) {
  15105. if (this.intent !== 'oplist') {
  15106. new QueueOptimizer().optimize(this);
  15107. }
  15108. var transfers = getTransfers(this);
  15109. this.messageHandler.send('RenderPageChunk', {
  15110. operatorList: {
  15111. fnArray: this.fnArray,
  15112. argsArray: this.argsArray,
  15113. lastChunk: lastChunk,
  15114. length: this.length
  15115. },
  15116. pageIndex: this.pageIndex,
  15117. intent: this.intent
  15118. }, transfers);
  15119. this.dependencies = {};
  15120. this.fnArray.length = 0;
  15121. this.argsArray.length = 0;
  15122. }
  15123. };
  15124. return OperatorList;
  15125. })();
  15126. var StateManager = (function StateManagerClosure() {
  15127. function StateManager(initialState) {
  15128. this.state = initialState;
  15129. this.stateStack = [];
  15130. }
  15131. StateManager.prototype = {
  15132. save: function () {
  15133. var old = this.state;
  15134. this.stateStack.push(this.state);
  15135. this.state = old.clone();
  15136. },
  15137. restore: function () {
  15138. var prev = this.stateStack.pop();
  15139. if (prev) {
  15140. this.state = prev;
  15141. }
  15142. },
  15143. transform: function (args) {
  15144. this.state.ctm = Util.transform(this.state.ctm, args);
  15145. }
  15146. };
  15147. return StateManager;
  15148. })();
  15149. var TextState = (function TextStateClosure() {
  15150. function TextState() {
  15151. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15152. this.fontSize = 0;
  15153. this.font = null;
  15154. this.fontMatrix = FONT_IDENTITY_MATRIX;
  15155. this.textMatrix = IDENTITY_MATRIX.slice();
  15156. this.textLineMatrix = IDENTITY_MATRIX.slice();
  15157. this.charSpacing = 0;
  15158. this.wordSpacing = 0;
  15159. this.leading = 0;
  15160. this.textHScale = 1;
  15161. this.textRise = 0;
  15162. }
  15163. TextState.prototype = {
  15164. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15165. var m = this.textMatrix;
  15166. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15167. },
  15168. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15169. var m = this.textLineMatrix;
  15170. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15171. },
  15172. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  15173. var m = this.textMatrix;
  15174. m[4] = m[0] * x + m[2] * y + m[4];
  15175. m[5] = m[1] * x + m[3] * y + m[5];
  15176. },
  15177. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  15178. var m = this.textLineMatrix;
  15179. m[4] = m[0] * x + m[2] * y + m[4];
  15180. m[5] = m[1] * x + m[3] * y + m[5];
  15181. },
  15182. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  15183. // 9.4.4 Text Space Details
  15184. var tsm = [this.fontSize * this.textHScale, 0,
  15185. 0, this.fontSize,
  15186. 0, this.textRise];
  15187. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  15188. },
  15189. carriageReturn: function TextState_carriageReturn() {
  15190. this.translateTextLineMatrix(0, -this.leading);
  15191. this.textMatrix = this.textLineMatrix.slice();
  15192. },
  15193. clone: function TextState_clone() {
  15194. var clone = Object.create(this);
  15195. clone.textMatrix = this.textMatrix.slice();
  15196. clone.textLineMatrix = this.textLineMatrix.slice();
  15197. clone.fontMatrix = this.fontMatrix.slice();
  15198. return clone;
  15199. }
  15200. };
  15201. return TextState;
  15202. })();
  15203. var EvalState = (function EvalStateClosure() {
  15204. function EvalState() {
  15205. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15206. this.font = null;
  15207. this.textRenderingMode = TextRenderingMode.FILL;
  15208. this.fillColorSpace = ColorSpace.singletons.gray;
  15209. this.strokeColorSpace = ColorSpace.singletons.gray;
  15210. }
  15211. EvalState.prototype = {
  15212. clone: function CanvasExtraState_clone() {
  15213. return Object.create(this);
  15214. },
  15215. };
  15216. return EvalState;
  15217. })();
  15218. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  15219. // Specifies properties for each command
  15220. //
  15221. // If variableArgs === true: [0, `numArgs`] expected
  15222. // If variableArgs === false: exactly `numArgs` expected
  15223. var OP_MAP = {
  15224. // Graphic state
  15225. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  15226. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  15227. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  15228. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  15229. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  15230. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  15231. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  15232. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  15233. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  15234. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  15235. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  15236. // Path
  15237. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  15238. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  15239. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  15240. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  15241. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  15242. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  15243. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  15244. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  15245. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  15246. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15247. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15248. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  15249. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  15250. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  15251. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  15252. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  15253. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  15254. // Clipping
  15255. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  15256. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  15257. // Text
  15258. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  15259. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  15260. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  15261. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  15262. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  15263. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  15264. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  15265. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  15266. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  15267. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  15268. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  15269. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  15270. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  15271. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  15272. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  15273. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  15274. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  15275. variableArgs: false },
  15276. // Type3 fonts
  15277. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  15278. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  15279. // Color
  15280. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  15281. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  15282. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  15283. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  15284. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  15285. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  15286. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  15287. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  15288. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  15289. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  15290. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  15291. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  15292. // Shading
  15293. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  15294. // Images
  15295. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  15296. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  15297. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  15298. // XObjects
  15299. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  15300. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  15301. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  15302. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  15303. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  15304. variableArgs: false },
  15305. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  15306. // Compatibility
  15307. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  15308. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  15309. // (reserved partial commands for the lexer)
  15310. BM: null,
  15311. BD: null,
  15312. 'true': null,
  15313. fa: null,
  15314. fal: null,
  15315. fals: null,
  15316. 'false': null,
  15317. nu: null,
  15318. nul: null,
  15319. 'null': null
  15320. };
  15321. function EvaluatorPreprocessor(stream, xref, stateManager) {
  15322. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  15323. // dictionary
  15324. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  15325. this.stateManager = stateManager;
  15326. this.nonProcessedArgs = [];
  15327. }
  15328. EvaluatorPreprocessor.prototype = {
  15329. get savedStatesDepth() {
  15330. return this.stateManager.stateStack.length;
  15331. },
  15332. read: function EvaluatorPreprocessor_read(operation) {
  15333. // We use an array to represent args, except we use |null| to represent
  15334. // no args because it's more compact than an empty array.
  15335. var args = null;
  15336. while (true) {
  15337. var obj = this.parser.getObj();
  15338. if (isCmd(obj)) {
  15339. var cmd = obj.cmd;
  15340. // Check that the command is valid
  15341. var opSpec = OP_MAP[cmd];
  15342. if (!opSpec) {
  15343. warn('Unknown command "' + cmd + '"');
  15344. continue;
  15345. }
  15346. var fn = opSpec.id;
  15347. var numArgs = opSpec.numArgs;
  15348. var argsLength = args !== null ? args.length : 0;
  15349. if (!opSpec.variableArgs) {
  15350. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  15351. if (argsLength !== numArgs) {
  15352. var nonProcessedArgs = this.nonProcessedArgs;
  15353. while (argsLength > numArgs) {
  15354. nonProcessedArgs.push(args.shift());
  15355. argsLength--;
  15356. }
  15357. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  15358. if (!args) {
  15359. args = [];
  15360. }
  15361. args.unshift(nonProcessedArgs.pop());
  15362. argsLength++;
  15363. }
  15364. }
  15365. if (argsLength < numArgs) {
  15366. // If we receive too few args, it's not possible to possible
  15367. // to execute the command, so skip the command
  15368. info('Command ' + fn + ': because expected ' +
  15369. numArgs + ' args, but received ' + argsLength +
  15370. ' args; skipping');
  15371. args = null;
  15372. continue;
  15373. }
  15374. } else if (argsLength > numArgs) {
  15375. info('Command ' + fn + ': expected [0,' + numArgs +
  15376. '] args, but received ' + argsLength + ' args');
  15377. }
  15378. // TODO figure out how to type-check vararg functions
  15379. this.preprocessCommand(fn, args);
  15380. operation.fn = fn;
  15381. operation.args = args;
  15382. return true;
  15383. } else {
  15384. if (isEOF(obj)) {
  15385. return false; // no more commands
  15386. }
  15387. // argument
  15388. if (obj !== null) {
  15389. if (!args) {
  15390. args = [];
  15391. }
  15392. args.push((obj instanceof Dict ? obj.getAll() : obj));
  15393. assert(args.length <= 33, 'Too many arguments');
  15394. }
  15395. }
  15396. }
  15397. },
  15398. preprocessCommand:
  15399. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  15400. switch (fn | 0) {
  15401. case OPS.save:
  15402. this.stateManager.save();
  15403. break;
  15404. case OPS.restore:
  15405. this.stateManager.restore();
  15406. break;
  15407. case OPS.transform:
  15408. this.stateManager.transform(args);
  15409. break;
  15410. }
  15411. }
  15412. };
  15413. return EvaluatorPreprocessor;
  15414. })();
  15415. var QueueOptimizer = (function QueueOptimizerClosure() {
  15416. function addState(parentState, pattern, fn) {
  15417. var state = parentState;
  15418. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  15419. var item = pattern[i];
  15420. state = (state[item] || (state[item] = []));
  15421. }
  15422. state[pattern[pattern.length - 1]] = fn;
  15423. }
  15424. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15425. argsArray) {
  15426. // Handles special case of mainly LaTeX documents which use image masks to
  15427. // draw lines with the current fill style.
  15428. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  15429. // have been found at iFirstSave.
  15430. var iFirstPIMXO = iFirstSave + 2;
  15431. for (var i = 0; i < count; i++) {
  15432. var arg = argsArray[iFirstPIMXO + 4 * i];
  15433. var imageMask = arg.length === 1 && arg[0];
  15434. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  15435. (!imageMask.data.length ||
  15436. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  15437. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  15438. continue;
  15439. }
  15440. break;
  15441. }
  15442. return count - i;
  15443. }
  15444. var InitialState = [];
  15445. // This replaces (save, transform, paintInlineImageXObject, restore)+
  15446. // sequences with one |paintInlineImageXObjectGroup| operation.
  15447. addState(InitialState,
  15448. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  15449. function foundInlineImageGroup(context) {
  15450. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  15451. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  15452. var MAX_WIDTH = 1000;
  15453. var IMAGE_PADDING = 1;
  15454. var fnArray = context.fnArray, argsArray = context.argsArray;
  15455. var curr = context.iCurr;
  15456. var iFirstSave = curr - 3;
  15457. var iFirstTransform = curr - 2;
  15458. var iFirstPIIXO = curr - 1;
  15459. // Look for the quartets.
  15460. var i = iFirstSave + 4;
  15461. var ii = fnArray.length;
  15462. while (i + 3 < ii) {
  15463. if (fnArray[i] !== OPS.save ||
  15464. fnArray[i + 1] !== OPS.transform ||
  15465. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  15466. fnArray[i + 3] !== OPS.restore) {
  15467. break; // ops don't match
  15468. }
  15469. i += 4;
  15470. }
  15471. // At this point, i is the index of the first op past the last valid
  15472. // quartet.
  15473. var count = Math.min((i - iFirstSave) / 4,
  15474. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  15475. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  15476. return i;
  15477. }
  15478. // assuming that heights of those image is too small (~1 pixel)
  15479. // packing as much as possible by lines
  15480. var maxX = 0;
  15481. var map = [], maxLineHeight = 0;
  15482. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  15483. var q;
  15484. for (q = 0; q < count; q++) {
  15485. var transform = argsArray[iFirstTransform + (q << 2)];
  15486. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  15487. if (currentX + img.width > MAX_WIDTH) {
  15488. // starting new line
  15489. maxX = Math.max(maxX, currentX);
  15490. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  15491. currentX = 0;
  15492. maxLineHeight = 0;
  15493. }
  15494. map.push({
  15495. transform: transform,
  15496. x: currentX, y: currentY,
  15497. w: img.width, h: img.height
  15498. });
  15499. currentX += img.width + 2 * IMAGE_PADDING;
  15500. maxLineHeight = Math.max(maxLineHeight, img.height);
  15501. }
  15502. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  15503. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  15504. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  15505. var imgRowSize = imgWidth << 2;
  15506. for (q = 0; q < count; q++) {
  15507. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  15508. // Copy image by lines and extends pixels into padding.
  15509. var rowSize = map[q].w << 2;
  15510. var dataOffset = 0;
  15511. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  15512. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  15513. for (var k = 0, kk = map[q].h; k < kk; k++) {
  15514. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  15515. dataOffset += rowSize;
  15516. offset += imgRowSize;
  15517. }
  15518. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  15519. while (offset >= 0) {
  15520. data[offset - 4] = data[offset];
  15521. data[offset - 3] = data[offset + 1];
  15522. data[offset - 2] = data[offset + 2];
  15523. data[offset - 1] = data[offset + 3];
  15524. data[offset + rowSize] = data[offset + rowSize - 4];
  15525. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  15526. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  15527. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  15528. offset -= imgRowSize;
  15529. }
  15530. }
  15531. // Replace queue items.
  15532. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  15533. argsArray.splice(iFirstSave, count * 4,
  15534. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  15535. data: imgData }, map]);
  15536. return iFirstSave + 1;
  15537. });
  15538. // This replaces (save, transform, paintImageMaskXObject, restore)+
  15539. // sequences with one |paintImageMaskXObjectGroup| or one
  15540. // |paintImageMaskXObjectRepeat| operation.
  15541. addState(InitialState,
  15542. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  15543. function foundImageMaskGroup(context) {
  15544. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  15545. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  15546. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  15547. var fnArray = context.fnArray, argsArray = context.argsArray;
  15548. var curr = context.iCurr;
  15549. var iFirstSave = curr - 3;
  15550. var iFirstTransform = curr - 2;
  15551. var iFirstPIMXO = curr - 1;
  15552. // Look for the quartets.
  15553. var i = iFirstSave + 4;
  15554. var ii = fnArray.length;
  15555. while (i + 3 < ii) {
  15556. if (fnArray[i] !== OPS.save ||
  15557. fnArray[i + 1] !== OPS.transform ||
  15558. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  15559. fnArray[i + 3] !== OPS.restore) {
  15560. break; // ops don't match
  15561. }
  15562. i += 4;
  15563. }
  15564. // At this point, i is the index of the first op past the last valid
  15565. // quartet.
  15566. var count = (i - iFirstSave) / 4;
  15567. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15568. argsArray);
  15569. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  15570. return i;
  15571. }
  15572. var q;
  15573. var isSameImage = false;
  15574. var iTransform, transformArgs;
  15575. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  15576. if (argsArray[iFirstTransform][1] === 0 &&
  15577. argsArray[iFirstTransform][2] === 0) {
  15578. isSameImage = true;
  15579. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15580. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15581. iTransform = iFirstTransform + 4;
  15582. var iPIMXO = iFirstPIMXO + 4;
  15583. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  15584. transformArgs = argsArray[iTransform];
  15585. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  15586. transformArgs[0] !== firstTransformArg0 ||
  15587. transformArgs[1] !== 0 ||
  15588. transformArgs[2] !== 0 ||
  15589. transformArgs[3] !== firstTransformArg3) {
  15590. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  15591. isSameImage = false;
  15592. } else {
  15593. count = q;
  15594. }
  15595. break; // different image or transform
  15596. }
  15597. }
  15598. }
  15599. if (isSameImage) {
  15600. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  15601. var positions = new Float32Array(count * 2);
  15602. iTransform = iFirstTransform;
  15603. for (q = 0; q < count; q++, iTransform += 4) {
  15604. transformArgs = argsArray[iTransform];
  15605. positions[(q << 1)] = transformArgs[4];
  15606. positions[(q << 1) + 1] = transformArgs[5];
  15607. }
  15608. // Replace queue items.
  15609. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  15610. argsArray.splice(iFirstSave, count * 4,
  15611. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  15612. } else {
  15613. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  15614. var images = [];
  15615. for (q = 0; q < count; q++) {
  15616. transformArgs = argsArray[iFirstTransform + (q << 2)];
  15617. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  15618. images.push({ data: maskParams.data, width: maskParams.width,
  15619. height: maskParams.height,
  15620. transform: transformArgs });
  15621. }
  15622. // Replace queue items.
  15623. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  15624. argsArray.splice(iFirstSave, count * 4, [images]);
  15625. }
  15626. return iFirstSave + 1;
  15627. });
  15628. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  15629. // with one paintImageXObjectRepeat operation, if the |transform| and
  15630. // |paintImageXObjectRepeat| ops are appropriate.
  15631. addState(InitialState,
  15632. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  15633. function (context) {
  15634. var MIN_IMAGES_IN_BLOCK = 3;
  15635. var MAX_IMAGES_IN_BLOCK = 1000;
  15636. var fnArray = context.fnArray, argsArray = context.argsArray;
  15637. var curr = context.iCurr;
  15638. var iFirstSave = curr - 3;
  15639. var iFirstTransform = curr - 2;
  15640. var iFirstPIXO = curr - 1;
  15641. var iFirstRestore = curr;
  15642. if (argsArray[iFirstTransform][1] !== 0 ||
  15643. argsArray[iFirstTransform][2] !== 0) {
  15644. return iFirstRestore + 1; // transform has the wrong form
  15645. }
  15646. // Look for the quartets.
  15647. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  15648. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15649. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15650. var i = iFirstSave + 4;
  15651. var ii = fnArray.length;
  15652. while (i + 3 < ii) {
  15653. if (fnArray[i] !== OPS.save ||
  15654. fnArray[i + 1] !== OPS.transform ||
  15655. fnArray[i + 2] !== OPS.paintImageXObject ||
  15656. fnArray[i + 3] !== OPS.restore) {
  15657. break; // ops don't match
  15658. }
  15659. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  15660. argsArray[i + 1][1] !== 0 ||
  15661. argsArray[i + 1][2] !== 0 ||
  15662. argsArray[i + 1][3] !== firstTransformArg3) {
  15663. break; // transforms don't match
  15664. }
  15665. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  15666. break; // images don't match
  15667. }
  15668. i += 4;
  15669. }
  15670. // At this point, i is the index of the first op past the last valid
  15671. // quartet.
  15672. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  15673. if (count < MIN_IMAGES_IN_BLOCK) {
  15674. return i;
  15675. }
  15676. // Extract the (x,y) positions from all of the matching transforms.
  15677. var positions = new Float32Array(count * 2);
  15678. var iTransform = iFirstTransform;
  15679. for (var q = 0; q < count; q++, iTransform += 4) {
  15680. var transformArgs = argsArray[iTransform];
  15681. positions[(q << 1)] = transformArgs[4];
  15682. positions[(q << 1) + 1] = transformArgs[5];
  15683. }
  15684. // Replace queue items.
  15685. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  15686. positions];
  15687. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  15688. argsArray.splice(iFirstSave, count * 4, args);
  15689. return iFirstSave + 1;
  15690. });
  15691. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  15692. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  15693. // sequences, if the font for each one is the same.
  15694. addState(InitialState,
  15695. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  15696. function (context) {
  15697. var MIN_CHARS_IN_BLOCK = 3;
  15698. var MAX_CHARS_IN_BLOCK = 1000;
  15699. var fnArray = context.fnArray, argsArray = context.argsArray;
  15700. var curr = context.iCurr;
  15701. var iFirstBeginText = curr - 4;
  15702. var iFirstSetFont = curr - 3;
  15703. var iFirstSetTextMatrix = curr - 2;
  15704. var iFirstShowText = curr - 1;
  15705. var iFirstEndText = curr;
  15706. // Look for the quintets.
  15707. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  15708. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  15709. var i = iFirstBeginText + 5;
  15710. var ii = fnArray.length;
  15711. while (i + 4 < ii) {
  15712. if (fnArray[i] !== OPS.beginText ||
  15713. fnArray[i + 1] !== OPS.setFont ||
  15714. fnArray[i + 2] !== OPS.setTextMatrix ||
  15715. fnArray[i + 3] !== OPS.showText ||
  15716. fnArray[i + 4] !== OPS.endText) {
  15717. break; // ops don't match
  15718. }
  15719. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  15720. argsArray[i + 1][1] !== firstSetFontArg1) {
  15721. break; // fonts don't match
  15722. }
  15723. i += 5;
  15724. }
  15725. // At this point, i is the index of the first op past the last valid
  15726. // quintet.
  15727. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  15728. if (count < MIN_CHARS_IN_BLOCK) {
  15729. return i;
  15730. }
  15731. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  15732. // showText, endText), include that as well. (E.g. <something> might be
  15733. // |dependency|.)
  15734. var iFirst = iFirstBeginText;
  15735. if (iFirstBeginText >= 4 &&
  15736. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  15737. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  15738. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  15739. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  15740. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  15741. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  15742. count++;
  15743. iFirst -= 5;
  15744. }
  15745. // Remove (endText, beginText, setFont) trios.
  15746. var iEndText = iFirst + 4;
  15747. for (var q = 1; q < count; q++) {
  15748. fnArray.splice(iEndText, 3);
  15749. argsArray.splice(iEndText, 3);
  15750. iEndText += 2;
  15751. }
  15752. return iEndText + 1;
  15753. });
  15754. function QueueOptimizer() {}
  15755. QueueOptimizer.prototype = {
  15756. optimize: function QueueOptimizer_optimize(queue) {
  15757. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15758. var context = {
  15759. iCurr: 0,
  15760. fnArray: fnArray,
  15761. argsArray: argsArray
  15762. };
  15763. var state;
  15764. var i = 0, ii = fnArray.length;
  15765. while (i < ii) {
  15766. state = (state || InitialState)[fnArray[i]];
  15767. if (typeof state === 'function') { // we found some handler
  15768. context.iCurr = i;
  15769. // state() returns the index of the first non-matching op (if we
  15770. // didn't match) or the first op past the modified ops (if we did
  15771. // match and replace).
  15772. i = state(context);
  15773. state = undefined; // reset the state machine
  15774. ii = context.fnArray.length;
  15775. } else {
  15776. i++;
  15777. }
  15778. }
  15779. }
  15780. };
  15781. return QueueOptimizer;
  15782. })();
  15783. var BUILT_IN_CMAPS = [
  15784. // << Start unicode maps.
  15785. 'Adobe-GB1-UCS2',
  15786. 'Adobe-CNS1-UCS2',
  15787. 'Adobe-Japan1-UCS2',
  15788. 'Adobe-Korea1-UCS2',
  15789. // >> End unicode maps.
  15790. '78-EUC-H',
  15791. '78-EUC-V',
  15792. '78-H',
  15793. '78-RKSJ-H',
  15794. '78-RKSJ-V',
  15795. '78-V',
  15796. '78ms-RKSJ-H',
  15797. '78ms-RKSJ-V',
  15798. '83pv-RKSJ-H',
  15799. '90ms-RKSJ-H',
  15800. '90ms-RKSJ-V',
  15801. '90msp-RKSJ-H',
  15802. '90msp-RKSJ-V',
  15803. '90pv-RKSJ-H',
  15804. '90pv-RKSJ-V',
  15805. 'Add-H',
  15806. 'Add-RKSJ-H',
  15807. 'Add-RKSJ-V',
  15808. 'Add-V',
  15809. 'Adobe-CNS1-0',
  15810. 'Adobe-CNS1-1',
  15811. 'Adobe-CNS1-2',
  15812. 'Adobe-CNS1-3',
  15813. 'Adobe-CNS1-4',
  15814. 'Adobe-CNS1-5',
  15815. 'Adobe-CNS1-6',
  15816. 'Adobe-GB1-0',
  15817. 'Adobe-GB1-1',
  15818. 'Adobe-GB1-2',
  15819. 'Adobe-GB1-3',
  15820. 'Adobe-GB1-4',
  15821. 'Adobe-GB1-5',
  15822. 'Adobe-Japan1-0',
  15823. 'Adobe-Japan1-1',
  15824. 'Adobe-Japan1-2',
  15825. 'Adobe-Japan1-3',
  15826. 'Adobe-Japan1-4',
  15827. 'Adobe-Japan1-5',
  15828. 'Adobe-Japan1-6',
  15829. 'Adobe-Korea1-0',
  15830. 'Adobe-Korea1-1',
  15831. 'Adobe-Korea1-2',
  15832. 'B5-H',
  15833. 'B5-V',
  15834. 'B5pc-H',
  15835. 'B5pc-V',
  15836. 'CNS-EUC-H',
  15837. 'CNS-EUC-V',
  15838. 'CNS1-H',
  15839. 'CNS1-V',
  15840. 'CNS2-H',
  15841. 'CNS2-V',
  15842. 'ETHK-B5-H',
  15843. 'ETHK-B5-V',
  15844. 'ETen-B5-H',
  15845. 'ETen-B5-V',
  15846. 'ETenms-B5-H',
  15847. 'ETenms-B5-V',
  15848. 'EUC-H',
  15849. 'EUC-V',
  15850. 'Ext-H',
  15851. 'Ext-RKSJ-H',
  15852. 'Ext-RKSJ-V',
  15853. 'Ext-V',
  15854. 'GB-EUC-H',
  15855. 'GB-EUC-V',
  15856. 'GB-H',
  15857. 'GB-V',
  15858. 'GBK-EUC-H',
  15859. 'GBK-EUC-V',
  15860. 'GBK2K-H',
  15861. 'GBK2K-V',
  15862. 'GBKp-EUC-H',
  15863. 'GBKp-EUC-V',
  15864. 'GBT-EUC-H',
  15865. 'GBT-EUC-V',
  15866. 'GBT-H',
  15867. 'GBT-V',
  15868. 'GBTpc-EUC-H',
  15869. 'GBTpc-EUC-V',
  15870. 'GBpc-EUC-H',
  15871. 'GBpc-EUC-V',
  15872. 'H',
  15873. 'HKdla-B5-H',
  15874. 'HKdla-B5-V',
  15875. 'HKdlb-B5-H',
  15876. 'HKdlb-B5-V',
  15877. 'HKgccs-B5-H',
  15878. 'HKgccs-B5-V',
  15879. 'HKm314-B5-H',
  15880. 'HKm314-B5-V',
  15881. 'HKm471-B5-H',
  15882. 'HKm471-B5-V',
  15883. 'HKscs-B5-H',
  15884. 'HKscs-B5-V',
  15885. 'Hankaku',
  15886. 'Hiragana',
  15887. 'KSC-EUC-H',
  15888. 'KSC-EUC-V',
  15889. 'KSC-H',
  15890. 'KSC-Johab-H',
  15891. 'KSC-Johab-V',
  15892. 'KSC-V',
  15893. 'KSCms-UHC-H',
  15894. 'KSCms-UHC-HW-H',
  15895. 'KSCms-UHC-HW-V',
  15896. 'KSCms-UHC-V',
  15897. 'KSCpc-EUC-H',
  15898. 'KSCpc-EUC-V',
  15899. 'Katakana',
  15900. 'NWP-H',
  15901. 'NWP-V',
  15902. 'RKSJ-H',
  15903. 'RKSJ-V',
  15904. 'Roman',
  15905. 'UniCNS-UCS2-H',
  15906. 'UniCNS-UCS2-V',
  15907. 'UniCNS-UTF16-H',
  15908. 'UniCNS-UTF16-V',
  15909. 'UniCNS-UTF32-H',
  15910. 'UniCNS-UTF32-V',
  15911. 'UniCNS-UTF8-H',
  15912. 'UniCNS-UTF8-V',
  15913. 'UniGB-UCS2-H',
  15914. 'UniGB-UCS2-V',
  15915. 'UniGB-UTF16-H',
  15916. 'UniGB-UTF16-V',
  15917. 'UniGB-UTF32-H',
  15918. 'UniGB-UTF32-V',
  15919. 'UniGB-UTF8-H',
  15920. 'UniGB-UTF8-V',
  15921. 'UniJIS-UCS2-H',
  15922. 'UniJIS-UCS2-HW-H',
  15923. 'UniJIS-UCS2-HW-V',
  15924. 'UniJIS-UCS2-V',
  15925. 'UniJIS-UTF16-H',
  15926. 'UniJIS-UTF16-V',
  15927. 'UniJIS-UTF32-H',
  15928. 'UniJIS-UTF32-V',
  15929. 'UniJIS-UTF8-H',
  15930. 'UniJIS-UTF8-V',
  15931. 'UniJIS2004-UTF16-H',
  15932. 'UniJIS2004-UTF16-V',
  15933. 'UniJIS2004-UTF32-H',
  15934. 'UniJIS2004-UTF32-V',
  15935. 'UniJIS2004-UTF8-H',
  15936. 'UniJIS2004-UTF8-V',
  15937. 'UniJISPro-UCS2-HW-V',
  15938. 'UniJISPro-UCS2-V',
  15939. 'UniJISPro-UTF8-V',
  15940. 'UniJISX0213-UTF32-H',
  15941. 'UniJISX0213-UTF32-V',
  15942. 'UniJISX02132004-UTF32-H',
  15943. 'UniJISX02132004-UTF32-V',
  15944. 'UniKS-UCS2-H',
  15945. 'UniKS-UCS2-V',
  15946. 'UniKS-UTF16-H',
  15947. 'UniKS-UTF16-V',
  15948. 'UniKS-UTF32-H',
  15949. 'UniKS-UTF32-V',
  15950. 'UniKS-UTF8-H',
  15951. 'UniKS-UTF8-V',
  15952. 'V',
  15953. 'WP-Symbol'];
  15954. // CMap, not to be confused with TrueType's cmap.
  15955. var CMap = (function CMapClosure() {
  15956. function CMap(builtInCMap) {
  15957. // Codespace ranges are stored as follows:
  15958. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  15959. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  15960. this.codespaceRanges = [[], [], [], []];
  15961. this.numCodespaceRanges = 0;
  15962. // Map entries have one of two forms.
  15963. // - cid chars are 16-bit unsigned integers, stored as integers.
  15964. // - bf chars are variable-length byte sequences, stored as strings, with
  15965. // one byte per character.
  15966. this._map = [];
  15967. this.vertical = false;
  15968. this.useCMap = null;
  15969. this.builtInCMap = builtInCMap;
  15970. }
  15971. CMap.prototype = {
  15972. addCodespaceRange: function(n, low, high) {
  15973. this.codespaceRanges[n - 1].push(low, high);
  15974. this.numCodespaceRanges++;
  15975. },
  15976. mapCidRange: function(low, high, dstLow) {
  15977. while (low <= high) {
  15978. this._map[low++] = dstLow++;
  15979. }
  15980. },
  15981. mapBfRange: function(low, high, dstLow) {
  15982. var lastByte = dstLow.length - 1;
  15983. while (low <= high) {
  15984. this._map[low++] = dstLow;
  15985. // Only the last byte has to be incremented.
  15986. dstLow = dstLow.substr(0, lastByte) +
  15987. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  15988. }
  15989. },
  15990. mapBfRangeToArray: function(low, high, array) {
  15991. var i = 0, ii = array.length;
  15992. while (low <= high && i < ii) {
  15993. this._map[low] = array[i++];
  15994. ++low;
  15995. }
  15996. },
  15997. // This is used for both bf and cid chars.
  15998. mapOne: function(src, dst) {
  15999. this._map[src] = dst;
  16000. },
  16001. lookup: function(code) {
  16002. return this._map[code];
  16003. },
  16004. contains: function(code) {
  16005. return this._map[code] !== undefined;
  16006. },
  16007. forEach: function(callback) {
  16008. // Most maps have fewer than 65536 entries, and for those we use normal
  16009. // array iteration. But really sparse tables are possible -- e.g. with
  16010. // indices in the *billions*. For such tables we use for..in, which isn't
  16011. // ideal because it stringifies the indices for all present elements, but
  16012. // it does avoid iterating over every undefined entry.
  16013. var map = this._map;
  16014. var length = map.length;
  16015. var i;
  16016. if (length <= 0x10000) {
  16017. for (i = 0; i < length; i++) {
  16018. if (map[i] !== undefined) {
  16019. callback(i, map[i]);
  16020. }
  16021. }
  16022. } else {
  16023. for (i in this._map) {
  16024. callback(i, map[i]);
  16025. }
  16026. }
  16027. },
  16028. charCodeOf: function(value) {
  16029. return this._map.indexOf(value);
  16030. },
  16031. getMap: function() {
  16032. return this._map;
  16033. },
  16034. readCharCode: function(str, offset) {
  16035. var c = 0;
  16036. var codespaceRanges = this.codespaceRanges;
  16037. var codespaceRangesLen = this.codespaceRanges.length;
  16038. // 9.7.6.2 CMap Mapping
  16039. // The code length is at most 4.
  16040. for (var n = 0; n < codespaceRangesLen; n++) {
  16041. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  16042. // Check each codespace range to see if it falls within.
  16043. var codespaceRange = codespaceRanges[n];
  16044. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  16045. var low = codespaceRange[k++];
  16046. var high = codespaceRange[k++];
  16047. if (c >= low && c <= high) {
  16048. return [c, n + 1];
  16049. }
  16050. }
  16051. }
  16052. return [0, 1];
  16053. }
  16054. };
  16055. return CMap;
  16056. })();
  16057. // A special case of CMap, where the _map array implicitly has a length of
  16058. // 65535 and each element is equal to its index.
  16059. var IdentityCMap = (function IdentityCMapClosure() {
  16060. function IdentityCMap(vertical, n) {
  16061. CMap.call(this);
  16062. this.vertical = vertical;
  16063. this.addCodespaceRange(n, 0, 0xffff);
  16064. }
  16065. Util.inherit(IdentityCMap, CMap, {});
  16066. IdentityCMap.prototype = {
  16067. addCodespaceRange: CMap.prototype.addCodespaceRange,
  16068. mapCidRange: function(low, high, dstLow) {
  16069. error('should not call mapCidRange');
  16070. },
  16071. mapBfRange: function(low, high, dstLow) {
  16072. error('should not call mapBfRange');
  16073. },
  16074. mapBfRangeToArray: function(low, high, array) {
  16075. error('should not call mapBfRangeToArray');
  16076. },
  16077. mapOne: function(src, dst) {
  16078. error('should not call mapCidOne');
  16079. },
  16080. lookup: function(code) {
  16081. return (isInt(code) && code <= 0xffff) ? code : undefined;
  16082. },
  16083. contains: function(code) {
  16084. return isInt(code) && code <= 0xffff;
  16085. },
  16086. forEach: function(callback) {
  16087. for (var i = 0; i <= 0xffff; i++) {
  16088. callback(i, i);
  16089. }
  16090. },
  16091. charCodeOf: function(value) {
  16092. return (isInt(value) && value <= 0xffff) ? value : -1;
  16093. },
  16094. getMap: function() {
  16095. // Sometimes identity maps must be instantiated, but it's rare.
  16096. var map = new Array(0x10000);
  16097. for (var i = 0; i <= 0xffff; i++) {
  16098. map[i] = i;
  16099. }
  16100. return map;
  16101. },
  16102. readCharCode: CMap.prototype.readCharCode
  16103. };
  16104. return IdentityCMap;
  16105. })();
  16106. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  16107. function fetchBinaryData(url) {
  16108. var nonBinaryRequest = PDFJS.disableWorker;
  16109. var request = new XMLHttpRequest();
  16110. request.open('GET', url, false);
  16111. if (!nonBinaryRequest) {
  16112. try {
  16113. request.responseType = 'arraybuffer';
  16114. nonBinaryRequest = request.responseType !== 'arraybuffer';
  16115. } catch (e) {
  16116. nonBinaryRequest = true;
  16117. }
  16118. }
  16119. if (nonBinaryRequest && request.overrideMimeType) {
  16120. request.overrideMimeType('text/plain; charset=x-user-defined');
  16121. }
  16122. request.send(null);
  16123. if (request.status === 0 && /^https?:/i.test(url)) {
  16124. error('Unable to get binary cMap at: ' + url);
  16125. }
  16126. if (nonBinaryRequest) {
  16127. var data = Array.prototype.map.call(request.responseText, function (ch) {
  16128. return ch.charCodeAt(0) & 255;
  16129. });
  16130. return new Uint8Array(data);
  16131. }
  16132. return new Uint8Array(request.response);
  16133. }
  16134. function hexToInt(a, size) {
  16135. var n = 0;
  16136. for (var i = 0; i <= size; i++) {
  16137. n = (n << 8) | a[i];
  16138. }
  16139. return n >>> 0;
  16140. }
  16141. function hexToStr(a, size) {
  16142. // This code is hot. Special-case some common values to avoid creating an
  16143. // object with subarray().
  16144. if (size === 1) {
  16145. return String.fromCharCode(a[0], a[1]);
  16146. }
  16147. if (size === 3) {
  16148. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  16149. }
  16150. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  16151. }
  16152. function addHex(a, b, size) {
  16153. var c = 0;
  16154. for (var i = size; i >= 0; i--) {
  16155. c += a[i] + b[i];
  16156. a[i] = c & 255;
  16157. c >>= 8;
  16158. }
  16159. }
  16160. function incHex(a, size) {
  16161. var c = 1;
  16162. for (var i = size; i >= 0 && c > 0; i--) {
  16163. c += a[i];
  16164. a[i] = c & 255;
  16165. c >>= 8;
  16166. }
  16167. }
  16168. var MAX_NUM_SIZE = 16;
  16169. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  16170. function BinaryCMapStream(data) {
  16171. this.buffer = data;
  16172. this.pos = 0;
  16173. this.end = data.length;
  16174. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  16175. }
  16176. BinaryCMapStream.prototype = {
  16177. readByte: function () {
  16178. if (this.pos >= this.end) {
  16179. return -1;
  16180. }
  16181. return this.buffer[this.pos++];
  16182. },
  16183. readNumber: function () {
  16184. var n = 0;
  16185. var last;
  16186. do {
  16187. var b = this.readByte();
  16188. if (b < 0) {
  16189. error('unexpected EOF in bcmap');
  16190. }
  16191. last = !(b & 0x80);
  16192. n = (n << 7) | (b & 0x7F);
  16193. } while (!last);
  16194. return n;
  16195. },
  16196. readSigned: function () {
  16197. var n = this.readNumber();
  16198. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  16199. },
  16200. readHex: function (num, size) {
  16201. num.set(this.buffer.subarray(this.pos,
  16202. this.pos + size + 1));
  16203. this.pos += size + 1;
  16204. },
  16205. readHexNumber: function (num, size) {
  16206. var last;
  16207. var stack = this.tmpBuf, sp = 0;
  16208. do {
  16209. var b = this.readByte();
  16210. if (b < 0) {
  16211. error('unexpected EOF in bcmap');
  16212. }
  16213. last = !(b & 0x80);
  16214. stack[sp++] = b & 0x7F;
  16215. } while (!last);
  16216. var i = size, buffer = 0, bufferSize = 0;
  16217. while (i >= 0) {
  16218. while (bufferSize < 8 && stack.length > 0) {
  16219. buffer = (stack[--sp] << bufferSize) | buffer;
  16220. bufferSize += 7;
  16221. }
  16222. num[i] = buffer & 255;
  16223. i--;
  16224. buffer >>= 8;
  16225. bufferSize -= 8;
  16226. }
  16227. },
  16228. readHexSigned: function (num, size) {
  16229. this.readHexNumber(num, size);
  16230. var sign = num[size] & 1 ? 255 : 0;
  16231. var c = 0;
  16232. for (var i = 0; i <= size; i++) {
  16233. c = ((c & 1) << 8) | num[i];
  16234. num[i] = (c >> 1) ^ sign;
  16235. }
  16236. },
  16237. readString: function () {
  16238. var len = this.readNumber();
  16239. var s = '';
  16240. for (var i = 0; i < len; i++) {
  16241. s += String.fromCharCode(this.readNumber());
  16242. }
  16243. return s;
  16244. }
  16245. };
  16246. function processBinaryCMap(url, cMap, extend) {
  16247. var data = fetchBinaryData(url);
  16248. var stream = new BinaryCMapStream(data);
  16249. var header = stream.readByte();
  16250. cMap.vertical = !!(header & 1);
  16251. var useCMap = null;
  16252. var start = new Uint8Array(MAX_NUM_SIZE);
  16253. var end = new Uint8Array(MAX_NUM_SIZE);
  16254. var char = new Uint8Array(MAX_NUM_SIZE);
  16255. var charCode = new Uint8Array(MAX_NUM_SIZE);
  16256. var tmp = new Uint8Array(MAX_NUM_SIZE);
  16257. var code;
  16258. var b;
  16259. while ((b = stream.readByte()) >= 0) {
  16260. var type = b >> 5;
  16261. if (type === 7) { // metadata, e.g. comment or usecmap
  16262. switch (b & 0x1F) {
  16263. case 0:
  16264. stream.readString(); // skipping comment
  16265. break;
  16266. case 1:
  16267. useCMap = stream.readString();
  16268. break;
  16269. }
  16270. continue;
  16271. }
  16272. var sequence = !!(b & 0x10);
  16273. var dataSize = b & 15;
  16274. assert(dataSize + 1 <= MAX_NUM_SIZE);
  16275. var ucs2DataSize = 1;
  16276. var subitemsCount = stream.readNumber();
  16277. var i;
  16278. switch (type) {
  16279. case 0: // codespacerange
  16280. stream.readHex(start, dataSize);
  16281. stream.readHexNumber(end, dataSize);
  16282. addHex(end, start, dataSize);
  16283. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16284. hexToInt(end, dataSize));
  16285. for (i = 1; i < subitemsCount; i++) {
  16286. incHex(end, dataSize);
  16287. stream.readHexNumber(start, dataSize);
  16288. addHex(start, end, dataSize);
  16289. stream.readHexNumber(end, dataSize);
  16290. addHex(end, start, dataSize);
  16291. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16292. hexToInt(end, dataSize));
  16293. }
  16294. break;
  16295. case 1: // notdefrange
  16296. stream.readHex(start, dataSize);
  16297. stream.readHexNumber(end, dataSize);
  16298. addHex(end, start, dataSize);
  16299. code = stream.readNumber();
  16300. // undefined range, skipping
  16301. for (i = 1; i < subitemsCount; i++) {
  16302. incHex(end, dataSize);
  16303. stream.readHexNumber(start, dataSize);
  16304. addHex(start, end, dataSize);
  16305. stream.readHexNumber(end, dataSize);
  16306. addHex(end, start, dataSize);
  16307. code = stream.readNumber();
  16308. // nop
  16309. }
  16310. break;
  16311. case 2: // cidchar
  16312. stream.readHex(char, dataSize);
  16313. code = stream.readNumber();
  16314. cMap.mapOne(hexToInt(char, dataSize), code);
  16315. for (i = 1; i < subitemsCount; i++) {
  16316. incHex(char, dataSize);
  16317. if (!sequence) {
  16318. stream.readHexNumber(tmp, dataSize);
  16319. addHex(char, tmp, dataSize);
  16320. }
  16321. code = stream.readSigned() + (code + 1);
  16322. cMap.mapOne(hexToInt(char, dataSize), code);
  16323. }
  16324. break;
  16325. case 3: // cidrange
  16326. stream.readHex(start, dataSize);
  16327. stream.readHexNumber(end, dataSize);
  16328. addHex(end, start, dataSize);
  16329. code = stream.readNumber();
  16330. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16331. code);
  16332. for (i = 1; i < subitemsCount; i++) {
  16333. incHex(end, dataSize);
  16334. if (!sequence) {
  16335. stream.readHexNumber(start, dataSize);
  16336. addHex(start, end, dataSize);
  16337. } else {
  16338. start.set(end);
  16339. }
  16340. stream.readHexNumber(end, dataSize);
  16341. addHex(end, start, dataSize);
  16342. code = stream.readNumber();
  16343. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16344. code);
  16345. }
  16346. break;
  16347. case 4: // bfchar
  16348. stream.readHex(char, ucs2DataSize);
  16349. stream.readHex(charCode, dataSize);
  16350. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16351. hexToStr(charCode, dataSize));
  16352. for (i = 1; i < subitemsCount; i++) {
  16353. incHex(char, ucs2DataSize);
  16354. if (!sequence) {
  16355. stream.readHexNumber(tmp, ucs2DataSize);
  16356. addHex(char, tmp, ucs2DataSize);
  16357. }
  16358. incHex(charCode, dataSize);
  16359. stream.readHexSigned(tmp, dataSize);
  16360. addHex(charCode, tmp, dataSize);
  16361. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16362. hexToStr(charCode, dataSize));
  16363. }
  16364. break;
  16365. case 5: // bfrange
  16366. stream.readHex(start, ucs2DataSize);
  16367. stream.readHexNumber(end, ucs2DataSize);
  16368. addHex(end, start, ucs2DataSize);
  16369. stream.readHex(charCode, dataSize);
  16370. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16371. hexToInt(end, ucs2DataSize),
  16372. hexToStr(charCode, dataSize));
  16373. for (i = 1; i < subitemsCount; i++) {
  16374. incHex(end, ucs2DataSize);
  16375. if (!sequence) {
  16376. stream.readHexNumber(start, ucs2DataSize);
  16377. addHex(start, end, ucs2DataSize);
  16378. } else {
  16379. start.set(end);
  16380. }
  16381. stream.readHexNumber(end, ucs2DataSize);
  16382. addHex(end, start, ucs2DataSize);
  16383. stream.readHex(charCode, dataSize);
  16384. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16385. hexToInt(end, ucs2DataSize),
  16386. hexToStr(charCode, dataSize));
  16387. }
  16388. break;
  16389. default:
  16390. error('Unknown type: ' + type);
  16391. break;
  16392. }
  16393. }
  16394. if (useCMap) {
  16395. extend(useCMap);
  16396. }
  16397. return cMap;
  16398. }
  16399. function BinaryCMapReader() {}
  16400. BinaryCMapReader.prototype = {
  16401. read: processBinaryCMap
  16402. };
  16403. return BinaryCMapReader;
  16404. })();
  16405. var CMapFactory = (function CMapFactoryClosure() {
  16406. function strToInt(str) {
  16407. var a = 0;
  16408. for (var i = 0; i < str.length; i++) {
  16409. a = (a << 8) | str.charCodeAt(i);
  16410. }
  16411. return a >>> 0;
  16412. }
  16413. function expectString(obj) {
  16414. if (!isString(obj)) {
  16415. error('Malformed CMap: expected string.');
  16416. }
  16417. }
  16418. function expectInt(obj) {
  16419. if (!isInt(obj)) {
  16420. error('Malformed CMap: expected int.');
  16421. }
  16422. }
  16423. function parseBfChar(cMap, lexer) {
  16424. while (true) {
  16425. var obj = lexer.getObj();
  16426. if (isEOF(obj)) {
  16427. break;
  16428. }
  16429. if (isCmd(obj, 'endbfchar')) {
  16430. return;
  16431. }
  16432. expectString(obj);
  16433. var src = strToInt(obj);
  16434. obj = lexer.getObj();
  16435. // TODO are /dstName used?
  16436. expectString(obj);
  16437. var dst = obj;
  16438. cMap.mapOne(src, dst);
  16439. }
  16440. }
  16441. function parseBfRange(cMap, lexer) {
  16442. while (true) {
  16443. var obj = lexer.getObj();
  16444. if (isEOF(obj)) {
  16445. break;
  16446. }
  16447. if (isCmd(obj, 'endbfrange')) {
  16448. return;
  16449. }
  16450. expectString(obj);
  16451. var low = strToInt(obj);
  16452. obj = lexer.getObj();
  16453. expectString(obj);
  16454. var high = strToInt(obj);
  16455. obj = lexer.getObj();
  16456. if (isInt(obj) || isString(obj)) {
  16457. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  16458. cMap.mapBfRange(low, high, dstLow);
  16459. } else if (isCmd(obj, '[')) {
  16460. obj = lexer.getObj();
  16461. var array = [];
  16462. while (!isCmd(obj, ']') && !isEOF(obj)) {
  16463. array.push(obj);
  16464. obj = lexer.getObj();
  16465. }
  16466. cMap.mapBfRangeToArray(low, high, array);
  16467. } else {
  16468. break;
  16469. }
  16470. }
  16471. error('Invalid bf range.');
  16472. }
  16473. function parseCidChar(cMap, lexer) {
  16474. while (true) {
  16475. var obj = lexer.getObj();
  16476. if (isEOF(obj)) {
  16477. break;
  16478. }
  16479. if (isCmd(obj, 'endcidchar')) {
  16480. return;
  16481. }
  16482. expectString(obj);
  16483. var src = strToInt(obj);
  16484. obj = lexer.getObj();
  16485. expectInt(obj);
  16486. var dst = obj;
  16487. cMap.mapOne(src, dst);
  16488. }
  16489. }
  16490. function parseCidRange(cMap, lexer) {
  16491. while (true) {
  16492. var obj = lexer.getObj();
  16493. if (isEOF(obj)) {
  16494. break;
  16495. }
  16496. if (isCmd(obj, 'endcidrange')) {
  16497. return;
  16498. }
  16499. expectString(obj);
  16500. var low = strToInt(obj);
  16501. obj = lexer.getObj();
  16502. expectString(obj);
  16503. var high = strToInt(obj);
  16504. obj = lexer.getObj();
  16505. expectInt(obj);
  16506. var dstLow = obj;
  16507. cMap.mapCidRange(low, high, dstLow);
  16508. }
  16509. }
  16510. function parseCodespaceRange(cMap, lexer) {
  16511. while (true) {
  16512. var obj = lexer.getObj();
  16513. if (isEOF(obj)) {
  16514. break;
  16515. }
  16516. if (isCmd(obj, 'endcodespacerange')) {
  16517. return;
  16518. }
  16519. if (!isString(obj)) {
  16520. break;
  16521. }
  16522. var low = strToInt(obj);
  16523. obj = lexer.getObj();
  16524. if (!isString(obj)) {
  16525. break;
  16526. }
  16527. var high = strToInt(obj);
  16528. cMap.addCodespaceRange(obj.length, low, high);
  16529. }
  16530. error('Invalid codespace range.');
  16531. }
  16532. function parseWMode(cMap, lexer) {
  16533. var obj = lexer.getObj();
  16534. if (isInt(obj)) {
  16535. cMap.vertical = !!obj;
  16536. }
  16537. }
  16538. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  16539. var previous;
  16540. var embededUseCMap;
  16541. objLoop: while (true) {
  16542. var obj = lexer.getObj();
  16543. if (isEOF(obj)) {
  16544. break;
  16545. } else if (isName(obj)) {
  16546. if (obj.name === 'WMode') {
  16547. parseWMode(cMap, lexer);
  16548. }
  16549. previous = obj;
  16550. } else if (isCmd(obj)) {
  16551. switch (obj.cmd) {
  16552. case 'endcmap':
  16553. break objLoop;
  16554. case 'usecmap':
  16555. if (isName(previous)) {
  16556. embededUseCMap = previous.name;
  16557. }
  16558. break;
  16559. case 'begincodespacerange':
  16560. parseCodespaceRange(cMap, lexer);
  16561. break;
  16562. case 'beginbfchar':
  16563. parseBfChar(cMap, lexer);
  16564. break;
  16565. case 'begincidchar':
  16566. parseCidChar(cMap, lexer);
  16567. break;
  16568. case 'beginbfrange':
  16569. parseBfRange(cMap, lexer);
  16570. break;
  16571. case 'begincidrange':
  16572. parseCidRange(cMap, lexer);
  16573. break;
  16574. }
  16575. }
  16576. }
  16577. if (!useCMap && embededUseCMap) {
  16578. // Load the usecmap definition from the file only if there wasn't one
  16579. // specified.
  16580. useCMap = embededUseCMap;
  16581. }
  16582. if (useCMap) {
  16583. extendCMap(cMap, builtInCMapParams, useCMap);
  16584. }
  16585. }
  16586. function extendCMap(cMap, builtInCMapParams, useCMap) {
  16587. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  16588. // If there aren't any code space ranges defined clone all the parent ones
  16589. // into this cMap.
  16590. if (cMap.numCodespaceRanges === 0) {
  16591. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  16592. for (var i = 0; i < useCodespaceRanges.length; i++) {
  16593. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  16594. }
  16595. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  16596. }
  16597. // Merge the map into the current one, making sure not to override
  16598. // any previously defined entries.
  16599. cMap.useCMap.forEach(function(key, value) {
  16600. if (!cMap.contains(key)) {
  16601. cMap.mapOne(key, cMap.useCMap.lookup(key));
  16602. }
  16603. });
  16604. }
  16605. function parseBinaryCMap(name, builtInCMapParams) {
  16606. var url = builtInCMapParams.url + name + '.bcmap';
  16607. var cMap = new CMap(true);
  16608. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  16609. extendCMap(cMap, builtInCMapParams, useCMap);
  16610. });
  16611. return cMap;
  16612. }
  16613. function createBuiltInCMap(name, builtInCMapParams) {
  16614. if (name === 'Identity-H') {
  16615. return new IdentityCMap(false, 2);
  16616. } else if (name === 'Identity-V') {
  16617. return new IdentityCMap(true, 2);
  16618. }
  16619. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  16620. error('Unknown cMap name: ' + name);
  16621. }
  16622. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  16623. if (builtInCMapParams.packed) {
  16624. return parseBinaryCMap(name, builtInCMapParams);
  16625. }
  16626. var request = new XMLHttpRequest();
  16627. var url = builtInCMapParams.url + name;
  16628. request.open('GET', url, false);
  16629. request.send(null);
  16630. if (request.status === 0 && /^https?:/i.test(url)) {
  16631. error('Unable to get cMap at: ' + url);
  16632. }
  16633. var cMap = new CMap(true);
  16634. var lexer = new Lexer(new StringStream(request.responseText));
  16635. parseCMap(cMap, lexer, builtInCMapParams, null);
  16636. return cMap;
  16637. }
  16638. return {
  16639. create: function (encoding, builtInCMapParams, useCMap) {
  16640. if (isName(encoding)) {
  16641. return createBuiltInCMap(encoding.name, builtInCMapParams);
  16642. } else if (isStream(encoding)) {
  16643. var cMap = new CMap();
  16644. var lexer = new Lexer(encoding);
  16645. try {
  16646. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  16647. } catch (e) {
  16648. warn('Invalid CMap data. ' + e);
  16649. }
  16650. return cMap;
  16651. }
  16652. error('Encoding required.');
  16653. }
  16654. };
  16655. })();
  16656. // Unicode Private Use Area
  16657. var PRIVATE_USE_OFFSET_START = 0xE000;
  16658. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  16659. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  16660. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  16661. // except for Type 3 fonts
  16662. var PDF_GLYPH_SPACE_UNITS = 1000;
  16663. // Hinting is currently disabled due to unknown problems on windows
  16664. // in tracemonkey and various other pdfs with type1 fonts.
  16665. var HINTING_ENABLED = false;
  16666. // Accented charactars are not displayed properly on windows, using this flag
  16667. // to control analysis of seac charstrings.
  16668. var SEAC_ANALYSIS_ENABLED = false;
  16669. var FontFlags = {
  16670. FixedPitch: 1,
  16671. Serif: 2,
  16672. Symbolic: 4,
  16673. Script: 8,
  16674. Nonsymbolic: 32,
  16675. Italic: 64,
  16676. AllCap: 65536,
  16677. SmallCap: 131072,
  16678. ForceBold: 262144
  16679. };
  16680. var Encodings = {
  16681. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16683. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  16684. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  16685. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  16686. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  16687. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  16688. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  16689. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  16690. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  16691. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  16692. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  16693. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  16694. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  16695. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  16696. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  16697. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  16698. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  16699. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  16700. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16701. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  16702. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  16703. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  16704. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  16705. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  16706. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  16707. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  16708. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  16709. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  16710. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  16711. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  16712. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  16713. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  16714. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  16715. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  16716. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  16717. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  16718. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  16719. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  16720. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  16721. 'Ydieresissmall'],
  16722. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16723. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16724. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  16725. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  16726. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  16727. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  16728. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  16729. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  16730. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  16731. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  16732. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  16733. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  16734. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  16735. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  16736. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  16737. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  16738. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  16739. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  16740. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  16741. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  16742. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  16743. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  16744. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  16745. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  16746. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  16747. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  16748. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  16749. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  16750. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  16751. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  16752. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  16753. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  16754. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  16755. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  16756. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  16757. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  16758. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  16759. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  16760. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  16761. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  16762. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16763. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16764. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16765. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16766. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16767. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16768. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16769. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16770. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16771. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16772. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16773. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  16774. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  16775. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  16776. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  16777. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  16778. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  16779. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  16780. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  16781. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  16782. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  16783. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  16784. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  16785. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  16786. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  16787. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  16788. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  16789. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  16790. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  16791. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  16792. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  16793. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  16794. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  16795. 'ogonek', 'caron'],
  16796. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16797. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16798. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16799. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  16800. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16801. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16802. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16803. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16804. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16805. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  16806. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  16807. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16808. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16809. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  16810. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  16811. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  16812. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  16813. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  16814. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  16815. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  16816. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  16817. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  16818. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  16819. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  16820. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  16821. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16822. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16823. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16824. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16825. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16826. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16827. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16828. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16829. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16830. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16831. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16832. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16833. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  16834. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  16835. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  16836. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  16837. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  16838. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  16839. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  16840. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  16841. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  16842. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  16843. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  16844. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  16845. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  16846. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  16847. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  16848. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  16849. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  16850. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  16851. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  16852. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  16853. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  16854. 'ydieresis'],
  16855. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16856. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16857. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  16858. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  16859. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  16860. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  16861. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  16862. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  16863. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  16864. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  16865. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  16866. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  16867. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  16868. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  16869. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  16870. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16871. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  16872. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  16873. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  16874. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  16875. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  16876. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  16877. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  16878. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  16879. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  16880. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  16881. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  16882. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  16883. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  16884. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  16885. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  16886. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  16887. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  16888. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  16889. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  16890. 'bracerightbt'],
  16891. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16892. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16893. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  16894. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  16895. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  16896. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  16897. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  16898. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  16899. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  16900. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  16901. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  16902. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16903. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16904. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  16905. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  16906. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  16907. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  16908. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  16909. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  16910. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  16911. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  16912. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  16913. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  16914. 'a188', 'a189', 'a190', 'a191']
  16915. };
  16916. /**
  16917. * Hold a map of decoded fonts and of the standard fourteen Type1
  16918. * fonts and their acronyms.
  16919. */
  16920. var stdFontMap = {
  16921. 'ArialNarrow': 'Helvetica',
  16922. 'ArialNarrow-Bold': 'Helvetica-Bold',
  16923. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  16924. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  16925. 'ArialBlack': 'Helvetica',
  16926. 'ArialBlack-Bold': 'Helvetica-Bold',
  16927. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  16928. 'ArialBlack-Italic': 'Helvetica-Oblique',
  16929. 'Arial': 'Helvetica',
  16930. 'Arial-Bold': 'Helvetica-Bold',
  16931. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  16932. 'Arial-Italic': 'Helvetica-Oblique',
  16933. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  16934. 'Arial-BoldMT': 'Helvetica-Bold',
  16935. 'Arial-ItalicMT': 'Helvetica-Oblique',
  16936. 'ArialMT': 'Helvetica',
  16937. 'Courier-Bold': 'Courier-Bold',
  16938. 'Courier-BoldItalic': 'Courier-BoldOblique',
  16939. 'Courier-Italic': 'Courier-Oblique',
  16940. 'CourierNew': 'Courier',
  16941. 'CourierNew-Bold': 'Courier-Bold',
  16942. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  16943. 'CourierNew-Italic': 'Courier-Oblique',
  16944. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  16945. 'CourierNewPS-BoldMT': 'Courier-Bold',
  16946. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  16947. 'CourierNewPSMT': 'Courier',
  16948. 'Helvetica-Bold': 'Helvetica-Bold',
  16949. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  16950. 'Helvetica-Italic': 'Helvetica-Oblique',
  16951. 'Symbol-Bold': 'Symbol',
  16952. 'Symbol-BoldItalic': 'Symbol',
  16953. 'Symbol-Italic': 'Symbol',
  16954. 'TimesNewRoman': 'Times-Roman',
  16955. 'TimesNewRoman-Bold': 'Times-Bold',
  16956. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  16957. 'TimesNewRoman-Italic': 'Times-Italic',
  16958. 'TimesNewRomanPS': 'Times-Roman',
  16959. 'TimesNewRomanPS-Bold': 'Times-Bold',
  16960. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  16961. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  16962. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  16963. 'TimesNewRomanPS-Italic': 'Times-Italic',
  16964. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  16965. 'TimesNewRomanPSMT': 'Times-Roman',
  16966. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  16967. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  16968. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  16969. };
  16970. /**
  16971. * Holds the map of the non-standard fonts that might be included as a standard
  16972. * fonts without glyph data.
  16973. */
  16974. var nonStdFontMap = {
  16975. 'ComicSansMS': 'Comic Sans MS',
  16976. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  16977. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  16978. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  16979. 'LucidaConsole': 'Courier',
  16980. 'LucidaConsole-Bold': 'Courier-Bold',
  16981. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  16982. 'LucidaConsole-Italic': 'Courier-Oblique',
  16983. 'MS-Gothic': 'MS Gothic',
  16984. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  16985. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  16986. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  16987. 'MS-Mincho': 'MS Mincho',
  16988. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  16989. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  16990. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  16991. 'MS-PGothic': 'MS PGothic',
  16992. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  16993. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  16994. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  16995. 'MS-PMincho': 'MS PMincho',
  16996. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  16997. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  16998. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  16999. };
  17000. var serifFonts = {
  17001. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  17002. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  17003. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  17004. 'Arno': true, 'Aster': true, 'Aurora': true,
  17005. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  17006. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  17007. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  17008. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  17009. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  17010. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  17011. 'Cartier': true, 'Caslon': true, 'Catull': true,
  17012. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  17013. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  17014. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  17015. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  17016. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  17017. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  17018. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  17019. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  17020. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  17021. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  17022. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  17023. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  17024. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  17025. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  17026. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  17027. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  17028. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  17029. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  17030. 'Miller': true, 'Minion': true, 'Modern': true,
  17031. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  17032. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  17033. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  17034. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  17035. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  17036. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  17037. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  17038. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  17039. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  17040. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  17041. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  17042. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  17043. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  17044. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  17045. };
  17046. var symbolsFonts = {
  17047. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  17048. };
  17049. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  17050. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  17051. // glyphs, but common for some set of the standard fonts.
  17052. var GlyphMapForStandardFonts = {
  17053. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  17054. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  17055. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  17056. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  17057. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  17058. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  17059. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  17060. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  17061. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  17062. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  17063. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  17064. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  17065. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  17066. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  17067. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  17068. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  17069. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  17070. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  17071. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  17072. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  17073. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  17074. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  17075. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  17076. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  17077. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  17078. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  17079. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  17080. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  17081. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  17082. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  17083. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  17084. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  17085. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  17086. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  17087. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  17088. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  17089. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  17090. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  17091. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  17092. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  17093. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  17094. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  17095. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  17096. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  17097. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  17098. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  17099. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  17100. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  17101. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  17102. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  17103. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  17104. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  17105. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  17106. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  17107. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  17108. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  17109. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  17110. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  17111. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  17112. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  17113. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  17114. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  17115. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  17116. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  17117. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  17118. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  17119. };
  17120. // Some characters, e.g. copyrightserif, mapped to the private use area and
  17121. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  17122. // to the similar equivalents in the normal characters range.
  17123. function mapSpecialUnicodeValues(code) {
  17124. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17125. return 0;
  17126. }
  17127. switch (code) {
  17128. case 0xF8E9: // copyrightsans
  17129. case 0xF6D9: // copyrightserif
  17130. return 0x00A9; // copyright
  17131. case 0xF8E8: // registersans
  17132. case 0xF6DA: // registerserif
  17133. return 0x00AE; // registered
  17134. case 0xF8EA: // trademarksans
  17135. case 0xF6DB: // trademarkserif
  17136. return 0x2122; // trademark
  17137. default:
  17138. return code;
  17139. }
  17140. }
  17141. var UnicodeRanges = [
  17142. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17143. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17144. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17145. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17146. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17147. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17148. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17149. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17150. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17151. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17152. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17153. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17154. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17155. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17156. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17157. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17158. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17159. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17160. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17161. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17162. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17163. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17164. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17165. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17166. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17167. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17168. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17169. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17170. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17171. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17172. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17173. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17174. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17175. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17176. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  17177. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17178. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17179. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17180. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17181. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17182. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17183. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17184. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17185. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17186. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17187. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17188. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17189. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17190. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17191. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17192. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17193. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17194. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17195. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17196. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17197. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17198. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17199. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17200. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17201. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17202. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17203. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17204. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17205. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17206. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17207. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17208. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17209. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17210. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17211. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17212. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17213. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17214. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17215. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17216. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17217. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17218. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17219. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17220. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17221. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17222. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17223. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17224. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17225. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17226. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17227. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17228. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17229. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17230. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17231. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17232. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17233. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17234. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17235. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17236. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17237. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17238. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17239. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17240. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17241. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17242. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17243. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17244. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17245. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17246. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17247. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17248. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17249. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17250. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17251. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17252. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17253. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17254. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17255. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17256. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17257. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17258. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17259. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17260. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17261. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17262. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17263. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17264. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17265. ];
  17266. var MacStandardGlyphOrdering = [
  17267. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  17268. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  17269. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  17270. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  17271. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  17272. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  17273. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  17274. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  17275. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  17276. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  17277. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  17278. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  17279. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  17280. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  17281. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  17282. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  17283. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  17284. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  17285. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  17286. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  17287. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  17288. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  17289. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  17290. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  17291. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  17292. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  17293. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  17294. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  17295. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  17296. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  17297. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  17298. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  17299. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  17300. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  17301. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  17302. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  17303. function getUnicodeRangeFor(value) {
  17304. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17305. var range = UnicodeRanges[i];
  17306. if (value >= range.begin && value < range.end) {
  17307. return i;
  17308. }
  17309. }
  17310. return -1;
  17311. }
  17312. function isRTLRangeFor(value) {
  17313. var range = UnicodeRanges[13];
  17314. if (value >= range.begin && value < range.end) {
  17315. return true;
  17316. }
  17317. range = UnicodeRanges[11];
  17318. if (value >= range.begin && value < range.end) {
  17319. return true;
  17320. }
  17321. return false;
  17322. }
  17323. // The normalization table is obtained by filtering the Unicode characters
  17324. // database with <compat> entries.
  17325. var NormalizedUnicodes = {
  17326. '\u00A8': '\u0020\u0308',
  17327. '\u00AF': '\u0020\u0304',
  17328. '\u00B4': '\u0020\u0301',
  17329. '\u00B5': '\u03BC',
  17330. '\u00B8': '\u0020\u0327',
  17331. '\u0132': '\u0049\u004A',
  17332. '\u0133': '\u0069\u006A',
  17333. '\u013F': '\u004C\u00B7',
  17334. '\u0140': '\u006C\u00B7',
  17335. '\u0149': '\u02BC\u006E',
  17336. '\u017F': '\u0073',
  17337. '\u01C4': '\u0044\u017D',
  17338. '\u01C5': '\u0044\u017E',
  17339. '\u01C6': '\u0064\u017E',
  17340. '\u01C7': '\u004C\u004A',
  17341. '\u01C8': '\u004C\u006A',
  17342. '\u01C9': '\u006C\u006A',
  17343. '\u01CA': '\u004E\u004A',
  17344. '\u01CB': '\u004E\u006A',
  17345. '\u01CC': '\u006E\u006A',
  17346. '\u01F1': '\u0044\u005A',
  17347. '\u01F2': '\u0044\u007A',
  17348. '\u01F3': '\u0064\u007A',
  17349. '\u02D8': '\u0020\u0306',
  17350. '\u02D9': '\u0020\u0307',
  17351. '\u02DA': '\u0020\u030A',
  17352. '\u02DB': '\u0020\u0328',
  17353. '\u02DC': '\u0020\u0303',
  17354. '\u02DD': '\u0020\u030B',
  17355. '\u037A': '\u0020\u0345',
  17356. '\u0384': '\u0020\u0301',
  17357. '\u03D0': '\u03B2',
  17358. '\u03D1': '\u03B8',
  17359. '\u03D2': '\u03A5',
  17360. '\u03D5': '\u03C6',
  17361. '\u03D6': '\u03C0',
  17362. '\u03F0': '\u03BA',
  17363. '\u03F1': '\u03C1',
  17364. '\u03F2': '\u03C2',
  17365. '\u03F4': '\u0398',
  17366. '\u03F5': '\u03B5',
  17367. '\u03F9': '\u03A3',
  17368. '\u0587': '\u0565\u0582',
  17369. '\u0675': '\u0627\u0674',
  17370. '\u0676': '\u0648\u0674',
  17371. '\u0677': '\u06C7\u0674',
  17372. '\u0678': '\u064A\u0674',
  17373. '\u0E33': '\u0E4D\u0E32',
  17374. '\u0EB3': '\u0ECD\u0EB2',
  17375. '\u0EDC': '\u0EAB\u0E99',
  17376. '\u0EDD': '\u0EAB\u0EA1',
  17377. '\u0F77': '\u0FB2\u0F81',
  17378. '\u0F79': '\u0FB3\u0F81',
  17379. '\u1E9A': '\u0061\u02BE',
  17380. '\u1FBD': '\u0020\u0313',
  17381. '\u1FBF': '\u0020\u0313',
  17382. '\u1FC0': '\u0020\u0342',
  17383. '\u1FFE': '\u0020\u0314',
  17384. '\u2002': '\u0020',
  17385. '\u2003': '\u0020',
  17386. '\u2004': '\u0020',
  17387. '\u2005': '\u0020',
  17388. '\u2006': '\u0020',
  17389. '\u2008': '\u0020',
  17390. '\u2009': '\u0020',
  17391. '\u200A': '\u0020',
  17392. '\u2017': '\u0020\u0333',
  17393. '\u2024': '\u002E',
  17394. '\u2025': '\u002E\u002E',
  17395. '\u2026': '\u002E\u002E\u002E',
  17396. '\u2033': '\u2032\u2032',
  17397. '\u2034': '\u2032\u2032\u2032',
  17398. '\u2036': '\u2035\u2035',
  17399. '\u2037': '\u2035\u2035\u2035',
  17400. '\u203C': '\u0021\u0021',
  17401. '\u203E': '\u0020\u0305',
  17402. '\u2047': '\u003F\u003F',
  17403. '\u2048': '\u003F\u0021',
  17404. '\u2049': '\u0021\u003F',
  17405. '\u2057': '\u2032\u2032\u2032\u2032',
  17406. '\u205F': '\u0020',
  17407. '\u20A8': '\u0052\u0073',
  17408. '\u2100': '\u0061\u002F\u0063',
  17409. '\u2101': '\u0061\u002F\u0073',
  17410. '\u2103': '\u00B0\u0043',
  17411. '\u2105': '\u0063\u002F\u006F',
  17412. '\u2106': '\u0063\u002F\u0075',
  17413. '\u2107': '\u0190',
  17414. '\u2109': '\u00B0\u0046',
  17415. '\u2116': '\u004E\u006F',
  17416. '\u2121': '\u0054\u0045\u004C',
  17417. '\u2135': '\u05D0',
  17418. '\u2136': '\u05D1',
  17419. '\u2137': '\u05D2',
  17420. '\u2138': '\u05D3',
  17421. '\u213B': '\u0046\u0041\u0058',
  17422. '\u2160': '\u0049',
  17423. '\u2161': '\u0049\u0049',
  17424. '\u2162': '\u0049\u0049\u0049',
  17425. '\u2163': '\u0049\u0056',
  17426. '\u2164': '\u0056',
  17427. '\u2165': '\u0056\u0049',
  17428. '\u2166': '\u0056\u0049\u0049',
  17429. '\u2167': '\u0056\u0049\u0049\u0049',
  17430. '\u2168': '\u0049\u0058',
  17431. '\u2169': '\u0058',
  17432. '\u216A': '\u0058\u0049',
  17433. '\u216B': '\u0058\u0049\u0049',
  17434. '\u216C': '\u004C',
  17435. '\u216D': '\u0043',
  17436. '\u216E': '\u0044',
  17437. '\u216F': '\u004D',
  17438. '\u2170': '\u0069',
  17439. '\u2171': '\u0069\u0069',
  17440. '\u2172': '\u0069\u0069\u0069',
  17441. '\u2173': '\u0069\u0076',
  17442. '\u2174': '\u0076',
  17443. '\u2175': '\u0076\u0069',
  17444. '\u2176': '\u0076\u0069\u0069',
  17445. '\u2177': '\u0076\u0069\u0069\u0069',
  17446. '\u2178': '\u0069\u0078',
  17447. '\u2179': '\u0078',
  17448. '\u217A': '\u0078\u0069',
  17449. '\u217B': '\u0078\u0069\u0069',
  17450. '\u217C': '\u006C',
  17451. '\u217D': '\u0063',
  17452. '\u217E': '\u0064',
  17453. '\u217F': '\u006D',
  17454. '\u222C': '\u222B\u222B',
  17455. '\u222D': '\u222B\u222B\u222B',
  17456. '\u222F': '\u222E\u222E',
  17457. '\u2230': '\u222E\u222E\u222E',
  17458. '\u2474': '\u0028\u0031\u0029',
  17459. '\u2475': '\u0028\u0032\u0029',
  17460. '\u2476': '\u0028\u0033\u0029',
  17461. '\u2477': '\u0028\u0034\u0029',
  17462. '\u2478': '\u0028\u0035\u0029',
  17463. '\u2479': '\u0028\u0036\u0029',
  17464. '\u247A': '\u0028\u0037\u0029',
  17465. '\u247B': '\u0028\u0038\u0029',
  17466. '\u247C': '\u0028\u0039\u0029',
  17467. '\u247D': '\u0028\u0031\u0030\u0029',
  17468. '\u247E': '\u0028\u0031\u0031\u0029',
  17469. '\u247F': '\u0028\u0031\u0032\u0029',
  17470. '\u2480': '\u0028\u0031\u0033\u0029',
  17471. '\u2481': '\u0028\u0031\u0034\u0029',
  17472. '\u2482': '\u0028\u0031\u0035\u0029',
  17473. '\u2483': '\u0028\u0031\u0036\u0029',
  17474. '\u2484': '\u0028\u0031\u0037\u0029',
  17475. '\u2485': '\u0028\u0031\u0038\u0029',
  17476. '\u2486': '\u0028\u0031\u0039\u0029',
  17477. '\u2487': '\u0028\u0032\u0030\u0029',
  17478. '\u2488': '\u0031\u002E',
  17479. '\u2489': '\u0032\u002E',
  17480. '\u248A': '\u0033\u002E',
  17481. '\u248B': '\u0034\u002E',
  17482. '\u248C': '\u0035\u002E',
  17483. '\u248D': '\u0036\u002E',
  17484. '\u248E': '\u0037\u002E',
  17485. '\u248F': '\u0038\u002E',
  17486. '\u2490': '\u0039\u002E',
  17487. '\u2491': '\u0031\u0030\u002E',
  17488. '\u2492': '\u0031\u0031\u002E',
  17489. '\u2493': '\u0031\u0032\u002E',
  17490. '\u2494': '\u0031\u0033\u002E',
  17491. '\u2495': '\u0031\u0034\u002E',
  17492. '\u2496': '\u0031\u0035\u002E',
  17493. '\u2497': '\u0031\u0036\u002E',
  17494. '\u2498': '\u0031\u0037\u002E',
  17495. '\u2499': '\u0031\u0038\u002E',
  17496. '\u249A': '\u0031\u0039\u002E',
  17497. '\u249B': '\u0032\u0030\u002E',
  17498. '\u249C': '\u0028\u0061\u0029',
  17499. '\u249D': '\u0028\u0062\u0029',
  17500. '\u249E': '\u0028\u0063\u0029',
  17501. '\u249F': '\u0028\u0064\u0029',
  17502. '\u24A0': '\u0028\u0065\u0029',
  17503. '\u24A1': '\u0028\u0066\u0029',
  17504. '\u24A2': '\u0028\u0067\u0029',
  17505. '\u24A3': '\u0028\u0068\u0029',
  17506. '\u24A4': '\u0028\u0069\u0029',
  17507. '\u24A5': '\u0028\u006A\u0029',
  17508. '\u24A6': '\u0028\u006B\u0029',
  17509. '\u24A7': '\u0028\u006C\u0029',
  17510. '\u24A8': '\u0028\u006D\u0029',
  17511. '\u24A9': '\u0028\u006E\u0029',
  17512. '\u24AA': '\u0028\u006F\u0029',
  17513. '\u24AB': '\u0028\u0070\u0029',
  17514. '\u24AC': '\u0028\u0071\u0029',
  17515. '\u24AD': '\u0028\u0072\u0029',
  17516. '\u24AE': '\u0028\u0073\u0029',
  17517. '\u24AF': '\u0028\u0074\u0029',
  17518. '\u24B0': '\u0028\u0075\u0029',
  17519. '\u24B1': '\u0028\u0076\u0029',
  17520. '\u24B2': '\u0028\u0077\u0029',
  17521. '\u24B3': '\u0028\u0078\u0029',
  17522. '\u24B4': '\u0028\u0079\u0029',
  17523. '\u24B5': '\u0028\u007A\u0029',
  17524. '\u2A0C': '\u222B\u222B\u222B\u222B',
  17525. '\u2A74': '\u003A\u003A\u003D',
  17526. '\u2A75': '\u003D\u003D',
  17527. '\u2A76': '\u003D\u003D\u003D',
  17528. '\u2E9F': '\u6BCD',
  17529. '\u2EF3': '\u9F9F',
  17530. '\u2F00': '\u4E00',
  17531. '\u2F01': '\u4E28',
  17532. '\u2F02': '\u4E36',
  17533. '\u2F03': '\u4E3F',
  17534. '\u2F04': '\u4E59',
  17535. '\u2F05': '\u4E85',
  17536. '\u2F06': '\u4E8C',
  17537. '\u2F07': '\u4EA0',
  17538. '\u2F08': '\u4EBA',
  17539. '\u2F09': '\u513F',
  17540. '\u2F0A': '\u5165',
  17541. '\u2F0B': '\u516B',
  17542. '\u2F0C': '\u5182',
  17543. '\u2F0D': '\u5196',
  17544. '\u2F0E': '\u51AB',
  17545. '\u2F0F': '\u51E0',
  17546. '\u2F10': '\u51F5',
  17547. '\u2F11': '\u5200',
  17548. '\u2F12': '\u529B',
  17549. '\u2F13': '\u52F9',
  17550. '\u2F14': '\u5315',
  17551. '\u2F15': '\u531A',
  17552. '\u2F16': '\u5338',
  17553. '\u2F17': '\u5341',
  17554. '\u2F18': '\u535C',
  17555. '\u2F19': '\u5369',
  17556. '\u2F1A': '\u5382',
  17557. '\u2F1B': '\u53B6',
  17558. '\u2F1C': '\u53C8',
  17559. '\u2F1D': '\u53E3',
  17560. '\u2F1E': '\u56D7',
  17561. '\u2F1F': '\u571F',
  17562. '\u2F20': '\u58EB',
  17563. '\u2F21': '\u5902',
  17564. '\u2F22': '\u590A',
  17565. '\u2F23': '\u5915',
  17566. '\u2F24': '\u5927',
  17567. '\u2F25': '\u5973',
  17568. '\u2F26': '\u5B50',
  17569. '\u2F27': '\u5B80',
  17570. '\u2F28': '\u5BF8',
  17571. '\u2F29': '\u5C0F',
  17572. '\u2F2A': '\u5C22',
  17573. '\u2F2B': '\u5C38',
  17574. '\u2F2C': '\u5C6E',
  17575. '\u2F2D': '\u5C71',
  17576. '\u2F2E': '\u5DDB',
  17577. '\u2F2F': '\u5DE5',
  17578. '\u2F30': '\u5DF1',
  17579. '\u2F31': '\u5DFE',
  17580. '\u2F32': '\u5E72',
  17581. '\u2F33': '\u5E7A',
  17582. '\u2F34': '\u5E7F',
  17583. '\u2F35': '\u5EF4',
  17584. '\u2F36': '\u5EFE',
  17585. '\u2F37': '\u5F0B',
  17586. '\u2F38': '\u5F13',
  17587. '\u2F39': '\u5F50',
  17588. '\u2F3A': '\u5F61',
  17589. '\u2F3B': '\u5F73',
  17590. '\u2F3C': '\u5FC3',
  17591. '\u2F3D': '\u6208',
  17592. '\u2F3E': '\u6236',
  17593. '\u2F3F': '\u624B',
  17594. '\u2F40': '\u652F',
  17595. '\u2F41': '\u6534',
  17596. '\u2F42': '\u6587',
  17597. '\u2F43': '\u6597',
  17598. '\u2F44': '\u65A4',
  17599. '\u2F45': '\u65B9',
  17600. '\u2F46': '\u65E0',
  17601. '\u2F47': '\u65E5',
  17602. '\u2F48': '\u66F0',
  17603. '\u2F49': '\u6708',
  17604. '\u2F4A': '\u6728',
  17605. '\u2F4B': '\u6B20',
  17606. '\u2F4C': '\u6B62',
  17607. '\u2F4D': '\u6B79',
  17608. '\u2F4E': '\u6BB3',
  17609. '\u2F4F': '\u6BCB',
  17610. '\u2F50': '\u6BD4',
  17611. '\u2F51': '\u6BDB',
  17612. '\u2F52': '\u6C0F',
  17613. '\u2F53': '\u6C14',
  17614. '\u2F54': '\u6C34',
  17615. '\u2F55': '\u706B',
  17616. '\u2F56': '\u722A',
  17617. '\u2F57': '\u7236',
  17618. '\u2F58': '\u723B',
  17619. '\u2F59': '\u723F',
  17620. '\u2F5A': '\u7247',
  17621. '\u2F5B': '\u7259',
  17622. '\u2F5C': '\u725B',
  17623. '\u2F5D': '\u72AC',
  17624. '\u2F5E': '\u7384',
  17625. '\u2F5F': '\u7389',
  17626. '\u2F60': '\u74DC',
  17627. '\u2F61': '\u74E6',
  17628. '\u2F62': '\u7518',
  17629. '\u2F63': '\u751F',
  17630. '\u2F64': '\u7528',
  17631. '\u2F65': '\u7530',
  17632. '\u2F66': '\u758B',
  17633. '\u2F67': '\u7592',
  17634. '\u2F68': '\u7676',
  17635. '\u2F69': '\u767D',
  17636. '\u2F6A': '\u76AE',
  17637. '\u2F6B': '\u76BF',
  17638. '\u2F6C': '\u76EE',
  17639. '\u2F6D': '\u77DB',
  17640. '\u2F6E': '\u77E2',
  17641. '\u2F6F': '\u77F3',
  17642. '\u2F70': '\u793A',
  17643. '\u2F71': '\u79B8',
  17644. '\u2F72': '\u79BE',
  17645. '\u2F73': '\u7A74',
  17646. '\u2F74': '\u7ACB',
  17647. '\u2F75': '\u7AF9',
  17648. '\u2F76': '\u7C73',
  17649. '\u2F77': '\u7CF8',
  17650. '\u2F78': '\u7F36',
  17651. '\u2F79': '\u7F51',
  17652. '\u2F7A': '\u7F8A',
  17653. '\u2F7B': '\u7FBD',
  17654. '\u2F7C': '\u8001',
  17655. '\u2F7D': '\u800C',
  17656. '\u2F7E': '\u8012',
  17657. '\u2F7F': '\u8033',
  17658. '\u2F80': '\u807F',
  17659. '\u2F81': '\u8089',
  17660. '\u2F82': '\u81E3',
  17661. '\u2F83': '\u81EA',
  17662. '\u2F84': '\u81F3',
  17663. '\u2F85': '\u81FC',
  17664. '\u2F86': '\u820C',
  17665. '\u2F87': '\u821B',
  17666. '\u2F88': '\u821F',
  17667. '\u2F89': '\u826E',
  17668. '\u2F8A': '\u8272',
  17669. '\u2F8B': '\u8278',
  17670. '\u2F8C': '\u864D',
  17671. '\u2F8D': '\u866B',
  17672. '\u2F8E': '\u8840',
  17673. '\u2F8F': '\u884C',
  17674. '\u2F90': '\u8863',
  17675. '\u2F91': '\u897E',
  17676. '\u2F92': '\u898B',
  17677. '\u2F93': '\u89D2',
  17678. '\u2F94': '\u8A00',
  17679. '\u2F95': '\u8C37',
  17680. '\u2F96': '\u8C46',
  17681. '\u2F97': '\u8C55',
  17682. '\u2F98': '\u8C78',
  17683. '\u2F99': '\u8C9D',
  17684. '\u2F9A': '\u8D64',
  17685. '\u2F9B': '\u8D70',
  17686. '\u2F9C': '\u8DB3',
  17687. '\u2F9D': '\u8EAB',
  17688. '\u2F9E': '\u8ECA',
  17689. '\u2F9F': '\u8F9B',
  17690. '\u2FA0': '\u8FB0',
  17691. '\u2FA1': '\u8FB5',
  17692. '\u2FA2': '\u9091',
  17693. '\u2FA3': '\u9149',
  17694. '\u2FA4': '\u91C6',
  17695. '\u2FA5': '\u91CC',
  17696. '\u2FA6': '\u91D1',
  17697. '\u2FA7': '\u9577',
  17698. '\u2FA8': '\u9580',
  17699. '\u2FA9': '\u961C',
  17700. '\u2FAA': '\u96B6',
  17701. '\u2FAB': '\u96B9',
  17702. '\u2FAC': '\u96E8',
  17703. '\u2FAD': '\u9751',
  17704. '\u2FAE': '\u975E',
  17705. '\u2FAF': '\u9762',
  17706. '\u2FB0': '\u9769',
  17707. '\u2FB1': '\u97CB',
  17708. '\u2FB2': '\u97ED',
  17709. '\u2FB3': '\u97F3',
  17710. '\u2FB4': '\u9801',
  17711. '\u2FB5': '\u98A8',
  17712. '\u2FB6': '\u98DB',
  17713. '\u2FB7': '\u98DF',
  17714. '\u2FB8': '\u9996',
  17715. '\u2FB9': '\u9999',
  17716. '\u2FBA': '\u99AC',
  17717. '\u2FBB': '\u9AA8',
  17718. '\u2FBC': '\u9AD8',
  17719. '\u2FBD': '\u9ADF',
  17720. '\u2FBE': '\u9B25',
  17721. '\u2FBF': '\u9B2F',
  17722. '\u2FC0': '\u9B32',
  17723. '\u2FC1': '\u9B3C',
  17724. '\u2FC2': '\u9B5A',
  17725. '\u2FC3': '\u9CE5',
  17726. '\u2FC4': '\u9E75',
  17727. '\u2FC5': '\u9E7F',
  17728. '\u2FC6': '\u9EA5',
  17729. '\u2FC7': '\u9EBB',
  17730. '\u2FC8': '\u9EC3',
  17731. '\u2FC9': '\u9ECD',
  17732. '\u2FCA': '\u9ED1',
  17733. '\u2FCB': '\u9EF9',
  17734. '\u2FCC': '\u9EFD',
  17735. '\u2FCD': '\u9F0E',
  17736. '\u2FCE': '\u9F13',
  17737. '\u2FCF': '\u9F20',
  17738. '\u2FD0': '\u9F3B',
  17739. '\u2FD1': '\u9F4A',
  17740. '\u2FD2': '\u9F52',
  17741. '\u2FD3': '\u9F8D',
  17742. '\u2FD4': '\u9F9C',
  17743. '\u2FD5': '\u9FA0',
  17744. '\u3036': '\u3012',
  17745. '\u3038': '\u5341',
  17746. '\u3039': '\u5344',
  17747. '\u303A': '\u5345',
  17748. '\u309B': '\u0020\u3099',
  17749. '\u309C': '\u0020\u309A',
  17750. '\u3131': '\u1100',
  17751. '\u3132': '\u1101',
  17752. '\u3133': '\u11AA',
  17753. '\u3134': '\u1102',
  17754. '\u3135': '\u11AC',
  17755. '\u3136': '\u11AD',
  17756. '\u3137': '\u1103',
  17757. '\u3138': '\u1104',
  17758. '\u3139': '\u1105',
  17759. '\u313A': '\u11B0',
  17760. '\u313B': '\u11B1',
  17761. '\u313C': '\u11B2',
  17762. '\u313D': '\u11B3',
  17763. '\u313E': '\u11B4',
  17764. '\u313F': '\u11B5',
  17765. '\u3140': '\u111A',
  17766. '\u3141': '\u1106',
  17767. '\u3142': '\u1107',
  17768. '\u3143': '\u1108',
  17769. '\u3144': '\u1121',
  17770. '\u3145': '\u1109',
  17771. '\u3146': '\u110A',
  17772. '\u3147': '\u110B',
  17773. '\u3148': '\u110C',
  17774. '\u3149': '\u110D',
  17775. '\u314A': '\u110E',
  17776. '\u314B': '\u110F',
  17777. '\u314C': '\u1110',
  17778. '\u314D': '\u1111',
  17779. '\u314E': '\u1112',
  17780. '\u314F': '\u1161',
  17781. '\u3150': '\u1162',
  17782. '\u3151': '\u1163',
  17783. '\u3152': '\u1164',
  17784. '\u3153': '\u1165',
  17785. '\u3154': '\u1166',
  17786. '\u3155': '\u1167',
  17787. '\u3156': '\u1168',
  17788. '\u3157': '\u1169',
  17789. '\u3158': '\u116A',
  17790. '\u3159': '\u116B',
  17791. '\u315A': '\u116C',
  17792. '\u315B': '\u116D',
  17793. '\u315C': '\u116E',
  17794. '\u315D': '\u116F',
  17795. '\u315E': '\u1170',
  17796. '\u315F': '\u1171',
  17797. '\u3160': '\u1172',
  17798. '\u3161': '\u1173',
  17799. '\u3162': '\u1174',
  17800. '\u3163': '\u1175',
  17801. '\u3164': '\u1160',
  17802. '\u3165': '\u1114',
  17803. '\u3166': '\u1115',
  17804. '\u3167': '\u11C7',
  17805. '\u3168': '\u11C8',
  17806. '\u3169': '\u11CC',
  17807. '\u316A': '\u11CE',
  17808. '\u316B': '\u11D3',
  17809. '\u316C': '\u11D7',
  17810. '\u316D': '\u11D9',
  17811. '\u316E': '\u111C',
  17812. '\u316F': '\u11DD',
  17813. '\u3170': '\u11DF',
  17814. '\u3171': '\u111D',
  17815. '\u3172': '\u111E',
  17816. '\u3173': '\u1120',
  17817. '\u3174': '\u1122',
  17818. '\u3175': '\u1123',
  17819. '\u3176': '\u1127',
  17820. '\u3177': '\u1129',
  17821. '\u3178': '\u112B',
  17822. '\u3179': '\u112C',
  17823. '\u317A': '\u112D',
  17824. '\u317B': '\u112E',
  17825. '\u317C': '\u112F',
  17826. '\u317D': '\u1132',
  17827. '\u317E': '\u1136',
  17828. '\u317F': '\u1140',
  17829. '\u3180': '\u1147',
  17830. '\u3181': '\u114C',
  17831. '\u3182': '\u11F1',
  17832. '\u3183': '\u11F2',
  17833. '\u3184': '\u1157',
  17834. '\u3185': '\u1158',
  17835. '\u3186': '\u1159',
  17836. '\u3187': '\u1184',
  17837. '\u3188': '\u1185',
  17838. '\u3189': '\u1188',
  17839. '\u318A': '\u1191',
  17840. '\u318B': '\u1192',
  17841. '\u318C': '\u1194',
  17842. '\u318D': '\u119E',
  17843. '\u318E': '\u11A1',
  17844. '\u3200': '\u0028\u1100\u0029',
  17845. '\u3201': '\u0028\u1102\u0029',
  17846. '\u3202': '\u0028\u1103\u0029',
  17847. '\u3203': '\u0028\u1105\u0029',
  17848. '\u3204': '\u0028\u1106\u0029',
  17849. '\u3205': '\u0028\u1107\u0029',
  17850. '\u3206': '\u0028\u1109\u0029',
  17851. '\u3207': '\u0028\u110B\u0029',
  17852. '\u3208': '\u0028\u110C\u0029',
  17853. '\u3209': '\u0028\u110E\u0029',
  17854. '\u320A': '\u0028\u110F\u0029',
  17855. '\u320B': '\u0028\u1110\u0029',
  17856. '\u320C': '\u0028\u1111\u0029',
  17857. '\u320D': '\u0028\u1112\u0029',
  17858. '\u320E': '\u0028\u1100\u1161\u0029',
  17859. '\u320F': '\u0028\u1102\u1161\u0029',
  17860. '\u3210': '\u0028\u1103\u1161\u0029',
  17861. '\u3211': '\u0028\u1105\u1161\u0029',
  17862. '\u3212': '\u0028\u1106\u1161\u0029',
  17863. '\u3213': '\u0028\u1107\u1161\u0029',
  17864. '\u3214': '\u0028\u1109\u1161\u0029',
  17865. '\u3215': '\u0028\u110B\u1161\u0029',
  17866. '\u3216': '\u0028\u110C\u1161\u0029',
  17867. '\u3217': '\u0028\u110E\u1161\u0029',
  17868. '\u3218': '\u0028\u110F\u1161\u0029',
  17869. '\u3219': '\u0028\u1110\u1161\u0029',
  17870. '\u321A': '\u0028\u1111\u1161\u0029',
  17871. '\u321B': '\u0028\u1112\u1161\u0029',
  17872. '\u321C': '\u0028\u110C\u116E\u0029',
  17873. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  17874. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  17875. '\u3220': '\u0028\u4E00\u0029',
  17876. '\u3221': '\u0028\u4E8C\u0029',
  17877. '\u3222': '\u0028\u4E09\u0029',
  17878. '\u3223': '\u0028\u56DB\u0029',
  17879. '\u3224': '\u0028\u4E94\u0029',
  17880. '\u3225': '\u0028\u516D\u0029',
  17881. '\u3226': '\u0028\u4E03\u0029',
  17882. '\u3227': '\u0028\u516B\u0029',
  17883. '\u3228': '\u0028\u4E5D\u0029',
  17884. '\u3229': '\u0028\u5341\u0029',
  17885. '\u322A': '\u0028\u6708\u0029',
  17886. '\u322B': '\u0028\u706B\u0029',
  17887. '\u322C': '\u0028\u6C34\u0029',
  17888. '\u322D': '\u0028\u6728\u0029',
  17889. '\u322E': '\u0028\u91D1\u0029',
  17890. '\u322F': '\u0028\u571F\u0029',
  17891. '\u3230': '\u0028\u65E5\u0029',
  17892. '\u3231': '\u0028\u682A\u0029',
  17893. '\u3232': '\u0028\u6709\u0029',
  17894. '\u3233': '\u0028\u793E\u0029',
  17895. '\u3234': '\u0028\u540D\u0029',
  17896. '\u3235': '\u0028\u7279\u0029',
  17897. '\u3236': '\u0028\u8CA1\u0029',
  17898. '\u3237': '\u0028\u795D\u0029',
  17899. '\u3238': '\u0028\u52B4\u0029',
  17900. '\u3239': '\u0028\u4EE3\u0029',
  17901. '\u323A': '\u0028\u547C\u0029',
  17902. '\u323B': '\u0028\u5B66\u0029',
  17903. '\u323C': '\u0028\u76E3\u0029',
  17904. '\u323D': '\u0028\u4F01\u0029',
  17905. '\u323E': '\u0028\u8CC7\u0029',
  17906. '\u323F': '\u0028\u5354\u0029',
  17907. '\u3240': '\u0028\u796D\u0029',
  17908. '\u3241': '\u0028\u4F11\u0029',
  17909. '\u3242': '\u0028\u81EA\u0029',
  17910. '\u3243': '\u0028\u81F3\u0029',
  17911. '\u32C0': '\u0031\u6708',
  17912. '\u32C1': '\u0032\u6708',
  17913. '\u32C2': '\u0033\u6708',
  17914. '\u32C3': '\u0034\u6708',
  17915. '\u32C4': '\u0035\u6708',
  17916. '\u32C5': '\u0036\u6708',
  17917. '\u32C6': '\u0037\u6708',
  17918. '\u32C7': '\u0038\u6708',
  17919. '\u32C8': '\u0039\u6708',
  17920. '\u32C9': '\u0031\u0030\u6708',
  17921. '\u32CA': '\u0031\u0031\u6708',
  17922. '\u32CB': '\u0031\u0032\u6708',
  17923. '\u3358': '\u0030\u70B9',
  17924. '\u3359': '\u0031\u70B9',
  17925. '\u335A': '\u0032\u70B9',
  17926. '\u335B': '\u0033\u70B9',
  17927. '\u335C': '\u0034\u70B9',
  17928. '\u335D': '\u0035\u70B9',
  17929. '\u335E': '\u0036\u70B9',
  17930. '\u335F': '\u0037\u70B9',
  17931. '\u3360': '\u0038\u70B9',
  17932. '\u3361': '\u0039\u70B9',
  17933. '\u3362': '\u0031\u0030\u70B9',
  17934. '\u3363': '\u0031\u0031\u70B9',
  17935. '\u3364': '\u0031\u0032\u70B9',
  17936. '\u3365': '\u0031\u0033\u70B9',
  17937. '\u3366': '\u0031\u0034\u70B9',
  17938. '\u3367': '\u0031\u0035\u70B9',
  17939. '\u3368': '\u0031\u0036\u70B9',
  17940. '\u3369': '\u0031\u0037\u70B9',
  17941. '\u336A': '\u0031\u0038\u70B9',
  17942. '\u336B': '\u0031\u0039\u70B9',
  17943. '\u336C': '\u0032\u0030\u70B9',
  17944. '\u336D': '\u0032\u0031\u70B9',
  17945. '\u336E': '\u0032\u0032\u70B9',
  17946. '\u336F': '\u0032\u0033\u70B9',
  17947. '\u3370': '\u0032\u0034\u70B9',
  17948. '\u33E0': '\u0031\u65E5',
  17949. '\u33E1': '\u0032\u65E5',
  17950. '\u33E2': '\u0033\u65E5',
  17951. '\u33E3': '\u0034\u65E5',
  17952. '\u33E4': '\u0035\u65E5',
  17953. '\u33E5': '\u0036\u65E5',
  17954. '\u33E6': '\u0037\u65E5',
  17955. '\u33E7': '\u0038\u65E5',
  17956. '\u33E8': '\u0039\u65E5',
  17957. '\u33E9': '\u0031\u0030\u65E5',
  17958. '\u33EA': '\u0031\u0031\u65E5',
  17959. '\u33EB': '\u0031\u0032\u65E5',
  17960. '\u33EC': '\u0031\u0033\u65E5',
  17961. '\u33ED': '\u0031\u0034\u65E5',
  17962. '\u33EE': '\u0031\u0035\u65E5',
  17963. '\u33EF': '\u0031\u0036\u65E5',
  17964. '\u33F0': '\u0031\u0037\u65E5',
  17965. '\u33F1': '\u0031\u0038\u65E5',
  17966. '\u33F2': '\u0031\u0039\u65E5',
  17967. '\u33F3': '\u0032\u0030\u65E5',
  17968. '\u33F4': '\u0032\u0031\u65E5',
  17969. '\u33F5': '\u0032\u0032\u65E5',
  17970. '\u33F6': '\u0032\u0033\u65E5',
  17971. '\u33F7': '\u0032\u0034\u65E5',
  17972. '\u33F8': '\u0032\u0035\u65E5',
  17973. '\u33F9': '\u0032\u0036\u65E5',
  17974. '\u33FA': '\u0032\u0037\u65E5',
  17975. '\u33FB': '\u0032\u0038\u65E5',
  17976. '\u33FC': '\u0032\u0039\u65E5',
  17977. '\u33FD': '\u0033\u0030\u65E5',
  17978. '\u33FE': '\u0033\u0031\u65E5',
  17979. '\uFB00': '\u0066\u0066',
  17980. '\uFB01': '\u0066\u0069',
  17981. '\uFB02': '\u0066\u006C',
  17982. '\uFB03': '\u0066\u0066\u0069',
  17983. '\uFB04': '\u0066\u0066\u006C',
  17984. '\uFB05': '\u017F\u0074',
  17985. '\uFB06': '\u0073\u0074',
  17986. '\uFB13': '\u0574\u0576',
  17987. '\uFB14': '\u0574\u0565',
  17988. '\uFB15': '\u0574\u056B',
  17989. '\uFB16': '\u057E\u0576',
  17990. '\uFB17': '\u0574\u056D',
  17991. '\uFB4F': '\u05D0\u05DC',
  17992. '\uFB50': '\u0671',
  17993. '\uFB51': '\u0671',
  17994. '\uFB52': '\u067B',
  17995. '\uFB53': '\u067B',
  17996. '\uFB54': '\u067B',
  17997. '\uFB55': '\u067B',
  17998. '\uFB56': '\u067E',
  17999. '\uFB57': '\u067E',
  18000. '\uFB58': '\u067E',
  18001. '\uFB59': '\u067E',
  18002. '\uFB5A': '\u0680',
  18003. '\uFB5B': '\u0680',
  18004. '\uFB5C': '\u0680',
  18005. '\uFB5D': '\u0680',
  18006. '\uFB5E': '\u067A',
  18007. '\uFB5F': '\u067A',
  18008. '\uFB60': '\u067A',
  18009. '\uFB61': '\u067A',
  18010. '\uFB62': '\u067F',
  18011. '\uFB63': '\u067F',
  18012. '\uFB64': '\u067F',
  18013. '\uFB65': '\u067F',
  18014. '\uFB66': '\u0679',
  18015. '\uFB67': '\u0679',
  18016. '\uFB68': '\u0679',
  18017. '\uFB69': '\u0679',
  18018. '\uFB6A': '\u06A4',
  18019. '\uFB6B': '\u06A4',
  18020. '\uFB6C': '\u06A4',
  18021. '\uFB6D': '\u06A4',
  18022. '\uFB6E': '\u06A6',
  18023. '\uFB6F': '\u06A6',
  18024. '\uFB70': '\u06A6',
  18025. '\uFB71': '\u06A6',
  18026. '\uFB72': '\u0684',
  18027. '\uFB73': '\u0684',
  18028. '\uFB74': '\u0684',
  18029. '\uFB75': '\u0684',
  18030. '\uFB76': '\u0683',
  18031. '\uFB77': '\u0683',
  18032. '\uFB78': '\u0683',
  18033. '\uFB79': '\u0683',
  18034. '\uFB7A': '\u0686',
  18035. '\uFB7B': '\u0686',
  18036. '\uFB7C': '\u0686',
  18037. '\uFB7D': '\u0686',
  18038. '\uFB7E': '\u0687',
  18039. '\uFB7F': '\u0687',
  18040. '\uFB80': '\u0687',
  18041. '\uFB81': '\u0687',
  18042. '\uFB82': '\u068D',
  18043. '\uFB83': '\u068D',
  18044. '\uFB84': '\u068C',
  18045. '\uFB85': '\u068C',
  18046. '\uFB86': '\u068E',
  18047. '\uFB87': '\u068E',
  18048. '\uFB88': '\u0688',
  18049. '\uFB89': '\u0688',
  18050. '\uFB8A': '\u0698',
  18051. '\uFB8B': '\u0698',
  18052. '\uFB8C': '\u0691',
  18053. '\uFB8D': '\u0691',
  18054. '\uFB8E': '\u06A9',
  18055. '\uFB8F': '\u06A9',
  18056. '\uFB90': '\u06A9',
  18057. '\uFB91': '\u06A9',
  18058. '\uFB92': '\u06AF',
  18059. '\uFB93': '\u06AF',
  18060. '\uFB94': '\u06AF',
  18061. '\uFB95': '\u06AF',
  18062. '\uFB96': '\u06B3',
  18063. '\uFB97': '\u06B3',
  18064. '\uFB98': '\u06B3',
  18065. '\uFB99': '\u06B3',
  18066. '\uFB9A': '\u06B1',
  18067. '\uFB9B': '\u06B1',
  18068. '\uFB9C': '\u06B1',
  18069. '\uFB9D': '\u06B1',
  18070. '\uFB9E': '\u06BA',
  18071. '\uFB9F': '\u06BA',
  18072. '\uFBA0': '\u06BB',
  18073. '\uFBA1': '\u06BB',
  18074. '\uFBA2': '\u06BB',
  18075. '\uFBA3': '\u06BB',
  18076. '\uFBA4': '\u06C0',
  18077. '\uFBA5': '\u06C0',
  18078. '\uFBA6': '\u06C1',
  18079. '\uFBA7': '\u06C1',
  18080. '\uFBA8': '\u06C1',
  18081. '\uFBA9': '\u06C1',
  18082. '\uFBAA': '\u06BE',
  18083. '\uFBAB': '\u06BE',
  18084. '\uFBAC': '\u06BE',
  18085. '\uFBAD': '\u06BE',
  18086. '\uFBAE': '\u06D2',
  18087. '\uFBAF': '\u06D2',
  18088. '\uFBB0': '\u06D3',
  18089. '\uFBB1': '\u06D3',
  18090. '\uFBD3': '\u06AD',
  18091. '\uFBD4': '\u06AD',
  18092. '\uFBD5': '\u06AD',
  18093. '\uFBD6': '\u06AD',
  18094. '\uFBD7': '\u06C7',
  18095. '\uFBD8': '\u06C7',
  18096. '\uFBD9': '\u06C6',
  18097. '\uFBDA': '\u06C6',
  18098. '\uFBDB': '\u06C8',
  18099. '\uFBDC': '\u06C8',
  18100. '\uFBDD': '\u0677',
  18101. '\uFBDE': '\u06CB',
  18102. '\uFBDF': '\u06CB',
  18103. '\uFBE0': '\u06C5',
  18104. '\uFBE1': '\u06C5',
  18105. '\uFBE2': '\u06C9',
  18106. '\uFBE3': '\u06C9',
  18107. '\uFBE4': '\u06D0',
  18108. '\uFBE5': '\u06D0',
  18109. '\uFBE6': '\u06D0',
  18110. '\uFBE7': '\u06D0',
  18111. '\uFBE8': '\u0649',
  18112. '\uFBE9': '\u0649',
  18113. '\uFBEA': '\u0626\u0627',
  18114. '\uFBEB': '\u0626\u0627',
  18115. '\uFBEC': '\u0626\u06D5',
  18116. '\uFBED': '\u0626\u06D5',
  18117. '\uFBEE': '\u0626\u0648',
  18118. '\uFBEF': '\u0626\u0648',
  18119. '\uFBF0': '\u0626\u06C7',
  18120. '\uFBF1': '\u0626\u06C7',
  18121. '\uFBF2': '\u0626\u06C6',
  18122. '\uFBF3': '\u0626\u06C6',
  18123. '\uFBF4': '\u0626\u06C8',
  18124. '\uFBF5': '\u0626\u06C8',
  18125. '\uFBF6': '\u0626\u06D0',
  18126. '\uFBF7': '\u0626\u06D0',
  18127. '\uFBF8': '\u0626\u06D0',
  18128. '\uFBF9': '\u0626\u0649',
  18129. '\uFBFA': '\u0626\u0649',
  18130. '\uFBFB': '\u0626\u0649',
  18131. '\uFBFC': '\u06CC',
  18132. '\uFBFD': '\u06CC',
  18133. '\uFBFE': '\u06CC',
  18134. '\uFBFF': '\u06CC',
  18135. '\uFC00': '\u0626\u062C',
  18136. '\uFC01': '\u0626\u062D',
  18137. '\uFC02': '\u0626\u0645',
  18138. '\uFC03': '\u0626\u0649',
  18139. '\uFC04': '\u0626\u064A',
  18140. '\uFC05': '\u0628\u062C',
  18141. '\uFC06': '\u0628\u062D',
  18142. '\uFC07': '\u0628\u062E',
  18143. '\uFC08': '\u0628\u0645',
  18144. '\uFC09': '\u0628\u0649',
  18145. '\uFC0A': '\u0628\u064A',
  18146. '\uFC0B': '\u062A\u062C',
  18147. '\uFC0C': '\u062A\u062D',
  18148. '\uFC0D': '\u062A\u062E',
  18149. '\uFC0E': '\u062A\u0645',
  18150. '\uFC0F': '\u062A\u0649',
  18151. '\uFC10': '\u062A\u064A',
  18152. '\uFC11': '\u062B\u062C',
  18153. '\uFC12': '\u062B\u0645',
  18154. '\uFC13': '\u062B\u0649',
  18155. '\uFC14': '\u062B\u064A',
  18156. '\uFC15': '\u062C\u062D',
  18157. '\uFC16': '\u062C\u0645',
  18158. '\uFC17': '\u062D\u062C',
  18159. '\uFC18': '\u062D\u0645',
  18160. '\uFC19': '\u062E\u062C',
  18161. '\uFC1A': '\u062E\u062D',
  18162. '\uFC1B': '\u062E\u0645',
  18163. '\uFC1C': '\u0633\u062C',
  18164. '\uFC1D': '\u0633\u062D',
  18165. '\uFC1E': '\u0633\u062E',
  18166. '\uFC1F': '\u0633\u0645',
  18167. '\uFC20': '\u0635\u062D',
  18168. '\uFC21': '\u0635\u0645',
  18169. '\uFC22': '\u0636\u062C',
  18170. '\uFC23': '\u0636\u062D',
  18171. '\uFC24': '\u0636\u062E',
  18172. '\uFC25': '\u0636\u0645',
  18173. '\uFC26': '\u0637\u062D',
  18174. '\uFC27': '\u0637\u0645',
  18175. '\uFC28': '\u0638\u0645',
  18176. '\uFC29': '\u0639\u062C',
  18177. '\uFC2A': '\u0639\u0645',
  18178. '\uFC2B': '\u063A\u062C',
  18179. '\uFC2C': '\u063A\u0645',
  18180. '\uFC2D': '\u0641\u062C',
  18181. '\uFC2E': '\u0641\u062D',
  18182. '\uFC2F': '\u0641\u062E',
  18183. '\uFC30': '\u0641\u0645',
  18184. '\uFC31': '\u0641\u0649',
  18185. '\uFC32': '\u0641\u064A',
  18186. '\uFC33': '\u0642\u062D',
  18187. '\uFC34': '\u0642\u0645',
  18188. '\uFC35': '\u0642\u0649',
  18189. '\uFC36': '\u0642\u064A',
  18190. '\uFC37': '\u0643\u0627',
  18191. '\uFC38': '\u0643\u062C',
  18192. '\uFC39': '\u0643\u062D',
  18193. '\uFC3A': '\u0643\u062E',
  18194. '\uFC3B': '\u0643\u0644',
  18195. '\uFC3C': '\u0643\u0645',
  18196. '\uFC3D': '\u0643\u0649',
  18197. '\uFC3E': '\u0643\u064A',
  18198. '\uFC3F': '\u0644\u062C',
  18199. '\uFC40': '\u0644\u062D',
  18200. '\uFC41': '\u0644\u062E',
  18201. '\uFC42': '\u0644\u0645',
  18202. '\uFC43': '\u0644\u0649',
  18203. '\uFC44': '\u0644\u064A',
  18204. '\uFC45': '\u0645\u062C',
  18205. '\uFC46': '\u0645\u062D',
  18206. '\uFC47': '\u0645\u062E',
  18207. '\uFC48': '\u0645\u0645',
  18208. '\uFC49': '\u0645\u0649',
  18209. '\uFC4A': '\u0645\u064A',
  18210. '\uFC4B': '\u0646\u062C',
  18211. '\uFC4C': '\u0646\u062D',
  18212. '\uFC4D': '\u0646\u062E',
  18213. '\uFC4E': '\u0646\u0645',
  18214. '\uFC4F': '\u0646\u0649',
  18215. '\uFC50': '\u0646\u064A',
  18216. '\uFC51': '\u0647\u062C',
  18217. '\uFC52': '\u0647\u0645',
  18218. '\uFC53': '\u0647\u0649',
  18219. '\uFC54': '\u0647\u064A',
  18220. '\uFC55': '\u064A\u062C',
  18221. '\uFC56': '\u064A\u062D',
  18222. '\uFC57': '\u064A\u062E',
  18223. '\uFC58': '\u064A\u0645',
  18224. '\uFC59': '\u064A\u0649',
  18225. '\uFC5A': '\u064A\u064A',
  18226. '\uFC5B': '\u0630\u0670',
  18227. '\uFC5C': '\u0631\u0670',
  18228. '\uFC5D': '\u0649\u0670',
  18229. '\uFC5E': '\u0020\u064C\u0651',
  18230. '\uFC5F': '\u0020\u064D\u0651',
  18231. '\uFC60': '\u0020\u064E\u0651',
  18232. '\uFC61': '\u0020\u064F\u0651',
  18233. '\uFC62': '\u0020\u0650\u0651',
  18234. '\uFC63': '\u0020\u0651\u0670',
  18235. '\uFC64': '\u0626\u0631',
  18236. '\uFC65': '\u0626\u0632',
  18237. '\uFC66': '\u0626\u0645',
  18238. '\uFC67': '\u0626\u0646',
  18239. '\uFC68': '\u0626\u0649',
  18240. '\uFC69': '\u0626\u064A',
  18241. '\uFC6A': '\u0628\u0631',
  18242. '\uFC6B': '\u0628\u0632',
  18243. '\uFC6C': '\u0628\u0645',
  18244. '\uFC6D': '\u0628\u0646',
  18245. '\uFC6E': '\u0628\u0649',
  18246. '\uFC6F': '\u0628\u064A',
  18247. '\uFC70': '\u062A\u0631',
  18248. '\uFC71': '\u062A\u0632',
  18249. '\uFC72': '\u062A\u0645',
  18250. '\uFC73': '\u062A\u0646',
  18251. '\uFC74': '\u062A\u0649',
  18252. '\uFC75': '\u062A\u064A',
  18253. '\uFC76': '\u062B\u0631',
  18254. '\uFC77': '\u062B\u0632',
  18255. '\uFC78': '\u062B\u0645',
  18256. '\uFC79': '\u062B\u0646',
  18257. '\uFC7A': '\u062B\u0649',
  18258. '\uFC7B': '\u062B\u064A',
  18259. '\uFC7C': '\u0641\u0649',
  18260. '\uFC7D': '\u0641\u064A',
  18261. '\uFC7E': '\u0642\u0649',
  18262. '\uFC7F': '\u0642\u064A',
  18263. '\uFC80': '\u0643\u0627',
  18264. '\uFC81': '\u0643\u0644',
  18265. '\uFC82': '\u0643\u0645',
  18266. '\uFC83': '\u0643\u0649',
  18267. '\uFC84': '\u0643\u064A',
  18268. '\uFC85': '\u0644\u0645',
  18269. '\uFC86': '\u0644\u0649',
  18270. '\uFC87': '\u0644\u064A',
  18271. '\uFC88': '\u0645\u0627',
  18272. '\uFC89': '\u0645\u0645',
  18273. '\uFC8A': '\u0646\u0631',
  18274. '\uFC8B': '\u0646\u0632',
  18275. '\uFC8C': '\u0646\u0645',
  18276. '\uFC8D': '\u0646\u0646',
  18277. '\uFC8E': '\u0646\u0649',
  18278. '\uFC8F': '\u0646\u064A',
  18279. '\uFC90': '\u0649\u0670',
  18280. '\uFC91': '\u064A\u0631',
  18281. '\uFC92': '\u064A\u0632',
  18282. '\uFC93': '\u064A\u0645',
  18283. '\uFC94': '\u064A\u0646',
  18284. '\uFC95': '\u064A\u0649',
  18285. '\uFC96': '\u064A\u064A',
  18286. '\uFC97': '\u0626\u062C',
  18287. '\uFC98': '\u0626\u062D',
  18288. '\uFC99': '\u0626\u062E',
  18289. '\uFC9A': '\u0626\u0645',
  18290. '\uFC9B': '\u0626\u0647',
  18291. '\uFC9C': '\u0628\u062C',
  18292. '\uFC9D': '\u0628\u062D',
  18293. '\uFC9E': '\u0628\u062E',
  18294. '\uFC9F': '\u0628\u0645',
  18295. '\uFCA0': '\u0628\u0647',
  18296. '\uFCA1': '\u062A\u062C',
  18297. '\uFCA2': '\u062A\u062D',
  18298. '\uFCA3': '\u062A\u062E',
  18299. '\uFCA4': '\u062A\u0645',
  18300. '\uFCA5': '\u062A\u0647',
  18301. '\uFCA6': '\u062B\u0645',
  18302. '\uFCA7': '\u062C\u062D',
  18303. '\uFCA8': '\u062C\u0645',
  18304. '\uFCA9': '\u062D\u062C',
  18305. '\uFCAA': '\u062D\u0645',
  18306. '\uFCAB': '\u062E\u062C',
  18307. '\uFCAC': '\u062E\u0645',
  18308. '\uFCAD': '\u0633\u062C',
  18309. '\uFCAE': '\u0633\u062D',
  18310. '\uFCAF': '\u0633\u062E',
  18311. '\uFCB0': '\u0633\u0645',
  18312. '\uFCB1': '\u0635\u062D',
  18313. '\uFCB2': '\u0635\u062E',
  18314. '\uFCB3': '\u0635\u0645',
  18315. '\uFCB4': '\u0636\u062C',
  18316. '\uFCB5': '\u0636\u062D',
  18317. '\uFCB6': '\u0636\u062E',
  18318. '\uFCB7': '\u0636\u0645',
  18319. '\uFCB8': '\u0637\u062D',
  18320. '\uFCB9': '\u0638\u0645',
  18321. '\uFCBA': '\u0639\u062C',
  18322. '\uFCBB': '\u0639\u0645',
  18323. '\uFCBC': '\u063A\u062C',
  18324. '\uFCBD': '\u063A\u0645',
  18325. '\uFCBE': '\u0641\u062C',
  18326. '\uFCBF': '\u0641\u062D',
  18327. '\uFCC0': '\u0641\u062E',
  18328. '\uFCC1': '\u0641\u0645',
  18329. '\uFCC2': '\u0642\u062D',
  18330. '\uFCC3': '\u0642\u0645',
  18331. '\uFCC4': '\u0643\u062C',
  18332. '\uFCC5': '\u0643\u062D',
  18333. '\uFCC6': '\u0643\u062E',
  18334. '\uFCC7': '\u0643\u0644',
  18335. '\uFCC8': '\u0643\u0645',
  18336. '\uFCC9': '\u0644\u062C',
  18337. '\uFCCA': '\u0644\u062D',
  18338. '\uFCCB': '\u0644\u062E',
  18339. '\uFCCC': '\u0644\u0645',
  18340. '\uFCCD': '\u0644\u0647',
  18341. '\uFCCE': '\u0645\u062C',
  18342. '\uFCCF': '\u0645\u062D',
  18343. '\uFCD0': '\u0645\u062E',
  18344. '\uFCD1': '\u0645\u0645',
  18345. '\uFCD2': '\u0646\u062C',
  18346. '\uFCD3': '\u0646\u062D',
  18347. '\uFCD4': '\u0646\u062E',
  18348. '\uFCD5': '\u0646\u0645',
  18349. '\uFCD6': '\u0646\u0647',
  18350. '\uFCD7': '\u0647\u062C',
  18351. '\uFCD8': '\u0647\u0645',
  18352. '\uFCD9': '\u0647\u0670',
  18353. '\uFCDA': '\u064A\u062C',
  18354. '\uFCDB': '\u064A\u062D',
  18355. '\uFCDC': '\u064A\u062E',
  18356. '\uFCDD': '\u064A\u0645',
  18357. '\uFCDE': '\u064A\u0647',
  18358. '\uFCDF': '\u0626\u0645',
  18359. '\uFCE0': '\u0626\u0647',
  18360. '\uFCE1': '\u0628\u0645',
  18361. '\uFCE2': '\u0628\u0647',
  18362. '\uFCE3': '\u062A\u0645',
  18363. '\uFCE4': '\u062A\u0647',
  18364. '\uFCE5': '\u062B\u0645',
  18365. '\uFCE6': '\u062B\u0647',
  18366. '\uFCE7': '\u0633\u0645',
  18367. '\uFCE8': '\u0633\u0647',
  18368. '\uFCE9': '\u0634\u0645',
  18369. '\uFCEA': '\u0634\u0647',
  18370. '\uFCEB': '\u0643\u0644',
  18371. '\uFCEC': '\u0643\u0645',
  18372. '\uFCED': '\u0644\u0645',
  18373. '\uFCEE': '\u0646\u0645',
  18374. '\uFCEF': '\u0646\u0647',
  18375. '\uFCF0': '\u064A\u0645',
  18376. '\uFCF1': '\u064A\u0647',
  18377. '\uFCF2': '\u0640\u064E\u0651',
  18378. '\uFCF3': '\u0640\u064F\u0651',
  18379. '\uFCF4': '\u0640\u0650\u0651',
  18380. '\uFCF5': '\u0637\u0649',
  18381. '\uFCF6': '\u0637\u064A',
  18382. '\uFCF7': '\u0639\u0649',
  18383. '\uFCF8': '\u0639\u064A',
  18384. '\uFCF9': '\u063A\u0649',
  18385. '\uFCFA': '\u063A\u064A',
  18386. '\uFCFB': '\u0633\u0649',
  18387. '\uFCFC': '\u0633\u064A',
  18388. '\uFCFD': '\u0634\u0649',
  18389. '\uFCFE': '\u0634\u064A',
  18390. '\uFCFF': '\u062D\u0649',
  18391. '\uFD00': '\u062D\u064A',
  18392. '\uFD01': '\u062C\u0649',
  18393. '\uFD02': '\u062C\u064A',
  18394. '\uFD03': '\u062E\u0649',
  18395. '\uFD04': '\u062E\u064A',
  18396. '\uFD05': '\u0635\u0649',
  18397. '\uFD06': '\u0635\u064A',
  18398. '\uFD07': '\u0636\u0649',
  18399. '\uFD08': '\u0636\u064A',
  18400. '\uFD09': '\u0634\u062C',
  18401. '\uFD0A': '\u0634\u062D',
  18402. '\uFD0B': '\u0634\u062E',
  18403. '\uFD0C': '\u0634\u0645',
  18404. '\uFD0D': '\u0634\u0631',
  18405. '\uFD0E': '\u0633\u0631',
  18406. '\uFD0F': '\u0635\u0631',
  18407. '\uFD10': '\u0636\u0631',
  18408. '\uFD11': '\u0637\u0649',
  18409. '\uFD12': '\u0637\u064A',
  18410. '\uFD13': '\u0639\u0649',
  18411. '\uFD14': '\u0639\u064A',
  18412. '\uFD15': '\u063A\u0649',
  18413. '\uFD16': '\u063A\u064A',
  18414. '\uFD17': '\u0633\u0649',
  18415. '\uFD18': '\u0633\u064A',
  18416. '\uFD19': '\u0634\u0649',
  18417. '\uFD1A': '\u0634\u064A',
  18418. '\uFD1B': '\u062D\u0649',
  18419. '\uFD1C': '\u062D\u064A',
  18420. '\uFD1D': '\u062C\u0649',
  18421. '\uFD1E': '\u062C\u064A',
  18422. '\uFD1F': '\u062E\u0649',
  18423. '\uFD20': '\u062E\u064A',
  18424. '\uFD21': '\u0635\u0649',
  18425. '\uFD22': '\u0635\u064A',
  18426. '\uFD23': '\u0636\u0649',
  18427. '\uFD24': '\u0636\u064A',
  18428. '\uFD25': '\u0634\u062C',
  18429. '\uFD26': '\u0634\u062D',
  18430. '\uFD27': '\u0634\u062E',
  18431. '\uFD28': '\u0634\u0645',
  18432. '\uFD29': '\u0634\u0631',
  18433. '\uFD2A': '\u0633\u0631',
  18434. '\uFD2B': '\u0635\u0631',
  18435. '\uFD2C': '\u0636\u0631',
  18436. '\uFD2D': '\u0634\u062C',
  18437. '\uFD2E': '\u0634\u062D',
  18438. '\uFD2F': '\u0634\u062E',
  18439. '\uFD30': '\u0634\u0645',
  18440. '\uFD31': '\u0633\u0647',
  18441. '\uFD32': '\u0634\u0647',
  18442. '\uFD33': '\u0637\u0645',
  18443. '\uFD34': '\u0633\u062C',
  18444. '\uFD35': '\u0633\u062D',
  18445. '\uFD36': '\u0633\u062E',
  18446. '\uFD37': '\u0634\u062C',
  18447. '\uFD38': '\u0634\u062D',
  18448. '\uFD39': '\u0634\u062E',
  18449. '\uFD3A': '\u0637\u0645',
  18450. '\uFD3B': '\u0638\u0645',
  18451. '\uFD3C': '\u0627\u064B',
  18452. '\uFD3D': '\u0627\u064B',
  18453. '\uFD50': '\u062A\u062C\u0645',
  18454. '\uFD51': '\u062A\u062D\u062C',
  18455. '\uFD52': '\u062A\u062D\u062C',
  18456. '\uFD53': '\u062A\u062D\u0645',
  18457. '\uFD54': '\u062A\u062E\u0645',
  18458. '\uFD55': '\u062A\u0645\u062C',
  18459. '\uFD56': '\u062A\u0645\u062D',
  18460. '\uFD57': '\u062A\u0645\u062E',
  18461. '\uFD58': '\u062C\u0645\u062D',
  18462. '\uFD59': '\u062C\u0645\u062D',
  18463. '\uFD5A': '\u062D\u0645\u064A',
  18464. '\uFD5B': '\u062D\u0645\u0649',
  18465. '\uFD5C': '\u0633\u062D\u062C',
  18466. '\uFD5D': '\u0633\u062C\u062D',
  18467. '\uFD5E': '\u0633\u062C\u0649',
  18468. '\uFD5F': '\u0633\u0645\u062D',
  18469. '\uFD60': '\u0633\u0645\u062D',
  18470. '\uFD61': '\u0633\u0645\u062C',
  18471. '\uFD62': '\u0633\u0645\u0645',
  18472. '\uFD63': '\u0633\u0645\u0645',
  18473. '\uFD64': '\u0635\u062D\u062D',
  18474. '\uFD65': '\u0635\u062D\u062D',
  18475. '\uFD66': '\u0635\u0645\u0645',
  18476. '\uFD67': '\u0634\u062D\u0645',
  18477. '\uFD68': '\u0634\u062D\u0645',
  18478. '\uFD69': '\u0634\u062C\u064A',
  18479. '\uFD6A': '\u0634\u0645\u062E',
  18480. '\uFD6B': '\u0634\u0645\u062E',
  18481. '\uFD6C': '\u0634\u0645\u0645',
  18482. '\uFD6D': '\u0634\u0645\u0645',
  18483. '\uFD6E': '\u0636\u062D\u0649',
  18484. '\uFD6F': '\u0636\u062E\u0645',
  18485. '\uFD70': '\u0636\u062E\u0645',
  18486. '\uFD71': '\u0637\u0645\u062D',
  18487. '\uFD72': '\u0637\u0645\u062D',
  18488. '\uFD73': '\u0637\u0645\u0645',
  18489. '\uFD74': '\u0637\u0645\u064A',
  18490. '\uFD75': '\u0639\u062C\u0645',
  18491. '\uFD76': '\u0639\u0645\u0645',
  18492. '\uFD77': '\u0639\u0645\u0645',
  18493. '\uFD78': '\u0639\u0645\u0649',
  18494. '\uFD79': '\u063A\u0645\u0645',
  18495. '\uFD7A': '\u063A\u0645\u064A',
  18496. '\uFD7B': '\u063A\u0645\u0649',
  18497. '\uFD7C': '\u0641\u062E\u0645',
  18498. '\uFD7D': '\u0641\u062E\u0645',
  18499. '\uFD7E': '\u0642\u0645\u062D',
  18500. '\uFD7F': '\u0642\u0645\u0645',
  18501. '\uFD80': '\u0644\u062D\u0645',
  18502. '\uFD81': '\u0644\u062D\u064A',
  18503. '\uFD82': '\u0644\u062D\u0649',
  18504. '\uFD83': '\u0644\u062C\u062C',
  18505. '\uFD84': '\u0644\u062C\u062C',
  18506. '\uFD85': '\u0644\u062E\u0645',
  18507. '\uFD86': '\u0644\u062E\u0645',
  18508. '\uFD87': '\u0644\u0645\u062D',
  18509. '\uFD88': '\u0644\u0645\u062D',
  18510. '\uFD89': '\u0645\u062D\u062C',
  18511. '\uFD8A': '\u0645\u062D\u0645',
  18512. '\uFD8B': '\u0645\u062D\u064A',
  18513. '\uFD8C': '\u0645\u062C\u062D',
  18514. '\uFD8D': '\u0645\u062C\u0645',
  18515. '\uFD8E': '\u0645\u062E\u062C',
  18516. '\uFD8F': '\u0645\u062E\u0645',
  18517. '\uFD92': '\u0645\u062C\u062E',
  18518. '\uFD93': '\u0647\u0645\u062C',
  18519. '\uFD94': '\u0647\u0645\u0645',
  18520. '\uFD95': '\u0646\u062D\u0645',
  18521. '\uFD96': '\u0646\u062D\u0649',
  18522. '\uFD97': '\u0646\u062C\u0645',
  18523. '\uFD98': '\u0646\u062C\u0645',
  18524. '\uFD99': '\u0646\u062C\u0649',
  18525. '\uFD9A': '\u0646\u0645\u064A',
  18526. '\uFD9B': '\u0646\u0645\u0649',
  18527. '\uFD9C': '\u064A\u0645\u0645',
  18528. '\uFD9D': '\u064A\u0645\u0645',
  18529. '\uFD9E': '\u0628\u062E\u064A',
  18530. '\uFD9F': '\u062A\u062C\u064A',
  18531. '\uFDA0': '\u062A\u062C\u0649',
  18532. '\uFDA1': '\u062A\u062E\u064A',
  18533. '\uFDA2': '\u062A\u062E\u0649',
  18534. '\uFDA3': '\u062A\u0645\u064A',
  18535. '\uFDA4': '\u062A\u0645\u0649',
  18536. '\uFDA5': '\u062C\u0645\u064A',
  18537. '\uFDA6': '\u062C\u062D\u0649',
  18538. '\uFDA7': '\u062C\u0645\u0649',
  18539. '\uFDA8': '\u0633\u062E\u0649',
  18540. '\uFDA9': '\u0635\u062D\u064A',
  18541. '\uFDAA': '\u0634\u062D\u064A',
  18542. '\uFDAB': '\u0636\u062D\u064A',
  18543. '\uFDAC': '\u0644\u062C\u064A',
  18544. '\uFDAD': '\u0644\u0645\u064A',
  18545. '\uFDAE': '\u064A\u062D\u064A',
  18546. '\uFDAF': '\u064A\u062C\u064A',
  18547. '\uFDB0': '\u064A\u0645\u064A',
  18548. '\uFDB1': '\u0645\u0645\u064A',
  18549. '\uFDB2': '\u0642\u0645\u064A',
  18550. '\uFDB3': '\u0646\u062D\u064A',
  18551. '\uFDB4': '\u0642\u0645\u062D',
  18552. '\uFDB5': '\u0644\u062D\u0645',
  18553. '\uFDB6': '\u0639\u0645\u064A',
  18554. '\uFDB7': '\u0643\u0645\u064A',
  18555. '\uFDB8': '\u0646\u062C\u062D',
  18556. '\uFDB9': '\u0645\u062E\u064A',
  18557. '\uFDBA': '\u0644\u062C\u0645',
  18558. '\uFDBB': '\u0643\u0645\u0645',
  18559. '\uFDBC': '\u0644\u062C\u0645',
  18560. '\uFDBD': '\u0646\u062C\u062D',
  18561. '\uFDBE': '\u062C\u062D\u064A',
  18562. '\uFDBF': '\u062D\u062C\u064A',
  18563. '\uFDC0': '\u0645\u062C\u064A',
  18564. '\uFDC1': '\u0641\u0645\u064A',
  18565. '\uFDC2': '\u0628\u062D\u064A',
  18566. '\uFDC3': '\u0643\u0645\u0645',
  18567. '\uFDC4': '\u0639\u062C\u0645',
  18568. '\uFDC5': '\u0635\u0645\u0645',
  18569. '\uFDC6': '\u0633\u062E\u064A',
  18570. '\uFDC7': '\u0646\u062C\u064A',
  18571. '\uFE49': '\u203E',
  18572. '\uFE4A': '\u203E',
  18573. '\uFE4B': '\u203E',
  18574. '\uFE4C': '\u203E',
  18575. '\uFE4D': '\u005F',
  18576. '\uFE4E': '\u005F',
  18577. '\uFE4F': '\u005F',
  18578. '\uFE80': '\u0621',
  18579. '\uFE81': '\u0622',
  18580. '\uFE82': '\u0622',
  18581. '\uFE83': '\u0623',
  18582. '\uFE84': '\u0623',
  18583. '\uFE85': '\u0624',
  18584. '\uFE86': '\u0624',
  18585. '\uFE87': '\u0625',
  18586. '\uFE88': '\u0625',
  18587. '\uFE89': '\u0626',
  18588. '\uFE8A': '\u0626',
  18589. '\uFE8B': '\u0626',
  18590. '\uFE8C': '\u0626',
  18591. '\uFE8D': '\u0627',
  18592. '\uFE8E': '\u0627',
  18593. '\uFE8F': '\u0628',
  18594. '\uFE90': '\u0628',
  18595. '\uFE91': '\u0628',
  18596. '\uFE92': '\u0628',
  18597. '\uFE93': '\u0629',
  18598. '\uFE94': '\u0629',
  18599. '\uFE95': '\u062A',
  18600. '\uFE96': '\u062A',
  18601. '\uFE97': '\u062A',
  18602. '\uFE98': '\u062A',
  18603. '\uFE99': '\u062B',
  18604. '\uFE9A': '\u062B',
  18605. '\uFE9B': '\u062B',
  18606. '\uFE9C': '\u062B',
  18607. '\uFE9D': '\u062C',
  18608. '\uFE9E': '\u062C',
  18609. '\uFE9F': '\u062C',
  18610. '\uFEA0': '\u062C',
  18611. '\uFEA1': '\u062D',
  18612. '\uFEA2': '\u062D',
  18613. '\uFEA3': '\u062D',
  18614. '\uFEA4': '\u062D',
  18615. '\uFEA5': '\u062E',
  18616. '\uFEA6': '\u062E',
  18617. '\uFEA7': '\u062E',
  18618. '\uFEA8': '\u062E',
  18619. '\uFEA9': '\u062F',
  18620. '\uFEAA': '\u062F',
  18621. '\uFEAB': '\u0630',
  18622. '\uFEAC': '\u0630',
  18623. '\uFEAD': '\u0631',
  18624. '\uFEAE': '\u0631',
  18625. '\uFEAF': '\u0632',
  18626. '\uFEB0': '\u0632',
  18627. '\uFEB1': '\u0633',
  18628. '\uFEB2': '\u0633',
  18629. '\uFEB3': '\u0633',
  18630. '\uFEB4': '\u0633',
  18631. '\uFEB5': '\u0634',
  18632. '\uFEB6': '\u0634',
  18633. '\uFEB7': '\u0634',
  18634. '\uFEB8': '\u0634',
  18635. '\uFEB9': '\u0635',
  18636. '\uFEBA': '\u0635',
  18637. '\uFEBB': '\u0635',
  18638. '\uFEBC': '\u0635',
  18639. '\uFEBD': '\u0636',
  18640. '\uFEBE': '\u0636',
  18641. '\uFEBF': '\u0636',
  18642. '\uFEC0': '\u0636',
  18643. '\uFEC1': '\u0637',
  18644. '\uFEC2': '\u0637',
  18645. '\uFEC3': '\u0637',
  18646. '\uFEC4': '\u0637',
  18647. '\uFEC5': '\u0638',
  18648. '\uFEC6': '\u0638',
  18649. '\uFEC7': '\u0638',
  18650. '\uFEC8': '\u0638',
  18651. '\uFEC9': '\u0639',
  18652. '\uFECA': '\u0639',
  18653. '\uFECB': '\u0639',
  18654. '\uFECC': '\u0639',
  18655. '\uFECD': '\u063A',
  18656. '\uFECE': '\u063A',
  18657. '\uFECF': '\u063A',
  18658. '\uFED0': '\u063A',
  18659. '\uFED1': '\u0641',
  18660. '\uFED2': '\u0641',
  18661. '\uFED3': '\u0641',
  18662. '\uFED4': '\u0641',
  18663. '\uFED5': '\u0642',
  18664. '\uFED6': '\u0642',
  18665. '\uFED7': '\u0642',
  18666. '\uFED8': '\u0642',
  18667. '\uFED9': '\u0643',
  18668. '\uFEDA': '\u0643',
  18669. '\uFEDB': '\u0643',
  18670. '\uFEDC': '\u0643',
  18671. '\uFEDD': '\u0644',
  18672. '\uFEDE': '\u0644',
  18673. '\uFEDF': '\u0644',
  18674. '\uFEE0': '\u0644',
  18675. '\uFEE1': '\u0645',
  18676. '\uFEE2': '\u0645',
  18677. '\uFEE3': '\u0645',
  18678. '\uFEE4': '\u0645',
  18679. '\uFEE5': '\u0646',
  18680. '\uFEE6': '\u0646',
  18681. '\uFEE7': '\u0646',
  18682. '\uFEE8': '\u0646',
  18683. '\uFEE9': '\u0647',
  18684. '\uFEEA': '\u0647',
  18685. '\uFEEB': '\u0647',
  18686. '\uFEEC': '\u0647',
  18687. '\uFEED': '\u0648',
  18688. '\uFEEE': '\u0648',
  18689. '\uFEEF': '\u0649',
  18690. '\uFEF0': '\u0649',
  18691. '\uFEF1': '\u064A',
  18692. '\uFEF2': '\u064A',
  18693. '\uFEF3': '\u064A',
  18694. '\uFEF4': '\u064A',
  18695. '\uFEF5': '\u0644\u0622',
  18696. '\uFEF6': '\u0644\u0622',
  18697. '\uFEF7': '\u0644\u0623',
  18698. '\uFEF8': '\u0644\u0623',
  18699. '\uFEF9': '\u0644\u0625',
  18700. '\uFEFA': '\u0644\u0625',
  18701. '\uFEFB': '\u0644\u0627',
  18702. '\uFEFC': '\u0644\u0627'
  18703. };
  18704. function reverseIfRtl(chars) {
  18705. var charsLength = chars.length;
  18706. //reverse an arabic ligature
  18707. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18708. return chars;
  18709. }
  18710. var s = '';
  18711. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18712. s += chars[ii];
  18713. }
  18714. return s;
  18715. }
  18716. function adjustWidths(properties) {
  18717. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  18718. return;
  18719. }
  18720. // adjusting width to fontMatrix scale
  18721. var scale = 0.001 / properties.fontMatrix[0];
  18722. var glyphsWidths = properties.widths;
  18723. for (var glyph in glyphsWidths) {
  18724. glyphsWidths[glyph] *= scale;
  18725. }
  18726. properties.defaultWidth *= scale;
  18727. }
  18728. function getFontType(type, subtype) {
  18729. switch (type) {
  18730. case 'Type1':
  18731. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  18732. case 'CIDFontType0':
  18733. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  18734. FontType.CIDFONTTYPE0;
  18735. case 'OpenType':
  18736. return FontType.OPENTYPE;
  18737. case 'TrueType':
  18738. return FontType.TRUETYPE;
  18739. case 'CIDFontType2':
  18740. return FontType.CIDFONTTYPE2;
  18741. case 'MMType1':
  18742. return FontType.MMTYPE1;
  18743. case 'Type0':
  18744. return FontType.TYPE0;
  18745. default:
  18746. return FontType.UNKNOWN;
  18747. }
  18748. }
  18749. var Glyph = (function GlyphClosure() {
  18750. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18751. this.fontChar = fontChar;
  18752. this.unicode = unicode;
  18753. this.accent = accent;
  18754. this.width = width;
  18755. this.vmetric = vmetric;
  18756. this.operatorListId = operatorListId;
  18757. }
  18758. Glyph.prototype.matchesForCache =
  18759. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18760. return this.fontChar === fontChar &&
  18761. this.unicode === unicode &&
  18762. this.accent === accent &&
  18763. this.width === width &&
  18764. this.vmetric === vmetric &&
  18765. this.operatorListId === operatorListId;
  18766. };
  18767. return Glyph;
  18768. })();
  18769. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  18770. function ToUnicodeMap(cmap) {
  18771. // The elements of this._map can be integers or strings, depending on how
  18772. // |cmap| was created.
  18773. this._map = cmap;
  18774. }
  18775. ToUnicodeMap.prototype = {
  18776. get length() {
  18777. return this._map.length;
  18778. },
  18779. forEach: function(callback) {
  18780. for (var charCode in this._map) {
  18781. callback(charCode, this._map[charCode].charCodeAt(0));
  18782. }
  18783. },
  18784. get: function(i) {
  18785. return this._map[i];
  18786. },
  18787. charCodeOf: function(v) {
  18788. return this._map.indexOf(v);
  18789. }
  18790. };
  18791. return ToUnicodeMap;
  18792. })();
  18793. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  18794. function IdentityToUnicodeMap(firstChar, lastChar) {
  18795. this.firstChar = firstChar;
  18796. this.lastChar = lastChar;
  18797. }
  18798. IdentityToUnicodeMap.prototype = {
  18799. get length() {
  18800. error('should not access .length');
  18801. },
  18802. forEach: function(callback) {
  18803. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  18804. callback(i, i);
  18805. }
  18806. },
  18807. get: function(i) {
  18808. if (this.firstChar <= i && i <= this.lastChar) {
  18809. return String.fromCharCode(i);
  18810. }
  18811. return undefined;
  18812. },
  18813. charCodeOf: function(v) {
  18814. error('should not call .charCodeOf');
  18815. }
  18816. };
  18817. return IdentityToUnicodeMap;
  18818. })();
  18819. /**
  18820. * 'Font' is the class the outside world should use, it encapsulate all the font
  18821. * decoding logics whatever type it is (assuming the font type is supported).
  18822. *
  18823. * For example to read a Type1 font and to attach it to the document:
  18824. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  18825. * type1Font.bind();
  18826. */
  18827. var Font = (function FontClosure() {
  18828. function Font(name, file, properties) {
  18829. var charCode, glyphName;
  18830. this.name = name;
  18831. this.loadedName = properties.loadedName;
  18832. this.isType3Font = properties.isType3Font;
  18833. this.sizes = [];
  18834. this.glyphCache = {};
  18835. var names = name.split('+');
  18836. names = names.length > 1 ? names[1] : names[0];
  18837. names = names.split(/[-,_]/g)[0];
  18838. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  18839. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  18840. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  18841. var type = properties.type;
  18842. var subtype = properties.subtype;
  18843. this.type = type;
  18844. this.fallbackName = (this.isMonospace ? 'monospace' :
  18845. (this.isSerifFont ? 'serif' : 'sans-serif'));
  18846. this.differences = properties.differences;
  18847. this.widths = properties.widths;
  18848. this.defaultWidth = properties.defaultWidth;
  18849. this.composite = properties.composite;
  18850. this.wideChars = properties.wideChars;
  18851. this.cMap = properties.cMap;
  18852. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  18853. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  18854. this.fontMatrix = properties.fontMatrix;
  18855. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  18856. this.toFontChar = [];
  18857. if (properties.type === 'Type3') {
  18858. for (charCode = 0; charCode < 256; charCode++) {
  18859. this.toFontChar[charCode] = (this.differences[charCode] ||
  18860. properties.defaultEncoding[charCode]);
  18861. }
  18862. this.fontType = FontType.TYPE3;
  18863. return;
  18864. }
  18865. this.cidEncoding = properties.cidEncoding;
  18866. this.vertical = properties.vertical;
  18867. if (this.vertical) {
  18868. this.vmetrics = properties.vmetrics;
  18869. this.defaultVMetrics = properties.defaultVMetrics;
  18870. }
  18871. if (!file || file.isEmpty) {
  18872. if (file) {
  18873. // Some bad PDF generators will include empty font files,
  18874. // attempting to recover by assuming that no file exists.
  18875. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  18876. }
  18877. this.missingFile = true;
  18878. // The file data is not specified. Trying to fix the font name
  18879. // to be used with the canvas.font.
  18880. var fontName = name.replace(/[,_]/g, '-');
  18881. var isStandardFont = fontName in stdFontMap;
  18882. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  18883. this.bold = (fontName.search(/bold/gi) !== -1);
  18884. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  18885. (fontName.search(/italic/gi) !== -1));
  18886. // Use 'name' instead of 'fontName' here because the original
  18887. // name ArialBlack for example will be replaced by Helvetica.
  18888. this.black = (name.search(/Black/g) !== -1);
  18889. // if at least one width is present, remeasure all chars when exists
  18890. this.remeasure = Object.keys(this.widths).length > 0;
  18891. if (isStandardFont && type === 'CIDFontType2' &&
  18892. properties.cidEncoding.indexOf('Identity-') === 0) {
  18893. // Standard fonts might be embedded as CID font without glyph mapping.
  18894. // Building one based on GlyphMapForStandardFonts.
  18895. var map = [];
  18896. for (var code in GlyphMapForStandardFonts) {
  18897. map[+code] = GlyphMapForStandardFonts[code];
  18898. }
  18899. this.toFontChar = map;
  18900. this.toUnicode = new ToUnicodeMap(map);
  18901. } else if (/Symbol/i.test(fontName)) {
  18902. var symbols = Encodings.SymbolSetEncoding;
  18903. for (charCode in symbols) {
  18904. var fontChar = GlyphsUnicode[symbols[charCode]];
  18905. if (!fontChar) {
  18906. continue;
  18907. }
  18908. this.toFontChar[charCode] = fontChar;
  18909. }
  18910. } else if (isStandardFont) {
  18911. this.toFontChar = [];
  18912. for (charCode in properties.defaultEncoding) {
  18913. glyphName = (properties.differences[charCode] ||
  18914. properties.defaultEncoding[charCode]);
  18915. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  18916. }
  18917. } else {
  18918. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  18919. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  18920. if (notCidFont) {
  18921. glyphName = (properties.differences[charCode] ||
  18922. properties.defaultEncoding[charCode]);
  18923. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  18924. }
  18925. this.toFontChar[charCode] = unicodeCharCode;
  18926. }.bind(this));
  18927. }
  18928. this.loadedName = fontName.split('-')[0];
  18929. this.loading = false;
  18930. this.fontType = getFontType(type, subtype);
  18931. return;
  18932. }
  18933. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  18934. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  18935. // Some TrueType fonts by mistake claim Type1C
  18936. if (isTrueTypeFile(file)) {
  18937. subtype = 'TrueType';
  18938. } else {
  18939. type = 'Type1';
  18940. }
  18941. }
  18942. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  18943. type = 'CIDFontType0';
  18944. }
  18945. // XXX: Temporarily change the type for open type so we trigger a warning.
  18946. // This should be removed when we add support for open type.
  18947. if (subtype === 'OpenType') {
  18948. type = 'OpenType';
  18949. }
  18950. var data;
  18951. switch (type) {
  18952. case 'Type1':
  18953. case 'CIDFontType0':
  18954. this.mimetype = 'font/opentype';
  18955. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  18956. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  18957. adjustWidths(properties);
  18958. // Wrap the CFF data inside an OTF font file
  18959. data = this.convert(name, cff, properties);
  18960. break;
  18961. case 'OpenType':
  18962. case 'TrueType':
  18963. case 'CIDFontType2':
  18964. this.mimetype = 'font/opentype';
  18965. // Repair the TrueType file. It is can be damaged in the point of
  18966. // view of the sanitizer
  18967. data = this.checkAndRepair(name, file, properties);
  18968. if (this.isOpenType) {
  18969. type = 'OpenType';
  18970. }
  18971. break;
  18972. default:
  18973. error('Font ' + type + ' is not supported');
  18974. break;
  18975. }
  18976. this.data = data;
  18977. this.fontType = getFontType(type, subtype);
  18978. // Transfer some properties again that could change during font conversion
  18979. this.fontMatrix = properties.fontMatrix;
  18980. this.widths = properties.widths;
  18981. this.defaultWidth = properties.defaultWidth;
  18982. this.encoding = properties.baseEncoding;
  18983. this.seacMap = properties.seacMap;
  18984. this.loading = true;
  18985. }
  18986. Font.getFontID = (function () {
  18987. var ID = 1;
  18988. return function Font_getFontID() {
  18989. return String(ID++);
  18990. };
  18991. })();
  18992. function int16(b0, b1) {
  18993. return (b0 << 8) + b1;
  18994. }
  18995. function int32(b0, b1, b2, b3) {
  18996. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18997. }
  18998. function getMaxPower2(number) {
  18999. var maxPower = 0;
  19000. var value = number;
  19001. while (value >= 2) {
  19002. value /= 2;
  19003. maxPower++;
  19004. }
  19005. value = 2;
  19006. for (var i = 1; i < maxPower; i++) {
  19007. value *= 2;
  19008. }
  19009. return value;
  19010. }
  19011. function string16(value) {
  19012. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  19013. }
  19014. function safeString16(value) {
  19015. // clamp value to the 16-bit int range
  19016. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  19017. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  19018. }
  19019. function createOpenTypeHeader(sfnt, file, numTables) {
  19020. // Windows hates the Mac TrueType sfnt version number
  19021. if (sfnt === 'true') {
  19022. sfnt = string32(0x00010000);
  19023. }
  19024. // sfnt version (4 bytes)
  19025. var header = sfnt;
  19026. // numTables (2 bytes)
  19027. header += string16(numTables);
  19028. // searchRange (2 bytes)
  19029. var tablesMaxPower2 = getMaxPower2(numTables);
  19030. var searchRange = tablesMaxPower2 * 16;
  19031. header += string16(searchRange);
  19032. // entrySelector (2 bytes)
  19033. header += string16(Math.log(tablesMaxPower2) / Math.log(2));
  19034. // rangeShift (2 bytes)
  19035. header += string16(numTables * 16 - searchRange);
  19036. file.file += header;
  19037. file.virtualOffset += header.length;
  19038. }
  19039. function createTableEntry(file, tag, data) {
  19040. // offset
  19041. var offset = file.virtualOffset;
  19042. // length
  19043. var length = data.length;
  19044. // Per spec tables must be 4-bytes align so add padding as needed.
  19045. var paddedLength = length;
  19046. while (paddedLength & 3) {
  19047. paddedLength++;
  19048. }
  19049. var i;
  19050. var padding = paddedLength - length;
  19051. if (padding !== 0) {
  19052. // Padding is required. |data| can be an Array, Uint8Array, or
  19053. // Uint16Array. In the latter two cases we need to create slightly larger
  19054. // typed arrays and copy the old contents in. Fortunately that's not a
  19055. // common case.
  19056. var data2;
  19057. if (data instanceof Array) {
  19058. for (i = 0; i < padding; i++) {
  19059. data.push(0);
  19060. }
  19061. } else if (data instanceof Uint8Array) {
  19062. data2 = new Uint8Array(paddedLength);
  19063. data2.set(data);
  19064. data = data2;
  19065. } else if (data instanceof Uint16Array) {
  19066. data2 = new Uint16Array(paddedLength);
  19067. data2.set(data);
  19068. data = data2;
  19069. } else {
  19070. error('bad array kind in createTableEntry');
  19071. }
  19072. }
  19073. while (file.virtualOffset & 3) {
  19074. file.virtualOffset++;
  19075. }
  19076. // checksum
  19077. var checksum = 0, n = data.length;
  19078. for (i = 0; i < n; i += 4) {
  19079. checksum = (checksum + int32(data[i], data[i + 1], data[i + 2],
  19080. data[i + 3])) | 0;
  19081. }
  19082. var tableEntry = (tag + string32(checksum) +
  19083. string32(offset) + string32(length));
  19084. file.file += tableEntry;
  19085. file.virtualOffset += data.length;
  19086. return data;
  19087. }
  19088. function isTrueTypeFile(file) {
  19089. var header = file.peekBytes(4);
  19090. return readUint32(header, 0) === 0x00010000;
  19091. }
  19092. /**
  19093. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  19094. * with their unicode value. It also moves char codes that are in known
  19095. * problematic locations.
  19096. * @return {Object} Two properties:
  19097. * 'toFontChar' - maps original char codes(the value that will be read
  19098. * from commands such as show text) to the char codes that will be used in the
  19099. * font that we build
  19100. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  19101. */
  19102. function adjustMapping(charCodeToGlyphId, properties) {
  19103. var toUnicode = properties.toUnicode;
  19104. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  19105. var isIdentityUnicode =
  19106. properties.toUnicode instanceof IdentityToUnicodeMap;
  19107. var isCidFontType2 = (properties.type === 'CIDFontType2');
  19108. var newMap = Object.create(null);
  19109. var toFontChar = [];
  19110. var usedFontCharCodes = [];
  19111. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  19112. for (var originalCharCode in charCodeToGlyphId) {
  19113. originalCharCode |= 0;
  19114. var glyphId = charCodeToGlyphId[originalCharCode];
  19115. var fontCharCode = originalCharCode;
  19116. // First try to map the value to a unicode position if a non identity map
  19117. // was created.
  19118. if (!isIdentityUnicode) {
  19119. if (toUnicode.get(originalCharCode) !== undefined) {
  19120. var unicode = toUnicode.get(fontCharCode);
  19121. // TODO: Try to map ligatures to the correct spot.
  19122. if (unicode.length === 1) {
  19123. fontCharCode = unicode.charCodeAt(0);
  19124. }
  19125. } else if (isCidFontType2) {
  19126. // For CIDFontType2, move characters not present in toUnicode
  19127. // to the private use area (fixes bug 1028735 and issue 4881).
  19128. fontCharCode = nextAvailableFontCharCode;
  19129. }
  19130. }
  19131. // Try to move control characters, special characters and already mapped
  19132. // characters to the private use area since they will not be drawn by
  19133. // canvas if left in their current position. Also, move characters if the
  19134. // font was symbolic and there is only an identity unicode map since the
  19135. // characters probably aren't in the correct position (fixes an issue
  19136. // with firefox and thuluthfont).
  19137. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  19138. fontCharCode <= 0x1f || // Control chars
  19139. fontCharCode === 0x7F || // Control char
  19140. fontCharCode === 0xAD || // Soft hyphen
  19141. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  19142. // Prevent drawing characters in the specials unicode block.
  19143. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  19144. (isSymbolic && isIdentityUnicode)) &&
  19145. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  19146. // Loop to try and find a free spot in the private use area.
  19147. do {
  19148. fontCharCode = nextAvailableFontCharCode++;
  19149. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  19150. fontCharCode = 0xF020;
  19151. nextAvailableFontCharCode = fontCharCode + 1;
  19152. }
  19153. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  19154. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  19155. }
  19156. newMap[fontCharCode] = glyphId;
  19157. toFontChar[originalCharCode] = fontCharCode;
  19158. usedFontCharCodes[fontCharCode] = true;
  19159. }
  19160. return {
  19161. toFontChar: toFontChar,
  19162. charCodeToGlyphId: newMap,
  19163. nextAvailableFontCharCode: nextAvailableFontCharCode
  19164. };
  19165. }
  19166. function getRanges(glyphs) {
  19167. // Array.sort() sorts by characters, not numerically, so convert to an
  19168. // array of characters.
  19169. var codes = [];
  19170. for (var charCode in glyphs) {
  19171. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  19172. }
  19173. codes.sort(function fontGetRangesSort(a, b) {
  19174. return a.fontCharCode - b.fontCharCode;
  19175. });
  19176. // Split the sorted codes into ranges.
  19177. var ranges = [];
  19178. var length = codes.length;
  19179. for (var n = 0; n < length; ) {
  19180. var start = codes[n].fontCharCode;
  19181. var codeIndices = [codes[n].glyphId];
  19182. ++n;
  19183. var end = start;
  19184. while (n < length && end + 1 === codes[n].fontCharCode) {
  19185. codeIndices.push(codes[n].glyphId);
  19186. ++end;
  19187. ++n;
  19188. if (end === 0xFFFF) {
  19189. break;
  19190. }
  19191. }
  19192. ranges.push([start, end, codeIndices]);
  19193. }
  19194. return ranges;
  19195. }
  19196. function createCmapTable(glyphs) {
  19197. var ranges = getRanges(glyphs);
  19198. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  19199. var cmap = '\x00\x00' + // version
  19200. string16(numTables) + // numTables
  19201. '\x00\x03' + // platformID
  19202. '\x00\x01' + // encodingID
  19203. string32(4 + numTables * 8); // start of the table record
  19204. var i, ii, j, jj;
  19205. for (i = ranges.length - 1; i >= 0; --i) {
  19206. if (ranges[i][0] <= 0xFFFF) { break; }
  19207. }
  19208. var bmpLength = i + 1;
  19209. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  19210. ranges[i][1] = 0xFFFE;
  19211. }
  19212. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  19213. var segCount = bmpLength + trailingRangesCount;
  19214. var segCount2 = segCount * 2;
  19215. var searchRange = getMaxPower2(segCount) * 2;
  19216. var searchEntry = Math.log(segCount) / Math.log(2);
  19217. var rangeShift = 2 * segCount - searchRange;
  19218. // Fill up the 4 parallel arrays describing the segments.
  19219. var startCount = '';
  19220. var endCount = '';
  19221. var idDeltas = '';
  19222. var idRangeOffsets = '';
  19223. var glyphsIds = '';
  19224. var bias = 0;
  19225. var range, start, end, codes;
  19226. for (i = 0, ii = bmpLength; i < ii; i++) {
  19227. range = ranges[i];
  19228. start = range[0];
  19229. end = range[1];
  19230. startCount += string16(start);
  19231. endCount += string16(end);
  19232. codes = range[2];
  19233. var contiguous = true;
  19234. for (j = 1, jj = codes.length; j < jj; ++j) {
  19235. if (codes[j] !== codes[j - 1] + 1) {
  19236. contiguous = false;
  19237. break;
  19238. }
  19239. }
  19240. if (!contiguous) {
  19241. var offset = (segCount - i) * 2 + bias * 2;
  19242. bias += (end - start + 1);
  19243. idDeltas += string16(0);
  19244. idRangeOffsets += string16(offset);
  19245. for (j = 0, jj = codes.length; j < jj; ++j) {
  19246. glyphsIds += string16(codes[j]);
  19247. }
  19248. } else {
  19249. var startCode = codes[0];
  19250. idDeltas += string16((startCode - start) & 0xFFFF);
  19251. idRangeOffsets += string16(0);
  19252. }
  19253. }
  19254. if (trailingRangesCount > 0) {
  19255. endCount += '\xFF\xFF';
  19256. startCount += '\xFF\xFF';
  19257. idDeltas += '\x00\x01';
  19258. idRangeOffsets += '\x00\x00';
  19259. }
  19260. var format314 = '\x00\x00' + // language
  19261. string16(segCount2) +
  19262. string16(searchRange) +
  19263. string16(searchEntry) +
  19264. string16(rangeShift) +
  19265. endCount + '\x00\x00' + startCount +
  19266. idDeltas + idRangeOffsets + glyphsIds;
  19267. var format31012 = '';
  19268. var header31012 = '';
  19269. if (numTables > 1) {
  19270. cmap += '\x00\x03' + // platformID
  19271. '\x00\x0A' + // encodingID
  19272. string32(4 + numTables * 8 +
  19273. 4 + format314.length); // start of the table record
  19274. format31012 = '';
  19275. for (i = 0, ii = ranges.length; i < ii; i++) {
  19276. range = ranges[i];
  19277. start = range[0];
  19278. codes = range[2];
  19279. var code = codes[0];
  19280. for (j = 1, jj = codes.length; j < jj; ++j) {
  19281. if (codes[j] !== codes[j - 1] + 1) {
  19282. end = range[0] + j - 1;
  19283. format31012 += string32(start) + // startCharCode
  19284. string32(end) + // endCharCode
  19285. string32(code); // startGlyphID
  19286. start = end + 1;
  19287. code = codes[j];
  19288. }
  19289. }
  19290. format31012 += string32(start) + // startCharCode
  19291. string32(range[1]) + // endCharCode
  19292. string32(code); // startGlyphID
  19293. }
  19294. header31012 = '\x00\x0C' + // format
  19295. '\x00\x00' + // reserved
  19296. string32(format31012.length + 16) + // length
  19297. '\x00\x00\x00\x00' + // language
  19298. string32(format31012.length / 12); // nGroups
  19299. }
  19300. return stringToArray(cmap +
  19301. '\x00\x04' + // format
  19302. string16(format314.length + 4) + // length
  19303. format314 + header31012 + format31012);
  19304. }
  19305. function validateOS2Table(os2) {
  19306. var stream = new Stream(os2.data);
  19307. var version = stream.getUint16();
  19308. // TODO verify all OS/2 tables fields, but currently we validate only those
  19309. // that give us issues
  19310. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  19311. var selection = stream.getUint16();
  19312. if (version < 4 && (selection & 0x0300)) {
  19313. return false;
  19314. }
  19315. var firstChar = stream.getUint16();
  19316. var lastChar = stream.getUint16();
  19317. if (firstChar > lastChar) {
  19318. return false;
  19319. }
  19320. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  19321. var usWinAscent = stream.getUint16();
  19322. if (usWinAscent === 0) { // makes font unreadable by windows
  19323. return false;
  19324. }
  19325. // OS/2 appears to be valid, resetting some fields
  19326. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  19327. return true;
  19328. }
  19329. function createOS2Table(properties, charstrings, override) {
  19330. override = override || {
  19331. unitsPerEm: 0,
  19332. yMax: 0,
  19333. yMin: 0,
  19334. ascent: 0,
  19335. descent: 0
  19336. };
  19337. var ulUnicodeRange1 = 0;
  19338. var ulUnicodeRange2 = 0;
  19339. var ulUnicodeRange3 = 0;
  19340. var ulUnicodeRange4 = 0;
  19341. var firstCharIndex = null;
  19342. var lastCharIndex = 0;
  19343. if (charstrings) {
  19344. for (var code in charstrings) {
  19345. code |= 0;
  19346. if (firstCharIndex > code || !firstCharIndex) {
  19347. firstCharIndex = code;
  19348. }
  19349. if (lastCharIndex < code) {
  19350. lastCharIndex = code;
  19351. }
  19352. var position = getUnicodeRangeFor(code);
  19353. if (position < 32) {
  19354. ulUnicodeRange1 |= 1 << position;
  19355. } else if (position < 64) {
  19356. ulUnicodeRange2 |= 1 << position - 32;
  19357. } else if (position < 96) {
  19358. ulUnicodeRange3 |= 1 << position - 64;
  19359. } else if (position < 123) {
  19360. ulUnicodeRange4 |= 1 << position - 96;
  19361. } else {
  19362. error('Unicode ranges Bits > 123 are reserved for internal usage');
  19363. }
  19364. }
  19365. } else {
  19366. // TODO
  19367. firstCharIndex = 0;
  19368. lastCharIndex = 255;
  19369. }
  19370. var bbox = properties.bbox || [0, 0, 0, 0];
  19371. var unitsPerEm = (override.unitsPerEm ||
  19372. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  19373. // if the font units differ to the PDF glyph space units
  19374. // then scale up the values
  19375. var scale = (properties.ascentScaled ? 1.0 :
  19376. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  19377. var typoAscent = (override.ascent ||
  19378. Math.round(scale * (properties.ascent || bbox[3])));
  19379. var typoDescent = (override.descent ||
  19380. Math.round(scale * (properties.descent || bbox[1])));
  19381. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  19382. typoDescent = -typoDescent; // fixing incorrect descent
  19383. }
  19384. var winAscent = override.yMax || typoAscent;
  19385. var winDescent = -override.yMin || -typoDescent;
  19386. return '\x00\x03' + // version
  19387. '\x02\x24' + // xAvgCharWidth
  19388. '\x01\xF4' + // usWeightClass
  19389. '\x00\x05' + // usWidthClass
  19390. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  19391. '\x02\x8A' + // ySubscriptXSize
  19392. '\x02\xBB' + // ySubscriptYSize
  19393. '\x00\x00' + // ySubscriptXOffset
  19394. '\x00\x8C' + // ySubscriptYOffset
  19395. '\x02\x8A' + // ySuperScriptXSize
  19396. '\x02\xBB' + // ySuperScriptYSize
  19397. '\x00\x00' + // ySuperScriptXOffset
  19398. '\x01\xDF' + // ySuperScriptYOffset
  19399. '\x00\x31' + // yStrikeOutSize
  19400. '\x01\x02' + // yStrikeOutPosition
  19401. '\x00\x00' + // sFamilyClass
  19402. '\x00\x00\x06' +
  19403. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  19404. '\x00\x00\x00\x00\x00\x00' + // Panose
  19405. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  19406. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  19407. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  19408. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  19409. '\x2A\x32\x31\x2A' + // achVendID
  19410. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  19411. string16(firstCharIndex ||
  19412. properties.firstChar) + // usFirstCharIndex
  19413. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  19414. string16(typoAscent) + // sTypoAscender
  19415. string16(typoDescent) + // sTypoDescender
  19416. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  19417. string16(winAscent) + // usWinAscent
  19418. string16(winDescent) + // usWinDescent
  19419. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  19420. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  19421. string16(properties.xHeight) + // sxHeight
  19422. string16(properties.capHeight) + // sCapHeight
  19423. string16(0) + // usDefaultChar
  19424. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  19425. '\x00\x03'; // usMaxContext
  19426. }
  19427. function createPostTable(properties) {
  19428. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  19429. return ('\x00\x03\x00\x00' + // Version number
  19430. string32(angle) + // italicAngle
  19431. '\x00\x00' + // underlinePosition
  19432. '\x00\x00' + // underlineThickness
  19433. string32(properties.fixedPitch) + // isFixedPitch
  19434. '\x00\x00\x00\x00' + // minMemType42
  19435. '\x00\x00\x00\x00' + // maxMemType42
  19436. '\x00\x00\x00\x00' + // minMemType1
  19437. '\x00\x00\x00\x00'); // maxMemType1
  19438. }
  19439. function createNameTable(name, proto) {
  19440. if (!proto) {
  19441. proto = [[], []]; // no strings and unicode strings
  19442. }
  19443. var strings = [
  19444. proto[0][0] || 'Original licence', // 0.Copyright
  19445. proto[0][1] || name, // 1.Font family
  19446. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  19447. proto[0][3] || 'uniqueID', // 3.Unique ID
  19448. proto[0][4] || name, // 4.Full font name
  19449. proto[0][5] || 'Version 0.11', // 5.Version
  19450. proto[0][6] || '', // 6.Postscript name
  19451. proto[0][7] || 'Unknown', // 7.Trademark
  19452. proto[0][8] || 'Unknown', // 8.Manufacturer
  19453. proto[0][9] || 'Unknown' // 9.Designer
  19454. ];
  19455. // Mac want 1-byte per character strings while Windows want
  19456. // 2-bytes per character, so duplicate the names table
  19457. var stringsUnicode = [];
  19458. var i, ii, j, jj, str;
  19459. for (i = 0, ii = strings.length; i < ii; i++) {
  19460. str = proto[1][i] || strings[i];
  19461. var strBufUnicode = [];
  19462. for (j = 0, jj = str.length; j < jj; j++) {
  19463. strBufUnicode.push(string16(str.charCodeAt(j)));
  19464. }
  19465. stringsUnicode.push(strBufUnicode.join(''));
  19466. }
  19467. var names = [strings, stringsUnicode];
  19468. var platforms = ['\x00\x01', '\x00\x03'];
  19469. var encodings = ['\x00\x00', '\x00\x01'];
  19470. var languages = ['\x00\x00', '\x04\x09'];
  19471. var namesRecordCount = strings.length * platforms.length;
  19472. var nameTable =
  19473. '\x00\x00' + // format
  19474. string16(namesRecordCount) + // Number of names Record
  19475. string16(namesRecordCount * 12 + 6); // Storage
  19476. // Build the name records field
  19477. var strOffset = 0;
  19478. for (i = 0, ii = platforms.length; i < ii; i++) {
  19479. var strs = names[i];
  19480. for (j = 0, jj = strs.length; j < jj; j++) {
  19481. str = strs[j];
  19482. var nameRecord =
  19483. platforms[i] + // platform ID
  19484. encodings[i] + // encoding ID
  19485. languages[i] + // language ID
  19486. string16(j) + // name ID
  19487. string16(str.length) +
  19488. string16(strOffset);
  19489. nameTable += nameRecord;
  19490. strOffset += str.length;
  19491. }
  19492. }
  19493. nameTable += strings.join('') + stringsUnicode.join('');
  19494. return nameTable;
  19495. }
  19496. Font.prototype = {
  19497. name: null,
  19498. font: null,
  19499. mimetype: null,
  19500. encoding: null,
  19501. get renderer() {
  19502. var renderer = FontRendererFactory.create(this);
  19503. return shadow(this, 'renderer', renderer);
  19504. },
  19505. exportData: function Font_exportData() {
  19506. var data = {};
  19507. for (var i in this) {
  19508. if (this.hasOwnProperty(i)) {
  19509. data[i] = this[i];
  19510. }
  19511. }
  19512. return data;
  19513. },
  19514. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  19515. function readTableEntry(file) {
  19516. var tag = bytesToString(file.getBytes(4));
  19517. var checksum = file.getInt32();
  19518. var offset = file.getInt32() >>> 0;
  19519. var length = file.getInt32() >>> 0;
  19520. // Read the table associated data
  19521. var previousPosition = file.pos;
  19522. file.pos = file.start ? file.start : 0;
  19523. file.skip(offset);
  19524. var data = file.getBytes(length);
  19525. file.pos = previousPosition;
  19526. if (tag === 'head') {
  19527. // clearing checksum adjustment
  19528. data[8] = data[9] = data[10] = data[11] = 0;
  19529. data[17] |= 0x20; //Set font optimized for cleartype flag
  19530. }
  19531. return {
  19532. tag: tag,
  19533. checksum: checksum,
  19534. length: length,
  19535. offset: offset,
  19536. data: data
  19537. };
  19538. }
  19539. function readOpenTypeHeader(ttf) {
  19540. return {
  19541. version: bytesToString(ttf.getBytes(4)),
  19542. numTables: ttf.getUint16(),
  19543. searchRange: ttf.getUint16(),
  19544. entrySelector: ttf.getUint16(),
  19545. rangeShift: ttf.getUint16()
  19546. };
  19547. }
  19548. /**
  19549. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  19550. * PDF spec
  19551. */
  19552. function readCmapTable(cmap, font, isSymbolicFont) {
  19553. var segment;
  19554. var start = (font.start ? font.start : 0) + cmap.offset;
  19555. font.pos = start;
  19556. var version = font.getUint16();
  19557. var numTables = font.getUint16();
  19558. var potentialTable;
  19559. var canBreak = false;
  19560. // There's an order of preference in terms of which cmap subtable to
  19561. // use:
  19562. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  19563. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  19564. // The following takes advantage of the fact that the tables are sorted
  19565. // to work.
  19566. for (var i = 0; i < numTables; i++) {
  19567. var platformId = font.getUint16();
  19568. var encodingId = font.getUint16();
  19569. var offset = font.getInt32() >>> 0;
  19570. var useTable = false;
  19571. if (platformId === 1 && encodingId === 0) {
  19572. useTable = true;
  19573. // Continue the loop since there still may be a higher priority
  19574. // table.
  19575. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  19576. useTable = true;
  19577. canBreak = true;
  19578. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  19579. useTable = true;
  19580. canBreak = true;
  19581. }
  19582. if (useTable) {
  19583. potentialTable = {
  19584. platformId: platformId,
  19585. encodingId: encodingId,
  19586. offset: offset
  19587. };
  19588. }
  19589. if (canBreak) {
  19590. break;
  19591. }
  19592. }
  19593. if (!potentialTable) {
  19594. warn('Could not find a preferred cmap table.');
  19595. return {
  19596. platformId: -1,
  19597. encodingId: -1,
  19598. mappings: [],
  19599. hasShortCmap: false
  19600. };
  19601. }
  19602. font.pos = start + potentialTable.offset;
  19603. var format = font.getUint16();
  19604. var length = font.getUint16();
  19605. var language = font.getUint16();
  19606. var hasShortCmap = false;
  19607. var mappings = [];
  19608. var j, glyphId;
  19609. // TODO(mack): refactor this cmap subtable reading logic out
  19610. if (format === 0) {
  19611. for (j = 0; j < 256; j++) {
  19612. var index = font.getByte();
  19613. if (!index) {
  19614. continue;
  19615. }
  19616. mappings.push({
  19617. charCode: j,
  19618. glyphId: index
  19619. });
  19620. }
  19621. hasShortCmap = true;
  19622. } else if (format === 4) {
  19623. // re-creating the table in format 4 since the encoding
  19624. // might be changed
  19625. var segCount = (font.getUint16() >> 1);
  19626. font.getBytes(6); // skipping range fields
  19627. var segIndex, segments = [];
  19628. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19629. segments.push({ end: font.getUint16() });
  19630. }
  19631. font.getUint16();
  19632. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19633. segments[segIndex].start = font.getUint16();
  19634. }
  19635. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19636. segments[segIndex].delta = font.getUint16();
  19637. }
  19638. var offsetsCount = 0;
  19639. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19640. segment = segments[segIndex];
  19641. var rangeOffset = font.getUint16();
  19642. if (!rangeOffset) {
  19643. segment.offsetIndex = -1;
  19644. continue;
  19645. }
  19646. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  19647. segment.offsetIndex = offsetIndex;
  19648. offsetsCount = Math.max(offsetsCount, offsetIndex +
  19649. segment.end - segment.start + 1);
  19650. }
  19651. var offsets = [];
  19652. for (j = 0; j < offsetsCount; j++) {
  19653. offsets.push(font.getUint16());
  19654. }
  19655. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19656. segment = segments[segIndex];
  19657. start = segment.start;
  19658. var end = segment.end;
  19659. var delta = segment.delta;
  19660. offsetIndex = segment.offsetIndex;
  19661. for (j = start; j <= end; j++) {
  19662. if (j === 0xFFFF) {
  19663. continue;
  19664. }
  19665. glyphId = (offsetIndex < 0 ?
  19666. j : offsets[offsetIndex + j - start]);
  19667. glyphId = (glyphId + delta) & 0xFFFF;
  19668. if (glyphId === 0) {
  19669. continue;
  19670. }
  19671. mappings.push({
  19672. charCode: j,
  19673. glyphId: glyphId
  19674. });
  19675. }
  19676. }
  19677. } else if (format === 6) {
  19678. // Format 6 is a 2-bytes dense mapping, which means the font data
  19679. // lives glue together even if they are pretty far in the unicode
  19680. // table. (This looks weird, so I can have missed something), this
  19681. // works on Linux but seems to fails on Mac so let's rewrite the
  19682. // cmap table to a 3-1-4 style
  19683. var firstCode = font.getUint16();
  19684. var entryCount = font.getUint16();
  19685. for (j = 0; j < entryCount; j++) {
  19686. glyphId = font.getUint16();
  19687. var charCode = firstCode + j;
  19688. mappings.push({
  19689. charCode: charCode,
  19690. glyphId: glyphId
  19691. });
  19692. }
  19693. } else {
  19694. error('cmap table has unsupported format: ' + format);
  19695. }
  19696. // removing duplicate entries
  19697. mappings.sort(function (a, b) {
  19698. return a.charCode - b.charCode;
  19699. });
  19700. for (i = 1; i < mappings.length; i++) {
  19701. if (mappings[i - 1].charCode === mappings[i].charCode) {
  19702. mappings.splice(i, 1);
  19703. i--;
  19704. }
  19705. }
  19706. return {
  19707. platformId: potentialTable.platformId,
  19708. encodingId: potentialTable.encodingId,
  19709. mappings: mappings,
  19710. hasShortCmap: hasShortCmap
  19711. };
  19712. }
  19713. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  19714. if (!header) {
  19715. if (metrics) {
  19716. metrics.data = null;
  19717. }
  19718. return;
  19719. }
  19720. font.pos = (font.start ? font.start : 0) + header.offset;
  19721. font.pos += header.length - 2;
  19722. var numOfMetrics = font.getUint16();
  19723. if (numOfMetrics > numGlyphs) {
  19724. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  19725. 'greater than the numGlyphs (' + numGlyphs + ')');
  19726. // Reduce numOfMetrics if it is greater than numGlyphs
  19727. numOfMetrics = numGlyphs;
  19728. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  19729. header.data[35] = numOfMetrics & 0x00ff;
  19730. }
  19731. var numOfSidebearings = numGlyphs - numOfMetrics;
  19732. var numMissing = numOfSidebearings -
  19733. ((metrics.length - numOfMetrics * 4) >> 1);
  19734. var i, ii;
  19735. if (numMissing > 0) {
  19736. font.pos = (font.start ? font.start : 0) + metrics.offset;
  19737. var entries = '';
  19738. for (i = 0, ii = metrics.length; i < ii; i++) {
  19739. entries += String.fromCharCode(font.getByte());
  19740. }
  19741. for (i = 0; i < numMissing; i++) {
  19742. entries += '\x00\x00';
  19743. }
  19744. metrics.data = stringToArray(entries);
  19745. }
  19746. }
  19747. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  19748. hintsValid) {
  19749. if (sourceEnd - sourceStart <= 12) {
  19750. // glyph with data less than 12 is invalid one
  19751. return 0;
  19752. }
  19753. var glyf = source.subarray(sourceStart, sourceEnd);
  19754. var contoursCount = (glyf[0] << 8) | glyf[1];
  19755. if (contoursCount & 0x8000) {
  19756. // complex glyph, writing as is
  19757. dest.set(glyf, destStart);
  19758. return glyf.length;
  19759. }
  19760. var i, j = 10, flagsCount = 0;
  19761. for (i = 0; i < contoursCount; i++) {
  19762. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  19763. flagsCount = endPoint + 1;
  19764. j += 2;
  19765. }
  19766. // skipping instructions
  19767. var instructionsStart = j;
  19768. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  19769. j += 2 + instructionsLength;
  19770. var instructionsEnd = j;
  19771. // validating flags
  19772. var coordinatesLength = 0;
  19773. for (i = 0; i < flagsCount; i++) {
  19774. var flag = glyf[j++];
  19775. if (flag & 0xC0) {
  19776. // reserved flags must be zero, cleaning up
  19777. glyf[j - 1] = flag & 0x3F;
  19778. }
  19779. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  19780. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  19781. coordinatesLength += xyLength;
  19782. if (flag & 8) {
  19783. var repeat = glyf[j++];
  19784. i += repeat;
  19785. coordinatesLength += repeat * xyLength;
  19786. }
  19787. }
  19788. // glyph without coordinates will be rejected
  19789. if (coordinatesLength === 0) {
  19790. return 0;
  19791. }
  19792. var glyphDataLength = j + coordinatesLength;
  19793. if (glyphDataLength > glyf.length) {
  19794. // not enough data for coordinates
  19795. return 0;
  19796. }
  19797. if (!hintsValid && instructionsLength > 0) {
  19798. dest.set(glyf.subarray(0, instructionsStart), destStart);
  19799. dest.set([0, 0], destStart + instructionsStart);
  19800. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  19801. destStart + instructionsStart + 2);
  19802. glyphDataLength -= instructionsLength;
  19803. if (glyf.length - glyphDataLength > 3) {
  19804. glyphDataLength = (glyphDataLength + 3) & ~3;
  19805. }
  19806. return glyphDataLength;
  19807. }
  19808. if (glyf.length - glyphDataLength > 3) {
  19809. // truncating and aligning to 4 bytes the long glyph data
  19810. glyphDataLength = (glyphDataLength + 3) & ~3;
  19811. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  19812. return glyphDataLength;
  19813. }
  19814. // glyph data is fine
  19815. dest.set(glyf, destStart);
  19816. return glyf.length;
  19817. }
  19818. function sanitizeHead(head, numGlyphs, locaLength) {
  19819. var data = head.data;
  19820. // Validate version:
  19821. // Should always be 0x00010000
  19822. var version = int32(data[0], data[1], data[2], data[3]);
  19823. if (version >> 16 !== 1) {
  19824. info('Attempting to fix invalid version in head table: ' + version);
  19825. data[0] = 0;
  19826. data[1] = 1;
  19827. data[2] = 0;
  19828. data[3] = 0;
  19829. }
  19830. var indexToLocFormat = int16(data[50], data[51]);
  19831. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  19832. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  19833. indexToLocFormat);
  19834. // The value of indexToLocFormat should be 0 if the loca table
  19835. // consists of short offsets, and should be 1 if the loca table
  19836. // consists of long offsets.
  19837. //
  19838. // The number of entries in the loca table should be numGlyphs + 1.
  19839. //
  19840. // Using this information, we can work backwards to deduce if the
  19841. // size of each offset in the loca table, and thus figure out the
  19842. // appropriate value for indexToLocFormat.
  19843. var numGlyphsPlusOne = numGlyphs + 1;
  19844. if (locaLength === numGlyphsPlusOne << 1) {
  19845. // 0x0000 indicates the loca table consists of short offsets
  19846. data[50] = 0;
  19847. data[51] = 0;
  19848. } else if (locaLength === numGlyphsPlusOne << 2) {
  19849. // 0x0001 indicates the loca table consists of long offsets
  19850. data[50] = 0;
  19851. data[51] = 1;
  19852. } else {
  19853. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  19854. }
  19855. }
  19856. }
  19857. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  19858. isGlyphLocationsLong, hintsValid,
  19859. dupFirstEntry) {
  19860. var itemSize, itemDecode, itemEncode;
  19861. if (isGlyphLocationsLong) {
  19862. itemSize = 4;
  19863. itemDecode = function fontItemDecodeLong(data, offset) {
  19864. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19865. (data[offset + 2] << 8) | data[offset + 3];
  19866. };
  19867. itemEncode = function fontItemEncodeLong(data, offset, value) {
  19868. data[offset] = (value >>> 24) & 0xFF;
  19869. data[offset + 1] = (value >> 16) & 0xFF;
  19870. data[offset + 2] = (value >> 8) & 0xFF;
  19871. data[offset + 3] = value & 0xFF;
  19872. };
  19873. } else {
  19874. itemSize = 2;
  19875. itemDecode = function fontItemDecode(data, offset) {
  19876. return (data[offset] << 9) | (data[offset + 1] << 1);
  19877. };
  19878. itemEncode = function fontItemEncode(data, offset, value) {
  19879. data[offset] = (value >> 9) & 0xFF;
  19880. data[offset + 1] = (value >> 1) & 0xFF;
  19881. };
  19882. }
  19883. var locaData = loca.data;
  19884. var locaDataSize = itemSize * (1 + numGlyphs);
  19885. // is loca.data too short or long?
  19886. if (locaData.length !== locaDataSize) {
  19887. locaData = new Uint8Array(locaDataSize);
  19888. locaData.set(loca.data.subarray(0, locaDataSize));
  19889. loca.data = locaData;
  19890. }
  19891. // removing the invalid glyphs
  19892. var oldGlyfData = glyf.data;
  19893. var oldGlyfDataLength = oldGlyfData.length;
  19894. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  19895. var startOffset = itemDecode(locaData, 0);
  19896. var writeOffset = 0;
  19897. itemEncode(locaData, 0, writeOffset);
  19898. var i, j;
  19899. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19900. var endOffset = itemDecode(locaData, j);
  19901. if (endOffset > oldGlyfDataLength &&
  19902. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  19903. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  19904. // the glyf table size, which makes last glyph out of range.
  19905. endOffset = oldGlyfDataLength;
  19906. }
  19907. if (endOffset > oldGlyfDataLength) {
  19908. // glyph end offset points outside glyf data, rejecting the glyph
  19909. itemEncode(locaData, j, writeOffset);
  19910. startOffset = endOffset;
  19911. continue;
  19912. }
  19913. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  19914. newGlyfData, writeOffset, hintsValid);
  19915. writeOffset += newLength;
  19916. itemEncode(locaData, j, writeOffset);
  19917. startOffset = endOffset;
  19918. }
  19919. if (writeOffset === 0) {
  19920. // glyf table cannot be empty -- redoing the glyf and loca tables
  19921. // to have single glyph with one point
  19922. var simpleGlyph = new Uint8Array(
  19923. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  19924. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19925. itemEncode(locaData, j, simpleGlyph.length);
  19926. }
  19927. glyf.data = simpleGlyph;
  19928. return;
  19929. }
  19930. if (dupFirstEntry) {
  19931. var firstEntryLength = itemDecode(locaData, itemSize);
  19932. if (newGlyfData.length > firstEntryLength + writeOffset) {
  19933. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  19934. } else {
  19935. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  19936. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  19937. }
  19938. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  19939. itemEncode(loca.data, locaData.length - itemSize,
  19940. writeOffset + firstEntryLength);
  19941. } else {
  19942. glyf.data = newGlyfData.subarray(0, writeOffset);
  19943. }
  19944. }
  19945. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  19946. var start = (font.start ? font.start : 0) + post.offset;
  19947. font.pos = start;
  19948. var length = post.length, end = start + length;
  19949. var version = font.getInt32();
  19950. // skip rest to the tables
  19951. font.getBytes(28);
  19952. var glyphNames;
  19953. var valid = true;
  19954. var i;
  19955. switch (version) {
  19956. case 0x00010000:
  19957. glyphNames = MacStandardGlyphOrdering;
  19958. break;
  19959. case 0x00020000:
  19960. var numGlyphs = font.getUint16();
  19961. if (numGlyphs !== maxpNumGlyphs) {
  19962. valid = false;
  19963. break;
  19964. }
  19965. var glyphNameIndexes = [];
  19966. for (i = 0; i < numGlyphs; ++i) {
  19967. var index = font.getUint16();
  19968. if (index >= 32768) {
  19969. valid = false;
  19970. break;
  19971. }
  19972. glyphNameIndexes.push(index);
  19973. }
  19974. if (!valid) {
  19975. break;
  19976. }
  19977. var customNames = [];
  19978. var strBuf = [];
  19979. while (font.pos < end) {
  19980. var stringLength = font.getByte();
  19981. strBuf.length = stringLength;
  19982. for (i = 0; i < stringLength; ++i) {
  19983. strBuf[i] = String.fromCharCode(font.getByte());
  19984. }
  19985. customNames.push(strBuf.join(''));
  19986. }
  19987. glyphNames = [];
  19988. for (i = 0; i < numGlyphs; ++i) {
  19989. var j = glyphNameIndexes[i];
  19990. if (j < 258) {
  19991. glyphNames.push(MacStandardGlyphOrdering[j]);
  19992. continue;
  19993. }
  19994. glyphNames.push(customNames[j - 258]);
  19995. }
  19996. break;
  19997. case 0x00030000:
  19998. break;
  19999. default:
  20000. warn('Unknown/unsupported post table version ' + version);
  20001. valid = false;
  20002. break;
  20003. }
  20004. properties.glyphNames = glyphNames;
  20005. return valid;
  20006. }
  20007. function readNameTable(nameTable) {
  20008. var start = (font.start ? font.start : 0) + nameTable.offset;
  20009. font.pos = start;
  20010. var names = [[], []];
  20011. var length = nameTable.length, end = start + length;
  20012. var format = font.getUint16();
  20013. var FORMAT_0_HEADER_LENGTH = 6;
  20014. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  20015. // unsupported name table format or table "too" small
  20016. return names;
  20017. }
  20018. var numRecords = font.getUint16();
  20019. var stringsStart = font.getUint16();
  20020. var records = [];
  20021. var NAME_RECORD_LENGTH = 12;
  20022. var i, ii;
  20023. for (i = 0; i < numRecords &&
  20024. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  20025. var r = {
  20026. platform: font.getUint16(),
  20027. encoding: font.getUint16(),
  20028. language: font.getUint16(),
  20029. name: font.getUint16(),
  20030. length: font.getUint16(),
  20031. offset: font.getUint16()
  20032. };
  20033. // using only Macintosh and Windows platform/encoding names
  20034. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  20035. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  20036. records.push(r);
  20037. }
  20038. }
  20039. for (i = 0, ii = records.length; i < ii; i++) {
  20040. var record = records[i];
  20041. var pos = start + stringsStart + record.offset;
  20042. if (pos + record.length > end) {
  20043. continue; // outside of name table, ignoring
  20044. }
  20045. font.pos = pos;
  20046. var nameIndex = record.name;
  20047. if (record.encoding) {
  20048. // unicode
  20049. var str = '';
  20050. for (var j = 0, jj = record.length; j < jj; j += 2) {
  20051. str += String.fromCharCode(font.getUint16());
  20052. }
  20053. names[1][nameIndex] = str;
  20054. } else {
  20055. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  20056. }
  20057. }
  20058. return names;
  20059. }
  20060. var TTOpsStackDeltas = [
  20061. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  20062. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  20063. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  20064. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  20065. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  20066. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  20067. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  20068. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  20069. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  20070. // 0xC0-DF == -1 and 0xE0-FF == -2
  20071. function sanitizeTTProgram(table, ttContext) {
  20072. var data = table.data;
  20073. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  20074. var stack = [];
  20075. var callstack = [];
  20076. var functionsCalled = [];
  20077. var tooComplexToFollowFunctions =
  20078. ttContext.tooComplexToFollowFunctions;
  20079. var inFDEF = false, ifLevel = 0, inELSE = 0;
  20080. for (var ii = data.length; i < ii;) {
  20081. var op = data[i++];
  20082. // The TrueType instruction set docs can be found at
  20083. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  20084. if (op === 0x40) { // NPUSHB - pushes n bytes
  20085. n = data[i++];
  20086. if (inFDEF || inELSE) {
  20087. i += n;
  20088. } else {
  20089. for (j = 0; j < n; j++) {
  20090. stack.push(data[i++]);
  20091. }
  20092. }
  20093. } else if (op === 0x41) { // NPUSHW - pushes n words
  20094. n = data[i++];
  20095. if (inFDEF || inELSE) {
  20096. i += n * 2;
  20097. } else {
  20098. for (j = 0; j < n; j++) {
  20099. b = data[i++];
  20100. stack.push((b << 8) | data[i++]);
  20101. }
  20102. }
  20103. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  20104. n = op - 0xB0 + 1;
  20105. if (inFDEF || inELSE) {
  20106. i += n;
  20107. } else {
  20108. for (j = 0; j < n; j++) {
  20109. stack.push(data[i++]);
  20110. }
  20111. }
  20112. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  20113. n = op - 0xB8 + 1;
  20114. if (inFDEF || inELSE) {
  20115. i += n * 2;
  20116. } else {
  20117. for (j = 0; j < n; j++) {
  20118. b = data[i++];
  20119. stack.push((b << 8) | data[i++]);
  20120. }
  20121. }
  20122. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  20123. if (!inFDEF && !inELSE) {
  20124. // collecting inforamtion about which functions are used
  20125. funcId = stack[stack.length - 1];
  20126. ttContext.functionsUsed[funcId] = true;
  20127. if (funcId in ttContext.functionsStackDeltas) {
  20128. stack.length += ttContext.functionsStackDeltas[funcId];
  20129. } else if (funcId in ttContext.functionsDefined &&
  20130. functionsCalled.indexOf(funcId) < 0) {
  20131. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  20132. functionsCalled.push(funcId);
  20133. pc = ttContext.functionsDefined[funcId];
  20134. if (!pc) {
  20135. warn('TT: CALL non-existent function');
  20136. ttContext.hintsValid = false;
  20137. return;
  20138. }
  20139. data = pc.data;
  20140. i = pc.i;
  20141. }
  20142. }
  20143. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  20144. if (inFDEF || inELSE) {
  20145. warn('TT: nested FDEFs not allowed');
  20146. tooComplexToFollowFunctions = true;
  20147. }
  20148. inFDEF = true;
  20149. // collecting inforamtion about which functions are defined
  20150. lastDeff = i;
  20151. funcId = stack.pop();
  20152. ttContext.functionsDefined[funcId] = {data: data, i: i};
  20153. } else if (op === 0x2D) { // ENDF - end of function
  20154. if (inFDEF) {
  20155. inFDEF = false;
  20156. lastEndf = i;
  20157. } else {
  20158. pc = callstack.pop();
  20159. if (!pc) {
  20160. warn('TT: ENDF bad stack');
  20161. ttContext.hintsValid = false;
  20162. return;
  20163. }
  20164. funcId = functionsCalled.pop();
  20165. data = pc.data;
  20166. i = pc.i;
  20167. ttContext.functionsStackDeltas[funcId] =
  20168. stack.length - pc.stackTop;
  20169. }
  20170. } else if (op === 0x89) { // IDEF - instruction definition
  20171. if (inFDEF || inELSE) {
  20172. warn('TT: nested IDEFs not allowed');
  20173. tooComplexToFollowFunctions = true;
  20174. }
  20175. inFDEF = true;
  20176. // recording it as a function to track ENDF
  20177. lastDeff = i;
  20178. } else if (op === 0x58) { // IF
  20179. ++ifLevel;
  20180. } else if (op === 0x1B) { // ELSE
  20181. inELSE = ifLevel;
  20182. } else if (op === 0x59) { // EIF
  20183. if (inELSE === ifLevel) {
  20184. inELSE = 0;
  20185. }
  20186. --ifLevel;
  20187. } else if (op === 0x1C) { // JMPR
  20188. if (!inFDEF && !inELSE) {
  20189. var offset = stack[stack.length - 1];
  20190. // only jumping forward to prevent infinite loop
  20191. if (offset > 0) {
  20192. i += offset - 1;
  20193. }
  20194. }
  20195. }
  20196. // Adjusting stack not extactly, but just enough to get function id
  20197. if (!inFDEF && !inELSE) {
  20198. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  20199. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  20200. if (op >= 0x71 && op <= 0x75) {
  20201. n = stack.pop();
  20202. if (n === n) {
  20203. stackDelta = -n * 2;
  20204. }
  20205. }
  20206. while (stackDelta < 0 && stack.length > 0) {
  20207. stack.pop();
  20208. stackDelta++;
  20209. }
  20210. while (stackDelta > 0) {
  20211. stack.push(NaN); // pushing any number into stack
  20212. stackDelta--;
  20213. }
  20214. }
  20215. }
  20216. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  20217. var content = [data];
  20218. if (i > data.length) {
  20219. content.push(new Uint8Array(i - data.length));
  20220. }
  20221. if (lastDeff > lastEndf) {
  20222. warn('TT: complementing a missing function tail');
  20223. // new function definition started, but not finished
  20224. // complete function by [CLEAR, ENDF]
  20225. content.push(new Uint8Array([0x22, 0x2D]));
  20226. }
  20227. foldTTTable(table, content);
  20228. }
  20229. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  20230. if (ttContext.tooComplexToFollowFunctions) {
  20231. return;
  20232. }
  20233. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  20234. warn('TT: more functions defined than expected');
  20235. ttContext.hintsValid = false;
  20236. return;
  20237. }
  20238. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  20239. if (j > maxFunctionDefs) {
  20240. warn('TT: invalid function id: ' + j);
  20241. ttContext.hintsValid = false;
  20242. return;
  20243. }
  20244. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  20245. warn('TT: undefined function: ' + j);
  20246. ttContext.hintsValid = false;
  20247. return;
  20248. }
  20249. }
  20250. }
  20251. function foldTTTable(table, content) {
  20252. if (content.length > 1) {
  20253. // concatenating the content items
  20254. var newLength = 0;
  20255. var j, jj;
  20256. for (j = 0, jj = content.length; j < jj; j++) {
  20257. newLength += content[j].length;
  20258. }
  20259. newLength = (newLength + 3) & ~3;
  20260. var result = new Uint8Array(newLength);
  20261. var pos = 0;
  20262. for (j = 0, jj = content.length; j < jj; j++) {
  20263. result.set(content[j], pos);
  20264. pos += content[j].length;
  20265. }
  20266. table.data = result;
  20267. table.length = newLength;
  20268. }
  20269. }
  20270. function sanitizeTTPrograms(fpgm, prep, cvt) {
  20271. var ttContext = {
  20272. functionsDefined: [],
  20273. functionsUsed: [],
  20274. functionsStackDeltas: [],
  20275. tooComplexToFollowFunctions: false,
  20276. hintsValid: true
  20277. };
  20278. if (fpgm) {
  20279. sanitizeTTProgram(fpgm, ttContext);
  20280. }
  20281. if (prep) {
  20282. sanitizeTTProgram(prep, ttContext);
  20283. }
  20284. if (fpgm) {
  20285. checkInvalidFunctions(ttContext, maxFunctionDefs);
  20286. }
  20287. if (cvt && (cvt.length & 1)) {
  20288. var cvtData = new Uint8Array(cvt.length + 1);
  20289. cvtData.set(cvt.data);
  20290. cvt.data = cvtData;
  20291. }
  20292. return ttContext.hintsValid;
  20293. }
  20294. // The following steps modify the original font data, making copy
  20295. font = new Stream(new Uint8Array(font.getBytes()));
  20296. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  20297. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  20298. var header = readOpenTypeHeader(font);
  20299. var numTables = header.numTables;
  20300. var cff, cffFile;
  20301. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  20302. hmtx: null, maxp: null, name: null, post: null };
  20303. var table, tableData;
  20304. for (var i = 0; i < numTables; i++) {
  20305. table = readTableEntry(font);
  20306. if (VALID_TABLES.indexOf(table.tag) < 0) {
  20307. continue; // skipping table if it's not a required or optional table
  20308. }
  20309. if (table.length === 0) {
  20310. continue; // skipping empty tables
  20311. }
  20312. tables[table.tag] = table;
  20313. }
  20314. var isTrueType = !tables['CFF '];
  20315. if (!isTrueType) {
  20316. // OpenType font
  20317. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  20318. // no major tables: throwing everything at CFFFont
  20319. cffFile = new Stream(tables['CFF '].data);
  20320. cff = new CFFFont(cffFile, properties);
  20321. return this.convert(name, cff, properties);
  20322. }
  20323. delete tables.glyf;
  20324. delete tables.loca;
  20325. delete tables.fpgm;
  20326. delete tables.prep;
  20327. delete tables['cvt '];
  20328. this.isOpenType = true;
  20329. } else {
  20330. if (!tables.glyf || !tables.loca) {
  20331. error('Required "glyf" or "loca" tables are not found');
  20332. }
  20333. this.isOpenType = false;
  20334. }
  20335. if (!tables.maxp) {
  20336. error('Required "maxp" table is not found');
  20337. }
  20338. font.pos = (font.start || 0) + tables.maxp.offset;
  20339. var version = font.getInt32();
  20340. var numGlyphs = font.getUint16();
  20341. var maxFunctionDefs = 0;
  20342. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  20343. // maxZones can be invalid
  20344. font.pos += 8;
  20345. var maxZones = font.getUint16();
  20346. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  20347. tables.maxp.data[14] = 0;
  20348. tables.maxp.data[15] = 2;
  20349. }
  20350. font.pos += 4;
  20351. maxFunctionDefs = font.getUint16();
  20352. }
  20353. var dupFirstEntry = false;
  20354. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  20355. properties.toUnicode.get(0) > '\u0000') {
  20356. // oracle's defect (see 3427), duplicating first entry
  20357. dupFirstEntry = true;
  20358. numGlyphs++;
  20359. tables.maxp.data[4] = numGlyphs >> 8;
  20360. tables.maxp.data[5] = numGlyphs & 255;
  20361. }
  20362. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  20363. tables['cvt '], maxFunctionDefs);
  20364. if (!hintsValid) {
  20365. delete tables.fpgm;
  20366. delete tables.prep;
  20367. delete tables['cvt '];
  20368. }
  20369. // Tables needs to be written by ascendant alphabetic order
  20370. var tablesNames = Object.keys(tables);
  20371. tablesNames.sort();
  20372. numTables = tablesNames.length;
  20373. // header and new offsets. Table entry information is appended to the
  20374. // end of file. The virtualOffset represents where to put the actual
  20375. // data of a particular table;
  20376. var ttf = {
  20377. file: '',
  20378. virtualOffset: numTables * (4 * 4)
  20379. };
  20380. // The new numbers of tables will be the last one plus the num
  20381. // of missing tables
  20382. createOpenTypeHeader(header.version, ttf, numTables);
  20383. // Ensure the hmtx table contains the advance width and
  20384. // sidebearings information for numGlyphs in the maxp table
  20385. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  20386. if (!tables.head) {
  20387. error('Required "head" table is not found');
  20388. }
  20389. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  20390. if (isTrueType) {
  20391. var isGlyphLocationsLong = int16(tables.head.data[50],
  20392. tables.head.data[51]);
  20393. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  20394. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  20395. }
  20396. if (!tables.hhea) {
  20397. error('Required "hhea" table is not found');
  20398. }
  20399. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  20400. // Sometimes it's 0. That needs to be fixed
  20401. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  20402. tables.hhea.data[10] = 0xFF;
  20403. tables.hhea.data[11] = 0xFF;
  20404. }
  20405. // The 'post' table has glyphs names.
  20406. if (tables.post) {
  20407. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  20408. if (!valid) {
  20409. tables.post = null;
  20410. }
  20411. }
  20412. var charCodeToGlyphId = [], charCode;
  20413. if (properties.type === 'CIDFontType2') {
  20414. var cidToGidMap = properties.cidToGidMap || [];
  20415. var cidToGidMapLength = cidToGidMap.length;
  20416. properties.cMap.forEach(function(charCode, cid) {
  20417. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20418. var glyphId = -1;
  20419. if (cidToGidMapLength === 0) {
  20420. glyphId = charCode;
  20421. } else if (cidToGidMap[cid] !== undefined) {
  20422. glyphId = cidToGidMap[cid];
  20423. }
  20424. if (glyphId >= 0 && glyphId < numGlyphs) {
  20425. charCodeToGlyphId[charCode] = glyphId;
  20426. }
  20427. });
  20428. if (dupFirstEntry) {
  20429. charCodeToGlyphId[0] = numGlyphs - 1;
  20430. }
  20431. } else {
  20432. // Most of the following logic in this code branch is based on the
  20433. // 9.6.6.4 of the PDF spec.
  20434. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  20435. var cmapPlatformId = cmapTable.platformId;
  20436. var cmapEncodingId = cmapTable.encodingId;
  20437. var cmapMappings = cmapTable.mappings;
  20438. var cmapMappingsLength = cmapMappings.length;
  20439. var hasEncoding = properties.differences.length ||
  20440. !!properties.baseEncodingName;
  20441. // The spec seems to imply that if the font is symbolic the encoding
  20442. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  20443. // where the the font is symbolic and it has an encoding.
  20444. if (hasEncoding &&
  20445. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  20446. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  20447. var baseEncoding = [];
  20448. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  20449. properties.baseEncodingName === 'WinAnsiEncoding') {
  20450. baseEncoding = Encodings[properties.baseEncodingName];
  20451. }
  20452. for (charCode = 0; charCode < 256; charCode++) {
  20453. var glyphName;
  20454. if (this.differences && charCode in this.differences) {
  20455. glyphName = this.differences[charCode];
  20456. } else if (charCode in baseEncoding &&
  20457. baseEncoding[charCode] !== '') {
  20458. glyphName = baseEncoding[charCode];
  20459. } else {
  20460. glyphName = Encodings.StandardEncoding[charCode];
  20461. }
  20462. if (!glyphName) {
  20463. continue;
  20464. }
  20465. var unicodeOrCharCode;
  20466. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  20467. unicodeOrCharCode = GlyphsUnicode[glyphName];
  20468. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  20469. // TODO: the encoding needs to be updated with mac os table.
  20470. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  20471. }
  20472. var found = false;
  20473. for (i = 0; i < cmapMappingsLength; ++i) {
  20474. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  20475. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20476. found = true;
  20477. break;
  20478. }
  20479. }
  20480. if (!found && properties.glyphNames) {
  20481. // Try to map using the post table. There are currently no known
  20482. // pdfs that this fixes.
  20483. var glyphId = properties.glyphNames.indexOf(glyphName);
  20484. if (glyphId > 0) {
  20485. charCodeToGlyphId[charCode] = glyphId;
  20486. }
  20487. }
  20488. }
  20489. } else {
  20490. // For (3, 0) cmap tables:
  20491. // The charcode key being stored in charCodeToGlyphId is the lower
  20492. // byte of the two-byte charcodes of the cmap table since according to
  20493. // the spec: 'each byte from the string shall be prepended with the
  20494. // high byte of the range [of charcodes in the cmap table], to form
  20495. // a two-byte character, which shall be used to select the
  20496. // associated glyph description from the subtable'.
  20497. //
  20498. // For (1, 0) cmap tables:
  20499. // 'single bytes from the string shall be used to look up the
  20500. // associated glyph descriptions from the subtable'. This means
  20501. // charcodes in the cmap will be single bytes, so no-op since
  20502. // glyph.charCode & 0xFF === glyph.charCode
  20503. for (i = 0; i < cmapMappingsLength; ++i) {
  20504. charCode = cmapMappings[i].charCode & 0xFF;
  20505. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20506. }
  20507. }
  20508. }
  20509. if (charCodeToGlyphId.length === 0) {
  20510. // defines at least one glyph
  20511. charCodeToGlyphId[0] = 0;
  20512. }
  20513. // Converting glyphs and ids into font's cmap table
  20514. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  20515. this.toFontChar = newMapping.toFontChar;
  20516. tables.cmap = {
  20517. tag: 'cmap',
  20518. data: createCmapTable(newMapping.charCodeToGlyphId)
  20519. };
  20520. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  20521. // extract some more font properties from the OpenType head and
  20522. // hhea tables; yMin and descent value are always negative
  20523. var override = {
  20524. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  20525. yMax: int16(tables.head.data[42], tables.head.data[43]),
  20526. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  20527. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  20528. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  20529. };
  20530. tables['OS/2'] = {
  20531. tag: 'OS/2',
  20532. data: stringToArray(createOS2Table(properties,
  20533. newMapping.charCodeToGlyphId,
  20534. override))
  20535. };
  20536. }
  20537. // Rewrite the 'post' table if needed
  20538. if (!tables.post) {
  20539. tables.post = {
  20540. tag: 'post',
  20541. data: stringToArray(createPostTable(properties))
  20542. };
  20543. }
  20544. if (!isTrueType) {
  20545. try {
  20546. // Trying to repair CFF file
  20547. cffFile = new Stream(tables['CFF '].data);
  20548. var parser = new CFFParser(cffFile, properties);
  20549. cff = parser.parse();
  20550. var compiler = new CFFCompiler(cff);
  20551. tables['CFF '].data = compiler.compile();
  20552. } catch (e) {
  20553. warn('Failed to compile font ' + properties.loadedName);
  20554. }
  20555. }
  20556. // Re-creating 'name' table
  20557. if (!tables.name) {
  20558. tables.name = {
  20559. tag: 'name',
  20560. data: stringToArray(createNameTable(this.name))
  20561. };
  20562. } else {
  20563. // ... using existing 'name' table as prototype
  20564. var namePrototype = readNameTable(tables.name);
  20565. tables.name.data = stringToArray(createNameTable(name, namePrototype));
  20566. }
  20567. // rewrite the tables but tweak offsets
  20568. for (i = 0; i < numTables; i++) {
  20569. table = tables[tablesNames[i]];
  20570. table.data = createTableEntry(ttf, table.tag, table.data);
  20571. }
  20572. // Add the table datas
  20573. for (i = 0; i < numTables; i++) {
  20574. table = tables[tablesNames[i]];
  20575. tableData = table.data;
  20576. ttf.file += bytesToString(new Uint8Array(tableData));
  20577. // 4-byte aligned data
  20578. while (ttf.file.length & 3) {
  20579. ttf.file += String.fromCharCode(0);
  20580. }
  20581. }
  20582. return stringToArray(ttf.file);
  20583. },
  20584. convert: function Font_convert(fontName, font, properties) {
  20585. // The offsets object holds at the same time a representation of where
  20586. // to write the table entry information about a table and another offset
  20587. // representing the offset where to draw the actual data of a particular
  20588. // table
  20589. var otf = {
  20590. file: '',
  20591. virtualOffset: 9 * (4 * 4)
  20592. };
  20593. createOpenTypeHeader('\x4F\x54\x54\x4F', otf, 9);
  20594. // TODO: Check the charstring widths to determine this.
  20595. properties.fixedPitch = false;
  20596. var mapping = font.getGlyphMapping(properties);
  20597. var newMapping = adjustMapping(mapping, properties);
  20598. this.toFontChar = newMapping.toFontChar;
  20599. var numGlyphs = font.numGlyphs;
  20600. function getCharCodes(charCodeToGlyphId, glyphId) {
  20601. var charCodes = null;
  20602. for (var charCode in charCodeToGlyphId) {
  20603. if (glyphId === charCodeToGlyphId[charCode]) {
  20604. if (!charCodes) {
  20605. charCodes = [];
  20606. }
  20607. charCodes.push(charCode | 0);
  20608. }
  20609. }
  20610. return charCodes;
  20611. }
  20612. function createCharCode(charCodeToGlyphId, glyphId) {
  20613. for (var charCode in charCodeToGlyphId) {
  20614. if (glyphId === charCodeToGlyphId[charCode]) {
  20615. return charCode | 0;
  20616. }
  20617. }
  20618. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  20619. glyphId;
  20620. return newMapping.nextAvailableFontCharCode++;
  20621. }
  20622. var seacs = font.seacs;
  20623. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  20624. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  20625. var charset = font.getCharset();
  20626. var seacMap = Object.create(null);
  20627. for (var glyphId in seacs) {
  20628. glyphId |= 0;
  20629. var seac = seacs[glyphId];
  20630. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  20631. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  20632. var baseGlyphId = charset.indexOf(baseGlyphName);
  20633. var accentGlyphId = charset.indexOf(accentGlyphName);
  20634. if (baseGlyphId < 0 || accentGlyphId < 0) {
  20635. continue;
  20636. }
  20637. var accentOffset = {
  20638. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  20639. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  20640. };
  20641. var charCodes = getCharCodes(mapping, glyphId);
  20642. if (!charCodes) {
  20643. // There's no point in mapping it if the char code was never mapped
  20644. // to begin with.
  20645. continue;
  20646. }
  20647. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  20648. var charCode = charCodes[i];
  20649. // Find a fontCharCode that maps to the base and accent glyphs.
  20650. // If one doesn't exists, create it.
  20651. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  20652. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  20653. baseGlyphId);
  20654. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  20655. accentGlyphId);
  20656. seacMap[charCode] = {
  20657. baseFontCharCode: baseFontCharCode,
  20658. accentFontCharCode: accentFontCharCode,
  20659. accentOffset: accentOffset
  20660. };
  20661. }
  20662. }
  20663. properties.seacMap = seacMap;
  20664. }
  20665. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  20666. var fields = {
  20667. // PostScript Font Program
  20668. 'CFF ': font.data,
  20669. // OS/2 and Windows Specific metrics
  20670. 'OS/2': stringToArray(createOS2Table(properties,
  20671. newMapping.charCodeToGlyphId)),
  20672. // Character to glyphs mapping
  20673. 'cmap': createCmapTable(newMapping.charCodeToGlyphId),
  20674. // Font header
  20675. 'head': (function fontFieldsHead() {
  20676. return stringToArray(
  20677. '\x00\x01\x00\x00' + // Version number
  20678. '\x00\x00\x10\x00' + // fontRevision
  20679. '\x00\x00\x00\x00' + // checksumAdjustement
  20680. '\x5F\x0F\x3C\xF5' + // magicNumber
  20681. '\x00\x00' + // Flags
  20682. safeString16(unitsPerEm) + // unitsPerEM
  20683. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  20684. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  20685. '\x00\x00' + // xMin
  20686. safeString16(properties.descent) + // yMin
  20687. '\x0F\xFF' + // xMax
  20688. safeString16(properties.ascent) + // yMax
  20689. string16(properties.italicAngle ? 2 : 0) + // macStyle
  20690. '\x00\x11' + // lowestRecPPEM
  20691. '\x00\x00' + // fontDirectionHint
  20692. '\x00\x00' + // indexToLocFormat
  20693. '\x00\x00'); // glyphDataFormat
  20694. })(),
  20695. // Horizontal header
  20696. 'hhea': (function fontFieldsHhea() {
  20697. return stringToArray(
  20698. '\x00\x01\x00\x00' + // Version number
  20699. safeString16(properties.ascent) + // Typographic Ascent
  20700. safeString16(properties.descent) + // Typographic Descent
  20701. '\x00\x00' + // Line Gap
  20702. '\xFF\xFF' + // advanceWidthMax
  20703. '\x00\x00' + // minLeftSidebearing
  20704. '\x00\x00' + // minRightSidebearing
  20705. '\x00\x00' + // xMaxExtent
  20706. safeString16(properties.capHeight) + // caretSlopeRise
  20707. safeString16(Math.tan(properties.italicAngle) *
  20708. properties.xHeight) + // caretSlopeRun
  20709. '\x00\x00' + // caretOffset
  20710. '\x00\x00' + // -reserved-
  20711. '\x00\x00' + // -reserved-
  20712. '\x00\x00' + // -reserved-
  20713. '\x00\x00' + // -reserved-
  20714. '\x00\x00' + // metricDataFormat
  20715. string16(numGlyphs)); // Number of HMetrics
  20716. })(),
  20717. // Horizontal metrics
  20718. 'hmtx': (function fontFieldsHmtx() {
  20719. var charstrings = font.charstrings;
  20720. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  20721. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  20722. // TODO: For CFF fonts the width should technically match th x in
  20723. // the glyph, but it doesn't seem to matter.
  20724. var charstring = charstrings ? charstrings[i - 1] : {};
  20725. var width = 'width' in charstring ? charstring.width : 0;
  20726. hmtx += string16(width) + string16(0);
  20727. }
  20728. return stringToArray(hmtx);
  20729. })(),
  20730. // Maximum profile
  20731. 'maxp': (function fontFieldsMaxp() {
  20732. return stringToArray(
  20733. '\x00\x00\x50\x00' + // Version number
  20734. string16(numGlyphs)); // Num of glyphs
  20735. })(),
  20736. // Naming tables
  20737. 'name': stringToArray(createNameTable(fontName)),
  20738. // PostScript informations
  20739. 'post': stringToArray(createPostTable(properties))
  20740. };
  20741. var field;
  20742. for (field in fields) {
  20743. fields[field] = createTableEntry(otf, field, fields[field]);
  20744. }
  20745. for (field in fields) {
  20746. var table = fields[field];
  20747. otf.file += bytesToString(new Uint8Array(table));
  20748. }
  20749. return stringToArray(otf.file);
  20750. },
  20751. /**
  20752. * Builds a char code to unicode map based on section 9.10 of the spec.
  20753. * @param {Object} properties Font properties object.
  20754. * @return {Object} A ToUnicodeMap object.
  20755. */
  20756. buildToUnicode: function Font_buildToUnicode(properties) {
  20757. // Section 9.10.2 Mapping Character Codes to Unicode Values
  20758. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  20759. return properties.toUnicode;
  20760. }
  20761. // According to the spec if the font is a simple font we should only map
  20762. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  20763. // the differences array only contains adobe standard or symbol set names,
  20764. // in pratice it seems better to always try to create a toUnicode
  20765. // map based of the default encoding.
  20766. var toUnicode, charcode;
  20767. if (!properties.composite /* is simple font */) {
  20768. toUnicode = [];
  20769. var encoding = properties.defaultEncoding.slice();
  20770. var baseEncodingName = properties.baseEncodingName;
  20771. // Merge in the differences array.
  20772. var differences = properties.differences;
  20773. for (charcode in differences) {
  20774. encoding[charcode] = differences[charcode];
  20775. }
  20776. for (charcode in encoding) {
  20777. // a) Map the character code to a character name.
  20778. var glyphName = encoding[charcode];
  20779. // b) Look up the character name in the Adobe Glyph List (see the
  20780. // Bibliography) to obtain the corresponding Unicode value.
  20781. if (glyphName === '') {
  20782. continue;
  20783. } else if (GlyphsUnicode[glyphName] === undefined) {
  20784. // (undocumented) c) Few heuristics to recognize unknown glyphs
  20785. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  20786. var code = 0;
  20787. switch (glyphName[0]) {
  20788. case 'G': // Gxx glyph
  20789. if (glyphName.length === 3) {
  20790. code = parseInt(glyphName.substr(1), 16);
  20791. }
  20792. break;
  20793. case 'g': // g00xx glyph
  20794. if (glyphName.length === 5) {
  20795. code = parseInt(glyphName.substr(1), 16);
  20796. }
  20797. break;
  20798. case 'C': // Cddd glyph
  20799. case 'c': // cddd glyph
  20800. if (glyphName.length >= 3) {
  20801. code = +glyphName.substr(1);
  20802. }
  20803. break;
  20804. }
  20805. if (code) {
  20806. // If |baseEncodingName| is one the predefined encodings,
  20807. // and |code| equals |charcode|, using the glyph defined in the
  20808. // baseEncoding seems to yield a better |toUnicode| mapping
  20809. // (fixes issue 5070).
  20810. if (baseEncodingName && code === +charcode) {
  20811. var baseEncoding = Encodings[baseEncodingName];
  20812. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  20813. toUnicode[charcode] =
  20814. String.fromCharCode(GlyphsUnicode[glyphName]);
  20815. continue;
  20816. }
  20817. }
  20818. toUnicode[charcode] = String.fromCharCode(code);
  20819. }
  20820. continue;
  20821. }
  20822. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  20823. }
  20824. return new ToUnicodeMap(toUnicode);
  20825. }
  20826. // If the font is a composite font that uses one of the predefined CMaps
  20827. // listed in Table 118 (except Identity–H and Identity–V) or whose
  20828. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  20829. // Adobe-Korea1 character collection:
  20830. if (properties.composite && (
  20831. (properties.cMap.builtInCMap &&
  20832. !(properties.cMap instanceof IdentityCMap)) ||
  20833. (properties.cidSystemInfo.registry === 'Adobe' &&
  20834. (properties.cidSystemInfo.ordering === 'GB1' ||
  20835. properties.cidSystemInfo.ordering === 'CNS1' ||
  20836. properties.cidSystemInfo.ordering === 'Japan1' ||
  20837. properties.cidSystemInfo.ordering === 'Korea1')))) {
  20838. // Then:
  20839. // a) Map the character code to a character identifier (CID) according
  20840. // to the font’s CMap.
  20841. // b) Obtain the registry and ordering of the character collection used
  20842. // by the font’s CMap (for example, Adobe and Japan1) from its
  20843. // CIDSystemInfo dictionary.
  20844. var registry = properties.cidSystemInfo.registry;
  20845. var ordering = properties.cidSystemInfo.ordering;
  20846. // c) Construct a second CMap name by concatenating the registry and
  20847. // ordering obtained in step (b) in the format registry–ordering–UCS2
  20848. // (for example, Adobe–Japan1–UCS2).
  20849. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  20850. // d) Obtain the CMap with the name constructed in step (c) (available
  20851. // from the ASN Web site; see the Bibliography).
  20852. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  20853. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  20854. var cMap = properties.cMap;
  20855. toUnicode = [];
  20856. cMap.forEach(function(charcode, cid) {
  20857. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20858. // e) Map the CID obtained in step (a) according to the CMap obtained
  20859. // in step (d), producing a Unicode value.
  20860. var ucs2 = ucs2CMap.lookup(cid);
  20861. if (ucs2) {
  20862. toUnicode[charcode] =
  20863. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  20864. ucs2.charCodeAt(1));
  20865. }
  20866. });
  20867. return new ToUnicodeMap(toUnicode);
  20868. }
  20869. // The viewer's choice, just use an identity map.
  20870. return new IdentityToUnicodeMap(properties.firstChar,
  20871. properties.lastChar);
  20872. },
  20873. get spaceWidth() {
  20874. if ('_shadowWidth' in this) {
  20875. return this._shadowWidth;
  20876. }
  20877. // trying to estimate space character width
  20878. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  20879. var width;
  20880. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  20881. var glyphName = possibleSpaceReplacements[i];
  20882. // if possible, getting width by glyph name
  20883. if (glyphName in this.widths) {
  20884. width = this.widths[glyphName];
  20885. break;
  20886. }
  20887. var glyphUnicode = GlyphsUnicode[glyphName];
  20888. // finding the charcode via unicodeToCID map
  20889. var charcode = 0;
  20890. if (this.composite) {
  20891. if (this.cMap.contains(glyphUnicode)) {
  20892. charcode = this.cMap.lookup(glyphUnicode);
  20893. }
  20894. }
  20895. // ... via toUnicode map
  20896. if (!charcode && 'toUnicode' in this) {
  20897. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  20898. }
  20899. // setting it to unicode if negative or undefined
  20900. if (charcode <= 0) {
  20901. charcode = glyphUnicode;
  20902. }
  20903. // trying to get width via charcode
  20904. width = this.widths[charcode];
  20905. if (width) {
  20906. break; // the non-zero width found
  20907. }
  20908. }
  20909. width = width || this.defaultWidth;
  20910. // Do not shadow the property here. See discussion:
  20911. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  20912. this._shadowWidth = width;
  20913. return width;
  20914. },
  20915. charToGlyph: function Font_charToGlyph(charcode) {
  20916. var fontCharCode, width, operatorListId;
  20917. var widthCode = charcode;
  20918. if (this.cMap && this.cMap.contains(charcode)) {
  20919. widthCode = this.cMap.lookup(charcode);
  20920. }
  20921. width = this.widths[widthCode];
  20922. width = isNum(width) ? width : this.defaultWidth;
  20923. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  20924. var unicode = this.toUnicode.get(charcode) || charcode;
  20925. if (typeof unicode === 'number') {
  20926. unicode = String.fromCharCode(unicode);
  20927. }
  20928. // First try the toFontChar map, if it's not there then try falling
  20929. // back to the char code.
  20930. fontCharCode = this.toFontChar[charcode] || charcode;
  20931. if (this.missingFile) {
  20932. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  20933. }
  20934. if (this.isType3Font) {
  20935. // Font char code in this case is actually a glyph name.
  20936. operatorListId = fontCharCode;
  20937. }
  20938. var accent = null;
  20939. if (this.seacMap && this.seacMap[charcode]) {
  20940. var seac = this.seacMap[charcode];
  20941. fontCharCode = seac.baseFontCharCode;
  20942. accent = {
  20943. fontChar: String.fromCharCode(seac.accentFontCharCode),
  20944. offset: seac.accentOffset
  20945. };
  20946. }
  20947. var fontChar = String.fromCharCode(fontCharCode);
  20948. var glyph = this.glyphCache[charcode];
  20949. if (!glyph ||
  20950. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  20951. operatorListId)) {
  20952. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  20953. operatorListId);
  20954. this.glyphCache[charcode] = glyph;
  20955. }
  20956. return glyph;
  20957. },
  20958. charsToGlyphs: function Font_charsToGlyphs(chars) {
  20959. var charsCache = this.charsCache;
  20960. var glyphs, glyph, charcode;
  20961. // if we translated this string before, just grab it from the cache
  20962. if (charsCache) {
  20963. glyphs = charsCache[chars];
  20964. if (glyphs) {
  20965. return glyphs;
  20966. }
  20967. }
  20968. // lazily create the translation cache
  20969. if (!charsCache) {
  20970. charsCache = this.charsCache = Object.create(null);
  20971. }
  20972. glyphs = [];
  20973. var charsCacheKey = chars;
  20974. var i = 0, ii;
  20975. if (this.cMap) {
  20976. // composite fonts have multi-byte strings convert the string from
  20977. // single-byte to multi-byte
  20978. while (i < chars.length) {
  20979. var c = this.cMap.readCharCode(chars, i);
  20980. charcode = c[0];
  20981. var length = c[1];
  20982. i += length;
  20983. glyph = this.charToGlyph(charcode);
  20984. glyphs.push(glyph);
  20985. // placing null after each word break charcode (ASCII SPACE)
  20986. // Ignore occurences of 0x20 in multiple-byte codes.
  20987. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  20988. glyphs.push(null);
  20989. }
  20990. }
  20991. } else {
  20992. for (i = 0, ii = chars.length; i < ii; ++i) {
  20993. charcode = chars.charCodeAt(i);
  20994. glyph = this.charToGlyph(charcode);
  20995. glyphs.push(glyph);
  20996. if (charcode === 0x20) {
  20997. glyphs.push(null);
  20998. }
  20999. }
  21000. }
  21001. // Enter the translated string into the cache
  21002. return (charsCache[charsCacheKey] = glyphs);
  21003. }
  21004. };
  21005. return Font;
  21006. })();
  21007. var ErrorFont = (function ErrorFontClosure() {
  21008. function ErrorFont(error) {
  21009. this.error = error;
  21010. this.loadedName = 'g_font_error';
  21011. this.loading = false;
  21012. }
  21013. ErrorFont.prototype = {
  21014. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  21015. return [];
  21016. },
  21017. exportData: function ErrorFont_exportData() {
  21018. return {error: this.error};
  21019. }
  21020. };
  21021. return ErrorFont;
  21022. })();
  21023. /**
  21024. * Shared logic for building a char code to glyph id mapping for Type1 and
  21025. * simple CFF fonts. See section 9.6.6.2 of the spec.
  21026. * @param {Object} properties Font properties object.
  21027. * @param {Object} builtInEncoding The encoding contained within the actual font
  21028. * data.
  21029. * @param {Array} Array of glyph names where the index is the glyph ID.
  21030. * @returns {Object} A char code to glyph ID map.
  21031. */
  21032. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  21033. var charCodeToGlyphId = Object.create(null);
  21034. var glyphId, charCode, baseEncoding;
  21035. if (properties.baseEncodingName) {
  21036. // If a valid base encoding name was used, the mapping is initialized with
  21037. // that.
  21038. baseEncoding = Encodings[properties.baseEncodingName];
  21039. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  21040. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  21041. if (glyphId >= 0) {
  21042. charCodeToGlyphId[charCode] = glyphId;
  21043. }
  21044. }
  21045. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  21046. // For a symbolic font the encoding should be the fonts built-in
  21047. // encoding.
  21048. for (charCode in builtInEncoding) {
  21049. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  21050. }
  21051. } else {
  21052. // For non-symbolic fonts that don't have a base encoding the standard
  21053. // encoding should be used.
  21054. baseEncoding = Encodings.StandardEncoding;
  21055. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  21056. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  21057. if (glyphId >= 0) {
  21058. charCodeToGlyphId[charCode] = glyphId;
  21059. }
  21060. }
  21061. }
  21062. // Lastly, merge in the differences.
  21063. var differences = properties.differences;
  21064. if (differences) {
  21065. for (charCode in differences) {
  21066. var glyphName = differences[charCode];
  21067. glyphId = glyphNames.indexOf(glyphName);
  21068. if (glyphId >= 0) {
  21069. charCodeToGlyphId[charCode] = glyphId;
  21070. }
  21071. }
  21072. }
  21073. return charCodeToGlyphId;
  21074. }
  21075. /*
  21076. * CharStrings are encoded following the the CharString Encoding sequence
  21077. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  21078. * The value in a byte indicates a command, a number, or subsequent bytes
  21079. * that are to be interpreted in a special way.
  21080. *
  21081. * CharString Number Encoding:
  21082. * A CharString byte containing the values from 32 through 255 inclusive
  21083. * indicate an integer. These values are decoded in four ranges.
  21084. *
  21085. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  21086. * indicate the integer v - 139. Thus, the integer values from -107 through
  21087. * 107 inclusive may be encoded in single byte.
  21088. *
  21089. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  21090. * indicates an integer involving the next byte, w, according to the formula:
  21091. * [(v - 247) x 256] + w + 108
  21092. *
  21093. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  21094. * indicates an integer involving the next byte, w, according to the formula:
  21095. * -[(v - 251) * 256] - w - 108
  21096. *
  21097. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  21098. * are a two complement signed integer. The first of these bytes contains the
  21099. * highest order bits, the second byte contains the next higher order bits
  21100. * and the fourth byte contain the lowest order bits.
  21101. *
  21102. *
  21103. * CharString Command Encoding:
  21104. * CharStrings commands are encoded in 1 or 2 bytes.
  21105. *
  21106. * Single byte commands are encoded in 1 byte that contains a value between
  21107. * 0 and 31 inclusive.
  21108. * If a command byte contains the value 12, then the value in the next byte
  21109. * indicates a command. This "escape" mechanism allows many extra commands
  21110. * to be encoded and this encoding technique helps to minimize the length of
  21111. * the charStrings.
  21112. */
  21113. var Type1CharString = (function Type1CharStringClosure() {
  21114. var COMMAND_MAP = {
  21115. 'hstem': [1],
  21116. 'vstem': [3],
  21117. 'vmoveto': [4],
  21118. 'rlineto': [5],
  21119. 'hlineto': [6],
  21120. 'vlineto': [7],
  21121. 'rrcurveto': [8],
  21122. 'callsubr': [10],
  21123. 'flex': [12, 35],
  21124. 'drop' : [12, 18],
  21125. 'endchar': [14],
  21126. 'rmoveto': [21],
  21127. 'hmoveto': [22],
  21128. 'vhcurveto': [30],
  21129. 'hvcurveto': [31]
  21130. };
  21131. function Type1CharString() {
  21132. this.width = 0;
  21133. this.lsb = 0;
  21134. this.flexing = false;
  21135. this.output = [];
  21136. this.stack = [];
  21137. }
  21138. Type1CharString.prototype = {
  21139. convert: function Type1CharString_convert(encoded, subrs) {
  21140. var count = encoded.length;
  21141. var error = false;
  21142. var wx, sbx, subrNumber;
  21143. for (var i = 0; i < count; i++) {
  21144. var value = encoded[i];
  21145. if (value < 32) {
  21146. if (value === 12) {
  21147. value = (value << 8) + encoded[++i];
  21148. }
  21149. switch (value) {
  21150. case 1: // hstem
  21151. if (!HINTING_ENABLED) {
  21152. this.stack = [];
  21153. break;
  21154. }
  21155. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21156. break;
  21157. case 3: // vstem
  21158. if (!HINTING_ENABLED) {
  21159. this.stack = [];
  21160. break;
  21161. }
  21162. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21163. break;
  21164. case 4: // vmoveto
  21165. if (this.flexing) {
  21166. if (this.stack.length < 1) {
  21167. error = true;
  21168. break;
  21169. }
  21170. // Add the dx for flex and but also swap the values so they are
  21171. // the right order.
  21172. var dy = this.stack.pop();
  21173. this.stack.push(0, dy);
  21174. break;
  21175. }
  21176. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  21177. break;
  21178. case 5: // rlineto
  21179. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  21180. break;
  21181. case 6: // hlineto
  21182. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  21183. break;
  21184. case 7: // vlineto
  21185. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  21186. break;
  21187. case 8: // rrcurveto
  21188. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  21189. break;
  21190. case 9: // closepath
  21191. // closepath is a Type1 command that does not take argument and is
  21192. // useless in Type2 and it can simply be ignored.
  21193. this.stack = [];
  21194. break;
  21195. case 10: // callsubr
  21196. if (this.stack.length < 1) {
  21197. error = true;
  21198. break;
  21199. }
  21200. subrNumber = this.stack.pop();
  21201. error = this.convert(subrs[subrNumber], subrs);
  21202. break;
  21203. case 11: // return
  21204. return error;
  21205. case 13: // hsbw
  21206. if (this.stack.length < 2) {
  21207. error = true;
  21208. break;
  21209. }
  21210. // To convert to type2 we have to move the width value to the
  21211. // first part of the charstring and then use hmoveto with lsb.
  21212. wx = this.stack.pop();
  21213. sbx = this.stack.pop();
  21214. this.lsb = sbx;
  21215. this.width = wx;
  21216. this.stack.push(sbx);
  21217. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21218. break;
  21219. case 14: // endchar
  21220. this.output.push(COMMAND_MAP.endchar[0]);
  21221. break;
  21222. case 21: // rmoveto
  21223. if (this.flexing) {
  21224. break;
  21225. }
  21226. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21227. break;
  21228. case 22: // hmoveto
  21229. if (this.flexing) {
  21230. // Add the dy for flex.
  21231. this.stack.push(0);
  21232. break;
  21233. }
  21234. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21235. break;
  21236. case 30: // vhcurveto
  21237. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  21238. break;
  21239. case 31: // hvcurveto
  21240. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  21241. break;
  21242. case (12 << 8) + 0: // dotsection
  21243. // dotsection is a Type1 command to specify some hinting feature
  21244. // for dots that do not take a parameter and it can safely be
  21245. // ignored for Type2.
  21246. this.stack = [];
  21247. break;
  21248. case (12 << 8) + 1: // vstem3
  21249. if (!HINTING_ENABLED) {
  21250. this.stack = [];
  21251. break;
  21252. }
  21253. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  21254. // multiple parameters, so instead of returning [vh]stem3 take a
  21255. // shortcut and return [vhstem] instead.
  21256. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21257. break;
  21258. case (12 << 8) + 2: // hstem3
  21259. if (!HINTING_ENABLED) {
  21260. this.stack = [];
  21261. break;
  21262. }
  21263. // See vstem3.
  21264. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21265. break;
  21266. case (12 << 8) + 6: // seac
  21267. // seac is like type 2's special endchar but it doesn't use the
  21268. // first argument asb, so remove it.
  21269. if (SEAC_ANALYSIS_ENABLED) {
  21270. this.seac = this.stack.splice(-4, 4);
  21271. error = this.executeCommand(0, COMMAND_MAP.endchar);
  21272. } else {
  21273. error = this.executeCommand(4, COMMAND_MAP.endchar);
  21274. }
  21275. break;
  21276. case (12 << 8) + 7: // sbw
  21277. if (this.stack.length < 4) {
  21278. error = true;
  21279. break;
  21280. }
  21281. // To convert to type2 we have to move the width value to the
  21282. // first part of the charstring and then use rmoveto with
  21283. // (dx, dy). The height argument will not be used for vmtx and
  21284. // vhea tables reconstruction -- ignoring it.
  21285. var wy = this.stack.pop();
  21286. wx = this.stack.pop();
  21287. var sby = this.stack.pop();
  21288. sbx = this.stack.pop();
  21289. this.lsb = sbx;
  21290. this.width = wx;
  21291. this.stack.push(sbx, sby);
  21292. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21293. break;
  21294. case (12 << 8) + 12: // div
  21295. if (this.stack.length < 2) {
  21296. error = true;
  21297. break;
  21298. }
  21299. var num2 = this.stack.pop();
  21300. var num1 = this.stack.pop();
  21301. this.stack.push(num1 / num2);
  21302. break;
  21303. case (12 << 8) + 16: // callothersubr
  21304. if (this.stack.length < 2) {
  21305. error = true;
  21306. break;
  21307. }
  21308. subrNumber = this.stack.pop();
  21309. var numArgs = this.stack.pop();
  21310. if (subrNumber === 0 && numArgs === 3) {
  21311. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  21312. this.stack.push(
  21313. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  21314. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  21315. flexArgs[4], // bcp2x
  21316. flexArgs[5], // bcp2y
  21317. flexArgs[6], // p2x
  21318. flexArgs[7], // p2y
  21319. flexArgs[8], // bcp3x
  21320. flexArgs[9], // bcp3y
  21321. flexArgs[10], // bcp4x
  21322. flexArgs[11], // bcp4y
  21323. flexArgs[12], // p3x
  21324. flexArgs[13], // p3y
  21325. flexArgs[14] // flexDepth
  21326. // 15 = finalx unused by flex
  21327. // 16 = finaly unused by flex
  21328. );
  21329. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  21330. this.flexing = false;
  21331. this.stack.push(flexArgs[15], flexArgs[16]);
  21332. } else if (subrNumber === 1 && numArgs === 0) {
  21333. this.flexing = true;
  21334. }
  21335. break;
  21336. case (12 << 8) + 17: // pop
  21337. // Ignore this since it is only used with othersubr.
  21338. break;
  21339. case (12 << 8) + 33: // setcurrentpoint
  21340. // Ignore for now.
  21341. this.stack = [];
  21342. break;
  21343. default:
  21344. warn('Unknown type 1 charstring command of "' + value + '"');
  21345. break;
  21346. }
  21347. if (error) {
  21348. break;
  21349. }
  21350. continue;
  21351. } else if (value <= 246) {
  21352. value = value - 139;
  21353. } else if (value <= 250) {
  21354. value = ((value - 247) * 256) + encoded[++i] + 108;
  21355. } else if (value <= 254) {
  21356. value = -((value - 251) * 256) - encoded[++i] - 108;
  21357. } else {
  21358. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  21359. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  21360. }
  21361. this.stack.push(value);
  21362. }
  21363. return error;
  21364. },
  21365. executeCommand: function(howManyArgs, command, keepStack) {
  21366. var stackLength = this.stack.length;
  21367. if (howManyArgs > stackLength) {
  21368. return true;
  21369. }
  21370. var start = stackLength - howManyArgs;
  21371. for (var i = start; i < stackLength; i++) {
  21372. var value = this.stack[i];
  21373. if (value === (value | 0)) { // int
  21374. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  21375. } else { // fixed point
  21376. value = (65536 * value) | 0;
  21377. this.output.push(255,
  21378. (value >> 24) & 0xFF,
  21379. (value >> 16) & 0xFF,
  21380. (value >> 8) & 0xFF,
  21381. value & 0xFF);
  21382. }
  21383. }
  21384. this.output.push.apply(this.output, command);
  21385. if (keepStack) {
  21386. this.stack.splice(start, howManyArgs);
  21387. } else {
  21388. this.stack.length = 0;
  21389. }
  21390. return false;
  21391. }
  21392. };
  21393. return Type1CharString;
  21394. })();
  21395. /*
  21396. * Type1Parser encapsulate the needed code for parsing a Type1 font
  21397. * program. Some of its logic depends on the Type2 charstrings
  21398. * structure.
  21399. * Note: this doesn't really parse the font since that would require evaluation
  21400. * of PostScript, but it is possible in most cases to extract what we need
  21401. * without a full parse.
  21402. */
  21403. var Type1Parser = (function Type1ParserClosure() {
  21404. /*
  21405. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  21406. * of Plaintext Bytes. The function took a key as a parameter which can be
  21407. * for decrypting the eexec block of for decoding charStrings.
  21408. */
  21409. var EEXEC_ENCRYPT_KEY = 55665;
  21410. var CHAR_STRS_ENCRYPT_KEY = 4330;
  21411. function isHexDigit(code) {
  21412. return code >= 48 && code <= 57 || // '0'-'9'
  21413. code >= 65 && code <= 70 || // 'A'-'F'
  21414. code >= 97 && code <= 102; // 'a'-'f'
  21415. }
  21416. function decrypt(data, key, discardNumber) {
  21417. var r = key | 0, c1 = 52845, c2 = 22719;
  21418. var count = data.length;
  21419. var decrypted = new Uint8Array(count);
  21420. for (var i = 0; i < count; i++) {
  21421. var value = data[i];
  21422. decrypted[i] = value ^ (r >> 8);
  21423. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21424. }
  21425. return Array.prototype.slice.call(decrypted, discardNumber);
  21426. }
  21427. function decryptAscii(data, key, discardNumber) {
  21428. var r = key | 0, c1 = 52845, c2 = 22719;
  21429. var count = data.length, maybeLength = count >>> 1;
  21430. var decrypted = new Uint8Array(maybeLength);
  21431. var i, j;
  21432. for (i = 0, j = 0; i < count; i++) {
  21433. var digit1 = data[i];
  21434. if (!isHexDigit(digit1)) {
  21435. continue;
  21436. }
  21437. i++;
  21438. var digit2;
  21439. while (i < count && !isHexDigit(digit2 = data[i])) {
  21440. i++;
  21441. }
  21442. if (i < count) {
  21443. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  21444. decrypted[j++] = value ^ (r >> 8);
  21445. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21446. }
  21447. }
  21448. return Array.prototype.slice.call(decrypted, discardNumber, j);
  21449. }
  21450. function isSpecial(c) {
  21451. return c === 0x2F || // '/'
  21452. c === 0x5B || c === 0x5D || // '[', ']'
  21453. c === 0x7B || c === 0x7D || // '{', '}'
  21454. c === 0x28 || c === 0x29; // '(', ')'
  21455. }
  21456. function Type1Parser(stream, encrypted) {
  21457. if (encrypted) {
  21458. var data = stream.getBytes();
  21459. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  21460. isHexDigit(data[2]) && isHexDigit(data[3]));
  21461. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  21462. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  21463. }
  21464. this.stream = stream;
  21465. this.nextChar();
  21466. }
  21467. Type1Parser.prototype = {
  21468. readNumberArray: function Type1Parser_readNumberArray() {
  21469. this.getToken(); // read '[' or '{' (arrays can start with either)
  21470. var array = [];
  21471. while (true) {
  21472. var token = this.getToken();
  21473. if (token === null || token === ']' || token === '}') {
  21474. break;
  21475. }
  21476. array.push(parseFloat(token || 0));
  21477. }
  21478. return array;
  21479. },
  21480. readNumber: function Type1Parser_readNumber() {
  21481. var token = this.getToken();
  21482. return parseFloat(token || 0);
  21483. },
  21484. readInt: function Type1Parser_readInt() {
  21485. // Use '| 0' to prevent setting a double into length such as the double
  21486. // does not flow into the loop variable.
  21487. var token = this.getToken();
  21488. return parseInt(token || 0, 10) | 0;
  21489. },
  21490. readBoolean: function Type1Parser_readBoolean() {
  21491. var token = this.getToken();
  21492. // Use 1 and 0 since that's what type2 charstrings use.
  21493. return token === 'true' ? 1 : 0;
  21494. },
  21495. nextChar : function Type1_nextChar() {
  21496. return (this.currentChar = this.stream.getByte());
  21497. },
  21498. getToken: function Type1Parser_getToken() {
  21499. // Eat whitespace and comments.
  21500. var comment = false;
  21501. var ch = this.currentChar;
  21502. while (true) {
  21503. if (ch === -1) {
  21504. return null;
  21505. }
  21506. if (comment) {
  21507. if (ch === 0x0A || ch === 0x0D) {
  21508. comment = false;
  21509. }
  21510. } else if (ch === 0x25) { // '%'
  21511. comment = true;
  21512. } else if (!Lexer.isSpace(ch)) {
  21513. break;
  21514. }
  21515. ch = this.nextChar();
  21516. }
  21517. if (isSpecial(ch)) {
  21518. this.nextChar();
  21519. return String.fromCharCode(ch);
  21520. }
  21521. var token = '';
  21522. do {
  21523. token += String.fromCharCode(ch);
  21524. ch = this.nextChar();
  21525. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  21526. return token;
  21527. },
  21528. /*
  21529. * Returns an object containing a Subrs array and a CharStrings
  21530. * array extracted from and eexec encrypted block of data
  21531. */
  21532. extractFontProgram: function Type1Parser_extractFontProgram() {
  21533. var stream = this.stream;
  21534. var subrs = [], charstrings = [];
  21535. var program = {
  21536. subrs: [],
  21537. charstrings: [],
  21538. properties: {
  21539. 'privateData': {
  21540. 'lenIV': 4
  21541. }
  21542. }
  21543. };
  21544. var token, length, data, lenIV, encoded;
  21545. while ((token = this.getToken()) !== null) {
  21546. if (token !== '/') {
  21547. continue;
  21548. }
  21549. token = this.getToken();
  21550. switch (token) {
  21551. case 'CharStrings':
  21552. // The number immediately following CharStrings must be greater or
  21553. // equal to the number of CharStrings.
  21554. this.getToken();
  21555. this.getToken(); // read in 'dict'
  21556. this.getToken(); // read in 'dup'
  21557. this.getToken(); // read in 'begin'
  21558. while(true) {
  21559. token = this.getToken();
  21560. if (token === null || token === 'end') {
  21561. break;
  21562. }
  21563. if (token !== '/') {
  21564. continue;
  21565. }
  21566. var glyph = this.getToken();
  21567. length = this.readInt();
  21568. this.getToken(); // read in 'RD' or '-|'
  21569. data = stream.makeSubStream(stream.pos, length);
  21570. lenIV = program.properties.privateData['lenIV'];
  21571. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21572. // Skip past the required space and binary data.
  21573. stream.skip(length);
  21574. this.nextChar();
  21575. token = this.getToken(); // read in 'ND' or '|-'
  21576. if (token === 'noaccess') {
  21577. this.getToken(); // read in 'def'
  21578. }
  21579. charstrings.push({
  21580. glyph: glyph,
  21581. encoded: encoded
  21582. });
  21583. }
  21584. break;
  21585. case 'Subrs':
  21586. var num = this.readInt();
  21587. this.getToken(); // read in 'array'
  21588. while ((token = this.getToken()) === 'dup') {
  21589. var index = this.readInt();
  21590. length = this.readInt();
  21591. this.getToken(); // read in 'RD' or '-|'
  21592. data = stream.makeSubStream(stream.pos, length);
  21593. lenIV = program.properties.privateData['lenIV'];
  21594. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21595. // Skip past the required space and binary data.
  21596. stream.skip(length);
  21597. this.nextChar();
  21598. token = this.getToken(); // read in 'NP' or '|'
  21599. if (token === 'noaccess') {
  21600. this.getToken(); // read in 'put'
  21601. }
  21602. subrs[index] = encoded;
  21603. }
  21604. break;
  21605. case 'BlueValues':
  21606. case 'OtherBlues':
  21607. case 'FamilyBlues':
  21608. case 'FamilyOtherBlues':
  21609. var blueArray = this.readNumberArray();
  21610. // *Blue* values may contain invalid data: disables reading of
  21611. // those values when hinting is disabled.
  21612. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  21613. HINTING_ENABLED) {
  21614. program.properties.privateData[token] = blueArray;
  21615. }
  21616. break;
  21617. case 'StemSnapH':
  21618. case 'StemSnapV':
  21619. program.properties.privateData[token] = this.readNumberArray();
  21620. break;
  21621. case 'StdHW':
  21622. case 'StdVW':
  21623. program.properties.privateData[token] =
  21624. this.readNumberArray()[0];
  21625. break;
  21626. case 'BlueShift':
  21627. case 'lenIV':
  21628. case 'BlueFuzz':
  21629. case 'BlueScale':
  21630. case 'LanguageGroup':
  21631. case 'ExpansionFactor':
  21632. program.properties.privateData[token] = this.readNumber();
  21633. break;
  21634. case 'ForceBold':
  21635. program.properties.privateData[token] = this.readBoolean();
  21636. break;
  21637. }
  21638. }
  21639. for (var i = 0; i < charstrings.length; i++) {
  21640. glyph = charstrings[i].glyph;
  21641. encoded = charstrings[i].encoded;
  21642. var charString = new Type1CharString();
  21643. var error = charString.convert(encoded, subrs);
  21644. var output = charString.output;
  21645. if (error) {
  21646. // It seems when FreeType encounters an error while evaluating a glyph
  21647. // that it completely ignores the glyph so we'll mimic that behaviour
  21648. // here and put an endchar to make the validator happy.
  21649. output = [14];
  21650. }
  21651. program.charstrings.push({
  21652. glyphName: glyph,
  21653. charstring: output,
  21654. width: charString.width,
  21655. lsb: charString.lsb,
  21656. seac: charString.seac
  21657. });
  21658. }
  21659. return program;
  21660. },
  21661. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  21662. var token;
  21663. while ((token = this.getToken()) !== null) {
  21664. if (token !== '/') {
  21665. continue;
  21666. }
  21667. token = this.getToken();
  21668. switch (token) {
  21669. case 'FontMatrix':
  21670. var matrix = this.readNumberArray();
  21671. properties.fontMatrix = matrix;
  21672. break;
  21673. case 'Encoding':
  21674. var encodingArg = this.getToken();
  21675. var encoding;
  21676. if (!/^\d+$/.test(encodingArg)) {
  21677. // encoding name is specified
  21678. encoding = Encodings[encodingArg];
  21679. } else {
  21680. encoding = [];
  21681. var size = parseInt(encodingArg, 10) | 0;
  21682. this.getToken(); // read in 'array'
  21683. for (var j = 0; j < size; j++) {
  21684. token = this.getToken();
  21685. // skipping till first dup or def (e.g. ignoring for statement)
  21686. while (token !== 'dup' && token !== 'def') {
  21687. token = this.getToken();
  21688. if (token === null) {
  21689. return; // invalid header
  21690. }
  21691. }
  21692. if (token === 'def') {
  21693. break; // read all array data
  21694. }
  21695. var index = this.readInt();
  21696. this.getToken(); // read in '/'
  21697. var glyph = this.getToken();
  21698. encoding[index] = glyph;
  21699. this.getToken(); // read the in 'put'
  21700. }
  21701. }
  21702. properties.builtInEncoding = encoding;
  21703. break;
  21704. case 'FontBBox':
  21705. var fontBBox = this.readNumberArray();
  21706. // adjusting ascent/descent
  21707. properties.ascent = fontBBox[3];
  21708. properties.descent = fontBBox[1];
  21709. properties.ascentScaled = true;
  21710. break;
  21711. }
  21712. }
  21713. }
  21714. };
  21715. return Type1Parser;
  21716. })();
  21717. /**
  21718. * The CFF class takes a Type1 file and wrap it into a
  21719. * 'Compact Font Format' which itself embed Type2 charstrings.
  21720. */
  21721. var CFFStandardStrings = [
  21722. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  21723. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  21724. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  21725. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  21726. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  21727. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  21728. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  21729. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  21730. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  21731. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  21732. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  21733. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  21734. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  21735. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  21736. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  21737. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  21738. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  21739. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  21740. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  21741. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  21742. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  21743. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  21744. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  21745. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  21746. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  21747. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  21748. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  21749. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  21750. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  21751. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  21752. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  21753. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  21754. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  21755. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  21756. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  21757. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  21758. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  21759. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  21760. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  21761. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  21762. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  21763. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  21764. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  21765. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  21766. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  21767. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  21768. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  21769. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  21770. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  21771. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  21772. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  21773. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  21774. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  21775. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  21776. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  21777. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  21778. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  21779. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  21780. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  21781. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  21782. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  21783. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  21784. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  21785. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  21786. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  21787. ];
  21788. // Type1Font is also a CIDFontType0.
  21789. var Type1Font = function Type1Font(name, file, properties) {
  21790. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  21791. // Also, length1 and length2 might be off by 6 bytes as well.
  21792. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  21793. var PFB_HEADER_SIZE = 6;
  21794. var headerBlockLength = properties.length1;
  21795. var eexecBlockLength = properties.length2;
  21796. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  21797. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  21798. if (pfbHeaderPresent) {
  21799. file.skip(PFB_HEADER_SIZE);
  21800. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21801. (pfbHeader[3] << 8) | pfbHeader[2];
  21802. }
  21803. // Get the data block containing glyphs and subrs informations
  21804. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  21805. var headerBlockParser = new Type1Parser(headerBlock);
  21806. headerBlockParser.extractFontHeader(properties);
  21807. if (pfbHeaderPresent) {
  21808. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  21809. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21810. (pfbHeader[3] << 8) | pfbHeader[2];
  21811. }
  21812. // Decrypt the data blocks and retrieve it's content
  21813. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  21814. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  21815. var data = eexecBlockParser.extractFontProgram();
  21816. for (var info in data.properties) {
  21817. properties[info] = data.properties[info];
  21818. }
  21819. var charstrings = data.charstrings;
  21820. var type2Charstrings = this.getType2Charstrings(charstrings);
  21821. var subrs = this.getType2Subrs(data.subrs);
  21822. this.charstrings = charstrings;
  21823. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  21824. subrs, properties);
  21825. this.seacs = this.getSeacs(data.charstrings);
  21826. };
  21827. Type1Font.prototype = {
  21828. get numGlyphs() {
  21829. return this.charstrings.length + 1;
  21830. },
  21831. getCharset: function Type1Font_getCharset() {
  21832. var charset = ['.notdef'];
  21833. var charstrings = this.charstrings;
  21834. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21835. charset.push(charstrings[glyphId].glyphName);
  21836. }
  21837. return charset;
  21838. },
  21839. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  21840. var charstrings = this.charstrings;
  21841. var glyphNames = ['.notdef'], glyphId;
  21842. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21843. glyphNames.push(charstrings[glyphId].glyphName);
  21844. }
  21845. var encoding = properties.builtInEncoding;
  21846. if (encoding) {
  21847. var builtInEncoding = {};
  21848. for (var charCode in encoding) {
  21849. glyphId = glyphNames.indexOf(encoding[charCode]);
  21850. if (glyphId >= 0) {
  21851. builtInEncoding[charCode] = glyphId;
  21852. }
  21853. }
  21854. }
  21855. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  21856. },
  21857. getSeacs: function Type1Font_getSeacs(charstrings) {
  21858. var i, ii;
  21859. var seacMap = [];
  21860. for (i = 0, ii = charstrings.length; i < ii; i++) {
  21861. var charstring = charstrings[i];
  21862. if (charstring.seac) {
  21863. // Offset by 1 for .notdef
  21864. seacMap[i + 1] = charstring.seac;
  21865. }
  21866. }
  21867. return seacMap;
  21868. },
  21869. getType2Charstrings: function Type1Font_getType2Charstrings(
  21870. type1Charstrings) {
  21871. var type2Charstrings = [];
  21872. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  21873. type2Charstrings.push(type1Charstrings[i].charstring);
  21874. }
  21875. return type2Charstrings;
  21876. },
  21877. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  21878. var bias = 0;
  21879. var count = type1Subrs.length;
  21880. if (count < 1133) {
  21881. bias = 107;
  21882. } else if (count < 33769) {
  21883. bias = 1131;
  21884. } else {
  21885. bias = 32768;
  21886. }
  21887. // Add a bunch of empty subrs to deal with the Type2 bias
  21888. var type2Subrs = [];
  21889. var i;
  21890. for (i = 0; i < bias; i++) {
  21891. type2Subrs.push([0x0B]);
  21892. }
  21893. for (i = 0; i < count; i++) {
  21894. type2Subrs.push(type1Subrs[i]);
  21895. }
  21896. return type2Subrs;
  21897. },
  21898. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  21899. var cff = new CFF();
  21900. cff.header = new CFFHeader(1, 0, 4, 4);
  21901. cff.names = [name];
  21902. var topDict = new CFFTopDict();
  21903. // CFF strings IDs 0...390 are predefined names, so refering
  21904. // to entries in our own String INDEX starts at SID 391.
  21905. topDict.setByName('version', 391);
  21906. topDict.setByName('Notice', 392);
  21907. topDict.setByName('FullName', 393);
  21908. topDict.setByName('FamilyName', 394);
  21909. topDict.setByName('Weight', 395);
  21910. topDict.setByName('Encoding', null); // placeholder
  21911. topDict.setByName('FontMatrix', properties.fontMatrix);
  21912. topDict.setByName('FontBBox', properties.bbox);
  21913. topDict.setByName('charset', null); // placeholder
  21914. topDict.setByName('CharStrings', null); // placeholder
  21915. topDict.setByName('Private', null); // placeholder
  21916. cff.topDict = topDict;
  21917. var strings = new CFFStrings();
  21918. strings.add('Version 0.11'); // Version
  21919. strings.add('See original notice'); // Notice
  21920. strings.add(name); // FullName
  21921. strings.add(name); // FamilyName
  21922. strings.add('Medium'); // Weight
  21923. cff.strings = strings;
  21924. cff.globalSubrIndex = new CFFIndex();
  21925. var count = glyphs.length;
  21926. var charsetArray = [0];
  21927. var i, ii;
  21928. for (i = 0; i < count; i++) {
  21929. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  21930. // TODO: Insert the string and correctly map it. Previously it was
  21931. // thought mapping names that aren't in the standard strings to .notdef
  21932. // was fine, however in issue818 when mapping them all to .notdef the
  21933. // adieresis glyph no longer worked.
  21934. if (index === -1) {
  21935. index = 0;
  21936. }
  21937. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  21938. }
  21939. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  21940. var charStringsIndex = new CFFIndex();
  21941. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  21942. for (i = 0; i < count; i++) {
  21943. charStringsIndex.add(glyphs[i]);
  21944. }
  21945. cff.charStrings = charStringsIndex;
  21946. var privateDict = new CFFPrivateDict();
  21947. privateDict.setByName('Subrs', null); // placeholder
  21948. var fields = [
  21949. 'BlueValues',
  21950. 'OtherBlues',
  21951. 'FamilyBlues',
  21952. 'FamilyOtherBlues',
  21953. 'StemSnapH',
  21954. 'StemSnapV',
  21955. 'BlueShift',
  21956. 'BlueFuzz',
  21957. 'BlueScale',
  21958. 'LanguageGroup',
  21959. 'ExpansionFactor',
  21960. 'ForceBold',
  21961. 'StdHW',
  21962. 'StdVW'
  21963. ];
  21964. for (i = 0, ii = fields.length; i < ii; i++) {
  21965. var field = fields[i];
  21966. if (!properties.privateData.hasOwnProperty(field)) {
  21967. continue;
  21968. }
  21969. var value = properties.privateData[field];
  21970. if (isArray(value)) {
  21971. // All of the private dictionary array data in CFF must be stored as
  21972. // "delta-encoded" numbers.
  21973. for (var j = value.length - 1; j > 0; j--) {
  21974. value[j] -= value[j - 1]; // ... difference from previous value
  21975. }
  21976. }
  21977. privateDict.setByName(field, value);
  21978. }
  21979. cff.topDict.privateDict = privateDict;
  21980. var subrIndex = new CFFIndex();
  21981. for (i = 0, ii = subrs.length; i < ii; i++) {
  21982. subrIndex.add(subrs[i]);
  21983. }
  21984. privateDict.subrsIndex = subrIndex;
  21985. var compiler = new CFFCompiler(cff);
  21986. return compiler.compile();
  21987. }
  21988. };
  21989. var CFFFont = (function CFFFontClosure() {
  21990. function CFFFont(file, properties) {
  21991. this.properties = properties;
  21992. var parser = new CFFParser(file, properties);
  21993. this.cff = parser.parse();
  21994. var compiler = new CFFCompiler(this.cff);
  21995. this.seacs = this.cff.seacs;
  21996. try {
  21997. this.data = compiler.compile();
  21998. } catch (e) {
  21999. warn('Failed to compile font ' + properties.loadedName);
  22000. // There may have just been an issue with the compiler, set the data
  22001. // anyway and hope the font loaded.
  22002. this.data = file;
  22003. }
  22004. }
  22005. CFFFont.prototype = {
  22006. get numGlyphs() {
  22007. return this.cff.charStrings.count;
  22008. },
  22009. getCharset: function CFFFont_getCharset() {
  22010. return this.cff.charset.charset;
  22011. },
  22012. getGlyphMapping: function CFFFont_getGlyphMapping() {
  22013. var cff = this.cff;
  22014. var properties = this.properties;
  22015. var charsets = cff.charset.charset;
  22016. var charCodeToGlyphId;
  22017. var glyphId;
  22018. if (properties.composite) {
  22019. charCodeToGlyphId = Object.create(null);
  22020. if (cff.isCIDFont) {
  22021. // If the font is actually a CID font then we should use the charset
  22022. // to map CIDs to GIDs.
  22023. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  22024. var cid = charsets[glyphId];
  22025. var charCode = properties.cMap.charCodeOf(cid);
  22026. charCodeToGlyphId[charCode] = glyphId;
  22027. }
  22028. } else {
  22029. // If it is NOT actually a CID font then CIDs should be mapped
  22030. // directly to GIDs.
  22031. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  22032. charCodeToGlyphId[glyphId] = glyphId;
  22033. }
  22034. }
  22035. return charCodeToGlyphId;
  22036. }
  22037. var encoding = cff.encoding ? cff.encoding.encoding : null;
  22038. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  22039. return charCodeToGlyphId;
  22040. }
  22041. };
  22042. return CFFFont;
  22043. })();
  22044. var CFFParser = (function CFFParserClosure() {
  22045. var CharstringValidationData = [
  22046. null,
  22047. { id: 'hstem', min: 2, resetStack: true, stem: true },
  22048. null,
  22049. { id: 'vstem', min: 2, resetStack: true, stem: true },
  22050. { id: 'vmoveto', min: 1, resetStack: true },
  22051. { id: 'rlineto', min: 2, resetStack: true },
  22052. { id: 'hlineto', min: 1, resetStack: true },
  22053. { id: 'vlineto', min: 1, resetStack: true },
  22054. { id: 'rrcurveto', min: 6, resetStack: true },
  22055. null,
  22056. { id: 'callsubr', min: 1, undefStack: true },
  22057. { id: 'return', min: 0, undefStack: true },
  22058. null, // 12
  22059. null,
  22060. null, // endchar
  22061. null,
  22062. null,
  22063. null,
  22064. { id: 'hstemhm', min: 2, resetStack: true, stem: true },
  22065. null, // hintmask
  22066. null, // cntrmask
  22067. { id: 'rmoveto', min: 2, resetStack: true },
  22068. { id: 'hmoveto', min: 1, resetStack: true },
  22069. { id: 'vstemhm', min: 2, resetStack: true, stem: true },
  22070. { id: 'rcurveline', min: 8, resetStack: true },
  22071. { id: 'rlinecurve', min: 8, resetStack: true },
  22072. { id: 'vvcurveto', min: 4, resetStack: true },
  22073. { id: 'hhcurveto', min: 4, resetStack: true },
  22074. null, // shortint
  22075. { id: 'callgsubr', min: 1, undefStack: true },
  22076. { id: 'vhcurveto', min: 4, resetStack: true },
  22077. { id: 'hvcurveto', min: 4, resetStack: true }
  22078. ];
  22079. var CharstringValidationData12 = [
  22080. null,
  22081. null,
  22082. null,
  22083. { id: 'and', min: 2, stackDelta: -1 },
  22084. { id: 'or', min: 2, stackDelta: -1 },
  22085. { id: 'not', min: 1, stackDelta: 0 },
  22086. null,
  22087. null,
  22088. null,
  22089. { id: 'abs', min: 1, stackDelta: 0 },
  22090. { id: 'add', min: 2, stackDelta: -1,
  22091. stackFn: function stack_div(stack, index) {
  22092. stack[index - 2] = stack[index - 2] + stack[index - 1];
  22093. }
  22094. },
  22095. { id: 'sub', min: 2, stackDelta: -1,
  22096. stackFn: function stack_div(stack, index) {
  22097. stack[index - 2] = stack[index - 2] - stack[index - 1];
  22098. }
  22099. },
  22100. { id: 'div', min: 2, stackDelta: -1,
  22101. stackFn: function stack_div(stack, index) {
  22102. stack[index - 2] = stack[index - 2] / stack[index - 1];
  22103. }
  22104. },
  22105. null,
  22106. { id: 'neg', min: 1, stackDelta: 0,
  22107. stackFn: function stack_div(stack, index) {
  22108. stack[index - 1] = -stack[index - 1];
  22109. }
  22110. },
  22111. { id: 'eq', min: 2, stackDelta: -1 },
  22112. null,
  22113. null,
  22114. { id: 'drop', min: 1, stackDelta: -1 },
  22115. null,
  22116. { id: 'put', min: 2, stackDelta: -2 },
  22117. { id: 'get', min: 1, stackDelta: 0 },
  22118. { id: 'ifelse', min: 4, stackDelta: -3 },
  22119. { id: 'random', min: 0, stackDelta: 1 },
  22120. { id: 'mul', min: 2, stackDelta: -1,
  22121. stackFn: function stack_div(stack, index) {
  22122. stack[index - 2] = stack[index - 2] * stack[index - 1];
  22123. }
  22124. },
  22125. null,
  22126. { id: 'sqrt', min: 1, stackDelta: 0 },
  22127. { id: 'dup', min: 1, stackDelta: 1 },
  22128. { id: 'exch', min: 2, stackDelta: 0 },
  22129. { id: 'index', min: 2, stackDelta: 0 },
  22130. { id: 'roll', min: 3, stackDelta: -2 },
  22131. null,
  22132. null,
  22133. null,
  22134. { id: 'hflex', min: 7, resetStack: true },
  22135. { id: 'flex', min: 13, resetStack: true },
  22136. { id: 'hflex1', min: 9, resetStack: true },
  22137. { id: 'flex1', min: 11, resetStack: true }
  22138. ];
  22139. function CFFParser(file, properties) {
  22140. this.bytes = file.getBytes();
  22141. this.properties = properties;
  22142. }
  22143. CFFParser.prototype = {
  22144. parse: function CFFParser_parse() {
  22145. var properties = this.properties;
  22146. var cff = new CFF();
  22147. this.cff = cff;
  22148. // The first five sections must be in order, all the others are reached
  22149. // via offsets contained in one of the below.
  22150. var header = this.parseHeader();
  22151. var nameIndex = this.parseIndex(header.endPos);
  22152. var topDictIndex = this.parseIndex(nameIndex.endPos);
  22153. var stringIndex = this.parseIndex(topDictIndex.endPos);
  22154. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  22155. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  22156. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  22157. cff.header = header.obj;
  22158. cff.names = this.parseNameIndex(nameIndex.obj);
  22159. cff.strings = this.parseStringIndex(stringIndex.obj);
  22160. cff.topDict = topDict;
  22161. cff.globalSubrIndex = globalSubrIndex.obj;
  22162. this.parsePrivateDict(cff.topDict);
  22163. cff.isCIDFont = topDict.hasName('ROS');
  22164. var charStringOffset = topDict.getByName('CharStrings');
  22165. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  22166. cff.charStrings = charStringsAndSeacs.charStrings;
  22167. cff.seacs = charStringsAndSeacs.seacs;
  22168. var fontMatrix = topDict.getByName('FontMatrix');
  22169. if (fontMatrix) {
  22170. properties.fontMatrix = fontMatrix;
  22171. }
  22172. var fontBBox = topDict.getByName('FontBBox');
  22173. if (fontBBox) {
  22174. // adjusting ascent/descent
  22175. properties.ascent = fontBBox[3];
  22176. properties.descent = fontBBox[1];
  22177. properties.ascentScaled = true;
  22178. }
  22179. var charset, encoding;
  22180. if (cff.isCIDFont) {
  22181. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  22182. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  22183. var dictRaw = fdArrayIndex.get(i);
  22184. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  22185. cff.strings);
  22186. this.parsePrivateDict(fontDict);
  22187. cff.fdArray.push(fontDict);
  22188. }
  22189. // cid fonts don't have an encoding
  22190. encoding = null;
  22191. charset = this.parseCharsets(topDict.getByName('charset'),
  22192. cff.charStrings.count, cff.strings, true);
  22193. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  22194. cff.charStrings.count);
  22195. } else {
  22196. charset = this.parseCharsets(topDict.getByName('charset'),
  22197. cff.charStrings.count, cff.strings, false);
  22198. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  22199. properties,
  22200. cff.strings, charset.charset);
  22201. }
  22202. cff.charset = charset;
  22203. cff.encoding = encoding;
  22204. return cff;
  22205. },
  22206. parseHeader: function CFFParser_parseHeader() {
  22207. var bytes = this.bytes;
  22208. var bytesLength = bytes.length;
  22209. var offset = 0;
  22210. // Prevent an infinite loop, by checking that the offset is within the
  22211. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  22212. while (offset < bytesLength && bytes[offset] !== 1) {
  22213. ++offset;
  22214. }
  22215. if (offset >= bytesLength) {
  22216. error('Invalid CFF header');
  22217. } else if (offset !== 0) {
  22218. info('cff data is shifted');
  22219. bytes = bytes.subarray(offset);
  22220. this.bytes = bytes;
  22221. }
  22222. var major = bytes[0];
  22223. var minor = bytes[1];
  22224. var hdrSize = bytes[2];
  22225. var offSize = bytes[3];
  22226. var header = new CFFHeader(major, minor, hdrSize, offSize);
  22227. return { obj: header, endPos: hdrSize };
  22228. },
  22229. parseDict: function CFFParser_parseDict(dict) {
  22230. var pos = 0;
  22231. function parseOperand() {
  22232. var value = dict[pos++];
  22233. if (value === 30) {
  22234. return parseFloatOperand(pos);
  22235. } else if (value === 28) {
  22236. value = dict[pos++];
  22237. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  22238. return value;
  22239. } else if (value === 29) {
  22240. value = dict[pos++];
  22241. value = (value << 8) | dict[pos++];
  22242. value = (value << 8) | dict[pos++];
  22243. value = (value << 8) | dict[pos++];
  22244. return value;
  22245. } else if (value >= 32 && value <= 246) {
  22246. return value - 139;
  22247. } else if (value >= 247 && value <= 250) {
  22248. return ((value - 247) * 256) + dict[pos++] + 108;
  22249. } else if (value >= 251 && value <= 254) {
  22250. return -((value - 251) * 256) - dict[pos++] - 108;
  22251. } else {
  22252. error('255 is not a valid DICT command');
  22253. }
  22254. return -1;
  22255. }
  22256. function parseFloatOperand() {
  22257. var str = '';
  22258. var eof = 15;
  22259. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  22260. '9', '.', 'E', 'E-', null, '-'];
  22261. var length = dict.length;
  22262. while (pos < length) {
  22263. var b = dict[pos++];
  22264. var b1 = b >> 4;
  22265. var b2 = b & 15;
  22266. if (b1 === eof) {
  22267. break;
  22268. }
  22269. str += lookup[b1];
  22270. if (b2 === eof) {
  22271. break;
  22272. }
  22273. str += lookup[b2];
  22274. }
  22275. return parseFloat(str);
  22276. }
  22277. var operands = [];
  22278. var entries = [];
  22279. pos = 0;
  22280. var end = dict.length;
  22281. while (pos < end) {
  22282. var b = dict[pos];
  22283. if (b <= 21) {
  22284. if (b === 12) {
  22285. b = (b << 8) | dict[++pos];
  22286. }
  22287. entries.push([b, operands]);
  22288. operands = [];
  22289. ++pos;
  22290. } else {
  22291. operands.push(parseOperand());
  22292. }
  22293. }
  22294. return entries;
  22295. },
  22296. parseIndex: function CFFParser_parseIndex(pos) {
  22297. var cffIndex = new CFFIndex();
  22298. var bytes = this.bytes;
  22299. var count = (bytes[pos++] << 8) | bytes[pos++];
  22300. var offsets = [];
  22301. var end = pos;
  22302. var i, ii;
  22303. if (count !== 0) {
  22304. var offsetSize = bytes[pos++];
  22305. // add 1 for offset to determine size of last object
  22306. var startPos = pos + ((count + 1) * offsetSize) - 1;
  22307. for (i = 0, ii = count + 1; i < ii; ++i) {
  22308. var offset = 0;
  22309. for (var j = 0; j < offsetSize; ++j) {
  22310. offset <<= 8;
  22311. offset += bytes[pos++];
  22312. }
  22313. offsets.push(startPos + offset);
  22314. }
  22315. end = offsets[count];
  22316. }
  22317. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  22318. var offsetStart = offsets[i];
  22319. var offsetEnd = offsets[i + 1];
  22320. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  22321. }
  22322. return {obj: cffIndex, endPos: end};
  22323. },
  22324. parseNameIndex: function CFFParser_parseNameIndex(index) {
  22325. var names = [];
  22326. for (var i = 0, ii = index.count; i < ii; ++i) {
  22327. var name = index.get(i);
  22328. // OTS doesn't allow names to be over 127 characters.
  22329. var length = Math.min(name.length, 127);
  22330. var data = [];
  22331. // OTS also only permits certain characters in the name.
  22332. for (var j = 0; j < length; ++j) {
  22333. var c = name[j];
  22334. if (j === 0 && c === 0) {
  22335. data[j] = c;
  22336. continue;
  22337. }
  22338. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  22339. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  22340. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  22341. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  22342. data[j] = 95;
  22343. continue;
  22344. }
  22345. data[j] = c;
  22346. }
  22347. names.push(bytesToString(data));
  22348. }
  22349. return names;
  22350. },
  22351. parseStringIndex: function CFFParser_parseStringIndex(index) {
  22352. var strings = new CFFStrings();
  22353. for (var i = 0, ii = index.count; i < ii; ++i) {
  22354. var data = index.get(i);
  22355. strings.add(bytesToString(data));
  22356. }
  22357. return strings;
  22358. },
  22359. createDict: function CFFParser_createDict(Type, dict, strings) {
  22360. var cffDict = new Type(strings);
  22361. for (var i = 0, ii = dict.length; i < ii; ++i) {
  22362. var pair = dict[i];
  22363. var key = pair[0];
  22364. var value = pair[1];
  22365. cffDict.setByKey(key, value);
  22366. }
  22367. return cffDict;
  22368. },
  22369. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  22370. var charStrings = this.parseIndex(charStringOffset).obj;
  22371. var seacs = [];
  22372. var count = charStrings.count;
  22373. for (var i = 0; i < count; i++) {
  22374. var charstring = charStrings.get(i);
  22375. var stackSize = 0;
  22376. var stack = [];
  22377. var undefStack = true;
  22378. var hints = 0;
  22379. var valid = true;
  22380. var data = charstring;
  22381. var length = data.length;
  22382. for (var j = 0; j < length;) {
  22383. var value = data[j++];
  22384. var validationCommand = null;
  22385. if (value === 12) {
  22386. var q = data[j++];
  22387. if (q === 0) {
  22388. // The CFF specification state that the 'dotsection' command
  22389. // (12, 0) is deprecated and treated as a no-op, but all Type2
  22390. // charstrings processors should support them. Unfortunately
  22391. // the font sanitizer don't. As a workaround the sequence (12, 0)
  22392. // is replaced by a useless (0, hmoveto).
  22393. data[j - 2] = 139;
  22394. data[j - 1] = 22;
  22395. stackSize = 0;
  22396. } else {
  22397. validationCommand = CharstringValidationData12[q];
  22398. }
  22399. } else if (value === 28) { // number (16 bit)
  22400. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  22401. j += 2;
  22402. stackSize++;
  22403. } else if (value === 14) {
  22404. if (stackSize >= 4) {
  22405. stackSize -= 4;
  22406. if (SEAC_ANALYSIS_ENABLED) {
  22407. seacs[i] = stack.slice(stackSize, stackSize + 4);
  22408. valid = false;
  22409. }
  22410. }
  22411. } else if (value >= 32 && value <= 246) { // number
  22412. stack[stackSize] = value - 139;
  22413. stackSize++;
  22414. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  22415. stack[stackSize] = (value < 251 ?
  22416. ((value - 247) << 8) + data[j] + 108 :
  22417. -((value - 251) << 8) - data[j] - 108);
  22418. j++;
  22419. stackSize++;
  22420. } else if (value === 255) { // number (32 bit)
  22421. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  22422. (data[j + 2] << 8) | data[j + 3]) / 65536;
  22423. j += 4;
  22424. stackSize++;
  22425. } else if (value === 19 || value === 20) {
  22426. hints += stackSize >> 1;
  22427. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  22428. stackSize = 0;
  22429. } else {
  22430. validationCommand = CharstringValidationData[value];
  22431. }
  22432. if (validationCommand) {
  22433. if (validationCommand.stem) {
  22434. hints += stackSize >> 1;
  22435. }
  22436. if ('min' in validationCommand) {
  22437. if (!undefStack && stackSize < validationCommand.min) {
  22438. warn('Not enough parameters for ' + validationCommand.id +
  22439. '; actual: ' + stackSize +
  22440. ', expected: ' + validationCommand.min);
  22441. valid = false;
  22442. break;
  22443. }
  22444. }
  22445. if ('stackDelta' in validationCommand) {
  22446. if ('stackFn' in validationCommand) {
  22447. validationCommand.stackFn(stack, stackSize);
  22448. }
  22449. stackSize += validationCommand.stackDelta;
  22450. } else if (validationCommand.resetStack) {
  22451. stackSize = 0;
  22452. undefStack = false;
  22453. } else if (validationCommand.undefStack) {
  22454. stackSize = 0;
  22455. undefStack = true;
  22456. }
  22457. }
  22458. }
  22459. if (!valid) {
  22460. // resetting invalid charstring to single 'endchar'
  22461. charStrings.set(i, new Uint8Array([14]));
  22462. }
  22463. }
  22464. return { charStrings: charStrings, seacs: seacs };
  22465. },
  22466. emptyPrivateDictionary:
  22467. function CFFParser_emptyPrivateDictionary(parentDict) {
  22468. var privateDict = this.createDict(CFFPrivateDict, [],
  22469. parentDict.strings);
  22470. parentDict.setByKey(18, [0, 0]);
  22471. parentDict.privateDict = privateDict;
  22472. },
  22473. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  22474. // no private dict, do nothing
  22475. if (!parentDict.hasName('Private')) {
  22476. this.emptyPrivateDictionary(parentDict);
  22477. return;
  22478. }
  22479. var privateOffset = parentDict.getByName('Private');
  22480. // make sure the params are formatted correctly
  22481. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  22482. parentDict.removeByName('Private');
  22483. return;
  22484. }
  22485. var size = privateOffset[0];
  22486. var offset = privateOffset[1];
  22487. // remove empty dicts or ones that refer to invalid location
  22488. if (size === 0 || offset >= this.bytes.length) {
  22489. this.emptyPrivateDictionary(parentDict);
  22490. return;
  22491. }
  22492. var privateDictEnd = offset + size;
  22493. var dictData = this.bytes.subarray(offset, privateDictEnd);
  22494. var dict = this.parseDict(dictData);
  22495. var privateDict = this.createDict(CFFPrivateDict, dict,
  22496. parentDict.strings);
  22497. parentDict.privateDict = privateDict;
  22498. // Parse the Subrs index also since it's relative to the private dict.
  22499. if (!privateDict.getByName('Subrs')) {
  22500. return;
  22501. }
  22502. var subrsOffset = privateDict.getByName('Subrs');
  22503. var relativeOffset = offset + subrsOffset;
  22504. // Validate the offset.
  22505. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  22506. this.emptyPrivateDictionary(parentDict);
  22507. return;
  22508. }
  22509. var subrsIndex = this.parseIndex(relativeOffset);
  22510. privateDict.subrsIndex = subrsIndex.obj;
  22511. },
  22512. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  22513. if (pos === 0) {
  22514. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  22515. ISOAdobeCharset);
  22516. } else if (pos === 1) {
  22517. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  22518. ExpertCharset);
  22519. } else if (pos === 2) {
  22520. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  22521. ExpertSubsetCharset);
  22522. }
  22523. var bytes = this.bytes;
  22524. var start = pos;
  22525. var format = bytes[pos++];
  22526. var charset = ['.notdef'];
  22527. var id, count, i;
  22528. // subtract 1 for the .notdef glyph
  22529. length -= 1;
  22530. switch (format) {
  22531. case 0:
  22532. for (i = 0; i < length; i++) {
  22533. id = (bytes[pos++] << 8) | bytes[pos++];
  22534. charset.push(cid ? id : strings.get(id));
  22535. }
  22536. break;
  22537. case 1:
  22538. while (charset.length <= length) {
  22539. id = (bytes[pos++] << 8) | bytes[pos++];
  22540. count = bytes[pos++];
  22541. for (i = 0; i <= count; i++) {
  22542. charset.push(cid ? id++ : strings.get(id++));
  22543. }
  22544. }
  22545. break;
  22546. case 2:
  22547. while (charset.length <= length) {
  22548. id = (bytes[pos++] << 8) | bytes[pos++];
  22549. count = (bytes[pos++] << 8) | bytes[pos++];
  22550. for (i = 0; i <= count; i++) {
  22551. charset.push(cid ? id++ : strings.get(id++));
  22552. }
  22553. }
  22554. break;
  22555. default:
  22556. error('Unknown charset format');
  22557. }
  22558. // Raw won't be needed if we actually compile the charset.
  22559. var end = pos;
  22560. var raw = bytes.subarray(start, end);
  22561. return new CFFCharset(false, format, charset, raw);
  22562. },
  22563. parseEncoding: function CFFParser_parseEncoding(pos,
  22564. properties,
  22565. strings,
  22566. charset) {
  22567. var encoding = {};
  22568. var bytes = this.bytes;
  22569. var predefined = false;
  22570. var hasSupplement = false;
  22571. var format, i, ii;
  22572. var raw = null;
  22573. function readSupplement() {
  22574. var supplementsCount = bytes[pos++];
  22575. for (i = 0; i < supplementsCount; i++) {
  22576. var code = bytes[pos++];
  22577. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  22578. encoding[code] = charset.indexOf(strings.get(sid));
  22579. }
  22580. }
  22581. if (pos === 0 || pos === 1) {
  22582. predefined = true;
  22583. format = pos;
  22584. var baseEncoding = pos ? Encodings.ExpertEncoding :
  22585. Encodings.StandardEncoding;
  22586. for (i = 0, ii = charset.length; i < ii; i++) {
  22587. var index = baseEncoding.indexOf(charset[i]);
  22588. if (index !== -1) {
  22589. encoding[index] = i;
  22590. }
  22591. }
  22592. } else {
  22593. var dataStart = pos;
  22594. format = bytes[pos++];
  22595. switch (format & 0x7f) {
  22596. case 0:
  22597. var glyphsCount = bytes[pos++];
  22598. for (i = 1; i <= glyphsCount; i++) {
  22599. encoding[bytes[pos++]] = i;
  22600. }
  22601. break;
  22602. case 1:
  22603. var rangesCount = bytes[pos++];
  22604. var gid = 1;
  22605. for (i = 0; i < rangesCount; i++) {
  22606. var start = bytes[pos++];
  22607. var left = bytes[pos++];
  22608. for (var j = start; j <= start + left; j++) {
  22609. encoding[j] = gid++;
  22610. }
  22611. }
  22612. break;
  22613. default:
  22614. error('Unknow encoding format: ' + format + ' in CFF');
  22615. break;
  22616. }
  22617. var dataEnd = pos;
  22618. if (format & 0x80) {
  22619. // The font sanitizer does not support CFF encoding with a
  22620. // supplement, since the encoding is not really used to map
  22621. // between gid to glyph, let's overwrite what is declared in
  22622. // the top dictionary to let the sanitizer think the font use
  22623. // StandardEncoding, that's a lie but that's ok.
  22624. bytes[dataStart] &= 0x7f;
  22625. readSupplement();
  22626. hasSupplement = true;
  22627. }
  22628. raw = bytes.subarray(dataStart, dataEnd);
  22629. }
  22630. format = format & 0x7f;
  22631. return new CFFEncoding(predefined, format, encoding, raw);
  22632. },
  22633. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  22634. var start = pos;
  22635. var bytes = this.bytes;
  22636. var format = bytes[pos++];
  22637. var fdSelect = [];
  22638. var i;
  22639. switch (format) {
  22640. case 0:
  22641. for (i = 0; i < length; ++i) {
  22642. var id = bytes[pos++];
  22643. fdSelect.push(id);
  22644. }
  22645. break;
  22646. case 3:
  22647. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  22648. for (i = 0; i < rangesCount; ++i) {
  22649. var first = (bytes[pos++] << 8) | bytes[pos++];
  22650. var fdIndex = bytes[pos++];
  22651. var next = (bytes[pos] << 8) | bytes[pos + 1];
  22652. for (var j = first; j < next; ++j) {
  22653. fdSelect.push(fdIndex);
  22654. }
  22655. }
  22656. // Advance past the sentinel(next).
  22657. pos += 2;
  22658. break;
  22659. default:
  22660. error('Unknown fdselect format ' + format);
  22661. break;
  22662. }
  22663. var end = pos;
  22664. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  22665. }
  22666. };
  22667. return CFFParser;
  22668. })();
  22669. // Compact Font Format
  22670. var CFF = (function CFFClosure() {
  22671. function CFF() {
  22672. this.header = null;
  22673. this.names = [];
  22674. this.topDict = null;
  22675. this.strings = new CFFStrings();
  22676. this.globalSubrIndex = null;
  22677. // The following could really be per font, but since we only have one font
  22678. // store them here.
  22679. this.encoding = null;
  22680. this.charset = null;
  22681. this.charStrings = null;
  22682. this.fdArray = [];
  22683. this.fdSelect = null;
  22684. this.isCIDFont = false;
  22685. }
  22686. return CFF;
  22687. })();
  22688. var CFFHeader = (function CFFHeaderClosure() {
  22689. function CFFHeader(major, minor, hdrSize, offSize) {
  22690. this.major = major;
  22691. this.minor = minor;
  22692. this.hdrSize = hdrSize;
  22693. this.offSize = offSize;
  22694. }
  22695. return CFFHeader;
  22696. })();
  22697. var CFFStrings = (function CFFStringsClosure() {
  22698. function CFFStrings() {
  22699. this.strings = [];
  22700. }
  22701. CFFStrings.prototype = {
  22702. get: function CFFStrings_get(index) {
  22703. if (index >= 0 && index <= 390) {
  22704. return CFFStandardStrings[index];
  22705. }
  22706. if (index - 391 <= this.strings.length) {
  22707. return this.strings[index - 391];
  22708. }
  22709. return CFFStandardStrings[0];
  22710. },
  22711. add: function CFFStrings_add(value) {
  22712. this.strings.push(value);
  22713. },
  22714. get count() {
  22715. return this.strings.length;
  22716. }
  22717. };
  22718. return CFFStrings;
  22719. })();
  22720. var CFFIndex = (function CFFIndexClosure() {
  22721. function CFFIndex() {
  22722. this.objects = [];
  22723. this.length = 0;
  22724. }
  22725. CFFIndex.prototype = {
  22726. add: function CFFIndex_add(data) {
  22727. this.length += data.length;
  22728. this.objects.push(data);
  22729. },
  22730. set: function CFFIndex_set(index, data) {
  22731. this.length += data.length - this.objects[index].length;
  22732. this.objects[index] = data;
  22733. },
  22734. get: function CFFIndex_get(index) {
  22735. return this.objects[index];
  22736. },
  22737. get count() {
  22738. return this.objects.length;
  22739. }
  22740. };
  22741. return CFFIndex;
  22742. })();
  22743. var CFFDict = (function CFFDictClosure() {
  22744. function CFFDict(tables, strings) {
  22745. this.keyToNameMap = tables.keyToNameMap;
  22746. this.nameToKeyMap = tables.nameToKeyMap;
  22747. this.defaults = tables.defaults;
  22748. this.types = tables.types;
  22749. this.opcodes = tables.opcodes;
  22750. this.order = tables.order;
  22751. this.strings = strings;
  22752. this.values = {};
  22753. }
  22754. CFFDict.prototype = {
  22755. // value should always be an array
  22756. setByKey: function CFFDict_setByKey(key, value) {
  22757. if (!(key in this.keyToNameMap)) {
  22758. return false;
  22759. }
  22760. // ignore empty values
  22761. if (value.length === 0) {
  22762. return true;
  22763. }
  22764. var type = this.types[key];
  22765. // remove the array wrapping these types of values
  22766. if (type === 'num' || type === 'sid' || type === 'offset') {
  22767. value = value[0];
  22768. }
  22769. this.values[key] = value;
  22770. return true;
  22771. },
  22772. setByName: function CFFDict_setByName(name, value) {
  22773. if (!(name in this.nameToKeyMap)) {
  22774. error('Invalid dictionary name "' + name + '"');
  22775. }
  22776. this.values[this.nameToKeyMap[name]] = value;
  22777. },
  22778. hasName: function CFFDict_hasName(name) {
  22779. return this.nameToKeyMap[name] in this.values;
  22780. },
  22781. getByName: function CFFDict_getByName(name) {
  22782. if (!(name in this.nameToKeyMap)) {
  22783. error('Invalid dictionary name "' + name + '"');
  22784. }
  22785. var key = this.nameToKeyMap[name];
  22786. if (!(key in this.values)) {
  22787. return this.defaults[key];
  22788. }
  22789. return this.values[key];
  22790. },
  22791. removeByName: function CFFDict_removeByName(name) {
  22792. delete this.values[this.nameToKeyMap[name]];
  22793. }
  22794. };
  22795. CFFDict.createTables = function CFFDict_createTables(layout) {
  22796. var tables = {
  22797. keyToNameMap: {},
  22798. nameToKeyMap: {},
  22799. defaults: {},
  22800. types: {},
  22801. opcodes: {},
  22802. order: []
  22803. };
  22804. for (var i = 0, ii = layout.length; i < ii; ++i) {
  22805. var entry = layout[i];
  22806. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  22807. tables.keyToNameMap[key] = entry[1];
  22808. tables.nameToKeyMap[entry[1]] = key;
  22809. tables.types[key] = entry[2];
  22810. tables.defaults[key] = entry[3];
  22811. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  22812. tables.order.push(key);
  22813. }
  22814. return tables;
  22815. };
  22816. return CFFDict;
  22817. })();
  22818. var CFFTopDict = (function CFFTopDictClosure() {
  22819. var layout = [
  22820. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  22821. [[12, 20], 'SyntheticBase', 'num', null],
  22822. [0, 'version', 'sid', null],
  22823. [1, 'Notice', 'sid', null],
  22824. [[12, 0], 'Copyright', 'sid', null],
  22825. [2, 'FullName', 'sid', null],
  22826. [3, 'FamilyName', 'sid', null],
  22827. [4, 'Weight', 'sid', null],
  22828. [[12, 1], 'isFixedPitch', 'num', 0],
  22829. [[12, 2], 'ItalicAngle', 'num', 0],
  22830. [[12, 3], 'UnderlinePosition', 'num', -100],
  22831. [[12, 4], 'UnderlineThickness', 'num', 50],
  22832. [[12, 5], 'PaintType', 'num', 0],
  22833. [[12, 6], 'CharstringType', 'num', 2],
  22834. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  22835. [0.001, 0, 0, 0.001, 0, 0]],
  22836. [13, 'UniqueID', 'num', null],
  22837. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  22838. [[12, 8], 'StrokeWidth', 'num', 0],
  22839. [14, 'XUID', 'array', null],
  22840. [15, 'charset', 'offset', 0],
  22841. [16, 'Encoding', 'offset', 0],
  22842. [17, 'CharStrings', 'offset', 0],
  22843. [18, 'Private', ['offset', 'offset'], null],
  22844. [[12, 21], 'PostScript', 'sid', null],
  22845. [[12, 22], 'BaseFontName', 'sid', null],
  22846. [[12, 23], 'BaseFontBlend', 'delta', null],
  22847. [[12, 31], 'CIDFontVersion', 'num', 0],
  22848. [[12, 32], 'CIDFontRevision', 'num', 0],
  22849. [[12, 33], 'CIDFontType', 'num', 0],
  22850. [[12, 34], 'CIDCount', 'num', 8720],
  22851. [[12, 35], 'UIDBase', 'num', null],
  22852. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  22853. // before FDArray.
  22854. [[12, 37], 'FDSelect', 'offset', null],
  22855. [[12, 36], 'FDArray', 'offset', null],
  22856. [[12, 38], 'FontName', 'sid', null]
  22857. ];
  22858. var tables = null;
  22859. function CFFTopDict(strings) {
  22860. if (tables === null) {
  22861. tables = CFFDict.createTables(layout);
  22862. }
  22863. CFFDict.call(this, tables, strings);
  22864. this.privateDict = null;
  22865. }
  22866. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  22867. return CFFTopDict;
  22868. })();
  22869. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  22870. var layout = [
  22871. [6, 'BlueValues', 'delta', null],
  22872. [7, 'OtherBlues', 'delta', null],
  22873. [8, 'FamilyBlues', 'delta', null],
  22874. [9, 'FamilyOtherBlues', 'delta', null],
  22875. [[12, 9], 'BlueScale', 'num', 0.039625],
  22876. [[12, 10], 'BlueShift', 'num', 7],
  22877. [[12, 11], 'BlueFuzz', 'num', 1],
  22878. [10, 'StdHW', 'num', null],
  22879. [11, 'StdVW', 'num', null],
  22880. [[12, 12], 'StemSnapH', 'delta', null],
  22881. [[12, 13], 'StemSnapV', 'delta', null],
  22882. [[12, 14], 'ForceBold', 'num', 0],
  22883. [[12, 17], 'LanguageGroup', 'num', 0],
  22884. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  22885. [[12, 19], 'initialRandomSeed', 'num', 0],
  22886. [20, 'defaultWidthX', 'num', 0],
  22887. [21, 'nominalWidthX', 'num', 0],
  22888. [19, 'Subrs', 'offset', null]
  22889. ];
  22890. var tables = null;
  22891. function CFFPrivateDict(strings) {
  22892. if (tables === null) {
  22893. tables = CFFDict.createTables(layout);
  22894. }
  22895. CFFDict.call(this, tables, strings);
  22896. this.subrsIndex = null;
  22897. }
  22898. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  22899. return CFFPrivateDict;
  22900. })();
  22901. var CFFCharsetPredefinedTypes = {
  22902. ISO_ADOBE: 0,
  22903. EXPERT: 1,
  22904. EXPERT_SUBSET: 2
  22905. };
  22906. var CFFCharset = (function CFFCharsetClosure() {
  22907. function CFFCharset(predefined, format, charset, raw) {
  22908. this.predefined = predefined;
  22909. this.format = format;
  22910. this.charset = charset;
  22911. this.raw = raw;
  22912. }
  22913. return CFFCharset;
  22914. })();
  22915. var CFFEncoding = (function CFFEncodingClosure() {
  22916. function CFFEncoding(predefined, format, encoding, raw) {
  22917. this.predefined = predefined;
  22918. this.format = format;
  22919. this.encoding = encoding;
  22920. this.raw = raw;
  22921. }
  22922. return CFFEncoding;
  22923. })();
  22924. var CFFFDSelect = (function CFFFDSelectClosure() {
  22925. function CFFFDSelect(fdSelect, raw) {
  22926. this.fdSelect = fdSelect;
  22927. this.raw = raw;
  22928. }
  22929. return CFFFDSelect;
  22930. })();
  22931. // Helper class to keep track of where an offset is within the data and helps
  22932. // filling in that offset once it's known.
  22933. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  22934. function CFFOffsetTracker() {
  22935. this.offsets = {};
  22936. }
  22937. CFFOffsetTracker.prototype = {
  22938. isTracking: function CFFOffsetTracker_isTracking(key) {
  22939. return key in this.offsets;
  22940. },
  22941. track: function CFFOffsetTracker_track(key, location) {
  22942. if (key in this.offsets) {
  22943. error('Already tracking location of ' + key);
  22944. }
  22945. this.offsets[key] = location;
  22946. },
  22947. offset: function CFFOffsetTracker_offset(value) {
  22948. for (var key in this.offsets) {
  22949. this.offsets[key] += value;
  22950. }
  22951. },
  22952. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  22953. values,
  22954. output) {
  22955. if (!(key in this.offsets)) {
  22956. error('Not tracking location of ' + key);
  22957. }
  22958. var data = output.data;
  22959. var dataOffset = this.offsets[key];
  22960. var size = 5;
  22961. for (var i = 0, ii = values.length; i < ii; ++i) {
  22962. var offset0 = i * size + dataOffset;
  22963. var offset1 = offset0 + 1;
  22964. var offset2 = offset0 + 2;
  22965. var offset3 = offset0 + 3;
  22966. var offset4 = offset0 + 4;
  22967. // It's easy to screw up offsets so perform this sanity check.
  22968. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  22969. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  22970. error('writing to an offset that is not empty');
  22971. }
  22972. var value = values[i];
  22973. data[offset0] = 0x1d;
  22974. data[offset1] = (value >> 24) & 0xFF;
  22975. data[offset2] = (value >> 16) & 0xFF;
  22976. data[offset3] = (value >> 8) & 0xFF;
  22977. data[offset4] = value & 0xFF;
  22978. }
  22979. }
  22980. };
  22981. return CFFOffsetTracker;
  22982. })();
  22983. // Takes a CFF and converts it to the binary representation.
  22984. var CFFCompiler = (function CFFCompilerClosure() {
  22985. function CFFCompiler(cff) {
  22986. this.cff = cff;
  22987. }
  22988. CFFCompiler.prototype = {
  22989. compile: function CFFCompiler_compile() {
  22990. var cff = this.cff;
  22991. var output = {
  22992. data: [],
  22993. length: 0,
  22994. add: function CFFCompiler_add(data) {
  22995. this.data = this.data.concat(data);
  22996. this.length = this.data.length;
  22997. }
  22998. };
  22999. // Compile the five entries that must be in order.
  23000. var header = this.compileHeader(cff.header);
  23001. output.add(header);
  23002. var nameIndex = this.compileNameIndex(cff.names);
  23003. output.add(nameIndex);
  23004. if (cff.isCIDFont) {
  23005. // The spec is unclear on how font matrices should relate to each other
  23006. // when there is one in the main top dict and the sub top dicts.
  23007. // Windows handles this differently than linux and osx so we have to
  23008. // normalize to work on all.
  23009. // Rules based off of some mailing list discussions:
  23010. // - If main font has a matrix and subfont doesn't, use the main matrix.
  23011. // - If no main font matrix and there is a subfont matrix, use the
  23012. // subfont matrix.
  23013. // - If both have matrices, concat together.
  23014. // - If neither have matrices, use default.
  23015. // To make this work on all platforms we move the top matrix into each
  23016. // sub top dict and concat if necessary.
  23017. if (cff.topDict.hasName('FontMatrix')) {
  23018. var base = cff.topDict.getByName('FontMatrix');
  23019. cff.topDict.removeByName('FontMatrix');
  23020. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  23021. var subDict = cff.fdArray[i];
  23022. var matrix = base.slice(0);
  23023. if (subDict.hasName('FontMatrix')) {
  23024. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  23025. }
  23026. subDict.setByName('FontMatrix', matrix);
  23027. }
  23028. }
  23029. }
  23030. var compiled = this.compileTopDicts([cff.topDict],
  23031. output.length,
  23032. cff.isCIDFont);
  23033. output.add(compiled.output);
  23034. var topDictTracker = compiled.trackers[0];
  23035. var stringIndex = this.compileStringIndex(cff.strings.strings);
  23036. output.add(stringIndex);
  23037. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  23038. output.add(globalSubrIndex);
  23039. // Now start on the other entries that have no specfic order.
  23040. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  23041. if (cff.encoding.predefined) {
  23042. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  23043. output);
  23044. } else {
  23045. var encoding = this.compileEncoding(cff.encoding);
  23046. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  23047. output.add(encoding);
  23048. }
  23049. }
  23050. if (cff.charset && cff.topDict.hasName('charset')) {
  23051. if (cff.charset.predefined) {
  23052. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  23053. output);
  23054. } else {
  23055. var charset = this.compileCharset(cff.charset);
  23056. topDictTracker.setEntryLocation('charset', [output.length], output);
  23057. output.add(charset);
  23058. }
  23059. }
  23060. var charStrings = this.compileCharStrings(cff.charStrings);
  23061. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  23062. output.add(charStrings);
  23063. if (cff.isCIDFont) {
  23064. // For some reason FDSelect must be in front of FDArray on windows. OSX
  23065. // and linux don't seem to care.
  23066. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  23067. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  23068. output.add(fdSelect);
  23069. // It is unclear if the sub font dictionary can have CID related
  23070. // dictionary keys, but the sanitizer doesn't like them so remove them.
  23071. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  23072. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  23073. output.add(compiled.output);
  23074. var fontDictTrackers = compiled.trackers;
  23075. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  23076. }
  23077. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  23078. // If the font data ends with INDEX whose object data is zero-length,
  23079. // the sanitizer will bail out. Add a dummy byte to avoid that.
  23080. output.add([0]);
  23081. return output.data;
  23082. },
  23083. encodeNumber: function CFFCompiler_encodeNumber(value) {
  23084. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  23085. return this.encodeInteger(value);
  23086. } else {
  23087. return this.encodeFloat(value);
  23088. }
  23089. },
  23090. encodeFloat: function CFFCompiler_encodeFloat(num) {
  23091. var value = num.toString();
  23092. // rounding inaccurate doubles
  23093. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  23094. if (m) {
  23095. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  23096. value = (Math.round(num * epsilon) / epsilon).toString();
  23097. }
  23098. var nibbles = '';
  23099. var i, ii;
  23100. for (i = 0, ii = value.length; i < ii; ++i) {
  23101. var a = value[i];
  23102. if (a === 'e') {
  23103. nibbles += value[++i] === '-' ? 'c' : 'b';
  23104. } else if (a === '.') {
  23105. nibbles += 'a';
  23106. } else if (a === '-') {
  23107. nibbles += 'e';
  23108. } else {
  23109. nibbles += a;
  23110. }
  23111. }
  23112. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  23113. var out = [30];
  23114. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  23115. out.push(parseInt(nibbles.substr(i, 2), 16));
  23116. }
  23117. return out;
  23118. },
  23119. encodeInteger: function CFFCompiler_encodeInteger(value) {
  23120. var code;
  23121. if (value >= -107 && value <= 107) {
  23122. code = [value + 139];
  23123. } else if (value >= 108 && value <= 1131) {
  23124. value = [value - 108];
  23125. code = [(value >> 8) + 247, value & 0xFF];
  23126. } else if (value >= -1131 && value <= -108) {
  23127. value = -value - 108;
  23128. code = [(value >> 8) + 251, value & 0xFF];
  23129. } else if (value >= -32768 && value <= 32767) {
  23130. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  23131. } else {
  23132. code = [0x1d,
  23133. (value >> 24) & 0xFF,
  23134. (value >> 16) & 0xFF,
  23135. (value >> 8) & 0xFF,
  23136. value & 0xFF];
  23137. }
  23138. return code;
  23139. },
  23140. compileHeader: function CFFCompiler_compileHeader(header) {
  23141. return [
  23142. header.major,
  23143. header.minor,
  23144. header.hdrSize,
  23145. header.offSize
  23146. ];
  23147. },
  23148. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  23149. var nameIndex = new CFFIndex();
  23150. for (var i = 0, ii = names.length; i < ii; ++i) {
  23151. nameIndex.add(stringToArray(names[i]));
  23152. }
  23153. return this.compileIndex(nameIndex);
  23154. },
  23155. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  23156. length,
  23157. removeCidKeys) {
  23158. var fontDictTrackers = [];
  23159. var fdArrayIndex = new CFFIndex();
  23160. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23161. var fontDict = dicts[i];
  23162. if (removeCidKeys) {
  23163. fontDict.removeByName('CIDFontVersion');
  23164. fontDict.removeByName('CIDFontRevision');
  23165. fontDict.removeByName('CIDFontType');
  23166. fontDict.removeByName('CIDCount');
  23167. fontDict.removeByName('UIDBase');
  23168. }
  23169. var fontDictTracker = new CFFOffsetTracker();
  23170. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  23171. fontDictTrackers.push(fontDictTracker);
  23172. fdArrayIndex.add(fontDictData);
  23173. fontDictTracker.offset(length);
  23174. }
  23175. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  23176. return {
  23177. trackers: fontDictTrackers,
  23178. output: fdArrayIndex
  23179. };
  23180. },
  23181. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  23182. trackers,
  23183. output) {
  23184. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23185. var fontDict = dicts[i];
  23186. assert(fontDict.privateDict && fontDict.hasName('Private'),
  23187. 'There must be an private dictionary.');
  23188. var privateDict = fontDict.privateDict;
  23189. var privateDictTracker = new CFFOffsetTracker();
  23190. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  23191. var outputLength = output.length;
  23192. privateDictTracker.offset(outputLength);
  23193. if (!privateDictData.length) {
  23194. // The private dictionary was empty, set the output length to zero to
  23195. // ensure the offset length isn't out of bounds in the eyes of the
  23196. // sanitizer.
  23197. outputLength = 0;
  23198. }
  23199. trackers[i].setEntryLocation('Private',
  23200. [privateDictData.length, outputLength],
  23201. output);
  23202. output.add(privateDictData);
  23203. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  23204. var subrs = this.compileIndex(privateDict.subrsIndex);
  23205. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  23206. output);
  23207. output.add(subrs);
  23208. }
  23209. }
  23210. },
  23211. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  23212. var out = [];
  23213. // The dictionary keys must be in a certain order.
  23214. var order = dict.order;
  23215. for (var i = 0; i < order.length; ++i) {
  23216. var key = order[i];
  23217. if (!(key in dict.values)) {
  23218. continue;
  23219. }
  23220. var values = dict.values[key];
  23221. var types = dict.types[key];
  23222. if (!isArray(types)) {
  23223. types = [types];
  23224. }
  23225. if (!isArray(values)) {
  23226. values = [values];
  23227. }
  23228. // Remove any empty dict values.
  23229. if (values.length === 0) {
  23230. continue;
  23231. }
  23232. for (var j = 0, jj = types.length; j < jj; ++j) {
  23233. var type = types[j];
  23234. var value = values[j];
  23235. switch (type) {
  23236. case 'num':
  23237. case 'sid':
  23238. out = out.concat(this.encodeNumber(value));
  23239. break;
  23240. case 'offset':
  23241. // For offsets we just insert a 32bit integer so we don't have to
  23242. // deal with figuring out the length of the offset when it gets
  23243. // replaced later on by the compiler.
  23244. var name = dict.keyToNameMap[key];
  23245. // Some offsets have the offset and the length, so just record the
  23246. // position of the first one.
  23247. if (!offsetTracker.isTracking(name)) {
  23248. offsetTracker.track(name, out.length);
  23249. }
  23250. out = out.concat([0x1d, 0, 0, 0, 0]);
  23251. break;
  23252. case 'array':
  23253. case 'delta':
  23254. out = out.concat(this.encodeNumber(value));
  23255. for (var k = 1, kk = values.length; k < kk; ++k) {
  23256. out = out.concat(this.encodeNumber(values[k]));
  23257. }
  23258. break;
  23259. default:
  23260. error('Unknown data type of ' + type);
  23261. break;
  23262. }
  23263. }
  23264. out = out.concat(dict.opcodes[key]);
  23265. }
  23266. return out;
  23267. },
  23268. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  23269. var stringIndex = new CFFIndex();
  23270. for (var i = 0, ii = strings.length; i < ii; ++i) {
  23271. stringIndex.add(stringToArray(strings[i]));
  23272. }
  23273. return this.compileIndex(stringIndex);
  23274. },
  23275. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  23276. var globalSubrIndex = this.cff.globalSubrIndex;
  23277. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  23278. },
  23279. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  23280. return this.compileIndex(charStrings);
  23281. },
  23282. compileCharset: function CFFCompiler_compileCharset(charset) {
  23283. return this.compileTypedArray(charset.raw);
  23284. },
  23285. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  23286. return this.compileTypedArray(encoding.raw);
  23287. },
  23288. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  23289. return this.compileTypedArray(fdSelect);
  23290. },
  23291. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  23292. var out = [];
  23293. for (var i = 0, ii = data.length; i < ii; ++i) {
  23294. out[i] = data[i];
  23295. }
  23296. return out;
  23297. },
  23298. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  23299. trackers = trackers || [];
  23300. var objects = index.objects;
  23301. // First 2 bytes contains the number of objects contained into this index
  23302. var count = objects.length;
  23303. // If there is no object, just create an index. This technically
  23304. // should just be [0, 0] but OTS has an issue with that.
  23305. if (count === 0) {
  23306. return [0, 0, 0];
  23307. }
  23308. var data = [(count >> 8) & 0xFF, count & 0xff];
  23309. var lastOffset = 1, i;
  23310. for (i = 0; i < count; ++i) {
  23311. lastOffset += objects[i].length;
  23312. }
  23313. var offsetSize;
  23314. if (lastOffset < 0x100) {
  23315. offsetSize = 1;
  23316. } else if (lastOffset < 0x10000) {
  23317. offsetSize = 2;
  23318. } else if (lastOffset < 0x1000000) {
  23319. offsetSize = 3;
  23320. } else {
  23321. offsetSize = 4;
  23322. }
  23323. // Next byte contains the offset size use to reference object in the file
  23324. data.push(offsetSize);
  23325. // Add another offset after this one because we need a new offset
  23326. var relativeOffset = 1;
  23327. for (i = 0; i < count + 1; i++) {
  23328. if (offsetSize === 1) {
  23329. data.push(relativeOffset & 0xFF);
  23330. } else if (offsetSize === 2) {
  23331. data.push((relativeOffset >> 8) & 0xFF,
  23332. relativeOffset & 0xFF);
  23333. } else if (offsetSize === 3) {
  23334. data.push((relativeOffset >> 16) & 0xFF,
  23335. (relativeOffset >> 8) & 0xFF,
  23336. relativeOffset & 0xFF);
  23337. } else {
  23338. data.push((relativeOffset >>> 24) & 0xFF,
  23339. (relativeOffset >> 16) & 0xFF,
  23340. (relativeOffset >> 8) & 0xFF,
  23341. relativeOffset & 0xFF);
  23342. }
  23343. if (objects[i]) {
  23344. relativeOffset += objects[i].length;
  23345. }
  23346. }
  23347. for (i = 0; i < count; i++) {
  23348. // Notify the tracker where the object will be offset in the data.
  23349. if (trackers[i]) {
  23350. trackers[i].offset(data.length);
  23351. }
  23352. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  23353. data.push(objects[i][j]);
  23354. }
  23355. }
  23356. return data;
  23357. }
  23358. };
  23359. return CFFCompiler;
  23360. })();
  23361. // Workaround for seac on Windows.
  23362. (function checkSeacSupport() {
  23363. if (/Windows/.test(navigator.userAgent)) {
  23364. SEAC_ANALYSIS_ENABLED = true;
  23365. }
  23366. })();
  23367. // Workaround for Private Use Area characters in Chrome on Windows
  23368. // http://code.google.com/p/chromium/issues/detail?id=122465
  23369. // https://github.com/mozilla/pdf.js/issues/1689
  23370. (function checkChromeWindows() {
  23371. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  23372. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  23373. }
  23374. })();
  23375. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23376. function getLong(data, offset) {
  23377. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23378. (data[offset + 2] << 8) | data[offset + 3];
  23379. }
  23380. function getUshort(data, offset) {
  23381. return (data[offset] << 8) | data[offset + 1];
  23382. }
  23383. function parseCmap(data, start, end) {
  23384. var offset = (getUshort(data, start + 2) === 1 ?
  23385. getLong(data, start + 8) : getLong(data, start + 16));
  23386. var format = getUshort(data, start + offset);
  23387. var length, ranges, p, i;
  23388. if (format === 4) {
  23389. length = getUshort(data, start + offset + 2);
  23390. var segCount = getUshort(data, start + offset + 6) >> 1;
  23391. p = start + offset + 14;
  23392. ranges = [];
  23393. for (i = 0; i < segCount; i++, p += 2) {
  23394. ranges[i] = {end: getUshort(data, p)};
  23395. }
  23396. p += 2;
  23397. for (i = 0; i < segCount; i++, p += 2) {
  23398. ranges[i].start = getUshort(data, p);
  23399. }
  23400. for (i = 0; i < segCount; i++, p += 2) {
  23401. ranges[i].idDelta = getUshort(data, p);
  23402. }
  23403. for (i = 0; i < segCount; i++, p += 2) {
  23404. var idOffset = getUshort(data, p);
  23405. if (idOffset === 0) {
  23406. continue;
  23407. }
  23408. ranges[i].ids = [];
  23409. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23410. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23411. idOffset += 2;
  23412. }
  23413. }
  23414. return ranges;
  23415. } else if (format === 12) {
  23416. length = getLong(data, start + offset + 4);
  23417. var groups = getLong(data, start + offset + 12);
  23418. p = start + offset + 16;
  23419. ranges = [];
  23420. for (i = 0; i < groups; i++) {
  23421. ranges.push({
  23422. start: getLong(data, p),
  23423. end: getLong(data, p + 4),
  23424. idDelta: getLong(data, p + 8) - getLong(data, p)
  23425. });
  23426. p += 12;
  23427. }
  23428. return ranges;
  23429. }
  23430. error('not supported cmap: ' + format);
  23431. }
  23432. function parseCff(data, start, end) {
  23433. var properties = {};
  23434. var parser = new CFFParser(new Stream(data, start, end - start),
  23435. properties);
  23436. var cff = parser.parse();
  23437. return {
  23438. glyphs: cff.charStrings.objects,
  23439. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23440. cff.topDict.privateDict.subrsIndex.objects),
  23441. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23442. };
  23443. }
  23444. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23445. var itemSize, itemDecode;
  23446. if (isGlyphLocationsLong) {
  23447. itemSize = 4;
  23448. itemDecode = function fontItemDecodeLong(data, offset) {
  23449. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23450. (data[offset + 2] << 8) | data[offset + 3];
  23451. };
  23452. } else {
  23453. itemSize = 2;
  23454. itemDecode = function fontItemDecode(data, offset) {
  23455. return (data[offset] << 9) | (data[offset + 1] << 1);
  23456. };
  23457. }
  23458. var glyphs = [];
  23459. var startOffset = itemDecode(loca, 0);
  23460. for (var j = itemSize; j < loca.length; j += itemSize) {
  23461. var endOffset = itemDecode(loca, j);
  23462. glyphs.push(glyf.subarray(startOffset, endOffset));
  23463. startOffset = endOffset;
  23464. }
  23465. return glyphs;
  23466. }
  23467. function lookupCmap(ranges, unicode) {
  23468. var code = unicode.charCodeAt(0);
  23469. var l = 0, r = ranges.length - 1;
  23470. while (l < r) {
  23471. var c = (l + r + 1) >> 1;
  23472. if (code < ranges[c].start) {
  23473. r = c - 1;
  23474. } else {
  23475. l = c;
  23476. }
  23477. }
  23478. if (ranges[l].start <= code && code <= ranges[l].end) {
  23479. return (ranges[l].idDelta + (ranges[l].ids ?
  23480. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23481. }
  23482. return 0;
  23483. }
  23484. function compileGlyf(code, js, font) {
  23485. function moveTo(x, y) {
  23486. js.push('c.moveTo(' + x + ',' + y + ');');
  23487. }
  23488. function lineTo(x, y) {
  23489. js.push('c.lineTo(' + x + ',' + y + ');');
  23490. }
  23491. function quadraticCurveTo(xa, ya, x, y) {
  23492. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  23493. x + ',' + y + ');');
  23494. }
  23495. var i = 0;
  23496. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23497. var flags;
  23498. var x = 0, y = 0;
  23499. i += 10;
  23500. if (numberOfContours < 0) {
  23501. // composite glyph
  23502. do {
  23503. flags = (code[i] << 8) | code[i + 1];
  23504. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23505. i += 4;
  23506. var arg1, arg2;
  23507. if ((flags & 0x01)) {
  23508. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23509. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23510. i += 4;
  23511. } else {
  23512. arg1 = code[i++]; arg2 = code[i++];
  23513. }
  23514. if ((flags & 0x02)) {
  23515. x = arg1;
  23516. y = arg2;
  23517. } else {
  23518. x = 0; y = 0; // TODO "they are points" ?
  23519. }
  23520. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23521. if ((flags & 0x08)) {
  23522. scaleX =
  23523. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23524. i += 2;
  23525. } else if ((flags & 0x40)) {
  23526. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23527. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23528. i += 4;
  23529. } else if ((flags & 0x80)) {
  23530. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23531. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23532. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23533. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23534. i += 8;
  23535. }
  23536. var subglyph = font.glyphs[glyphIndex];
  23537. if (subglyph) {
  23538. js.push('c.save();');
  23539. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  23540. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  23541. compileGlyf(subglyph, js, font);
  23542. js.push('c.restore();');
  23543. }
  23544. } while ((flags & 0x20));
  23545. } else {
  23546. // simple glyph
  23547. var endPtsOfContours = [];
  23548. var j, jj;
  23549. for (j = 0; j < numberOfContours; j++) {
  23550. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23551. i += 2;
  23552. }
  23553. var instructionLength = (code[i] << 8) | code[i + 1];
  23554. i += 2 + instructionLength; // skipping the instructions
  23555. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23556. var points = [];
  23557. while (points.length < numberOfPoints) {
  23558. flags = code[i++];
  23559. var repeat = 1;
  23560. if ((flags & 0x08)) {
  23561. repeat += code[i++];
  23562. }
  23563. while (repeat-- > 0) {
  23564. points.push({flags: flags});
  23565. }
  23566. }
  23567. for (j = 0; j < numberOfPoints; j++) {
  23568. switch (points[j].flags & 0x12) {
  23569. case 0x00:
  23570. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23571. i += 2;
  23572. break;
  23573. case 0x02:
  23574. x -= code[i++];
  23575. break;
  23576. case 0x12:
  23577. x += code[i++];
  23578. break;
  23579. }
  23580. points[j].x = x;
  23581. }
  23582. for (j = 0; j < numberOfPoints; j++) {
  23583. switch (points[j].flags & 0x24) {
  23584. case 0x00:
  23585. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23586. i += 2;
  23587. break;
  23588. case 0x04:
  23589. y -= code[i++];
  23590. break;
  23591. case 0x24:
  23592. y += code[i++];
  23593. break;
  23594. }
  23595. points[j].y = y;
  23596. }
  23597. var startPoint = 0;
  23598. for (i = 0; i < numberOfContours; i++) {
  23599. var endPoint = endPtsOfContours[i];
  23600. // contours might have implicit points, which is located in the middle
  23601. // between two neighboring off-curve points
  23602. var contour = points.slice(startPoint, endPoint + 1);
  23603. if ((contour[0].flags & 1)) {
  23604. contour.push(contour[0]); // using start point at the contour end
  23605. } else if ((contour[contour.length - 1].flags & 1)) {
  23606. // first is off-curve point, trying to use one from the end
  23607. contour.unshift(contour[contour.length - 1]);
  23608. } else {
  23609. // start and end are off-curve points, creating implicit one
  23610. var p = {
  23611. flags: 1,
  23612. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23613. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23614. };
  23615. contour.unshift(p);
  23616. contour.push(p);
  23617. }
  23618. moveTo(contour[0].x, contour[0].y);
  23619. for (j = 1, jj = contour.length; j < jj; j++) {
  23620. if ((contour[j].flags & 1)) {
  23621. lineTo(contour[j].x, contour[j].y);
  23622. } else if ((contour[j + 1].flags & 1)){
  23623. quadraticCurveTo(contour[j].x, contour[j].y,
  23624. contour[j + 1].x, contour[j + 1].y);
  23625. j++;
  23626. } else {
  23627. quadraticCurveTo(contour[j].x, contour[j].y,
  23628. (contour[j].x + contour[j + 1].x) / 2,
  23629. (contour[j].y + contour[j + 1].y) / 2);
  23630. }
  23631. }
  23632. startPoint = endPoint + 1;
  23633. }
  23634. }
  23635. }
  23636. function compileCharString(code, js, font) {
  23637. var stack = [];
  23638. var x = 0, y = 0;
  23639. var stems = 0;
  23640. function moveTo(x, y) {
  23641. js.push('c.moveTo(' + x + ',' + y + ');');
  23642. }
  23643. function lineTo(x, y) {
  23644. js.push('c.lineTo(' + x + ',' + y + ');');
  23645. }
  23646. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23647. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  23648. x + ',' + y + ');');
  23649. }
  23650. function parse(code) {
  23651. var i = 0;
  23652. while (i < code.length) {
  23653. var stackClean = false;
  23654. var v = code[i++];
  23655. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23656. switch (v) {
  23657. case 1: // hstem
  23658. stems += stack.length >> 1;
  23659. stackClean = true;
  23660. break;
  23661. case 3: // vstem
  23662. stems += stack.length >> 1;
  23663. stackClean = true;
  23664. break;
  23665. case 4: // vmoveto
  23666. y += stack.pop();
  23667. moveTo(x, y);
  23668. stackClean = true;
  23669. break;
  23670. case 5: // rlineto
  23671. while (stack.length > 0) {
  23672. x += stack.shift();
  23673. y += stack.shift();
  23674. lineTo(x, y);
  23675. }
  23676. break;
  23677. case 6: // hlineto
  23678. while (stack.length > 0) {
  23679. x += stack.shift();
  23680. lineTo(x, y);
  23681. if (stack.length === 0) {
  23682. break;
  23683. }
  23684. y += stack.shift();
  23685. lineTo(x, y);
  23686. }
  23687. break;
  23688. case 7: // vlineto
  23689. while (stack.length > 0) {
  23690. y += stack.shift();
  23691. lineTo(x, y);
  23692. if (stack.length === 0) {
  23693. break;
  23694. }
  23695. x += stack.shift();
  23696. lineTo(x, y);
  23697. }
  23698. break;
  23699. case 8: // rrcurveto
  23700. while (stack.length > 0) {
  23701. xa = x + stack.shift(); ya = y + stack.shift();
  23702. xb = xa + stack.shift(); yb = ya + stack.shift();
  23703. x = xb + stack.shift(); y = yb + stack.shift();
  23704. bezierCurveTo(xa, ya, xb, yb, x, y);
  23705. }
  23706. break;
  23707. case 10: // callsubr
  23708. n = stack.pop() + font.subrsBias;
  23709. subrCode = font.subrs[n];
  23710. if (subrCode) {
  23711. parse(subrCode);
  23712. }
  23713. break;
  23714. case 11: // return
  23715. return;
  23716. case 12:
  23717. v = code[i++];
  23718. switch (v) {
  23719. case 34: // flex
  23720. xa = x + stack.shift();
  23721. xb = xa + stack.shift(); y1 = y + stack.shift();
  23722. x = xb + stack.shift();
  23723. bezierCurveTo(xa, y, xb, y1, x, y1);
  23724. xa = x + stack.shift();
  23725. xb = xa + stack.shift();
  23726. x = xb + stack.shift();
  23727. bezierCurveTo(xa, y1, xb, y, x, y);
  23728. break;
  23729. case 35: // flex
  23730. xa = x + stack.shift(); ya = y + stack.shift();
  23731. xb = xa + stack.shift(); yb = ya + stack.shift();
  23732. x = xb + stack.shift(); y = yb + stack.shift();
  23733. bezierCurveTo(xa, ya, xb, yb, x, y);
  23734. xa = x + stack.shift(); ya = y + stack.shift();
  23735. xb = xa + stack.shift(); yb = ya + stack.shift();
  23736. x = xb + stack.shift(); y = yb + stack.shift();
  23737. bezierCurveTo(xa, ya, xb, yb, x, y);
  23738. stack.pop(); // fd
  23739. break;
  23740. case 36: // hflex1
  23741. xa = x + stack.shift(); y1 = y + stack.shift();
  23742. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23743. x = xb + stack.shift();
  23744. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23745. xa = x + stack.shift();
  23746. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23747. x = xb + stack.shift();
  23748. bezierCurveTo(xa, y2, xb, y3, x, y);
  23749. break;
  23750. case 37: // flex1
  23751. var x0 = x, y0 = y;
  23752. xa = x + stack.shift(); ya = y + stack.shift();
  23753. xb = xa + stack.shift(); yb = ya + stack.shift();
  23754. x = xb + stack.shift(); y = yb + stack.shift();
  23755. bezierCurveTo(xa, ya, xb, yb, x, y);
  23756. xa = x + stack.shift(); ya = y + stack.shift();
  23757. xb = xa + stack.shift(); yb = ya + stack.shift();
  23758. x = xb; y = yb;
  23759. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23760. x += stack.shift();
  23761. } else {
  23762. y += stack.shift();
  23763. }
  23764. bezierCurveTo(xa, ya, xb, yb, x, y);
  23765. break;
  23766. default:
  23767. error('unknown operator: 12 ' + v);
  23768. }
  23769. break;
  23770. case 14: // endchar
  23771. if (stack.length >= 4) {
  23772. var achar = stack.pop();
  23773. var bchar = stack.pop();
  23774. y = stack.pop();
  23775. x = stack.pop();
  23776. js.push('c.save();');
  23777. js.push('c.translate('+ x + ',' + y + ');');
  23778. var gid = lookupCmap(font.cmap, String.fromCharCode(
  23779. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  23780. compileCharString(font.glyphs[gid], js, font);
  23781. js.push('c.restore();');
  23782. gid = lookupCmap(font.cmap, String.fromCharCode(
  23783. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  23784. compileCharString(font.glyphs[gid], js, font);
  23785. }
  23786. return;
  23787. case 18: // hstemhm
  23788. stems += stack.length >> 1;
  23789. stackClean = true;
  23790. break;
  23791. case 19: // hintmask
  23792. stems += stack.length >> 1;
  23793. i += (stems + 7) >> 3;
  23794. stackClean = true;
  23795. break;
  23796. case 20: // cntrmask
  23797. stems += stack.length >> 1;
  23798. i += (stems + 7) >> 3;
  23799. stackClean = true;
  23800. break;
  23801. case 21: // rmoveto
  23802. y += stack.pop();
  23803. x += stack.pop();
  23804. moveTo(x, y);
  23805. stackClean = true;
  23806. break;
  23807. case 22: // hmoveto
  23808. x += stack.pop();
  23809. moveTo(x, y);
  23810. stackClean = true;
  23811. break;
  23812. case 23: // vstemhm
  23813. stems += stack.length >> 1;
  23814. stackClean = true;
  23815. break;
  23816. case 24: // rcurveline
  23817. while (stack.length > 2) {
  23818. xa = x + stack.shift(); ya = y + stack.shift();
  23819. xb = xa + stack.shift(); yb = ya + stack.shift();
  23820. x = xb + stack.shift(); y = yb + stack.shift();
  23821. bezierCurveTo(xa, ya, xb, yb, x, y);
  23822. }
  23823. x += stack.shift();
  23824. y += stack.shift();
  23825. lineTo(x, y);
  23826. break;
  23827. case 25: // rlinecurve
  23828. while (stack.length > 6) {
  23829. x += stack.shift();
  23830. y += stack.shift();
  23831. lineTo(x, y);
  23832. }
  23833. xa = x + stack.shift(); ya = y + stack.shift();
  23834. xb = xa + stack.shift(); yb = ya + stack.shift();
  23835. x = xb + stack.shift(); y = yb + stack.shift();
  23836. bezierCurveTo(xa, ya, xb, yb, x, y);
  23837. break;
  23838. case 26: // vvcurveto
  23839. if (stack.length % 2) {
  23840. x += stack.shift();
  23841. }
  23842. while (stack.length > 0) {
  23843. xa = x; ya = y + stack.shift();
  23844. xb = xa + stack.shift(); yb = ya + stack.shift();
  23845. x = xb; y = yb + stack.shift();
  23846. bezierCurveTo(xa, ya, xb, yb, x, y);
  23847. }
  23848. break;
  23849. case 27: // hhcurveto
  23850. if (stack.length % 2) {
  23851. y += stack.shift();
  23852. }
  23853. while (stack.length > 0) {
  23854. xa = x + stack.shift(); ya = y;
  23855. xb = xa + stack.shift(); yb = ya + stack.shift();
  23856. x = xb + stack.shift(); y = yb;
  23857. bezierCurveTo(xa, ya, xb, yb, x, y);
  23858. }
  23859. break;
  23860. case 28:
  23861. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23862. i += 2;
  23863. break;
  23864. case 29: // callgsubr
  23865. n = stack.pop() + font.gsubrsBias;
  23866. subrCode = font.gsubrs[n];
  23867. if (subrCode) {
  23868. parse(subrCode);
  23869. }
  23870. break;
  23871. case 30: // vhcurveto
  23872. while (stack.length > 0) {
  23873. xa = x; ya = y + stack.shift();
  23874. xb = xa + stack.shift(); yb = ya + stack.shift();
  23875. x = xb + stack.shift();
  23876. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23877. bezierCurveTo(xa, ya, xb, yb, x, y);
  23878. if (stack.length === 0) {
  23879. break;
  23880. }
  23881. xa = x + stack.shift(); ya = y;
  23882. xb = xa + stack.shift(); yb = ya + stack.shift();
  23883. y = yb + stack.shift();
  23884. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23885. bezierCurveTo(xa, ya, xb, yb, x, y);
  23886. }
  23887. break;
  23888. case 31: // hvcurveto
  23889. while (stack.length > 0) {
  23890. xa = x + stack.shift(); ya = y;
  23891. xb = xa + stack.shift(); yb = ya + stack.shift();
  23892. y = yb + stack.shift();
  23893. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23894. bezierCurveTo(xa, ya, xb, yb, x, y);
  23895. if (stack.length === 0) {
  23896. break;
  23897. }
  23898. xa = x; ya = y + stack.shift();
  23899. xb = xa + stack.shift(); yb = ya + stack.shift();
  23900. x = xb + stack.shift();
  23901. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23902. bezierCurveTo(xa, ya, xb, yb, x, y);
  23903. }
  23904. break;
  23905. default:
  23906. if (v < 32) {
  23907. error('unknown operator: ' + v);
  23908. }
  23909. if (v < 247) {
  23910. stack.push(v - 139);
  23911. } else if (v < 251) {
  23912. stack.push((v - 247) * 256 + code[i++] + 108);
  23913. } else if (v < 255) {
  23914. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23915. } else {
  23916. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23917. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23918. i += 4;
  23919. }
  23920. break;
  23921. }
  23922. if (stackClean) {
  23923. stack.length = 0;
  23924. }
  23925. }
  23926. }
  23927. parse(code);
  23928. }
  23929. var noop = '';
  23930. function CompiledFont(fontMatrix) {
  23931. this.compiledGlyphs = {};
  23932. this.fontMatrix = fontMatrix;
  23933. }
  23934. CompiledFont.prototype = {
  23935. getPathJs: function (unicode) {
  23936. var gid = lookupCmap(this.cmap, unicode);
  23937. var fn = this.compiledGlyphs[gid];
  23938. if (!fn) {
  23939. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  23940. }
  23941. return fn;
  23942. },
  23943. compileGlyph: function (code) {
  23944. if (!code || code.length === 0 || code[0] === 14) {
  23945. return noop;
  23946. }
  23947. var js = [];
  23948. js.push('c.save();');
  23949. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  23950. js.push('c.scale(size, -size);');
  23951. this.compileGlyphImpl(code, js);
  23952. js.push('c.restore();');
  23953. return js.join('\n');
  23954. },
  23955. compileGlyphImpl: function () {
  23956. error('Children classes should implement this.');
  23957. },
  23958. hasBuiltPath: function (unicode) {
  23959. var gid = lookupCmap(this.cmap, unicode);
  23960. return gid in this.compiledGlyphs;
  23961. }
  23962. };
  23963. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23964. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23965. CompiledFont.call(this, fontMatrix);
  23966. this.glyphs = glyphs;
  23967. this.cmap = cmap;
  23968. this.compiledGlyphs = [];
  23969. }
  23970. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23971. compileGlyphImpl: function (code, js) {
  23972. compileGlyf(code, js, this);
  23973. }
  23974. });
  23975. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23976. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23977. CompiledFont.call(this, fontMatrix);
  23978. this.glyphs = cffInfo.glyphs;
  23979. this.gsubrs = cffInfo.gsubrs || [];
  23980. this.subrs = cffInfo.subrs || [];
  23981. this.cmap = cmap;
  23982. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  23983. this.compiledGlyphs = [];
  23984. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23985. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23986. this.subrsBias = (this.subrs.length < 1240 ?
  23987. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23988. }
  23989. Util.inherit(Type2Compiled, CompiledFont, {
  23990. compileGlyphImpl: function (code, js) {
  23991. compileCharString(code, js, this);
  23992. }
  23993. });
  23994. return {
  23995. create: function FontRendererFactory_create(font) {
  23996. var data = new Uint8Array(font.data);
  23997. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23998. var numTables = getUshort(data, 4);
  23999. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  24000. var tag = bytesToString(data.subarray(p, p + 4));
  24001. var offset = getLong(data, p + 8);
  24002. var length = getLong(data, p + 12);
  24003. switch (tag) {
  24004. case 'cmap':
  24005. cmap = parseCmap(data, offset, offset + length);
  24006. break;
  24007. case 'glyf':
  24008. glyf = data.subarray(offset, offset + length);
  24009. break;
  24010. case 'loca':
  24011. loca = data.subarray(offset, offset + length);
  24012. break;
  24013. case 'head':
  24014. unitsPerEm = getUshort(data, offset + 18);
  24015. indexToLocFormat = getUshort(data, offset + 50);
  24016. break;
  24017. case 'CFF ':
  24018. cff = parseCff(data, offset, offset + length);
  24019. break;
  24020. }
  24021. }
  24022. if (glyf) {
  24023. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  24024. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  24025. return new TrueTypeCompiled(
  24026. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  24027. } else {
  24028. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  24029. }
  24030. }
  24031. };
  24032. })();
  24033. var GlyphsUnicode = {
  24034. A: 0x0041,
  24035. AE: 0x00C6,
  24036. AEacute: 0x01FC,
  24037. AEmacron: 0x01E2,
  24038. AEsmall: 0xF7E6,
  24039. Aacute: 0x00C1,
  24040. Aacutesmall: 0xF7E1,
  24041. Abreve: 0x0102,
  24042. Abreveacute: 0x1EAE,
  24043. Abrevecyrillic: 0x04D0,
  24044. Abrevedotbelow: 0x1EB6,
  24045. Abrevegrave: 0x1EB0,
  24046. Abrevehookabove: 0x1EB2,
  24047. Abrevetilde: 0x1EB4,
  24048. Acaron: 0x01CD,
  24049. Acircle: 0x24B6,
  24050. Acircumflex: 0x00C2,
  24051. Acircumflexacute: 0x1EA4,
  24052. Acircumflexdotbelow: 0x1EAC,
  24053. Acircumflexgrave: 0x1EA6,
  24054. Acircumflexhookabove: 0x1EA8,
  24055. Acircumflexsmall: 0xF7E2,
  24056. Acircumflextilde: 0x1EAA,
  24057. Acute: 0xF6C9,
  24058. Acutesmall: 0xF7B4,
  24059. Acyrillic: 0x0410,
  24060. Adblgrave: 0x0200,
  24061. Adieresis: 0x00C4,
  24062. Adieresiscyrillic: 0x04D2,
  24063. Adieresismacron: 0x01DE,
  24064. Adieresissmall: 0xF7E4,
  24065. Adotbelow: 0x1EA0,
  24066. Adotmacron: 0x01E0,
  24067. Agrave: 0x00C0,
  24068. Agravesmall: 0xF7E0,
  24069. Ahookabove: 0x1EA2,
  24070. Aiecyrillic: 0x04D4,
  24071. Ainvertedbreve: 0x0202,
  24072. Alpha: 0x0391,
  24073. Alphatonos: 0x0386,
  24074. Amacron: 0x0100,
  24075. Amonospace: 0xFF21,
  24076. Aogonek: 0x0104,
  24077. Aring: 0x00C5,
  24078. Aringacute: 0x01FA,
  24079. Aringbelow: 0x1E00,
  24080. Aringsmall: 0xF7E5,
  24081. Asmall: 0xF761,
  24082. Atilde: 0x00C3,
  24083. Atildesmall: 0xF7E3,
  24084. Aybarmenian: 0x0531,
  24085. B: 0x0042,
  24086. Bcircle: 0x24B7,
  24087. Bdotaccent: 0x1E02,
  24088. Bdotbelow: 0x1E04,
  24089. Becyrillic: 0x0411,
  24090. Benarmenian: 0x0532,
  24091. Beta: 0x0392,
  24092. Bhook: 0x0181,
  24093. Blinebelow: 0x1E06,
  24094. Bmonospace: 0xFF22,
  24095. Brevesmall: 0xF6F4,
  24096. Bsmall: 0xF762,
  24097. Btopbar: 0x0182,
  24098. C: 0x0043,
  24099. Caarmenian: 0x053E,
  24100. Cacute: 0x0106,
  24101. Caron: 0xF6CA,
  24102. Caronsmall: 0xF6F5,
  24103. Ccaron: 0x010C,
  24104. Ccedilla: 0x00C7,
  24105. Ccedillaacute: 0x1E08,
  24106. Ccedillasmall: 0xF7E7,
  24107. Ccircle: 0x24B8,
  24108. Ccircumflex: 0x0108,
  24109. Cdot: 0x010A,
  24110. Cdotaccent: 0x010A,
  24111. Cedillasmall: 0xF7B8,
  24112. Chaarmenian: 0x0549,
  24113. Cheabkhasiancyrillic: 0x04BC,
  24114. Checyrillic: 0x0427,
  24115. Chedescenderabkhasiancyrillic: 0x04BE,
  24116. Chedescendercyrillic: 0x04B6,
  24117. Chedieresiscyrillic: 0x04F4,
  24118. Cheharmenian: 0x0543,
  24119. Chekhakassiancyrillic: 0x04CB,
  24120. Cheverticalstrokecyrillic: 0x04B8,
  24121. Chi: 0x03A7,
  24122. Chook: 0x0187,
  24123. Circumflexsmall: 0xF6F6,
  24124. Cmonospace: 0xFF23,
  24125. Coarmenian: 0x0551,
  24126. Csmall: 0xF763,
  24127. D: 0x0044,
  24128. DZ: 0x01F1,
  24129. DZcaron: 0x01C4,
  24130. Daarmenian: 0x0534,
  24131. Dafrican: 0x0189,
  24132. Dcaron: 0x010E,
  24133. Dcedilla: 0x1E10,
  24134. Dcircle: 0x24B9,
  24135. Dcircumflexbelow: 0x1E12,
  24136. Dcroat: 0x0110,
  24137. Ddotaccent: 0x1E0A,
  24138. Ddotbelow: 0x1E0C,
  24139. Decyrillic: 0x0414,
  24140. Deicoptic: 0x03EE,
  24141. Delta: 0x2206,
  24142. Deltagreek: 0x0394,
  24143. Dhook: 0x018A,
  24144. Dieresis: 0xF6CB,
  24145. DieresisAcute: 0xF6CC,
  24146. DieresisGrave: 0xF6CD,
  24147. Dieresissmall: 0xF7A8,
  24148. Digammagreek: 0x03DC,
  24149. Djecyrillic: 0x0402,
  24150. Dlinebelow: 0x1E0E,
  24151. Dmonospace: 0xFF24,
  24152. Dotaccentsmall: 0xF6F7,
  24153. Dslash: 0x0110,
  24154. Dsmall: 0xF764,
  24155. Dtopbar: 0x018B,
  24156. Dz: 0x01F2,
  24157. Dzcaron: 0x01C5,
  24158. Dzeabkhasiancyrillic: 0x04E0,
  24159. Dzecyrillic: 0x0405,
  24160. Dzhecyrillic: 0x040F,
  24161. E: 0x0045,
  24162. Eacute: 0x00C9,
  24163. Eacutesmall: 0xF7E9,
  24164. Ebreve: 0x0114,
  24165. Ecaron: 0x011A,
  24166. Ecedillabreve: 0x1E1C,
  24167. Echarmenian: 0x0535,
  24168. Ecircle: 0x24BA,
  24169. Ecircumflex: 0x00CA,
  24170. Ecircumflexacute: 0x1EBE,
  24171. Ecircumflexbelow: 0x1E18,
  24172. Ecircumflexdotbelow: 0x1EC6,
  24173. Ecircumflexgrave: 0x1EC0,
  24174. Ecircumflexhookabove: 0x1EC2,
  24175. Ecircumflexsmall: 0xF7EA,
  24176. Ecircumflextilde: 0x1EC4,
  24177. Ecyrillic: 0x0404,
  24178. Edblgrave: 0x0204,
  24179. Edieresis: 0x00CB,
  24180. Edieresissmall: 0xF7EB,
  24181. Edot: 0x0116,
  24182. Edotaccent: 0x0116,
  24183. Edotbelow: 0x1EB8,
  24184. Efcyrillic: 0x0424,
  24185. Egrave: 0x00C8,
  24186. Egravesmall: 0xF7E8,
  24187. Eharmenian: 0x0537,
  24188. Ehookabove: 0x1EBA,
  24189. Eightroman: 0x2167,
  24190. Einvertedbreve: 0x0206,
  24191. Eiotifiedcyrillic: 0x0464,
  24192. Elcyrillic: 0x041B,
  24193. Elevenroman: 0x216A,
  24194. Emacron: 0x0112,
  24195. Emacronacute: 0x1E16,
  24196. Emacrongrave: 0x1E14,
  24197. Emcyrillic: 0x041C,
  24198. Emonospace: 0xFF25,
  24199. Encyrillic: 0x041D,
  24200. Endescendercyrillic: 0x04A2,
  24201. Eng: 0x014A,
  24202. Enghecyrillic: 0x04A4,
  24203. Enhookcyrillic: 0x04C7,
  24204. Eogonek: 0x0118,
  24205. Eopen: 0x0190,
  24206. Epsilon: 0x0395,
  24207. Epsilontonos: 0x0388,
  24208. Ercyrillic: 0x0420,
  24209. Ereversed: 0x018E,
  24210. Ereversedcyrillic: 0x042D,
  24211. Escyrillic: 0x0421,
  24212. Esdescendercyrillic: 0x04AA,
  24213. Esh: 0x01A9,
  24214. Esmall: 0xF765,
  24215. Eta: 0x0397,
  24216. Etarmenian: 0x0538,
  24217. Etatonos: 0x0389,
  24218. Eth: 0x00D0,
  24219. Ethsmall: 0xF7F0,
  24220. Etilde: 0x1EBC,
  24221. Etildebelow: 0x1E1A,
  24222. Euro: 0x20AC,
  24223. Ezh: 0x01B7,
  24224. Ezhcaron: 0x01EE,
  24225. Ezhreversed: 0x01B8,
  24226. F: 0x0046,
  24227. Fcircle: 0x24BB,
  24228. Fdotaccent: 0x1E1E,
  24229. Feharmenian: 0x0556,
  24230. Feicoptic: 0x03E4,
  24231. Fhook: 0x0191,
  24232. Fitacyrillic: 0x0472,
  24233. Fiveroman: 0x2164,
  24234. Fmonospace: 0xFF26,
  24235. Fourroman: 0x2163,
  24236. Fsmall: 0xF766,
  24237. G: 0x0047,
  24238. GBsquare: 0x3387,
  24239. Gacute: 0x01F4,
  24240. Gamma: 0x0393,
  24241. Gammaafrican: 0x0194,
  24242. Gangiacoptic: 0x03EA,
  24243. Gbreve: 0x011E,
  24244. Gcaron: 0x01E6,
  24245. Gcedilla: 0x0122,
  24246. Gcircle: 0x24BC,
  24247. Gcircumflex: 0x011C,
  24248. Gcommaaccent: 0x0122,
  24249. Gdot: 0x0120,
  24250. Gdotaccent: 0x0120,
  24251. Gecyrillic: 0x0413,
  24252. Ghadarmenian: 0x0542,
  24253. Ghemiddlehookcyrillic: 0x0494,
  24254. Ghestrokecyrillic: 0x0492,
  24255. Gheupturncyrillic: 0x0490,
  24256. Ghook: 0x0193,
  24257. Gimarmenian: 0x0533,
  24258. Gjecyrillic: 0x0403,
  24259. Gmacron: 0x1E20,
  24260. Gmonospace: 0xFF27,
  24261. Grave: 0xF6CE,
  24262. Gravesmall: 0xF760,
  24263. Gsmall: 0xF767,
  24264. Gsmallhook: 0x029B,
  24265. Gstroke: 0x01E4,
  24266. H: 0x0048,
  24267. H18533: 0x25CF,
  24268. H18543: 0x25AA,
  24269. H18551: 0x25AB,
  24270. H22073: 0x25A1,
  24271. HPsquare: 0x33CB,
  24272. Haabkhasiancyrillic: 0x04A8,
  24273. Hadescendercyrillic: 0x04B2,
  24274. Hardsigncyrillic: 0x042A,
  24275. Hbar: 0x0126,
  24276. Hbrevebelow: 0x1E2A,
  24277. Hcedilla: 0x1E28,
  24278. Hcircle: 0x24BD,
  24279. Hcircumflex: 0x0124,
  24280. Hdieresis: 0x1E26,
  24281. Hdotaccent: 0x1E22,
  24282. Hdotbelow: 0x1E24,
  24283. Hmonospace: 0xFF28,
  24284. Hoarmenian: 0x0540,
  24285. Horicoptic: 0x03E8,
  24286. Hsmall: 0xF768,
  24287. Hungarumlaut: 0xF6CF,
  24288. Hungarumlautsmall: 0xF6F8,
  24289. Hzsquare: 0x3390,
  24290. I: 0x0049,
  24291. IAcyrillic: 0x042F,
  24292. IJ: 0x0132,
  24293. IUcyrillic: 0x042E,
  24294. Iacute: 0x00CD,
  24295. Iacutesmall: 0xF7ED,
  24296. Ibreve: 0x012C,
  24297. Icaron: 0x01CF,
  24298. Icircle: 0x24BE,
  24299. Icircumflex: 0x00CE,
  24300. Icircumflexsmall: 0xF7EE,
  24301. Icyrillic: 0x0406,
  24302. Idblgrave: 0x0208,
  24303. Idieresis: 0x00CF,
  24304. Idieresisacute: 0x1E2E,
  24305. Idieresiscyrillic: 0x04E4,
  24306. Idieresissmall: 0xF7EF,
  24307. Idot: 0x0130,
  24308. Idotaccent: 0x0130,
  24309. Idotbelow: 0x1ECA,
  24310. Iebrevecyrillic: 0x04D6,
  24311. Iecyrillic: 0x0415,
  24312. Ifraktur: 0x2111,
  24313. Igrave: 0x00CC,
  24314. Igravesmall: 0xF7EC,
  24315. Ihookabove: 0x1EC8,
  24316. Iicyrillic: 0x0418,
  24317. Iinvertedbreve: 0x020A,
  24318. Iishortcyrillic: 0x0419,
  24319. Imacron: 0x012A,
  24320. Imacroncyrillic: 0x04E2,
  24321. Imonospace: 0xFF29,
  24322. Iniarmenian: 0x053B,
  24323. Iocyrillic: 0x0401,
  24324. Iogonek: 0x012E,
  24325. Iota: 0x0399,
  24326. Iotaafrican: 0x0196,
  24327. Iotadieresis: 0x03AA,
  24328. Iotatonos: 0x038A,
  24329. Ismall: 0xF769,
  24330. Istroke: 0x0197,
  24331. Itilde: 0x0128,
  24332. Itildebelow: 0x1E2C,
  24333. Izhitsacyrillic: 0x0474,
  24334. Izhitsadblgravecyrillic: 0x0476,
  24335. J: 0x004A,
  24336. Jaarmenian: 0x0541,
  24337. Jcircle: 0x24BF,
  24338. Jcircumflex: 0x0134,
  24339. Jecyrillic: 0x0408,
  24340. Jheharmenian: 0x054B,
  24341. Jmonospace: 0xFF2A,
  24342. Jsmall: 0xF76A,
  24343. K: 0x004B,
  24344. KBsquare: 0x3385,
  24345. KKsquare: 0x33CD,
  24346. Kabashkircyrillic: 0x04A0,
  24347. Kacute: 0x1E30,
  24348. Kacyrillic: 0x041A,
  24349. Kadescendercyrillic: 0x049A,
  24350. Kahookcyrillic: 0x04C3,
  24351. Kappa: 0x039A,
  24352. Kastrokecyrillic: 0x049E,
  24353. Kaverticalstrokecyrillic: 0x049C,
  24354. Kcaron: 0x01E8,
  24355. Kcedilla: 0x0136,
  24356. Kcircle: 0x24C0,
  24357. Kcommaaccent: 0x0136,
  24358. Kdotbelow: 0x1E32,
  24359. Keharmenian: 0x0554,
  24360. Kenarmenian: 0x053F,
  24361. Khacyrillic: 0x0425,
  24362. Kheicoptic: 0x03E6,
  24363. Khook: 0x0198,
  24364. Kjecyrillic: 0x040C,
  24365. Klinebelow: 0x1E34,
  24366. Kmonospace: 0xFF2B,
  24367. Koppacyrillic: 0x0480,
  24368. Koppagreek: 0x03DE,
  24369. Ksicyrillic: 0x046E,
  24370. Ksmall: 0xF76B,
  24371. L: 0x004C,
  24372. LJ: 0x01C7,
  24373. LL: 0xF6BF,
  24374. Lacute: 0x0139,
  24375. Lambda: 0x039B,
  24376. Lcaron: 0x013D,
  24377. Lcedilla: 0x013B,
  24378. Lcircle: 0x24C1,
  24379. Lcircumflexbelow: 0x1E3C,
  24380. Lcommaaccent: 0x013B,
  24381. Ldot: 0x013F,
  24382. Ldotaccent: 0x013F,
  24383. Ldotbelow: 0x1E36,
  24384. Ldotbelowmacron: 0x1E38,
  24385. Liwnarmenian: 0x053C,
  24386. Lj: 0x01C8,
  24387. Ljecyrillic: 0x0409,
  24388. Llinebelow: 0x1E3A,
  24389. Lmonospace: 0xFF2C,
  24390. Lslash: 0x0141,
  24391. Lslashsmall: 0xF6F9,
  24392. Lsmall: 0xF76C,
  24393. M: 0x004D,
  24394. MBsquare: 0x3386,
  24395. Macron: 0xF6D0,
  24396. Macronsmall: 0xF7AF,
  24397. Macute: 0x1E3E,
  24398. Mcircle: 0x24C2,
  24399. Mdotaccent: 0x1E40,
  24400. Mdotbelow: 0x1E42,
  24401. Menarmenian: 0x0544,
  24402. Mmonospace: 0xFF2D,
  24403. Msmall: 0xF76D,
  24404. Mturned: 0x019C,
  24405. Mu: 0x039C,
  24406. N: 0x004E,
  24407. NJ: 0x01CA,
  24408. Nacute: 0x0143,
  24409. Ncaron: 0x0147,
  24410. Ncedilla: 0x0145,
  24411. Ncircle: 0x24C3,
  24412. Ncircumflexbelow: 0x1E4A,
  24413. Ncommaaccent: 0x0145,
  24414. Ndotaccent: 0x1E44,
  24415. Ndotbelow: 0x1E46,
  24416. Nhookleft: 0x019D,
  24417. Nineroman: 0x2168,
  24418. Nj: 0x01CB,
  24419. Njecyrillic: 0x040A,
  24420. Nlinebelow: 0x1E48,
  24421. Nmonospace: 0xFF2E,
  24422. Nowarmenian: 0x0546,
  24423. Nsmall: 0xF76E,
  24424. Ntilde: 0x00D1,
  24425. Ntildesmall: 0xF7F1,
  24426. Nu: 0x039D,
  24427. O: 0x004F,
  24428. OE: 0x0152,
  24429. OEsmall: 0xF6FA,
  24430. Oacute: 0x00D3,
  24431. Oacutesmall: 0xF7F3,
  24432. Obarredcyrillic: 0x04E8,
  24433. Obarreddieresiscyrillic: 0x04EA,
  24434. Obreve: 0x014E,
  24435. Ocaron: 0x01D1,
  24436. Ocenteredtilde: 0x019F,
  24437. Ocircle: 0x24C4,
  24438. Ocircumflex: 0x00D4,
  24439. Ocircumflexacute: 0x1ED0,
  24440. Ocircumflexdotbelow: 0x1ED8,
  24441. Ocircumflexgrave: 0x1ED2,
  24442. Ocircumflexhookabove: 0x1ED4,
  24443. Ocircumflexsmall: 0xF7F4,
  24444. Ocircumflextilde: 0x1ED6,
  24445. Ocyrillic: 0x041E,
  24446. Odblacute: 0x0150,
  24447. Odblgrave: 0x020C,
  24448. Odieresis: 0x00D6,
  24449. Odieresiscyrillic: 0x04E6,
  24450. Odieresissmall: 0xF7F6,
  24451. Odotbelow: 0x1ECC,
  24452. Ogoneksmall: 0xF6FB,
  24453. Ograve: 0x00D2,
  24454. Ogravesmall: 0xF7F2,
  24455. Oharmenian: 0x0555,
  24456. Ohm: 0x2126,
  24457. Ohookabove: 0x1ECE,
  24458. Ohorn: 0x01A0,
  24459. Ohornacute: 0x1EDA,
  24460. Ohorndotbelow: 0x1EE2,
  24461. Ohorngrave: 0x1EDC,
  24462. Ohornhookabove: 0x1EDE,
  24463. Ohorntilde: 0x1EE0,
  24464. Ohungarumlaut: 0x0150,
  24465. Oi: 0x01A2,
  24466. Oinvertedbreve: 0x020E,
  24467. Omacron: 0x014C,
  24468. Omacronacute: 0x1E52,
  24469. Omacrongrave: 0x1E50,
  24470. Omega: 0x2126,
  24471. Omegacyrillic: 0x0460,
  24472. Omegagreek: 0x03A9,
  24473. Omegaroundcyrillic: 0x047A,
  24474. Omegatitlocyrillic: 0x047C,
  24475. Omegatonos: 0x038F,
  24476. Omicron: 0x039F,
  24477. Omicrontonos: 0x038C,
  24478. Omonospace: 0xFF2F,
  24479. Oneroman: 0x2160,
  24480. Oogonek: 0x01EA,
  24481. Oogonekmacron: 0x01EC,
  24482. Oopen: 0x0186,
  24483. Oslash: 0x00D8,
  24484. Oslashacute: 0x01FE,
  24485. Oslashsmall: 0xF7F8,
  24486. Osmall: 0xF76F,
  24487. Ostrokeacute: 0x01FE,
  24488. Otcyrillic: 0x047E,
  24489. Otilde: 0x00D5,
  24490. Otildeacute: 0x1E4C,
  24491. Otildedieresis: 0x1E4E,
  24492. Otildesmall: 0xF7F5,
  24493. P: 0x0050,
  24494. Pacute: 0x1E54,
  24495. Pcircle: 0x24C5,
  24496. Pdotaccent: 0x1E56,
  24497. Pecyrillic: 0x041F,
  24498. Peharmenian: 0x054A,
  24499. Pemiddlehookcyrillic: 0x04A6,
  24500. Phi: 0x03A6,
  24501. Phook: 0x01A4,
  24502. Pi: 0x03A0,
  24503. Piwrarmenian: 0x0553,
  24504. Pmonospace: 0xFF30,
  24505. Psi: 0x03A8,
  24506. Psicyrillic: 0x0470,
  24507. Psmall: 0xF770,
  24508. Q: 0x0051,
  24509. Qcircle: 0x24C6,
  24510. Qmonospace: 0xFF31,
  24511. Qsmall: 0xF771,
  24512. R: 0x0052,
  24513. Raarmenian: 0x054C,
  24514. Racute: 0x0154,
  24515. Rcaron: 0x0158,
  24516. Rcedilla: 0x0156,
  24517. Rcircle: 0x24C7,
  24518. Rcommaaccent: 0x0156,
  24519. Rdblgrave: 0x0210,
  24520. Rdotaccent: 0x1E58,
  24521. Rdotbelow: 0x1E5A,
  24522. Rdotbelowmacron: 0x1E5C,
  24523. Reharmenian: 0x0550,
  24524. Rfraktur: 0x211C,
  24525. Rho: 0x03A1,
  24526. Ringsmall: 0xF6FC,
  24527. Rinvertedbreve: 0x0212,
  24528. Rlinebelow: 0x1E5E,
  24529. Rmonospace: 0xFF32,
  24530. Rsmall: 0xF772,
  24531. Rsmallinverted: 0x0281,
  24532. Rsmallinvertedsuperior: 0x02B6,
  24533. S: 0x0053,
  24534. SF010000: 0x250C,
  24535. SF020000: 0x2514,
  24536. SF030000: 0x2510,
  24537. SF040000: 0x2518,
  24538. SF050000: 0x253C,
  24539. SF060000: 0x252C,
  24540. SF070000: 0x2534,
  24541. SF080000: 0x251C,
  24542. SF090000: 0x2524,
  24543. SF100000: 0x2500,
  24544. SF110000: 0x2502,
  24545. SF190000: 0x2561,
  24546. SF200000: 0x2562,
  24547. SF210000: 0x2556,
  24548. SF220000: 0x2555,
  24549. SF230000: 0x2563,
  24550. SF240000: 0x2551,
  24551. SF250000: 0x2557,
  24552. SF260000: 0x255D,
  24553. SF270000: 0x255C,
  24554. SF280000: 0x255B,
  24555. SF360000: 0x255E,
  24556. SF370000: 0x255F,
  24557. SF380000: 0x255A,
  24558. SF390000: 0x2554,
  24559. SF400000: 0x2569,
  24560. SF410000: 0x2566,
  24561. SF420000: 0x2560,
  24562. SF430000: 0x2550,
  24563. SF440000: 0x256C,
  24564. SF450000: 0x2567,
  24565. SF460000: 0x2568,
  24566. SF470000: 0x2564,
  24567. SF480000: 0x2565,
  24568. SF490000: 0x2559,
  24569. SF500000: 0x2558,
  24570. SF510000: 0x2552,
  24571. SF520000: 0x2553,
  24572. SF530000: 0x256B,
  24573. SF540000: 0x256A,
  24574. Sacute: 0x015A,
  24575. Sacutedotaccent: 0x1E64,
  24576. Sampigreek: 0x03E0,
  24577. Scaron: 0x0160,
  24578. Scarondotaccent: 0x1E66,
  24579. Scaronsmall: 0xF6FD,
  24580. Scedilla: 0x015E,
  24581. Schwa: 0x018F,
  24582. Schwacyrillic: 0x04D8,
  24583. Schwadieresiscyrillic: 0x04DA,
  24584. Scircle: 0x24C8,
  24585. Scircumflex: 0x015C,
  24586. Scommaaccent: 0x0218,
  24587. Sdotaccent: 0x1E60,
  24588. Sdotbelow: 0x1E62,
  24589. Sdotbelowdotaccent: 0x1E68,
  24590. Seharmenian: 0x054D,
  24591. Sevenroman: 0x2166,
  24592. Shaarmenian: 0x0547,
  24593. Shacyrillic: 0x0428,
  24594. Shchacyrillic: 0x0429,
  24595. Sheicoptic: 0x03E2,
  24596. Shhacyrillic: 0x04BA,
  24597. Shimacoptic: 0x03EC,
  24598. Sigma: 0x03A3,
  24599. Sixroman: 0x2165,
  24600. Smonospace: 0xFF33,
  24601. Softsigncyrillic: 0x042C,
  24602. Ssmall: 0xF773,
  24603. Stigmagreek: 0x03DA,
  24604. T: 0x0054,
  24605. Tau: 0x03A4,
  24606. Tbar: 0x0166,
  24607. Tcaron: 0x0164,
  24608. Tcedilla: 0x0162,
  24609. Tcircle: 0x24C9,
  24610. Tcircumflexbelow: 0x1E70,
  24611. Tcommaaccent: 0x0162,
  24612. Tdotaccent: 0x1E6A,
  24613. Tdotbelow: 0x1E6C,
  24614. Tecyrillic: 0x0422,
  24615. Tedescendercyrillic: 0x04AC,
  24616. Tenroman: 0x2169,
  24617. Tetsecyrillic: 0x04B4,
  24618. Theta: 0x0398,
  24619. Thook: 0x01AC,
  24620. Thorn: 0x00DE,
  24621. Thornsmall: 0xF7FE,
  24622. Threeroman: 0x2162,
  24623. Tildesmall: 0xF6FE,
  24624. Tiwnarmenian: 0x054F,
  24625. Tlinebelow: 0x1E6E,
  24626. Tmonospace: 0xFF34,
  24627. Toarmenian: 0x0539,
  24628. Tonefive: 0x01BC,
  24629. Tonesix: 0x0184,
  24630. Tonetwo: 0x01A7,
  24631. Tretroflexhook: 0x01AE,
  24632. Tsecyrillic: 0x0426,
  24633. Tshecyrillic: 0x040B,
  24634. Tsmall: 0xF774,
  24635. Twelveroman: 0x216B,
  24636. Tworoman: 0x2161,
  24637. U: 0x0055,
  24638. Uacute: 0x00DA,
  24639. Uacutesmall: 0xF7FA,
  24640. Ubreve: 0x016C,
  24641. Ucaron: 0x01D3,
  24642. Ucircle: 0x24CA,
  24643. Ucircumflex: 0x00DB,
  24644. Ucircumflexbelow: 0x1E76,
  24645. Ucircumflexsmall: 0xF7FB,
  24646. Ucyrillic: 0x0423,
  24647. Udblacute: 0x0170,
  24648. Udblgrave: 0x0214,
  24649. Udieresis: 0x00DC,
  24650. Udieresisacute: 0x01D7,
  24651. Udieresisbelow: 0x1E72,
  24652. Udieresiscaron: 0x01D9,
  24653. Udieresiscyrillic: 0x04F0,
  24654. Udieresisgrave: 0x01DB,
  24655. Udieresismacron: 0x01D5,
  24656. Udieresissmall: 0xF7FC,
  24657. Udotbelow: 0x1EE4,
  24658. Ugrave: 0x00D9,
  24659. Ugravesmall: 0xF7F9,
  24660. Uhookabove: 0x1EE6,
  24661. Uhorn: 0x01AF,
  24662. Uhornacute: 0x1EE8,
  24663. Uhorndotbelow: 0x1EF0,
  24664. Uhorngrave: 0x1EEA,
  24665. Uhornhookabove: 0x1EEC,
  24666. Uhorntilde: 0x1EEE,
  24667. Uhungarumlaut: 0x0170,
  24668. Uhungarumlautcyrillic: 0x04F2,
  24669. Uinvertedbreve: 0x0216,
  24670. Ukcyrillic: 0x0478,
  24671. Umacron: 0x016A,
  24672. Umacroncyrillic: 0x04EE,
  24673. Umacrondieresis: 0x1E7A,
  24674. Umonospace: 0xFF35,
  24675. Uogonek: 0x0172,
  24676. Upsilon: 0x03A5,
  24677. Upsilon1: 0x03D2,
  24678. Upsilonacutehooksymbolgreek: 0x03D3,
  24679. Upsilonafrican: 0x01B1,
  24680. Upsilondieresis: 0x03AB,
  24681. Upsilondieresishooksymbolgreek: 0x03D4,
  24682. Upsilonhooksymbol: 0x03D2,
  24683. Upsilontonos: 0x038E,
  24684. Uring: 0x016E,
  24685. Ushortcyrillic: 0x040E,
  24686. Usmall: 0xF775,
  24687. Ustraightcyrillic: 0x04AE,
  24688. Ustraightstrokecyrillic: 0x04B0,
  24689. Utilde: 0x0168,
  24690. Utildeacute: 0x1E78,
  24691. Utildebelow: 0x1E74,
  24692. V: 0x0056,
  24693. Vcircle: 0x24CB,
  24694. Vdotbelow: 0x1E7E,
  24695. Vecyrillic: 0x0412,
  24696. Vewarmenian: 0x054E,
  24697. Vhook: 0x01B2,
  24698. Vmonospace: 0xFF36,
  24699. Voarmenian: 0x0548,
  24700. Vsmall: 0xF776,
  24701. Vtilde: 0x1E7C,
  24702. W: 0x0057,
  24703. Wacute: 0x1E82,
  24704. Wcircle: 0x24CC,
  24705. Wcircumflex: 0x0174,
  24706. Wdieresis: 0x1E84,
  24707. Wdotaccent: 0x1E86,
  24708. Wdotbelow: 0x1E88,
  24709. Wgrave: 0x1E80,
  24710. Wmonospace: 0xFF37,
  24711. Wsmall: 0xF777,
  24712. X: 0x0058,
  24713. Xcircle: 0x24CD,
  24714. Xdieresis: 0x1E8C,
  24715. Xdotaccent: 0x1E8A,
  24716. Xeharmenian: 0x053D,
  24717. Xi: 0x039E,
  24718. Xmonospace: 0xFF38,
  24719. Xsmall: 0xF778,
  24720. Y: 0x0059,
  24721. Yacute: 0x00DD,
  24722. Yacutesmall: 0xF7FD,
  24723. Yatcyrillic: 0x0462,
  24724. Ycircle: 0x24CE,
  24725. Ycircumflex: 0x0176,
  24726. Ydieresis: 0x0178,
  24727. Ydieresissmall: 0xF7FF,
  24728. Ydotaccent: 0x1E8E,
  24729. Ydotbelow: 0x1EF4,
  24730. Yericyrillic: 0x042B,
  24731. Yerudieresiscyrillic: 0x04F8,
  24732. Ygrave: 0x1EF2,
  24733. Yhook: 0x01B3,
  24734. Yhookabove: 0x1EF6,
  24735. Yiarmenian: 0x0545,
  24736. Yicyrillic: 0x0407,
  24737. Yiwnarmenian: 0x0552,
  24738. Ymonospace: 0xFF39,
  24739. Ysmall: 0xF779,
  24740. Ytilde: 0x1EF8,
  24741. Yusbigcyrillic: 0x046A,
  24742. Yusbigiotifiedcyrillic: 0x046C,
  24743. Yuslittlecyrillic: 0x0466,
  24744. Yuslittleiotifiedcyrillic: 0x0468,
  24745. Z: 0x005A,
  24746. Zaarmenian: 0x0536,
  24747. Zacute: 0x0179,
  24748. Zcaron: 0x017D,
  24749. Zcaronsmall: 0xF6FF,
  24750. Zcircle: 0x24CF,
  24751. Zcircumflex: 0x1E90,
  24752. Zdot: 0x017B,
  24753. Zdotaccent: 0x017B,
  24754. Zdotbelow: 0x1E92,
  24755. Zecyrillic: 0x0417,
  24756. Zedescendercyrillic: 0x0498,
  24757. Zedieresiscyrillic: 0x04DE,
  24758. Zeta: 0x0396,
  24759. Zhearmenian: 0x053A,
  24760. Zhebrevecyrillic: 0x04C1,
  24761. Zhecyrillic: 0x0416,
  24762. Zhedescendercyrillic: 0x0496,
  24763. Zhedieresiscyrillic: 0x04DC,
  24764. Zlinebelow: 0x1E94,
  24765. Zmonospace: 0xFF3A,
  24766. Zsmall: 0xF77A,
  24767. Zstroke: 0x01B5,
  24768. a: 0x0061,
  24769. aabengali: 0x0986,
  24770. aacute: 0x00E1,
  24771. aadeva: 0x0906,
  24772. aagujarati: 0x0A86,
  24773. aagurmukhi: 0x0A06,
  24774. aamatragurmukhi: 0x0A3E,
  24775. aarusquare: 0x3303,
  24776. aavowelsignbengali: 0x09BE,
  24777. aavowelsigndeva: 0x093E,
  24778. aavowelsigngujarati: 0x0ABE,
  24779. abbreviationmarkarmenian: 0x055F,
  24780. abbreviationsigndeva: 0x0970,
  24781. abengali: 0x0985,
  24782. abopomofo: 0x311A,
  24783. abreve: 0x0103,
  24784. abreveacute: 0x1EAF,
  24785. abrevecyrillic: 0x04D1,
  24786. abrevedotbelow: 0x1EB7,
  24787. abrevegrave: 0x1EB1,
  24788. abrevehookabove: 0x1EB3,
  24789. abrevetilde: 0x1EB5,
  24790. acaron: 0x01CE,
  24791. acircle: 0x24D0,
  24792. acircumflex: 0x00E2,
  24793. acircumflexacute: 0x1EA5,
  24794. acircumflexdotbelow: 0x1EAD,
  24795. acircumflexgrave: 0x1EA7,
  24796. acircumflexhookabove: 0x1EA9,
  24797. acircumflextilde: 0x1EAB,
  24798. acute: 0x00B4,
  24799. acutebelowcmb: 0x0317,
  24800. acutecmb: 0x0301,
  24801. acutecomb: 0x0301,
  24802. acutedeva: 0x0954,
  24803. acutelowmod: 0x02CF,
  24804. acutetonecmb: 0x0341,
  24805. acyrillic: 0x0430,
  24806. adblgrave: 0x0201,
  24807. addakgurmukhi: 0x0A71,
  24808. adeva: 0x0905,
  24809. adieresis: 0x00E4,
  24810. adieresiscyrillic: 0x04D3,
  24811. adieresismacron: 0x01DF,
  24812. adotbelow: 0x1EA1,
  24813. adotmacron: 0x01E1,
  24814. ae: 0x00E6,
  24815. aeacute: 0x01FD,
  24816. aekorean: 0x3150,
  24817. aemacron: 0x01E3,
  24818. afii00208: 0x2015,
  24819. afii08941: 0x20A4,
  24820. afii10017: 0x0410,
  24821. afii10018: 0x0411,
  24822. afii10019: 0x0412,
  24823. afii10020: 0x0413,
  24824. afii10021: 0x0414,
  24825. afii10022: 0x0415,
  24826. afii10023: 0x0401,
  24827. afii10024: 0x0416,
  24828. afii10025: 0x0417,
  24829. afii10026: 0x0418,
  24830. afii10027: 0x0419,
  24831. afii10028: 0x041A,
  24832. afii10029: 0x041B,
  24833. afii10030: 0x041C,
  24834. afii10031: 0x041D,
  24835. afii10032: 0x041E,
  24836. afii10033: 0x041F,
  24837. afii10034: 0x0420,
  24838. afii10035: 0x0421,
  24839. afii10036: 0x0422,
  24840. afii10037: 0x0423,
  24841. afii10038: 0x0424,
  24842. afii10039: 0x0425,
  24843. afii10040: 0x0426,
  24844. afii10041: 0x0427,
  24845. afii10042: 0x0428,
  24846. afii10043: 0x0429,
  24847. afii10044: 0x042A,
  24848. afii10045: 0x042B,
  24849. afii10046: 0x042C,
  24850. afii10047: 0x042D,
  24851. afii10048: 0x042E,
  24852. afii10049: 0x042F,
  24853. afii10050: 0x0490,
  24854. afii10051: 0x0402,
  24855. afii10052: 0x0403,
  24856. afii10053: 0x0404,
  24857. afii10054: 0x0405,
  24858. afii10055: 0x0406,
  24859. afii10056: 0x0407,
  24860. afii10057: 0x0408,
  24861. afii10058: 0x0409,
  24862. afii10059: 0x040A,
  24863. afii10060: 0x040B,
  24864. afii10061: 0x040C,
  24865. afii10062: 0x040E,
  24866. afii10063: 0xF6C4,
  24867. afii10064: 0xF6C5,
  24868. afii10065: 0x0430,
  24869. afii10066: 0x0431,
  24870. afii10067: 0x0432,
  24871. afii10068: 0x0433,
  24872. afii10069: 0x0434,
  24873. afii10070: 0x0435,
  24874. afii10071: 0x0451,
  24875. afii10072: 0x0436,
  24876. afii10073: 0x0437,
  24877. afii10074: 0x0438,
  24878. afii10075: 0x0439,
  24879. afii10076: 0x043A,
  24880. afii10077: 0x043B,
  24881. afii10078: 0x043C,
  24882. afii10079: 0x043D,
  24883. afii10080: 0x043E,
  24884. afii10081: 0x043F,
  24885. afii10082: 0x0440,
  24886. afii10083: 0x0441,
  24887. afii10084: 0x0442,
  24888. afii10085: 0x0443,
  24889. afii10086: 0x0444,
  24890. afii10087: 0x0445,
  24891. afii10088: 0x0446,
  24892. afii10089: 0x0447,
  24893. afii10090: 0x0448,
  24894. afii10091: 0x0449,
  24895. afii10092: 0x044A,
  24896. afii10093: 0x044B,
  24897. afii10094: 0x044C,
  24898. afii10095: 0x044D,
  24899. afii10096: 0x044E,
  24900. afii10097: 0x044F,
  24901. afii10098: 0x0491,
  24902. afii10099: 0x0452,
  24903. afii10100: 0x0453,
  24904. afii10101: 0x0454,
  24905. afii10102: 0x0455,
  24906. afii10103: 0x0456,
  24907. afii10104: 0x0457,
  24908. afii10105: 0x0458,
  24909. afii10106: 0x0459,
  24910. afii10107: 0x045A,
  24911. afii10108: 0x045B,
  24912. afii10109: 0x045C,
  24913. afii10110: 0x045E,
  24914. afii10145: 0x040F,
  24915. afii10146: 0x0462,
  24916. afii10147: 0x0472,
  24917. afii10148: 0x0474,
  24918. afii10192: 0xF6C6,
  24919. afii10193: 0x045F,
  24920. afii10194: 0x0463,
  24921. afii10195: 0x0473,
  24922. afii10196: 0x0475,
  24923. afii10831: 0xF6C7,
  24924. afii10832: 0xF6C8,
  24925. afii10846: 0x04D9,
  24926. afii299: 0x200E,
  24927. afii300: 0x200F,
  24928. afii301: 0x200D,
  24929. afii57381: 0x066A,
  24930. afii57388: 0x060C,
  24931. afii57392: 0x0660,
  24932. afii57393: 0x0661,
  24933. afii57394: 0x0662,
  24934. afii57395: 0x0663,
  24935. afii57396: 0x0664,
  24936. afii57397: 0x0665,
  24937. afii57398: 0x0666,
  24938. afii57399: 0x0667,
  24939. afii57400: 0x0668,
  24940. afii57401: 0x0669,
  24941. afii57403: 0x061B,
  24942. afii57407: 0x061F,
  24943. afii57409: 0x0621,
  24944. afii57410: 0x0622,
  24945. afii57411: 0x0623,
  24946. afii57412: 0x0624,
  24947. afii57413: 0x0625,
  24948. afii57414: 0x0626,
  24949. afii57415: 0x0627,
  24950. afii57416: 0x0628,
  24951. afii57417: 0x0629,
  24952. afii57418: 0x062A,
  24953. afii57419: 0x062B,
  24954. afii57420: 0x062C,
  24955. afii57421: 0x062D,
  24956. afii57422: 0x062E,
  24957. afii57423: 0x062F,
  24958. afii57424: 0x0630,
  24959. afii57425: 0x0631,
  24960. afii57426: 0x0632,
  24961. afii57427: 0x0633,
  24962. afii57428: 0x0634,
  24963. afii57429: 0x0635,
  24964. afii57430: 0x0636,
  24965. afii57431: 0x0637,
  24966. afii57432: 0x0638,
  24967. afii57433: 0x0639,
  24968. afii57434: 0x063A,
  24969. afii57440: 0x0640,
  24970. afii57441: 0x0641,
  24971. afii57442: 0x0642,
  24972. afii57443: 0x0643,
  24973. afii57444: 0x0644,
  24974. afii57445: 0x0645,
  24975. afii57446: 0x0646,
  24976. afii57448: 0x0648,
  24977. afii57449: 0x0649,
  24978. afii57450: 0x064A,
  24979. afii57451: 0x064B,
  24980. afii57452: 0x064C,
  24981. afii57453: 0x064D,
  24982. afii57454: 0x064E,
  24983. afii57455: 0x064F,
  24984. afii57456: 0x0650,
  24985. afii57457: 0x0651,
  24986. afii57458: 0x0652,
  24987. afii57470: 0x0647,
  24988. afii57505: 0x06A4,
  24989. afii57506: 0x067E,
  24990. afii57507: 0x0686,
  24991. afii57508: 0x0698,
  24992. afii57509: 0x06AF,
  24993. afii57511: 0x0679,
  24994. afii57512: 0x0688,
  24995. afii57513: 0x0691,
  24996. afii57514: 0x06BA,
  24997. afii57519: 0x06D2,
  24998. afii57534: 0x06D5,
  24999. afii57636: 0x20AA,
  25000. afii57645: 0x05BE,
  25001. afii57658: 0x05C3,
  25002. afii57664: 0x05D0,
  25003. afii57665: 0x05D1,
  25004. afii57666: 0x05D2,
  25005. afii57667: 0x05D3,
  25006. afii57668: 0x05D4,
  25007. afii57669: 0x05D5,
  25008. afii57670: 0x05D6,
  25009. afii57671: 0x05D7,
  25010. afii57672: 0x05D8,
  25011. afii57673: 0x05D9,
  25012. afii57674: 0x05DA,
  25013. afii57675: 0x05DB,
  25014. afii57676: 0x05DC,
  25015. afii57677: 0x05DD,
  25016. afii57678: 0x05DE,
  25017. afii57679: 0x05DF,
  25018. afii57680: 0x05E0,
  25019. afii57681: 0x05E1,
  25020. afii57682: 0x05E2,
  25021. afii57683: 0x05E3,
  25022. afii57684: 0x05E4,
  25023. afii57685: 0x05E5,
  25024. afii57686: 0x05E6,
  25025. afii57687: 0x05E7,
  25026. afii57688: 0x05E8,
  25027. afii57689: 0x05E9,
  25028. afii57690: 0x05EA,
  25029. afii57694: 0xFB2A,
  25030. afii57695: 0xFB2B,
  25031. afii57700: 0xFB4B,
  25032. afii57705: 0xFB1F,
  25033. afii57716: 0x05F0,
  25034. afii57717: 0x05F1,
  25035. afii57718: 0x05F2,
  25036. afii57723: 0xFB35,
  25037. afii57793: 0x05B4,
  25038. afii57794: 0x05B5,
  25039. afii57795: 0x05B6,
  25040. afii57796: 0x05BB,
  25041. afii57797: 0x05B8,
  25042. afii57798: 0x05B7,
  25043. afii57799: 0x05B0,
  25044. afii57800: 0x05B2,
  25045. afii57801: 0x05B1,
  25046. afii57802: 0x05B3,
  25047. afii57803: 0x05C2,
  25048. afii57804: 0x05C1,
  25049. afii57806: 0x05B9,
  25050. afii57807: 0x05BC,
  25051. afii57839: 0x05BD,
  25052. afii57841: 0x05BF,
  25053. afii57842: 0x05C0,
  25054. afii57929: 0x02BC,
  25055. afii61248: 0x2105,
  25056. afii61289: 0x2113,
  25057. afii61352: 0x2116,
  25058. afii61573: 0x202C,
  25059. afii61574: 0x202D,
  25060. afii61575: 0x202E,
  25061. afii61664: 0x200C,
  25062. afii63167: 0x066D,
  25063. afii64937: 0x02BD,
  25064. agrave: 0x00E0,
  25065. agujarati: 0x0A85,
  25066. agurmukhi: 0x0A05,
  25067. ahiragana: 0x3042,
  25068. ahookabove: 0x1EA3,
  25069. aibengali: 0x0990,
  25070. aibopomofo: 0x311E,
  25071. aideva: 0x0910,
  25072. aiecyrillic: 0x04D5,
  25073. aigujarati: 0x0A90,
  25074. aigurmukhi: 0x0A10,
  25075. aimatragurmukhi: 0x0A48,
  25076. ainarabic: 0x0639,
  25077. ainfinalarabic: 0xFECA,
  25078. aininitialarabic: 0xFECB,
  25079. ainmedialarabic: 0xFECC,
  25080. ainvertedbreve: 0x0203,
  25081. aivowelsignbengali: 0x09C8,
  25082. aivowelsigndeva: 0x0948,
  25083. aivowelsigngujarati: 0x0AC8,
  25084. akatakana: 0x30A2,
  25085. akatakanahalfwidth: 0xFF71,
  25086. akorean: 0x314F,
  25087. alef: 0x05D0,
  25088. alefarabic: 0x0627,
  25089. alefdageshhebrew: 0xFB30,
  25090. aleffinalarabic: 0xFE8E,
  25091. alefhamzaabovearabic: 0x0623,
  25092. alefhamzaabovefinalarabic: 0xFE84,
  25093. alefhamzabelowarabic: 0x0625,
  25094. alefhamzabelowfinalarabic: 0xFE88,
  25095. alefhebrew: 0x05D0,
  25096. aleflamedhebrew: 0xFB4F,
  25097. alefmaddaabovearabic: 0x0622,
  25098. alefmaddaabovefinalarabic: 0xFE82,
  25099. alefmaksuraarabic: 0x0649,
  25100. alefmaksurafinalarabic: 0xFEF0,
  25101. alefmaksurainitialarabic: 0xFEF3,
  25102. alefmaksuramedialarabic: 0xFEF4,
  25103. alefpatahhebrew: 0xFB2E,
  25104. alefqamatshebrew: 0xFB2F,
  25105. aleph: 0x2135,
  25106. allequal: 0x224C,
  25107. alpha: 0x03B1,
  25108. alphatonos: 0x03AC,
  25109. amacron: 0x0101,
  25110. amonospace: 0xFF41,
  25111. ampersand: 0x0026,
  25112. ampersandmonospace: 0xFF06,
  25113. ampersandsmall: 0xF726,
  25114. amsquare: 0x33C2,
  25115. anbopomofo: 0x3122,
  25116. angbopomofo: 0x3124,
  25117. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  25118. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  25119. angkhankhuthai: 0x0E5A,
  25120. angle: 0x2220,
  25121. anglebracketleft: 0x3008,
  25122. anglebracketleftvertical: 0xFE3F,
  25123. anglebracketright: 0x3009,
  25124. anglebracketrightvertical: 0xFE40,
  25125. angleleft: 0x2329,
  25126. angleright: 0x232A,
  25127. angstrom: 0x212B,
  25128. anoteleia: 0x0387,
  25129. anudattadeva: 0x0952,
  25130. anusvarabengali: 0x0982,
  25131. anusvaradeva: 0x0902,
  25132. anusvaragujarati: 0x0A82,
  25133. aogonek: 0x0105,
  25134. apaatosquare: 0x3300,
  25135. aparen: 0x249C,
  25136. apostrophearmenian: 0x055A,
  25137. apostrophemod: 0x02BC,
  25138. apple: 0xF8FF,
  25139. approaches: 0x2250,
  25140. approxequal: 0x2248,
  25141. approxequalorimage: 0x2252,
  25142. approximatelyequal: 0x2245,
  25143. araeaekorean: 0x318E,
  25144. araeakorean: 0x318D,
  25145. arc: 0x2312,
  25146. arighthalfring: 0x1E9A,
  25147. aring: 0x00E5,
  25148. aringacute: 0x01FB,
  25149. aringbelow: 0x1E01,
  25150. arrowboth: 0x2194,
  25151. arrowdashdown: 0x21E3,
  25152. arrowdashleft: 0x21E0,
  25153. arrowdashright: 0x21E2,
  25154. arrowdashup: 0x21E1,
  25155. arrowdblboth: 0x21D4,
  25156. arrowdbldown: 0x21D3,
  25157. arrowdblleft: 0x21D0,
  25158. arrowdblright: 0x21D2,
  25159. arrowdblup: 0x21D1,
  25160. arrowdown: 0x2193,
  25161. arrowdownleft: 0x2199,
  25162. arrowdownright: 0x2198,
  25163. arrowdownwhite: 0x21E9,
  25164. arrowheaddownmod: 0x02C5,
  25165. arrowheadleftmod: 0x02C2,
  25166. arrowheadrightmod: 0x02C3,
  25167. arrowheadupmod: 0x02C4,
  25168. arrowhorizex: 0xF8E7,
  25169. arrowleft: 0x2190,
  25170. arrowleftdbl: 0x21D0,
  25171. arrowleftdblstroke: 0x21CD,
  25172. arrowleftoverright: 0x21C6,
  25173. arrowleftwhite: 0x21E6,
  25174. arrowright: 0x2192,
  25175. arrowrightdblstroke: 0x21CF,
  25176. arrowrightheavy: 0x279E,
  25177. arrowrightoverleft: 0x21C4,
  25178. arrowrightwhite: 0x21E8,
  25179. arrowtableft: 0x21E4,
  25180. arrowtabright: 0x21E5,
  25181. arrowup: 0x2191,
  25182. arrowupdn: 0x2195,
  25183. arrowupdnbse: 0x21A8,
  25184. arrowupdownbase: 0x21A8,
  25185. arrowupleft: 0x2196,
  25186. arrowupleftofdown: 0x21C5,
  25187. arrowupright: 0x2197,
  25188. arrowupwhite: 0x21E7,
  25189. arrowvertex: 0xF8E6,
  25190. asciicircum: 0x005E,
  25191. asciicircummonospace: 0xFF3E,
  25192. asciitilde: 0x007E,
  25193. asciitildemonospace: 0xFF5E,
  25194. ascript: 0x0251,
  25195. ascriptturned: 0x0252,
  25196. asmallhiragana: 0x3041,
  25197. asmallkatakana: 0x30A1,
  25198. asmallkatakanahalfwidth: 0xFF67,
  25199. asterisk: 0x002A,
  25200. asteriskaltonearabic: 0x066D,
  25201. asteriskarabic: 0x066D,
  25202. asteriskmath: 0x2217,
  25203. asteriskmonospace: 0xFF0A,
  25204. asterisksmall: 0xFE61,
  25205. asterism: 0x2042,
  25206. asuperior: 0xF6E9,
  25207. asymptoticallyequal: 0x2243,
  25208. at: 0x0040,
  25209. atilde: 0x00E3,
  25210. atmonospace: 0xFF20,
  25211. atsmall: 0xFE6B,
  25212. aturned: 0x0250,
  25213. aubengali: 0x0994,
  25214. aubopomofo: 0x3120,
  25215. audeva: 0x0914,
  25216. augujarati: 0x0A94,
  25217. augurmukhi: 0x0A14,
  25218. aulengthmarkbengali: 0x09D7,
  25219. aumatragurmukhi: 0x0A4C,
  25220. auvowelsignbengali: 0x09CC,
  25221. auvowelsigndeva: 0x094C,
  25222. auvowelsigngujarati: 0x0ACC,
  25223. avagrahadeva: 0x093D,
  25224. aybarmenian: 0x0561,
  25225. ayin: 0x05E2,
  25226. ayinaltonehebrew: 0xFB20,
  25227. ayinhebrew: 0x05E2,
  25228. b: 0x0062,
  25229. babengali: 0x09AC,
  25230. backslash: 0x005C,
  25231. backslashmonospace: 0xFF3C,
  25232. badeva: 0x092C,
  25233. bagujarati: 0x0AAC,
  25234. bagurmukhi: 0x0A2C,
  25235. bahiragana: 0x3070,
  25236. bahtthai: 0x0E3F,
  25237. bakatakana: 0x30D0,
  25238. bar: 0x007C,
  25239. barmonospace: 0xFF5C,
  25240. bbopomofo: 0x3105,
  25241. bcircle: 0x24D1,
  25242. bdotaccent: 0x1E03,
  25243. bdotbelow: 0x1E05,
  25244. beamedsixteenthnotes: 0x266C,
  25245. because: 0x2235,
  25246. becyrillic: 0x0431,
  25247. beharabic: 0x0628,
  25248. behfinalarabic: 0xFE90,
  25249. behinitialarabic: 0xFE91,
  25250. behiragana: 0x3079,
  25251. behmedialarabic: 0xFE92,
  25252. behmeeminitialarabic: 0xFC9F,
  25253. behmeemisolatedarabic: 0xFC08,
  25254. behnoonfinalarabic: 0xFC6D,
  25255. bekatakana: 0x30D9,
  25256. benarmenian: 0x0562,
  25257. bet: 0x05D1,
  25258. beta: 0x03B2,
  25259. betasymbolgreek: 0x03D0,
  25260. betdagesh: 0xFB31,
  25261. betdageshhebrew: 0xFB31,
  25262. bethebrew: 0x05D1,
  25263. betrafehebrew: 0xFB4C,
  25264. bhabengali: 0x09AD,
  25265. bhadeva: 0x092D,
  25266. bhagujarati: 0x0AAD,
  25267. bhagurmukhi: 0x0A2D,
  25268. bhook: 0x0253,
  25269. bihiragana: 0x3073,
  25270. bikatakana: 0x30D3,
  25271. bilabialclick: 0x0298,
  25272. bindigurmukhi: 0x0A02,
  25273. birusquare: 0x3331,
  25274. blackcircle: 0x25CF,
  25275. blackdiamond: 0x25C6,
  25276. blackdownpointingtriangle: 0x25BC,
  25277. blackleftpointingpointer: 0x25C4,
  25278. blackleftpointingtriangle: 0x25C0,
  25279. blacklenticularbracketleft: 0x3010,
  25280. blacklenticularbracketleftvertical: 0xFE3B,
  25281. blacklenticularbracketright: 0x3011,
  25282. blacklenticularbracketrightvertical: 0xFE3C,
  25283. blacklowerlefttriangle: 0x25E3,
  25284. blacklowerrighttriangle: 0x25E2,
  25285. blackrectangle: 0x25AC,
  25286. blackrightpointingpointer: 0x25BA,
  25287. blackrightpointingtriangle: 0x25B6,
  25288. blacksmallsquare: 0x25AA,
  25289. blacksmilingface: 0x263B,
  25290. blacksquare: 0x25A0,
  25291. blackstar: 0x2605,
  25292. blackupperlefttriangle: 0x25E4,
  25293. blackupperrighttriangle: 0x25E5,
  25294. blackuppointingsmalltriangle: 0x25B4,
  25295. blackuppointingtriangle: 0x25B2,
  25296. blank: 0x2423,
  25297. blinebelow: 0x1E07,
  25298. block: 0x2588,
  25299. bmonospace: 0xFF42,
  25300. bobaimaithai: 0x0E1A,
  25301. bohiragana: 0x307C,
  25302. bokatakana: 0x30DC,
  25303. bparen: 0x249D,
  25304. bqsquare: 0x33C3,
  25305. braceex: 0xF8F4,
  25306. braceleft: 0x007B,
  25307. braceleftbt: 0xF8F3,
  25308. braceleftmid: 0xF8F2,
  25309. braceleftmonospace: 0xFF5B,
  25310. braceleftsmall: 0xFE5B,
  25311. bracelefttp: 0xF8F1,
  25312. braceleftvertical: 0xFE37,
  25313. braceright: 0x007D,
  25314. bracerightbt: 0xF8FE,
  25315. bracerightmid: 0xF8FD,
  25316. bracerightmonospace: 0xFF5D,
  25317. bracerightsmall: 0xFE5C,
  25318. bracerighttp: 0xF8FC,
  25319. bracerightvertical: 0xFE38,
  25320. bracketleft: 0x005B,
  25321. bracketleftbt: 0xF8F0,
  25322. bracketleftex: 0xF8EF,
  25323. bracketleftmonospace: 0xFF3B,
  25324. bracketlefttp: 0xF8EE,
  25325. bracketright: 0x005D,
  25326. bracketrightbt: 0xF8FB,
  25327. bracketrightex: 0xF8FA,
  25328. bracketrightmonospace: 0xFF3D,
  25329. bracketrighttp: 0xF8F9,
  25330. breve: 0x02D8,
  25331. brevebelowcmb: 0x032E,
  25332. brevecmb: 0x0306,
  25333. breveinvertedbelowcmb: 0x032F,
  25334. breveinvertedcmb: 0x0311,
  25335. breveinverteddoublecmb: 0x0361,
  25336. bridgebelowcmb: 0x032A,
  25337. bridgeinvertedbelowcmb: 0x033A,
  25338. brokenbar: 0x00A6,
  25339. bstroke: 0x0180,
  25340. bsuperior: 0xF6EA,
  25341. btopbar: 0x0183,
  25342. buhiragana: 0x3076,
  25343. bukatakana: 0x30D6,
  25344. bullet: 0x2022,
  25345. bulletinverse: 0x25D8,
  25346. bulletoperator: 0x2219,
  25347. bullseye: 0x25CE,
  25348. c: 0x0063,
  25349. caarmenian: 0x056E,
  25350. cabengali: 0x099A,
  25351. cacute: 0x0107,
  25352. cadeva: 0x091A,
  25353. cagujarati: 0x0A9A,
  25354. cagurmukhi: 0x0A1A,
  25355. calsquare: 0x3388,
  25356. candrabindubengali: 0x0981,
  25357. candrabinducmb: 0x0310,
  25358. candrabindudeva: 0x0901,
  25359. candrabindugujarati: 0x0A81,
  25360. capslock: 0x21EA,
  25361. careof: 0x2105,
  25362. caron: 0x02C7,
  25363. caronbelowcmb: 0x032C,
  25364. caroncmb: 0x030C,
  25365. carriagereturn: 0x21B5,
  25366. cbopomofo: 0x3118,
  25367. ccaron: 0x010D,
  25368. ccedilla: 0x00E7,
  25369. ccedillaacute: 0x1E09,
  25370. ccircle: 0x24D2,
  25371. ccircumflex: 0x0109,
  25372. ccurl: 0x0255,
  25373. cdot: 0x010B,
  25374. cdotaccent: 0x010B,
  25375. cdsquare: 0x33C5,
  25376. cedilla: 0x00B8,
  25377. cedillacmb: 0x0327,
  25378. cent: 0x00A2,
  25379. centigrade: 0x2103,
  25380. centinferior: 0xF6DF,
  25381. centmonospace: 0xFFE0,
  25382. centoldstyle: 0xF7A2,
  25383. centsuperior: 0xF6E0,
  25384. chaarmenian: 0x0579,
  25385. chabengali: 0x099B,
  25386. chadeva: 0x091B,
  25387. chagujarati: 0x0A9B,
  25388. chagurmukhi: 0x0A1B,
  25389. chbopomofo: 0x3114,
  25390. cheabkhasiancyrillic: 0x04BD,
  25391. checkmark: 0x2713,
  25392. checyrillic: 0x0447,
  25393. chedescenderabkhasiancyrillic: 0x04BF,
  25394. chedescendercyrillic: 0x04B7,
  25395. chedieresiscyrillic: 0x04F5,
  25396. cheharmenian: 0x0573,
  25397. chekhakassiancyrillic: 0x04CC,
  25398. cheverticalstrokecyrillic: 0x04B9,
  25399. chi: 0x03C7,
  25400. chieuchacirclekorean: 0x3277,
  25401. chieuchaparenkorean: 0x3217,
  25402. chieuchcirclekorean: 0x3269,
  25403. chieuchkorean: 0x314A,
  25404. chieuchparenkorean: 0x3209,
  25405. chochangthai: 0x0E0A,
  25406. chochanthai: 0x0E08,
  25407. chochingthai: 0x0E09,
  25408. chochoethai: 0x0E0C,
  25409. chook: 0x0188,
  25410. cieucacirclekorean: 0x3276,
  25411. cieucaparenkorean: 0x3216,
  25412. cieuccirclekorean: 0x3268,
  25413. cieuckorean: 0x3148,
  25414. cieucparenkorean: 0x3208,
  25415. cieucuparenkorean: 0x321C,
  25416. circle: 0x25CB,
  25417. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  25418. circlemultiply: 0x2297,
  25419. circleot: 0x2299,
  25420. circleplus: 0x2295,
  25421. circlepostalmark: 0x3036,
  25422. circlewithlefthalfblack: 0x25D0,
  25423. circlewithrighthalfblack: 0x25D1,
  25424. circumflex: 0x02C6,
  25425. circumflexbelowcmb: 0x032D,
  25426. circumflexcmb: 0x0302,
  25427. clear: 0x2327,
  25428. clickalveolar: 0x01C2,
  25429. clickdental: 0x01C0,
  25430. clicklateral: 0x01C1,
  25431. clickretroflex: 0x01C3,
  25432. club: 0x2663,
  25433. clubsuitblack: 0x2663,
  25434. clubsuitwhite: 0x2667,
  25435. cmcubedsquare: 0x33A4,
  25436. cmonospace: 0xFF43,
  25437. cmsquaredsquare: 0x33A0,
  25438. coarmenian: 0x0581,
  25439. colon: 0x003A,
  25440. colonmonetary: 0x20A1,
  25441. colonmonospace: 0xFF1A,
  25442. colonsign: 0x20A1,
  25443. colonsmall: 0xFE55,
  25444. colontriangularhalfmod: 0x02D1,
  25445. colontriangularmod: 0x02D0,
  25446. comma: 0x002C,
  25447. commaabovecmb: 0x0313,
  25448. commaaboverightcmb: 0x0315,
  25449. commaaccent: 0xF6C3,
  25450. commaarabic: 0x060C,
  25451. commaarmenian: 0x055D,
  25452. commainferior: 0xF6E1,
  25453. commamonospace: 0xFF0C,
  25454. commareversedabovecmb: 0x0314,
  25455. commareversedmod: 0x02BD,
  25456. commasmall: 0xFE50,
  25457. commasuperior: 0xF6E2,
  25458. commaturnedabovecmb: 0x0312,
  25459. commaturnedmod: 0x02BB,
  25460. compass: 0x263C,
  25461. congruent: 0x2245,
  25462. contourintegral: 0x222E,
  25463. control: 0x2303,
  25464. controlACK: 0x0006,
  25465. controlBEL: 0x0007,
  25466. controlBS: 0x0008,
  25467. controlCAN: 0x0018,
  25468. controlCR: 0x000D,
  25469. controlDC1: 0x0011,
  25470. controlDC2: 0x0012,
  25471. controlDC3: 0x0013,
  25472. controlDC4: 0x0014,
  25473. controlDEL: 0x007F,
  25474. controlDLE: 0x0010,
  25475. controlEM: 0x0019,
  25476. controlENQ: 0x0005,
  25477. controlEOT: 0x0004,
  25478. controlESC: 0x001B,
  25479. controlETB: 0x0017,
  25480. controlETX: 0x0003,
  25481. controlFF: 0x000C,
  25482. controlFS: 0x001C,
  25483. controlGS: 0x001D,
  25484. controlHT: 0x0009,
  25485. controlLF: 0x000A,
  25486. controlNAK: 0x0015,
  25487. controlRS: 0x001E,
  25488. controlSI: 0x000F,
  25489. controlSO: 0x000E,
  25490. controlSOT: 0x0002,
  25491. controlSTX: 0x0001,
  25492. controlSUB: 0x001A,
  25493. controlSYN: 0x0016,
  25494. controlUS: 0x001F,
  25495. controlVT: 0x000B,
  25496. copyright: 0x00A9,
  25497. copyrightsans: 0xF8E9,
  25498. copyrightserif: 0xF6D9,
  25499. cornerbracketleft: 0x300C,
  25500. cornerbracketlefthalfwidth: 0xFF62,
  25501. cornerbracketleftvertical: 0xFE41,
  25502. cornerbracketright: 0x300D,
  25503. cornerbracketrighthalfwidth: 0xFF63,
  25504. cornerbracketrightvertical: 0xFE42,
  25505. corporationsquare: 0x337F,
  25506. cosquare: 0x33C7,
  25507. coverkgsquare: 0x33C6,
  25508. cparen: 0x249E,
  25509. cruzeiro: 0x20A2,
  25510. cstretched: 0x0297,
  25511. curlyand: 0x22CF,
  25512. curlyor: 0x22CE,
  25513. currency: 0x00A4,
  25514. cyrBreve: 0xF6D1,
  25515. cyrFlex: 0xF6D2,
  25516. cyrbreve: 0xF6D4,
  25517. cyrflex: 0xF6D5,
  25518. d: 0x0064,
  25519. daarmenian: 0x0564,
  25520. dabengali: 0x09A6,
  25521. dadarabic: 0x0636,
  25522. dadeva: 0x0926,
  25523. dadfinalarabic: 0xFEBE,
  25524. dadinitialarabic: 0xFEBF,
  25525. dadmedialarabic: 0xFEC0,
  25526. dagesh: 0x05BC,
  25527. dageshhebrew: 0x05BC,
  25528. dagger: 0x2020,
  25529. daggerdbl: 0x2021,
  25530. dagujarati: 0x0AA6,
  25531. dagurmukhi: 0x0A26,
  25532. dahiragana: 0x3060,
  25533. dakatakana: 0x30C0,
  25534. dalarabic: 0x062F,
  25535. dalet: 0x05D3,
  25536. daletdagesh: 0xFB33,
  25537. daletdageshhebrew: 0xFB33,
  25538. dalethebrew: 0x05D3,
  25539. dalfinalarabic: 0xFEAA,
  25540. dammaarabic: 0x064F,
  25541. dammalowarabic: 0x064F,
  25542. dammatanaltonearabic: 0x064C,
  25543. dammatanarabic: 0x064C,
  25544. danda: 0x0964,
  25545. dargahebrew: 0x05A7,
  25546. dargalefthebrew: 0x05A7,
  25547. dasiapneumatacyrilliccmb: 0x0485,
  25548. dblGrave: 0xF6D3,
  25549. dblanglebracketleft: 0x300A,
  25550. dblanglebracketleftvertical: 0xFE3D,
  25551. dblanglebracketright: 0x300B,
  25552. dblanglebracketrightvertical: 0xFE3E,
  25553. dblarchinvertedbelowcmb: 0x032B,
  25554. dblarrowleft: 0x21D4,
  25555. dblarrowright: 0x21D2,
  25556. dbldanda: 0x0965,
  25557. dblgrave: 0xF6D6,
  25558. dblgravecmb: 0x030F,
  25559. dblintegral: 0x222C,
  25560. dbllowline: 0x2017,
  25561. dbllowlinecmb: 0x0333,
  25562. dbloverlinecmb: 0x033F,
  25563. dblprimemod: 0x02BA,
  25564. dblverticalbar: 0x2016,
  25565. dblverticallineabovecmb: 0x030E,
  25566. dbopomofo: 0x3109,
  25567. dbsquare: 0x33C8,
  25568. dcaron: 0x010F,
  25569. dcedilla: 0x1E11,
  25570. dcircle: 0x24D3,
  25571. dcircumflexbelow: 0x1E13,
  25572. dcroat: 0x0111,
  25573. ddabengali: 0x09A1,
  25574. ddadeva: 0x0921,
  25575. ddagujarati: 0x0AA1,
  25576. ddagurmukhi: 0x0A21,
  25577. ddalarabic: 0x0688,
  25578. ddalfinalarabic: 0xFB89,
  25579. dddhadeva: 0x095C,
  25580. ddhabengali: 0x09A2,
  25581. ddhadeva: 0x0922,
  25582. ddhagujarati: 0x0AA2,
  25583. ddhagurmukhi: 0x0A22,
  25584. ddotaccent: 0x1E0B,
  25585. ddotbelow: 0x1E0D,
  25586. decimalseparatorarabic: 0x066B,
  25587. decimalseparatorpersian: 0x066B,
  25588. decyrillic: 0x0434,
  25589. degree: 0x00B0,
  25590. dehihebrew: 0x05AD,
  25591. dehiragana: 0x3067,
  25592. deicoptic: 0x03EF,
  25593. dekatakana: 0x30C7,
  25594. deleteleft: 0x232B,
  25595. deleteright: 0x2326,
  25596. delta: 0x03B4,
  25597. deltaturned: 0x018D,
  25598. denominatorminusonenumeratorbengali: 0x09F8,
  25599. dezh: 0x02A4,
  25600. dhabengali: 0x09A7,
  25601. dhadeva: 0x0927,
  25602. dhagujarati: 0x0AA7,
  25603. dhagurmukhi: 0x0A27,
  25604. dhook: 0x0257,
  25605. dialytikatonos: 0x0385,
  25606. dialytikatonoscmb: 0x0344,
  25607. diamond: 0x2666,
  25608. diamondsuitwhite: 0x2662,
  25609. dieresis: 0x00A8,
  25610. dieresisacute: 0xF6D7,
  25611. dieresisbelowcmb: 0x0324,
  25612. dieresiscmb: 0x0308,
  25613. dieresisgrave: 0xF6D8,
  25614. dieresistonos: 0x0385,
  25615. dihiragana: 0x3062,
  25616. dikatakana: 0x30C2,
  25617. dittomark: 0x3003,
  25618. divide: 0x00F7,
  25619. divides: 0x2223,
  25620. divisionslash: 0x2215,
  25621. djecyrillic: 0x0452,
  25622. dkshade: 0x2593,
  25623. dlinebelow: 0x1E0F,
  25624. dlsquare: 0x3397,
  25625. dmacron: 0x0111,
  25626. dmonospace: 0xFF44,
  25627. dnblock: 0x2584,
  25628. dochadathai: 0x0E0E,
  25629. dodekthai: 0x0E14,
  25630. dohiragana: 0x3069,
  25631. dokatakana: 0x30C9,
  25632. dollar: 0x0024,
  25633. dollarinferior: 0xF6E3,
  25634. dollarmonospace: 0xFF04,
  25635. dollaroldstyle: 0xF724,
  25636. dollarsmall: 0xFE69,
  25637. dollarsuperior: 0xF6E4,
  25638. dong: 0x20AB,
  25639. dorusquare: 0x3326,
  25640. dotaccent: 0x02D9,
  25641. dotaccentcmb: 0x0307,
  25642. dotbelowcmb: 0x0323,
  25643. dotbelowcomb: 0x0323,
  25644. dotkatakana: 0x30FB,
  25645. dotlessi: 0x0131,
  25646. dotlessj: 0xF6BE,
  25647. dotlessjstrokehook: 0x0284,
  25648. dotmath: 0x22C5,
  25649. dottedcircle: 0x25CC,
  25650. doubleyodpatah: 0xFB1F,
  25651. doubleyodpatahhebrew: 0xFB1F,
  25652. downtackbelowcmb: 0x031E,
  25653. downtackmod: 0x02D5,
  25654. dparen: 0x249F,
  25655. dsuperior: 0xF6EB,
  25656. dtail: 0x0256,
  25657. dtopbar: 0x018C,
  25658. duhiragana: 0x3065,
  25659. dukatakana: 0x30C5,
  25660. dz: 0x01F3,
  25661. dzaltone: 0x02A3,
  25662. dzcaron: 0x01C6,
  25663. dzcurl: 0x02A5,
  25664. dzeabkhasiancyrillic: 0x04E1,
  25665. dzecyrillic: 0x0455,
  25666. dzhecyrillic: 0x045F,
  25667. e: 0x0065,
  25668. eacute: 0x00E9,
  25669. earth: 0x2641,
  25670. ebengali: 0x098F,
  25671. ebopomofo: 0x311C,
  25672. ebreve: 0x0115,
  25673. ecandradeva: 0x090D,
  25674. ecandragujarati: 0x0A8D,
  25675. ecandravowelsigndeva: 0x0945,
  25676. ecandravowelsigngujarati: 0x0AC5,
  25677. ecaron: 0x011B,
  25678. ecedillabreve: 0x1E1D,
  25679. echarmenian: 0x0565,
  25680. echyiwnarmenian: 0x0587,
  25681. ecircle: 0x24D4,
  25682. ecircumflex: 0x00EA,
  25683. ecircumflexacute: 0x1EBF,
  25684. ecircumflexbelow: 0x1E19,
  25685. ecircumflexdotbelow: 0x1EC7,
  25686. ecircumflexgrave: 0x1EC1,
  25687. ecircumflexhookabove: 0x1EC3,
  25688. ecircumflextilde: 0x1EC5,
  25689. ecyrillic: 0x0454,
  25690. edblgrave: 0x0205,
  25691. edeva: 0x090F,
  25692. edieresis: 0x00EB,
  25693. edot: 0x0117,
  25694. edotaccent: 0x0117,
  25695. edotbelow: 0x1EB9,
  25696. eegurmukhi: 0x0A0F,
  25697. eematragurmukhi: 0x0A47,
  25698. efcyrillic: 0x0444,
  25699. egrave: 0x00E8,
  25700. egujarati: 0x0A8F,
  25701. eharmenian: 0x0567,
  25702. ehbopomofo: 0x311D,
  25703. ehiragana: 0x3048,
  25704. ehookabove: 0x1EBB,
  25705. eibopomofo: 0x311F,
  25706. eight: 0x0038,
  25707. eightarabic: 0x0668,
  25708. eightbengali: 0x09EE,
  25709. eightcircle: 0x2467,
  25710. eightcircleinversesansserif: 0x2791,
  25711. eightdeva: 0x096E,
  25712. eighteencircle: 0x2471,
  25713. eighteenparen: 0x2485,
  25714. eighteenperiod: 0x2499,
  25715. eightgujarati: 0x0AEE,
  25716. eightgurmukhi: 0x0A6E,
  25717. eighthackarabic: 0x0668,
  25718. eighthangzhou: 0x3028,
  25719. eighthnotebeamed: 0x266B,
  25720. eightideographicparen: 0x3227,
  25721. eightinferior: 0x2088,
  25722. eightmonospace: 0xFF18,
  25723. eightoldstyle: 0xF738,
  25724. eightparen: 0x247B,
  25725. eightperiod: 0x248F,
  25726. eightpersian: 0x06F8,
  25727. eightroman: 0x2177,
  25728. eightsuperior: 0x2078,
  25729. eightthai: 0x0E58,
  25730. einvertedbreve: 0x0207,
  25731. eiotifiedcyrillic: 0x0465,
  25732. ekatakana: 0x30A8,
  25733. ekatakanahalfwidth: 0xFF74,
  25734. ekonkargurmukhi: 0x0A74,
  25735. ekorean: 0x3154,
  25736. elcyrillic: 0x043B,
  25737. element: 0x2208,
  25738. elevencircle: 0x246A,
  25739. elevenparen: 0x247E,
  25740. elevenperiod: 0x2492,
  25741. elevenroman: 0x217A,
  25742. ellipsis: 0x2026,
  25743. ellipsisvertical: 0x22EE,
  25744. emacron: 0x0113,
  25745. emacronacute: 0x1E17,
  25746. emacrongrave: 0x1E15,
  25747. emcyrillic: 0x043C,
  25748. emdash: 0x2014,
  25749. emdashvertical: 0xFE31,
  25750. emonospace: 0xFF45,
  25751. emphasismarkarmenian: 0x055B,
  25752. emptyset: 0x2205,
  25753. enbopomofo: 0x3123,
  25754. encyrillic: 0x043D,
  25755. endash: 0x2013,
  25756. endashvertical: 0xFE32,
  25757. endescendercyrillic: 0x04A3,
  25758. eng: 0x014B,
  25759. engbopomofo: 0x3125,
  25760. enghecyrillic: 0x04A5,
  25761. enhookcyrillic: 0x04C8,
  25762. enspace: 0x2002,
  25763. eogonek: 0x0119,
  25764. eokorean: 0x3153,
  25765. eopen: 0x025B,
  25766. eopenclosed: 0x029A,
  25767. eopenreversed: 0x025C,
  25768. eopenreversedclosed: 0x025E,
  25769. eopenreversedhook: 0x025D,
  25770. eparen: 0x24A0,
  25771. epsilon: 0x03B5,
  25772. epsilontonos: 0x03AD,
  25773. equal: 0x003D,
  25774. equalmonospace: 0xFF1D,
  25775. equalsmall: 0xFE66,
  25776. equalsuperior: 0x207C,
  25777. equivalence: 0x2261,
  25778. erbopomofo: 0x3126,
  25779. ercyrillic: 0x0440,
  25780. ereversed: 0x0258,
  25781. ereversedcyrillic: 0x044D,
  25782. escyrillic: 0x0441,
  25783. esdescendercyrillic: 0x04AB,
  25784. esh: 0x0283,
  25785. eshcurl: 0x0286,
  25786. eshortdeva: 0x090E,
  25787. eshortvowelsigndeva: 0x0946,
  25788. eshreversedloop: 0x01AA,
  25789. eshsquatreversed: 0x0285,
  25790. esmallhiragana: 0x3047,
  25791. esmallkatakana: 0x30A7,
  25792. esmallkatakanahalfwidth: 0xFF6A,
  25793. estimated: 0x212E,
  25794. esuperior: 0xF6EC,
  25795. eta: 0x03B7,
  25796. etarmenian: 0x0568,
  25797. etatonos: 0x03AE,
  25798. eth: 0x00F0,
  25799. etilde: 0x1EBD,
  25800. etildebelow: 0x1E1B,
  25801. etnahtafoukhhebrew: 0x0591,
  25802. etnahtafoukhlefthebrew: 0x0591,
  25803. etnahtahebrew: 0x0591,
  25804. etnahtalefthebrew: 0x0591,
  25805. eturned: 0x01DD,
  25806. eukorean: 0x3161,
  25807. euro: 0x20AC,
  25808. evowelsignbengali: 0x09C7,
  25809. evowelsigndeva: 0x0947,
  25810. evowelsigngujarati: 0x0AC7,
  25811. exclam: 0x0021,
  25812. exclamarmenian: 0x055C,
  25813. exclamdbl: 0x203C,
  25814. exclamdown: 0x00A1,
  25815. exclamdownsmall: 0xF7A1,
  25816. exclammonospace: 0xFF01,
  25817. exclamsmall: 0xF721,
  25818. existential: 0x2203,
  25819. ezh: 0x0292,
  25820. ezhcaron: 0x01EF,
  25821. ezhcurl: 0x0293,
  25822. ezhreversed: 0x01B9,
  25823. ezhtail: 0x01BA,
  25824. f: 0x0066,
  25825. fadeva: 0x095E,
  25826. fagurmukhi: 0x0A5E,
  25827. fahrenheit: 0x2109,
  25828. fathaarabic: 0x064E,
  25829. fathalowarabic: 0x064E,
  25830. fathatanarabic: 0x064B,
  25831. fbopomofo: 0x3108,
  25832. fcircle: 0x24D5,
  25833. fdotaccent: 0x1E1F,
  25834. feharabic: 0x0641,
  25835. feharmenian: 0x0586,
  25836. fehfinalarabic: 0xFED2,
  25837. fehinitialarabic: 0xFED3,
  25838. fehmedialarabic: 0xFED4,
  25839. feicoptic: 0x03E5,
  25840. female: 0x2640,
  25841. ff: 0xFB00,
  25842. ffi: 0xFB03,
  25843. ffl: 0xFB04,
  25844. fi: 0xFB01,
  25845. fifteencircle: 0x246E,
  25846. fifteenparen: 0x2482,
  25847. fifteenperiod: 0x2496,
  25848. figuredash: 0x2012,
  25849. filledbox: 0x25A0,
  25850. filledrect: 0x25AC,
  25851. finalkaf: 0x05DA,
  25852. finalkafdagesh: 0xFB3A,
  25853. finalkafdageshhebrew: 0xFB3A,
  25854. finalkafhebrew: 0x05DA,
  25855. finalmem: 0x05DD,
  25856. finalmemhebrew: 0x05DD,
  25857. finalnun: 0x05DF,
  25858. finalnunhebrew: 0x05DF,
  25859. finalpe: 0x05E3,
  25860. finalpehebrew: 0x05E3,
  25861. finaltsadi: 0x05E5,
  25862. finaltsadihebrew: 0x05E5,
  25863. firsttonechinese: 0x02C9,
  25864. fisheye: 0x25C9,
  25865. fitacyrillic: 0x0473,
  25866. five: 0x0035,
  25867. fivearabic: 0x0665,
  25868. fivebengali: 0x09EB,
  25869. fivecircle: 0x2464,
  25870. fivecircleinversesansserif: 0x278E,
  25871. fivedeva: 0x096B,
  25872. fiveeighths: 0x215D,
  25873. fivegujarati: 0x0AEB,
  25874. fivegurmukhi: 0x0A6B,
  25875. fivehackarabic: 0x0665,
  25876. fivehangzhou: 0x3025,
  25877. fiveideographicparen: 0x3224,
  25878. fiveinferior: 0x2085,
  25879. fivemonospace: 0xFF15,
  25880. fiveoldstyle: 0xF735,
  25881. fiveparen: 0x2478,
  25882. fiveperiod: 0x248C,
  25883. fivepersian: 0x06F5,
  25884. fiveroman: 0x2174,
  25885. fivesuperior: 0x2075,
  25886. fivethai: 0x0E55,
  25887. fl: 0xFB02,
  25888. florin: 0x0192,
  25889. fmonospace: 0xFF46,
  25890. fmsquare: 0x3399,
  25891. fofanthai: 0x0E1F,
  25892. fofathai: 0x0E1D,
  25893. fongmanthai: 0x0E4F,
  25894. forall: 0x2200,
  25895. four: 0x0034,
  25896. fourarabic: 0x0664,
  25897. fourbengali: 0x09EA,
  25898. fourcircle: 0x2463,
  25899. fourcircleinversesansserif: 0x278D,
  25900. fourdeva: 0x096A,
  25901. fourgujarati: 0x0AEA,
  25902. fourgurmukhi: 0x0A6A,
  25903. fourhackarabic: 0x0664,
  25904. fourhangzhou: 0x3024,
  25905. fourideographicparen: 0x3223,
  25906. fourinferior: 0x2084,
  25907. fourmonospace: 0xFF14,
  25908. fournumeratorbengali: 0x09F7,
  25909. fouroldstyle: 0xF734,
  25910. fourparen: 0x2477,
  25911. fourperiod: 0x248B,
  25912. fourpersian: 0x06F4,
  25913. fourroman: 0x2173,
  25914. foursuperior: 0x2074,
  25915. fourteencircle: 0x246D,
  25916. fourteenparen: 0x2481,
  25917. fourteenperiod: 0x2495,
  25918. fourthai: 0x0E54,
  25919. fourthtonechinese: 0x02CB,
  25920. fparen: 0x24A1,
  25921. fraction: 0x2044,
  25922. franc: 0x20A3,
  25923. g: 0x0067,
  25924. gabengali: 0x0997,
  25925. gacute: 0x01F5,
  25926. gadeva: 0x0917,
  25927. gafarabic: 0x06AF,
  25928. gaffinalarabic: 0xFB93,
  25929. gafinitialarabic: 0xFB94,
  25930. gafmedialarabic: 0xFB95,
  25931. gagujarati: 0x0A97,
  25932. gagurmukhi: 0x0A17,
  25933. gahiragana: 0x304C,
  25934. gakatakana: 0x30AC,
  25935. gamma: 0x03B3,
  25936. gammalatinsmall: 0x0263,
  25937. gammasuperior: 0x02E0,
  25938. gangiacoptic: 0x03EB,
  25939. gbopomofo: 0x310D,
  25940. gbreve: 0x011F,
  25941. gcaron: 0x01E7,
  25942. gcedilla: 0x0123,
  25943. gcircle: 0x24D6,
  25944. gcircumflex: 0x011D,
  25945. gcommaaccent: 0x0123,
  25946. gdot: 0x0121,
  25947. gdotaccent: 0x0121,
  25948. gecyrillic: 0x0433,
  25949. gehiragana: 0x3052,
  25950. gekatakana: 0x30B2,
  25951. geometricallyequal: 0x2251,
  25952. gereshaccenthebrew: 0x059C,
  25953. gereshhebrew: 0x05F3,
  25954. gereshmuqdamhebrew: 0x059D,
  25955. germandbls: 0x00DF,
  25956. gershayimaccenthebrew: 0x059E,
  25957. gershayimhebrew: 0x05F4,
  25958. getamark: 0x3013,
  25959. ghabengali: 0x0998,
  25960. ghadarmenian: 0x0572,
  25961. ghadeva: 0x0918,
  25962. ghagujarati: 0x0A98,
  25963. ghagurmukhi: 0x0A18,
  25964. ghainarabic: 0x063A,
  25965. ghainfinalarabic: 0xFECE,
  25966. ghaininitialarabic: 0xFECF,
  25967. ghainmedialarabic: 0xFED0,
  25968. ghemiddlehookcyrillic: 0x0495,
  25969. ghestrokecyrillic: 0x0493,
  25970. gheupturncyrillic: 0x0491,
  25971. ghhadeva: 0x095A,
  25972. ghhagurmukhi: 0x0A5A,
  25973. ghook: 0x0260,
  25974. ghzsquare: 0x3393,
  25975. gihiragana: 0x304E,
  25976. gikatakana: 0x30AE,
  25977. gimarmenian: 0x0563,
  25978. gimel: 0x05D2,
  25979. gimeldagesh: 0xFB32,
  25980. gimeldageshhebrew: 0xFB32,
  25981. gimelhebrew: 0x05D2,
  25982. gjecyrillic: 0x0453,
  25983. glottalinvertedstroke: 0x01BE,
  25984. glottalstop: 0x0294,
  25985. glottalstopinverted: 0x0296,
  25986. glottalstopmod: 0x02C0,
  25987. glottalstopreversed: 0x0295,
  25988. glottalstopreversedmod: 0x02C1,
  25989. glottalstopreversedsuperior: 0x02E4,
  25990. glottalstopstroke: 0x02A1,
  25991. glottalstopstrokereversed: 0x02A2,
  25992. gmacron: 0x1E21,
  25993. gmonospace: 0xFF47,
  25994. gohiragana: 0x3054,
  25995. gokatakana: 0x30B4,
  25996. gparen: 0x24A2,
  25997. gpasquare: 0x33AC,
  25998. gradient: 0x2207,
  25999. grave: 0x0060,
  26000. gravebelowcmb: 0x0316,
  26001. gravecmb: 0x0300,
  26002. gravecomb: 0x0300,
  26003. gravedeva: 0x0953,
  26004. gravelowmod: 0x02CE,
  26005. gravemonospace: 0xFF40,
  26006. gravetonecmb: 0x0340,
  26007. greater: 0x003E,
  26008. greaterequal: 0x2265,
  26009. greaterequalorless: 0x22DB,
  26010. greatermonospace: 0xFF1E,
  26011. greaterorequivalent: 0x2273,
  26012. greaterorless: 0x2277,
  26013. greateroverequal: 0x2267,
  26014. greatersmall: 0xFE65,
  26015. gscript: 0x0261,
  26016. gstroke: 0x01E5,
  26017. guhiragana: 0x3050,
  26018. guillemotleft: 0x00AB,
  26019. guillemotright: 0x00BB,
  26020. guilsinglleft: 0x2039,
  26021. guilsinglright: 0x203A,
  26022. gukatakana: 0x30B0,
  26023. guramusquare: 0x3318,
  26024. gysquare: 0x33C9,
  26025. h: 0x0068,
  26026. haabkhasiancyrillic: 0x04A9,
  26027. haaltonearabic: 0x06C1,
  26028. habengali: 0x09B9,
  26029. hadescendercyrillic: 0x04B3,
  26030. hadeva: 0x0939,
  26031. hagujarati: 0x0AB9,
  26032. hagurmukhi: 0x0A39,
  26033. haharabic: 0x062D,
  26034. hahfinalarabic: 0xFEA2,
  26035. hahinitialarabic: 0xFEA3,
  26036. hahiragana: 0x306F,
  26037. hahmedialarabic: 0xFEA4,
  26038. haitusquare: 0x332A,
  26039. hakatakana: 0x30CF,
  26040. hakatakanahalfwidth: 0xFF8A,
  26041. halantgurmukhi: 0x0A4D,
  26042. hamzaarabic: 0x0621,
  26043. hamzalowarabic: 0x0621,
  26044. hangulfiller: 0x3164,
  26045. hardsigncyrillic: 0x044A,
  26046. harpoonleftbarbup: 0x21BC,
  26047. harpoonrightbarbup: 0x21C0,
  26048. hasquare: 0x33CA,
  26049. hatafpatah: 0x05B2,
  26050. hatafpatah16: 0x05B2,
  26051. hatafpatah23: 0x05B2,
  26052. hatafpatah2f: 0x05B2,
  26053. hatafpatahhebrew: 0x05B2,
  26054. hatafpatahnarrowhebrew: 0x05B2,
  26055. hatafpatahquarterhebrew: 0x05B2,
  26056. hatafpatahwidehebrew: 0x05B2,
  26057. hatafqamats: 0x05B3,
  26058. hatafqamats1b: 0x05B3,
  26059. hatafqamats28: 0x05B3,
  26060. hatafqamats34: 0x05B3,
  26061. hatafqamatshebrew: 0x05B3,
  26062. hatafqamatsnarrowhebrew: 0x05B3,
  26063. hatafqamatsquarterhebrew: 0x05B3,
  26064. hatafqamatswidehebrew: 0x05B3,
  26065. hatafsegol: 0x05B1,
  26066. hatafsegol17: 0x05B1,
  26067. hatafsegol24: 0x05B1,
  26068. hatafsegol30: 0x05B1,
  26069. hatafsegolhebrew: 0x05B1,
  26070. hatafsegolnarrowhebrew: 0x05B1,
  26071. hatafsegolquarterhebrew: 0x05B1,
  26072. hatafsegolwidehebrew: 0x05B1,
  26073. hbar: 0x0127,
  26074. hbopomofo: 0x310F,
  26075. hbrevebelow: 0x1E2B,
  26076. hcedilla: 0x1E29,
  26077. hcircle: 0x24D7,
  26078. hcircumflex: 0x0125,
  26079. hdieresis: 0x1E27,
  26080. hdotaccent: 0x1E23,
  26081. hdotbelow: 0x1E25,
  26082. he: 0x05D4,
  26083. heart: 0x2665,
  26084. heartsuitblack: 0x2665,
  26085. heartsuitwhite: 0x2661,
  26086. hedagesh: 0xFB34,
  26087. hedageshhebrew: 0xFB34,
  26088. hehaltonearabic: 0x06C1,
  26089. heharabic: 0x0647,
  26090. hehebrew: 0x05D4,
  26091. hehfinalaltonearabic: 0xFBA7,
  26092. hehfinalalttwoarabic: 0xFEEA,
  26093. hehfinalarabic: 0xFEEA,
  26094. hehhamzaabovefinalarabic: 0xFBA5,
  26095. hehhamzaaboveisolatedarabic: 0xFBA4,
  26096. hehinitialaltonearabic: 0xFBA8,
  26097. hehinitialarabic: 0xFEEB,
  26098. hehiragana: 0x3078,
  26099. hehmedialaltonearabic: 0xFBA9,
  26100. hehmedialarabic: 0xFEEC,
  26101. heiseierasquare: 0x337B,
  26102. hekatakana: 0x30D8,
  26103. hekatakanahalfwidth: 0xFF8D,
  26104. hekutaarusquare: 0x3336,
  26105. henghook: 0x0267,
  26106. herutusquare: 0x3339,
  26107. het: 0x05D7,
  26108. hethebrew: 0x05D7,
  26109. hhook: 0x0266,
  26110. hhooksuperior: 0x02B1,
  26111. hieuhacirclekorean: 0x327B,
  26112. hieuhaparenkorean: 0x321B,
  26113. hieuhcirclekorean: 0x326D,
  26114. hieuhkorean: 0x314E,
  26115. hieuhparenkorean: 0x320D,
  26116. hihiragana: 0x3072,
  26117. hikatakana: 0x30D2,
  26118. hikatakanahalfwidth: 0xFF8B,
  26119. hiriq: 0x05B4,
  26120. hiriq14: 0x05B4,
  26121. hiriq21: 0x05B4,
  26122. hiriq2d: 0x05B4,
  26123. hiriqhebrew: 0x05B4,
  26124. hiriqnarrowhebrew: 0x05B4,
  26125. hiriqquarterhebrew: 0x05B4,
  26126. hiriqwidehebrew: 0x05B4,
  26127. hlinebelow: 0x1E96,
  26128. hmonospace: 0xFF48,
  26129. hoarmenian: 0x0570,
  26130. hohipthai: 0x0E2B,
  26131. hohiragana: 0x307B,
  26132. hokatakana: 0x30DB,
  26133. hokatakanahalfwidth: 0xFF8E,
  26134. holam: 0x05B9,
  26135. holam19: 0x05B9,
  26136. holam26: 0x05B9,
  26137. holam32: 0x05B9,
  26138. holamhebrew: 0x05B9,
  26139. holamnarrowhebrew: 0x05B9,
  26140. holamquarterhebrew: 0x05B9,
  26141. holamwidehebrew: 0x05B9,
  26142. honokhukthai: 0x0E2E,
  26143. hookabovecomb: 0x0309,
  26144. hookcmb: 0x0309,
  26145. hookpalatalizedbelowcmb: 0x0321,
  26146. hookretroflexbelowcmb: 0x0322,
  26147. hoonsquare: 0x3342,
  26148. horicoptic: 0x03E9,
  26149. horizontalbar: 0x2015,
  26150. horncmb: 0x031B,
  26151. hotsprings: 0x2668,
  26152. house: 0x2302,
  26153. hparen: 0x24A3,
  26154. hsuperior: 0x02B0,
  26155. hturned: 0x0265,
  26156. huhiragana: 0x3075,
  26157. huiitosquare: 0x3333,
  26158. hukatakana: 0x30D5,
  26159. hukatakanahalfwidth: 0xFF8C,
  26160. hungarumlaut: 0x02DD,
  26161. hungarumlautcmb: 0x030B,
  26162. hv: 0x0195,
  26163. hyphen: 0x002D,
  26164. hypheninferior: 0xF6E5,
  26165. hyphenmonospace: 0xFF0D,
  26166. hyphensmall: 0xFE63,
  26167. hyphensuperior: 0xF6E6,
  26168. hyphentwo: 0x2010,
  26169. i: 0x0069,
  26170. iacute: 0x00ED,
  26171. iacyrillic: 0x044F,
  26172. ibengali: 0x0987,
  26173. ibopomofo: 0x3127,
  26174. ibreve: 0x012D,
  26175. icaron: 0x01D0,
  26176. icircle: 0x24D8,
  26177. icircumflex: 0x00EE,
  26178. icyrillic: 0x0456,
  26179. idblgrave: 0x0209,
  26180. ideographearthcircle: 0x328F,
  26181. ideographfirecircle: 0x328B,
  26182. ideographicallianceparen: 0x323F,
  26183. ideographiccallparen: 0x323A,
  26184. ideographiccentrecircle: 0x32A5,
  26185. ideographicclose: 0x3006,
  26186. ideographiccomma: 0x3001,
  26187. ideographiccommaleft: 0xFF64,
  26188. ideographiccongratulationparen: 0x3237,
  26189. ideographiccorrectcircle: 0x32A3,
  26190. ideographicearthparen: 0x322F,
  26191. ideographicenterpriseparen: 0x323D,
  26192. ideographicexcellentcircle: 0x329D,
  26193. ideographicfestivalparen: 0x3240,
  26194. ideographicfinancialcircle: 0x3296,
  26195. ideographicfinancialparen: 0x3236,
  26196. ideographicfireparen: 0x322B,
  26197. ideographichaveparen: 0x3232,
  26198. ideographichighcircle: 0x32A4,
  26199. ideographiciterationmark: 0x3005,
  26200. ideographiclaborcircle: 0x3298,
  26201. ideographiclaborparen: 0x3238,
  26202. ideographicleftcircle: 0x32A7,
  26203. ideographiclowcircle: 0x32A6,
  26204. ideographicmedicinecircle: 0x32A9,
  26205. ideographicmetalparen: 0x322E,
  26206. ideographicmoonparen: 0x322A,
  26207. ideographicnameparen: 0x3234,
  26208. ideographicperiod: 0x3002,
  26209. ideographicprintcircle: 0x329E,
  26210. ideographicreachparen: 0x3243,
  26211. ideographicrepresentparen: 0x3239,
  26212. ideographicresourceparen: 0x323E,
  26213. ideographicrightcircle: 0x32A8,
  26214. ideographicsecretcircle: 0x3299,
  26215. ideographicselfparen: 0x3242,
  26216. ideographicsocietyparen: 0x3233,
  26217. ideographicspace: 0x3000,
  26218. ideographicspecialparen: 0x3235,
  26219. ideographicstockparen: 0x3231,
  26220. ideographicstudyparen: 0x323B,
  26221. ideographicsunparen: 0x3230,
  26222. ideographicsuperviseparen: 0x323C,
  26223. ideographicwaterparen: 0x322C,
  26224. ideographicwoodparen: 0x322D,
  26225. ideographiczero: 0x3007,
  26226. ideographmetalcircle: 0x328E,
  26227. ideographmooncircle: 0x328A,
  26228. ideographnamecircle: 0x3294,
  26229. ideographsuncircle: 0x3290,
  26230. ideographwatercircle: 0x328C,
  26231. ideographwoodcircle: 0x328D,
  26232. ideva: 0x0907,
  26233. idieresis: 0x00EF,
  26234. idieresisacute: 0x1E2F,
  26235. idieresiscyrillic: 0x04E5,
  26236. idotbelow: 0x1ECB,
  26237. iebrevecyrillic: 0x04D7,
  26238. iecyrillic: 0x0435,
  26239. ieungacirclekorean: 0x3275,
  26240. ieungaparenkorean: 0x3215,
  26241. ieungcirclekorean: 0x3267,
  26242. ieungkorean: 0x3147,
  26243. ieungparenkorean: 0x3207,
  26244. igrave: 0x00EC,
  26245. igujarati: 0x0A87,
  26246. igurmukhi: 0x0A07,
  26247. ihiragana: 0x3044,
  26248. ihookabove: 0x1EC9,
  26249. iibengali: 0x0988,
  26250. iicyrillic: 0x0438,
  26251. iideva: 0x0908,
  26252. iigujarati: 0x0A88,
  26253. iigurmukhi: 0x0A08,
  26254. iimatragurmukhi: 0x0A40,
  26255. iinvertedbreve: 0x020B,
  26256. iishortcyrillic: 0x0439,
  26257. iivowelsignbengali: 0x09C0,
  26258. iivowelsigndeva: 0x0940,
  26259. iivowelsigngujarati: 0x0AC0,
  26260. ij: 0x0133,
  26261. ikatakana: 0x30A4,
  26262. ikatakanahalfwidth: 0xFF72,
  26263. ikorean: 0x3163,
  26264. ilde: 0x02DC,
  26265. iluyhebrew: 0x05AC,
  26266. imacron: 0x012B,
  26267. imacroncyrillic: 0x04E3,
  26268. imageorapproximatelyequal: 0x2253,
  26269. imatragurmukhi: 0x0A3F,
  26270. imonospace: 0xFF49,
  26271. increment: 0x2206,
  26272. infinity: 0x221E,
  26273. iniarmenian: 0x056B,
  26274. integral: 0x222B,
  26275. integralbottom: 0x2321,
  26276. integralbt: 0x2321,
  26277. integralex: 0xF8F5,
  26278. integraltop: 0x2320,
  26279. integraltp: 0x2320,
  26280. intersection: 0x2229,
  26281. intisquare: 0x3305,
  26282. invbullet: 0x25D8,
  26283. invcircle: 0x25D9,
  26284. invsmileface: 0x263B,
  26285. iocyrillic: 0x0451,
  26286. iogonek: 0x012F,
  26287. iota: 0x03B9,
  26288. iotadieresis: 0x03CA,
  26289. iotadieresistonos: 0x0390,
  26290. iotalatin: 0x0269,
  26291. iotatonos: 0x03AF,
  26292. iparen: 0x24A4,
  26293. irigurmukhi: 0x0A72,
  26294. ismallhiragana: 0x3043,
  26295. ismallkatakana: 0x30A3,
  26296. ismallkatakanahalfwidth: 0xFF68,
  26297. issharbengali: 0x09FA,
  26298. istroke: 0x0268,
  26299. isuperior: 0xF6ED,
  26300. iterationhiragana: 0x309D,
  26301. iterationkatakana: 0x30FD,
  26302. itilde: 0x0129,
  26303. itildebelow: 0x1E2D,
  26304. iubopomofo: 0x3129,
  26305. iucyrillic: 0x044E,
  26306. ivowelsignbengali: 0x09BF,
  26307. ivowelsigndeva: 0x093F,
  26308. ivowelsigngujarati: 0x0ABF,
  26309. izhitsacyrillic: 0x0475,
  26310. izhitsadblgravecyrillic: 0x0477,
  26311. j: 0x006A,
  26312. jaarmenian: 0x0571,
  26313. jabengali: 0x099C,
  26314. jadeva: 0x091C,
  26315. jagujarati: 0x0A9C,
  26316. jagurmukhi: 0x0A1C,
  26317. jbopomofo: 0x3110,
  26318. jcaron: 0x01F0,
  26319. jcircle: 0x24D9,
  26320. jcircumflex: 0x0135,
  26321. jcrossedtail: 0x029D,
  26322. jdotlessstroke: 0x025F,
  26323. jecyrillic: 0x0458,
  26324. jeemarabic: 0x062C,
  26325. jeemfinalarabic: 0xFE9E,
  26326. jeeminitialarabic: 0xFE9F,
  26327. jeemmedialarabic: 0xFEA0,
  26328. jeharabic: 0x0698,
  26329. jehfinalarabic: 0xFB8B,
  26330. jhabengali: 0x099D,
  26331. jhadeva: 0x091D,
  26332. jhagujarati: 0x0A9D,
  26333. jhagurmukhi: 0x0A1D,
  26334. jheharmenian: 0x057B,
  26335. jis: 0x3004,
  26336. jmonospace: 0xFF4A,
  26337. jparen: 0x24A5,
  26338. jsuperior: 0x02B2,
  26339. k: 0x006B,
  26340. kabashkircyrillic: 0x04A1,
  26341. kabengali: 0x0995,
  26342. kacute: 0x1E31,
  26343. kacyrillic: 0x043A,
  26344. kadescendercyrillic: 0x049B,
  26345. kadeva: 0x0915,
  26346. kaf: 0x05DB,
  26347. kafarabic: 0x0643,
  26348. kafdagesh: 0xFB3B,
  26349. kafdageshhebrew: 0xFB3B,
  26350. kaffinalarabic: 0xFEDA,
  26351. kafhebrew: 0x05DB,
  26352. kafinitialarabic: 0xFEDB,
  26353. kafmedialarabic: 0xFEDC,
  26354. kafrafehebrew: 0xFB4D,
  26355. kagujarati: 0x0A95,
  26356. kagurmukhi: 0x0A15,
  26357. kahiragana: 0x304B,
  26358. kahookcyrillic: 0x04C4,
  26359. kakatakana: 0x30AB,
  26360. kakatakanahalfwidth: 0xFF76,
  26361. kappa: 0x03BA,
  26362. kappasymbolgreek: 0x03F0,
  26363. kapyeounmieumkorean: 0x3171,
  26364. kapyeounphieuphkorean: 0x3184,
  26365. kapyeounpieupkorean: 0x3178,
  26366. kapyeounssangpieupkorean: 0x3179,
  26367. karoriisquare: 0x330D,
  26368. kashidaautoarabic: 0x0640,
  26369. kashidaautonosidebearingarabic: 0x0640,
  26370. kasmallkatakana: 0x30F5,
  26371. kasquare: 0x3384,
  26372. kasraarabic: 0x0650,
  26373. kasratanarabic: 0x064D,
  26374. kastrokecyrillic: 0x049F,
  26375. katahiraprolongmarkhalfwidth: 0xFF70,
  26376. kaverticalstrokecyrillic: 0x049D,
  26377. kbopomofo: 0x310E,
  26378. kcalsquare: 0x3389,
  26379. kcaron: 0x01E9,
  26380. kcedilla: 0x0137,
  26381. kcircle: 0x24DA,
  26382. kcommaaccent: 0x0137,
  26383. kdotbelow: 0x1E33,
  26384. keharmenian: 0x0584,
  26385. kehiragana: 0x3051,
  26386. kekatakana: 0x30B1,
  26387. kekatakanahalfwidth: 0xFF79,
  26388. kenarmenian: 0x056F,
  26389. kesmallkatakana: 0x30F6,
  26390. kgreenlandic: 0x0138,
  26391. khabengali: 0x0996,
  26392. khacyrillic: 0x0445,
  26393. khadeva: 0x0916,
  26394. khagujarati: 0x0A96,
  26395. khagurmukhi: 0x0A16,
  26396. khaharabic: 0x062E,
  26397. khahfinalarabic: 0xFEA6,
  26398. khahinitialarabic: 0xFEA7,
  26399. khahmedialarabic: 0xFEA8,
  26400. kheicoptic: 0x03E7,
  26401. khhadeva: 0x0959,
  26402. khhagurmukhi: 0x0A59,
  26403. khieukhacirclekorean: 0x3278,
  26404. khieukhaparenkorean: 0x3218,
  26405. khieukhcirclekorean: 0x326A,
  26406. khieukhkorean: 0x314B,
  26407. khieukhparenkorean: 0x320A,
  26408. khokhaithai: 0x0E02,
  26409. khokhonthai: 0x0E05,
  26410. khokhuatthai: 0x0E03,
  26411. khokhwaithai: 0x0E04,
  26412. khomutthai: 0x0E5B,
  26413. khook: 0x0199,
  26414. khorakhangthai: 0x0E06,
  26415. khzsquare: 0x3391,
  26416. kihiragana: 0x304D,
  26417. kikatakana: 0x30AD,
  26418. kikatakanahalfwidth: 0xFF77,
  26419. kiroguramusquare: 0x3315,
  26420. kiromeetorusquare: 0x3316,
  26421. kirosquare: 0x3314,
  26422. kiyeokacirclekorean: 0x326E,
  26423. kiyeokaparenkorean: 0x320E,
  26424. kiyeokcirclekorean: 0x3260,
  26425. kiyeokkorean: 0x3131,
  26426. kiyeokparenkorean: 0x3200,
  26427. kiyeoksioskorean: 0x3133,
  26428. kjecyrillic: 0x045C,
  26429. klinebelow: 0x1E35,
  26430. klsquare: 0x3398,
  26431. kmcubedsquare: 0x33A6,
  26432. kmonospace: 0xFF4B,
  26433. kmsquaredsquare: 0x33A2,
  26434. kohiragana: 0x3053,
  26435. kohmsquare: 0x33C0,
  26436. kokaithai: 0x0E01,
  26437. kokatakana: 0x30B3,
  26438. kokatakanahalfwidth: 0xFF7A,
  26439. kooposquare: 0x331E,
  26440. koppacyrillic: 0x0481,
  26441. koreanstandardsymbol: 0x327F,
  26442. koroniscmb: 0x0343,
  26443. kparen: 0x24A6,
  26444. kpasquare: 0x33AA,
  26445. ksicyrillic: 0x046F,
  26446. ktsquare: 0x33CF,
  26447. kturned: 0x029E,
  26448. kuhiragana: 0x304F,
  26449. kukatakana: 0x30AF,
  26450. kukatakanahalfwidth: 0xFF78,
  26451. kvsquare: 0x33B8,
  26452. kwsquare: 0x33BE,
  26453. l: 0x006C,
  26454. labengali: 0x09B2,
  26455. lacute: 0x013A,
  26456. ladeva: 0x0932,
  26457. lagujarati: 0x0AB2,
  26458. lagurmukhi: 0x0A32,
  26459. lakkhangyaothai: 0x0E45,
  26460. lamaleffinalarabic: 0xFEFC,
  26461. lamalefhamzaabovefinalarabic: 0xFEF8,
  26462. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  26463. lamalefhamzabelowfinalarabic: 0xFEFA,
  26464. lamalefhamzabelowisolatedarabic: 0xFEF9,
  26465. lamalefisolatedarabic: 0xFEFB,
  26466. lamalefmaddaabovefinalarabic: 0xFEF6,
  26467. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  26468. lamarabic: 0x0644,
  26469. lambda: 0x03BB,
  26470. lambdastroke: 0x019B,
  26471. lamed: 0x05DC,
  26472. lameddagesh: 0xFB3C,
  26473. lameddageshhebrew: 0xFB3C,
  26474. lamedhebrew: 0x05DC,
  26475. lamfinalarabic: 0xFEDE,
  26476. lamhahinitialarabic: 0xFCCA,
  26477. laminitialarabic: 0xFEDF,
  26478. lamjeeminitialarabic: 0xFCC9,
  26479. lamkhahinitialarabic: 0xFCCB,
  26480. lamlamhehisolatedarabic: 0xFDF2,
  26481. lammedialarabic: 0xFEE0,
  26482. lammeemhahinitialarabic: 0xFD88,
  26483. lammeeminitialarabic: 0xFCCC,
  26484. largecircle: 0x25EF,
  26485. lbar: 0x019A,
  26486. lbelt: 0x026C,
  26487. lbopomofo: 0x310C,
  26488. lcaron: 0x013E,
  26489. lcedilla: 0x013C,
  26490. lcircle: 0x24DB,
  26491. lcircumflexbelow: 0x1E3D,
  26492. lcommaaccent: 0x013C,
  26493. ldot: 0x0140,
  26494. ldotaccent: 0x0140,
  26495. ldotbelow: 0x1E37,
  26496. ldotbelowmacron: 0x1E39,
  26497. leftangleabovecmb: 0x031A,
  26498. lefttackbelowcmb: 0x0318,
  26499. less: 0x003C,
  26500. lessequal: 0x2264,
  26501. lessequalorgreater: 0x22DA,
  26502. lessmonospace: 0xFF1C,
  26503. lessorequivalent: 0x2272,
  26504. lessorgreater: 0x2276,
  26505. lessoverequal: 0x2266,
  26506. lesssmall: 0xFE64,
  26507. lezh: 0x026E,
  26508. lfblock: 0x258C,
  26509. lhookretroflex: 0x026D,
  26510. lira: 0x20A4,
  26511. liwnarmenian: 0x056C,
  26512. lj: 0x01C9,
  26513. ljecyrillic: 0x0459,
  26514. ll: 0xF6C0,
  26515. lladeva: 0x0933,
  26516. llagujarati: 0x0AB3,
  26517. llinebelow: 0x1E3B,
  26518. llladeva: 0x0934,
  26519. llvocalicbengali: 0x09E1,
  26520. llvocalicdeva: 0x0961,
  26521. llvocalicvowelsignbengali: 0x09E3,
  26522. llvocalicvowelsigndeva: 0x0963,
  26523. lmiddletilde: 0x026B,
  26524. lmonospace: 0xFF4C,
  26525. lmsquare: 0x33D0,
  26526. lochulathai: 0x0E2C,
  26527. logicaland: 0x2227,
  26528. logicalnot: 0x00AC,
  26529. logicalnotreversed: 0x2310,
  26530. logicalor: 0x2228,
  26531. lolingthai: 0x0E25,
  26532. longs: 0x017F,
  26533. lowlinecenterline: 0xFE4E,
  26534. lowlinecmb: 0x0332,
  26535. lowlinedashed: 0xFE4D,
  26536. lozenge: 0x25CA,
  26537. lparen: 0x24A7,
  26538. lslash: 0x0142,
  26539. lsquare: 0x2113,
  26540. lsuperior: 0xF6EE,
  26541. ltshade: 0x2591,
  26542. luthai: 0x0E26,
  26543. lvocalicbengali: 0x098C,
  26544. lvocalicdeva: 0x090C,
  26545. lvocalicvowelsignbengali: 0x09E2,
  26546. lvocalicvowelsigndeva: 0x0962,
  26547. lxsquare: 0x33D3,
  26548. m: 0x006D,
  26549. mabengali: 0x09AE,
  26550. macron: 0x00AF,
  26551. macronbelowcmb: 0x0331,
  26552. macroncmb: 0x0304,
  26553. macronlowmod: 0x02CD,
  26554. macronmonospace: 0xFFE3,
  26555. macute: 0x1E3F,
  26556. madeva: 0x092E,
  26557. magujarati: 0x0AAE,
  26558. magurmukhi: 0x0A2E,
  26559. mahapakhhebrew: 0x05A4,
  26560. mahapakhlefthebrew: 0x05A4,
  26561. mahiragana: 0x307E,
  26562. maichattawalowleftthai: 0xF895,
  26563. maichattawalowrightthai: 0xF894,
  26564. maichattawathai: 0x0E4B,
  26565. maichattawaupperleftthai: 0xF893,
  26566. maieklowleftthai: 0xF88C,
  26567. maieklowrightthai: 0xF88B,
  26568. maiekthai: 0x0E48,
  26569. maiekupperleftthai: 0xF88A,
  26570. maihanakatleftthai: 0xF884,
  26571. maihanakatthai: 0x0E31,
  26572. maitaikhuleftthai: 0xF889,
  26573. maitaikhuthai: 0x0E47,
  26574. maitholowleftthai: 0xF88F,
  26575. maitholowrightthai: 0xF88E,
  26576. maithothai: 0x0E49,
  26577. maithoupperleftthai: 0xF88D,
  26578. maitrilowleftthai: 0xF892,
  26579. maitrilowrightthai: 0xF891,
  26580. maitrithai: 0x0E4A,
  26581. maitriupperleftthai: 0xF890,
  26582. maiyamokthai: 0x0E46,
  26583. makatakana: 0x30DE,
  26584. makatakanahalfwidth: 0xFF8F,
  26585. male: 0x2642,
  26586. mansyonsquare: 0x3347,
  26587. maqafhebrew: 0x05BE,
  26588. mars: 0x2642,
  26589. masoracirclehebrew: 0x05AF,
  26590. masquare: 0x3383,
  26591. mbopomofo: 0x3107,
  26592. mbsquare: 0x33D4,
  26593. mcircle: 0x24DC,
  26594. mcubedsquare: 0x33A5,
  26595. mdotaccent: 0x1E41,
  26596. mdotbelow: 0x1E43,
  26597. meemarabic: 0x0645,
  26598. meemfinalarabic: 0xFEE2,
  26599. meeminitialarabic: 0xFEE3,
  26600. meemmedialarabic: 0xFEE4,
  26601. meemmeeminitialarabic: 0xFCD1,
  26602. meemmeemisolatedarabic: 0xFC48,
  26603. meetorusquare: 0x334D,
  26604. mehiragana: 0x3081,
  26605. meizierasquare: 0x337E,
  26606. mekatakana: 0x30E1,
  26607. mekatakanahalfwidth: 0xFF92,
  26608. mem: 0x05DE,
  26609. memdagesh: 0xFB3E,
  26610. memdageshhebrew: 0xFB3E,
  26611. memhebrew: 0x05DE,
  26612. menarmenian: 0x0574,
  26613. merkhahebrew: 0x05A5,
  26614. merkhakefulahebrew: 0x05A6,
  26615. merkhakefulalefthebrew: 0x05A6,
  26616. merkhalefthebrew: 0x05A5,
  26617. mhook: 0x0271,
  26618. mhzsquare: 0x3392,
  26619. middledotkatakanahalfwidth: 0xFF65,
  26620. middot: 0x00B7,
  26621. mieumacirclekorean: 0x3272,
  26622. mieumaparenkorean: 0x3212,
  26623. mieumcirclekorean: 0x3264,
  26624. mieumkorean: 0x3141,
  26625. mieumpansioskorean: 0x3170,
  26626. mieumparenkorean: 0x3204,
  26627. mieumpieupkorean: 0x316E,
  26628. mieumsioskorean: 0x316F,
  26629. mihiragana: 0x307F,
  26630. mikatakana: 0x30DF,
  26631. mikatakanahalfwidth: 0xFF90,
  26632. minus: 0x2212,
  26633. minusbelowcmb: 0x0320,
  26634. minuscircle: 0x2296,
  26635. minusmod: 0x02D7,
  26636. minusplus: 0x2213,
  26637. minute: 0x2032,
  26638. miribaarusquare: 0x334A,
  26639. mirisquare: 0x3349,
  26640. mlonglegturned: 0x0270,
  26641. mlsquare: 0x3396,
  26642. mmcubedsquare: 0x33A3,
  26643. mmonospace: 0xFF4D,
  26644. mmsquaredsquare: 0x339F,
  26645. mohiragana: 0x3082,
  26646. mohmsquare: 0x33C1,
  26647. mokatakana: 0x30E2,
  26648. mokatakanahalfwidth: 0xFF93,
  26649. molsquare: 0x33D6,
  26650. momathai: 0x0E21,
  26651. moverssquare: 0x33A7,
  26652. moverssquaredsquare: 0x33A8,
  26653. mparen: 0x24A8,
  26654. mpasquare: 0x33AB,
  26655. mssquare: 0x33B3,
  26656. msuperior: 0xF6EF,
  26657. mturned: 0x026F,
  26658. mu: 0x00B5,
  26659. mu1: 0x00B5,
  26660. muasquare: 0x3382,
  26661. muchgreater: 0x226B,
  26662. muchless: 0x226A,
  26663. mufsquare: 0x338C,
  26664. mugreek: 0x03BC,
  26665. mugsquare: 0x338D,
  26666. muhiragana: 0x3080,
  26667. mukatakana: 0x30E0,
  26668. mukatakanahalfwidth: 0xFF91,
  26669. mulsquare: 0x3395,
  26670. multiply: 0x00D7,
  26671. mumsquare: 0x339B,
  26672. munahhebrew: 0x05A3,
  26673. munahlefthebrew: 0x05A3,
  26674. musicalnote: 0x266A,
  26675. musicalnotedbl: 0x266B,
  26676. musicflatsign: 0x266D,
  26677. musicsharpsign: 0x266F,
  26678. mussquare: 0x33B2,
  26679. muvsquare: 0x33B6,
  26680. muwsquare: 0x33BC,
  26681. mvmegasquare: 0x33B9,
  26682. mvsquare: 0x33B7,
  26683. mwmegasquare: 0x33BF,
  26684. mwsquare: 0x33BD,
  26685. n: 0x006E,
  26686. nabengali: 0x09A8,
  26687. nabla: 0x2207,
  26688. nacute: 0x0144,
  26689. nadeva: 0x0928,
  26690. nagujarati: 0x0AA8,
  26691. nagurmukhi: 0x0A28,
  26692. nahiragana: 0x306A,
  26693. nakatakana: 0x30CA,
  26694. nakatakanahalfwidth: 0xFF85,
  26695. napostrophe: 0x0149,
  26696. nasquare: 0x3381,
  26697. nbopomofo: 0x310B,
  26698. nbspace: 0x00A0,
  26699. ncaron: 0x0148,
  26700. ncedilla: 0x0146,
  26701. ncircle: 0x24DD,
  26702. ncircumflexbelow: 0x1E4B,
  26703. ncommaaccent: 0x0146,
  26704. ndotaccent: 0x1E45,
  26705. ndotbelow: 0x1E47,
  26706. nehiragana: 0x306D,
  26707. nekatakana: 0x30CD,
  26708. nekatakanahalfwidth: 0xFF88,
  26709. newsheqelsign: 0x20AA,
  26710. nfsquare: 0x338B,
  26711. ngabengali: 0x0999,
  26712. ngadeva: 0x0919,
  26713. ngagujarati: 0x0A99,
  26714. ngagurmukhi: 0x0A19,
  26715. ngonguthai: 0x0E07,
  26716. nhiragana: 0x3093,
  26717. nhookleft: 0x0272,
  26718. nhookretroflex: 0x0273,
  26719. nieunacirclekorean: 0x326F,
  26720. nieunaparenkorean: 0x320F,
  26721. nieuncieuckorean: 0x3135,
  26722. nieuncirclekorean: 0x3261,
  26723. nieunhieuhkorean: 0x3136,
  26724. nieunkorean: 0x3134,
  26725. nieunpansioskorean: 0x3168,
  26726. nieunparenkorean: 0x3201,
  26727. nieunsioskorean: 0x3167,
  26728. nieuntikeutkorean: 0x3166,
  26729. nihiragana: 0x306B,
  26730. nikatakana: 0x30CB,
  26731. nikatakanahalfwidth: 0xFF86,
  26732. nikhahitleftthai: 0xF899,
  26733. nikhahitthai: 0x0E4D,
  26734. nine: 0x0039,
  26735. ninearabic: 0x0669,
  26736. ninebengali: 0x09EF,
  26737. ninecircle: 0x2468,
  26738. ninecircleinversesansserif: 0x2792,
  26739. ninedeva: 0x096F,
  26740. ninegujarati: 0x0AEF,
  26741. ninegurmukhi: 0x0A6F,
  26742. ninehackarabic: 0x0669,
  26743. ninehangzhou: 0x3029,
  26744. nineideographicparen: 0x3228,
  26745. nineinferior: 0x2089,
  26746. ninemonospace: 0xFF19,
  26747. nineoldstyle: 0xF739,
  26748. nineparen: 0x247C,
  26749. nineperiod: 0x2490,
  26750. ninepersian: 0x06F9,
  26751. nineroman: 0x2178,
  26752. ninesuperior: 0x2079,
  26753. nineteencircle: 0x2472,
  26754. nineteenparen: 0x2486,
  26755. nineteenperiod: 0x249A,
  26756. ninethai: 0x0E59,
  26757. nj: 0x01CC,
  26758. njecyrillic: 0x045A,
  26759. nkatakana: 0x30F3,
  26760. nkatakanahalfwidth: 0xFF9D,
  26761. nlegrightlong: 0x019E,
  26762. nlinebelow: 0x1E49,
  26763. nmonospace: 0xFF4E,
  26764. nmsquare: 0x339A,
  26765. nnabengali: 0x09A3,
  26766. nnadeva: 0x0923,
  26767. nnagujarati: 0x0AA3,
  26768. nnagurmukhi: 0x0A23,
  26769. nnnadeva: 0x0929,
  26770. nohiragana: 0x306E,
  26771. nokatakana: 0x30CE,
  26772. nokatakanahalfwidth: 0xFF89,
  26773. nonbreakingspace: 0x00A0,
  26774. nonenthai: 0x0E13,
  26775. nonuthai: 0x0E19,
  26776. noonarabic: 0x0646,
  26777. noonfinalarabic: 0xFEE6,
  26778. noonghunnaarabic: 0x06BA,
  26779. noonghunnafinalarabic: 0xFB9F,
  26780. nooninitialarabic: 0xFEE7,
  26781. noonjeeminitialarabic: 0xFCD2,
  26782. noonjeemisolatedarabic: 0xFC4B,
  26783. noonmedialarabic: 0xFEE8,
  26784. noonmeeminitialarabic: 0xFCD5,
  26785. noonmeemisolatedarabic: 0xFC4E,
  26786. noonnoonfinalarabic: 0xFC8D,
  26787. notcontains: 0x220C,
  26788. notelement: 0x2209,
  26789. notelementof: 0x2209,
  26790. notequal: 0x2260,
  26791. notgreater: 0x226F,
  26792. notgreaternorequal: 0x2271,
  26793. notgreaternorless: 0x2279,
  26794. notidentical: 0x2262,
  26795. notless: 0x226E,
  26796. notlessnorequal: 0x2270,
  26797. notparallel: 0x2226,
  26798. notprecedes: 0x2280,
  26799. notsubset: 0x2284,
  26800. notsucceeds: 0x2281,
  26801. notsuperset: 0x2285,
  26802. nowarmenian: 0x0576,
  26803. nparen: 0x24A9,
  26804. nssquare: 0x33B1,
  26805. nsuperior: 0x207F,
  26806. ntilde: 0x00F1,
  26807. nu: 0x03BD,
  26808. nuhiragana: 0x306C,
  26809. nukatakana: 0x30CC,
  26810. nukatakanahalfwidth: 0xFF87,
  26811. nuktabengali: 0x09BC,
  26812. nuktadeva: 0x093C,
  26813. nuktagujarati: 0x0ABC,
  26814. nuktagurmukhi: 0x0A3C,
  26815. numbersign: 0x0023,
  26816. numbersignmonospace: 0xFF03,
  26817. numbersignsmall: 0xFE5F,
  26818. numeralsigngreek: 0x0374,
  26819. numeralsignlowergreek: 0x0375,
  26820. numero: 0x2116,
  26821. nun: 0x05E0,
  26822. nundagesh: 0xFB40,
  26823. nundageshhebrew: 0xFB40,
  26824. nunhebrew: 0x05E0,
  26825. nvsquare: 0x33B5,
  26826. nwsquare: 0x33BB,
  26827. nyabengali: 0x099E,
  26828. nyadeva: 0x091E,
  26829. nyagujarati: 0x0A9E,
  26830. nyagurmukhi: 0x0A1E,
  26831. o: 0x006F,
  26832. oacute: 0x00F3,
  26833. oangthai: 0x0E2D,
  26834. obarred: 0x0275,
  26835. obarredcyrillic: 0x04E9,
  26836. obarreddieresiscyrillic: 0x04EB,
  26837. obengali: 0x0993,
  26838. obopomofo: 0x311B,
  26839. obreve: 0x014F,
  26840. ocandradeva: 0x0911,
  26841. ocandragujarati: 0x0A91,
  26842. ocandravowelsigndeva: 0x0949,
  26843. ocandravowelsigngujarati: 0x0AC9,
  26844. ocaron: 0x01D2,
  26845. ocircle: 0x24DE,
  26846. ocircumflex: 0x00F4,
  26847. ocircumflexacute: 0x1ED1,
  26848. ocircumflexdotbelow: 0x1ED9,
  26849. ocircumflexgrave: 0x1ED3,
  26850. ocircumflexhookabove: 0x1ED5,
  26851. ocircumflextilde: 0x1ED7,
  26852. ocyrillic: 0x043E,
  26853. odblacute: 0x0151,
  26854. odblgrave: 0x020D,
  26855. odeva: 0x0913,
  26856. odieresis: 0x00F6,
  26857. odieresiscyrillic: 0x04E7,
  26858. odotbelow: 0x1ECD,
  26859. oe: 0x0153,
  26860. oekorean: 0x315A,
  26861. ogonek: 0x02DB,
  26862. ogonekcmb: 0x0328,
  26863. ograve: 0x00F2,
  26864. ogujarati: 0x0A93,
  26865. oharmenian: 0x0585,
  26866. ohiragana: 0x304A,
  26867. ohookabove: 0x1ECF,
  26868. ohorn: 0x01A1,
  26869. ohornacute: 0x1EDB,
  26870. ohorndotbelow: 0x1EE3,
  26871. ohorngrave: 0x1EDD,
  26872. ohornhookabove: 0x1EDF,
  26873. ohorntilde: 0x1EE1,
  26874. ohungarumlaut: 0x0151,
  26875. oi: 0x01A3,
  26876. oinvertedbreve: 0x020F,
  26877. okatakana: 0x30AA,
  26878. okatakanahalfwidth: 0xFF75,
  26879. okorean: 0x3157,
  26880. olehebrew: 0x05AB,
  26881. omacron: 0x014D,
  26882. omacronacute: 0x1E53,
  26883. omacrongrave: 0x1E51,
  26884. omdeva: 0x0950,
  26885. omega: 0x03C9,
  26886. omega1: 0x03D6,
  26887. omegacyrillic: 0x0461,
  26888. omegalatinclosed: 0x0277,
  26889. omegaroundcyrillic: 0x047B,
  26890. omegatitlocyrillic: 0x047D,
  26891. omegatonos: 0x03CE,
  26892. omgujarati: 0x0AD0,
  26893. omicron: 0x03BF,
  26894. omicrontonos: 0x03CC,
  26895. omonospace: 0xFF4F,
  26896. one: 0x0031,
  26897. onearabic: 0x0661,
  26898. onebengali: 0x09E7,
  26899. onecircle: 0x2460,
  26900. onecircleinversesansserif: 0x278A,
  26901. onedeva: 0x0967,
  26902. onedotenleader: 0x2024,
  26903. oneeighth: 0x215B,
  26904. onefitted: 0xF6DC,
  26905. onegujarati: 0x0AE7,
  26906. onegurmukhi: 0x0A67,
  26907. onehackarabic: 0x0661,
  26908. onehalf: 0x00BD,
  26909. onehangzhou: 0x3021,
  26910. oneideographicparen: 0x3220,
  26911. oneinferior: 0x2081,
  26912. onemonospace: 0xFF11,
  26913. onenumeratorbengali: 0x09F4,
  26914. oneoldstyle: 0xF731,
  26915. oneparen: 0x2474,
  26916. oneperiod: 0x2488,
  26917. onepersian: 0x06F1,
  26918. onequarter: 0x00BC,
  26919. oneroman: 0x2170,
  26920. onesuperior: 0x00B9,
  26921. onethai: 0x0E51,
  26922. onethird: 0x2153,
  26923. oogonek: 0x01EB,
  26924. oogonekmacron: 0x01ED,
  26925. oogurmukhi: 0x0A13,
  26926. oomatragurmukhi: 0x0A4B,
  26927. oopen: 0x0254,
  26928. oparen: 0x24AA,
  26929. openbullet: 0x25E6,
  26930. option: 0x2325,
  26931. ordfeminine: 0x00AA,
  26932. ordmasculine: 0x00BA,
  26933. orthogonal: 0x221F,
  26934. oshortdeva: 0x0912,
  26935. oshortvowelsigndeva: 0x094A,
  26936. oslash: 0x00F8,
  26937. oslashacute: 0x01FF,
  26938. osmallhiragana: 0x3049,
  26939. osmallkatakana: 0x30A9,
  26940. osmallkatakanahalfwidth: 0xFF6B,
  26941. ostrokeacute: 0x01FF,
  26942. osuperior: 0xF6F0,
  26943. otcyrillic: 0x047F,
  26944. otilde: 0x00F5,
  26945. otildeacute: 0x1E4D,
  26946. otildedieresis: 0x1E4F,
  26947. oubopomofo: 0x3121,
  26948. overline: 0x203E,
  26949. overlinecenterline: 0xFE4A,
  26950. overlinecmb: 0x0305,
  26951. overlinedashed: 0xFE49,
  26952. overlinedblwavy: 0xFE4C,
  26953. overlinewavy: 0xFE4B,
  26954. overscore: 0x00AF,
  26955. ovowelsignbengali: 0x09CB,
  26956. ovowelsigndeva: 0x094B,
  26957. ovowelsigngujarati: 0x0ACB,
  26958. p: 0x0070,
  26959. paampssquare: 0x3380,
  26960. paasentosquare: 0x332B,
  26961. pabengali: 0x09AA,
  26962. pacute: 0x1E55,
  26963. padeva: 0x092A,
  26964. pagedown: 0x21DF,
  26965. pageup: 0x21DE,
  26966. pagujarati: 0x0AAA,
  26967. pagurmukhi: 0x0A2A,
  26968. pahiragana: 0x3071,
  26969. paiyannoithai: 0x0E2F,
  26970. pakatakana: 0x30D1,
  26971. palatalizationcyrilliccmb: 0x0484,
  26972. palochkacyrillic: 0x04C0,
  26973. pansioskorean: 0x317F,
  26974. paragraph: 0x00B6,
  26975. parallel: 0x2225,
  26976. parenleft: 0x0028,
  26977. parenleftaltonearabic: 0xFD3E,
  26978. parenleftbt: 0xF8ED,
  26979. parenleftex: 0xF8EC,
  26980. parenleftinferior: 0x208D,
  26981. parenleftmonospace: 0xFF08,
  26982. parenleftsmall: 0xFE59,
  26983. parenleftsuperior: 0x207D,
  26984. parenlefttp: 0xF8EB,
  26985. parenleftvertical: 0xFE35,
  26986. parenright: 0x0029,
  26987. parenrightaltonearabic: 0xFD3F,
  26988. parenrightbt: 0xF8F8,
  26989. parenrightex: 0xF8F7,
  26990. parenrightinferior: 0x208E,
  26991. parenrightmonospace: 0xFF09,
  26992. parenrightsmall: 0xFE5A,
  26993. parenrightsuperior: 0x207E,
  26994. parenrighttp: 0xF8F6,
  26995. parenrightvertical: 0xFE36,
  26996. partialdiff: 0x2202,
  26997. paseqhebrew: 0x05C0,
  26998. pashtahebrew: 0x0599,
  26999. pasquare: 0x33A9,
  27000. patah: 0x05B7,
  27001. patah11: 0x05B7,
  27002. patah1d: 0x05B7,
  27003. patah2a: 0x05B7,
  27004. patahhebrew: 0x05B7,
  27005. patahnarrowhebrew: 0x05B7,
  27006. patahquarterhebrew: 0x05B7,
  27007. patahwidehebrew: 0x05B7,
  27008. pazerhebrew: 0x05A1,
  27009. pbopomofo: 0x3106,
  27010. pcircle: 0x24DF,
  27011. pdotaccent: 0x1E57,
  27012. pe: 0x05E4,
  27013. pecyrillic: 0x043F,
  27014. pedagesh: 0xFB44,
  27015. pedageshhebrew: 0xFB44,
  27016. peezisquare: 0x333B,
  27017. pefinaldageshhebrew: 0xFB43,
  27018. peharabic: 0x067E,
  27019. peharmenian: 0x057A,
  27020. pehebrew: 0x05E4,
  27021. pehfinalarabic: 0xFB57,
  27022. pehinitialarabic: 0xFB58,
  27023. pehiragana: 0x307A,
  27024. pehmedialarabic: 0xFB59,
  27025. pekatakana: 0x30DA,
  27026. pemiddlehookcyrillic: 0x04A7,
  27027. perafehebrew: 0xFB4E,
  27028. percent: 0x0025,
  27029. percentarabic: 0x066A,
  27030. percentmonospace: 0xFF05,
  27031. percentsmall: 0xFE6A,
  27032. period: 0x002E,
  27033. periodarmenian: 0x0589,
  27034. periodcentered: 0x00B7,
  27035. periodhalfwidth: 0xFF61,
  27036. periodinferior: 0xF6E7,
  27037. periodmonospace: 0xFF0E,
  27038. periodsmall: 0xFE52,
  27039. periodsuperior: 0xF6E8,
  27040. perispomenigreekcmb: 0x0342,
  27041. perpendicular: 0x22A5,
  27042. perthousand: 0x2030,
  27043. peseta: 0x20A7,
  27044. pfsquare: 0x338A,
  27045. phabengali: 0x09AB,
  27046. phadeva: 0x092B,
  27047. phagujarati: 0x0AAB,
  27048. phagurmukhi: 0x0A2B,
  27049. phi: 0x03C6,
  27050. phi1: 0x03D5,
  27051. phieuphacirclekorean: 0x327A,
  27052. phieuphaparenkorean: 0x321A,
  27053. phieuphcirclekorean: 0x326C,
  27054. phieuphkorean: 0x314D,
  27055. phieuphparenkorean: 0x320C,
  27056. philatin: 0x0278,
  27057. phinthuthai: 0x0E3A,
  27058. phisymbolgreek: 0x03D5,
  27059. phook: 0x01A5,
  27060. phophanthai: 0x0E1E,
  27061. phophungthai: 0x0E1C,
  27062. phosamphaothai: 0x0E20,
  27063. pi: 0x03C0,
  27064. pieupacirclekorean: 0x3273,
  27065. pieupaparenkorean: 0x3213,
  27066. pieupcieuckorean: 0x3176,
  27067. pieupcirclekorean: 0x3265,
  27068. pieupkiyeokkorean: 0x3172,
  27069. pieupkorean: 0x3142,
  27070. pieupparenkorean: 0x3205,
  27071. pieupsioskiyeokkorean: 0x3174,
  27072. pieupsioskorean: 0x3144,
  27073. pieupsiostikeutkorean: 0x3175,
  27074. pieupthieuthkorean: 0x3177,
  27075. pieuptikeutkorean: 0x3173,
  27076. pihiragana: 0x3074,
  27077. pikatakana: 0x30D4,
  27078. pisymbolgreek: 0x03D6,
  27079. piwrarmenian: 0x0583,
  27080. plus: 0x002B,
  27081. plusbelowcmb: 0x031F,
  27082. pluscircle: 0x2295,
  27083. plusminus: 0x00B1,
  27084. plusmod: 0x02D6,
  27085. plusmonospace: 0xFF0B,
  27086. plussmall: 0xFE62,
  27087. plussuperior: 0x207A,
  27088. pmonospace: 0xFF50,
  27089. pmsquare: 0x33D8,
  27090. pohiragana: 0x307D,
  27091. pointingindexdownwhite: 0x261F,
  27092. pointingindexleftwhite: 0x261C,
  27093. pointingindexrightwhite: 0x261E,
  27094. pointingindexupwhite: 0x261D,
  27095. pokatakana: 0x30DD,
  27096. poplathai: 0x0E1B,
  27097. postalmark: 0x3012,
  27098. postalmarkface: 0x3020,
  27099. pparen: 0x24AB,
  27100. precedes: 0x227A,
  27101. prescription: 0x211E,
  27102. primemod: 0x02B9,
  27103. primereversed: 0x2035,
  27104. product: 0x220F,
  27105. projective: 0x2305,
  27106. prolongedkana: 0x30FC,
  27107. propellor: 0x2318,
  27108. propersubset: 0x2282,
  27109. propersuperset: 0x2283,
  27110. proportion: 0x2237,
  27111. proportional: 0x221D,
  27112. psi: 0x03C8,
  27113. psicyrillic: 0x0471,
  27114. psilipneumatacyrilliccmb: 0x0486,
  27115. pssquare: 0x33B0,
  27116. puhiragana: 0x3077,
  27117. pukatakana: 0x30D7,
  27118. pvsquare: 0x33B4,
  27119. pwsquare: 0x33BA,
  27120. q: 0x0071,
  27121. qadeva: 0x0958,
  27122. qadmahebrew: 0x05A8,
  27123. qafarabic: 0x0642,
  27124. qaffinalarabic: 0xFED6,
  27125. qafinitialarabic: 0xFED7,
  27126. qafmedialarabic: 0xFED8,
  27127. qamats: 0x05B8,
  27128. qamats10: 0x05B8,
  27129. qamats1a: 0x05B8,
  27130. qamats1c: 0x05B8,
  27131. qamats27: 0x05B8,
  27132. qamats29: 0x05B8,
  27133. qamats33: 0x05B8,
  27134. qamatsde: 0x05B8,
  27135. qamatshebrew: 0x05B8,
  27136. qamatsnarrowhebrew: 0x05B8,
  27137. qamatsqatanhebrew: 0x05B8,
  27138. qamatsqatannarrowhebrew: 0x05B8,
  27139. qamatsqatanquarterhebrew: 0x05B8,
  27140. qamatsqatanwidehebrew: 0x05B8,
  27141. qamatsquarterhebrew: 0x05B8,
  27142. qamatswidehebrew: 0x05B8,
  27143. qarneyparahebrew: 0x059F,
  27144. qbopomofo: 0x3111,
  27145. qcircle: 0x24E0,
  27146. qhook: 0x02A0,
  27147. qmonospace: 0xFF51,
  27148. qof: 0x05E7,
  27149. qofdagesh: 0xFB47,
  27150. qofdageshhebrew: 0xFB47,
  27151. qofhebrew: 0x05E7,
  27152. qparen: 0x24AC,
  27153. quarternote: 0x2669,
  27154. qubuts: 0x05BB,
  27155. qubuts18: 0x05BB,
  27156. qubuts25: 0x05BB,
  27157. qubuts31: 0x05BB,
  27158. qubutshebrew: 0x05BB,
  27159. qubutsnarrowhebrew: 0x05BB,
  27160. qubutsquarterhebrew: 0x05BB,
  27161. qubutswidehebrew: 0x05BB,
  27162. question: 0x003F,
  27163. questionarabic: 0x061F,
  27164. questionarmenian: 0x055E,
  27165. questiondown: 0x00BF,
  27166. questiondownsmall: 0xF7BF,
  27167. questiongreek: 0x037E,
  27168. questionmonospace: 0xFF1F,
  27169. questionsmall: 0xF73F,
  27170. quotedbl: 0x0022,
  27171. quotedblbase: 0x201E,
  27172. quotedblleft: 0x201C,
  27173. quotedblmonospace: 0xFF02,
  27174. quotedblprime: 0x301E,
  27175. quotedblprimereversed: 0x301D,
  27176. quotedblright: 0x201D,
  27177. quoteleft: 0x2018,
  27178. quoteleftreversed: 0x201B,
  27179. quotereversed: 0x201B,
  27180. quoteright: 0x2019,
  27181. quoterightn: 0x0149,
  27182. quotesinglbase: 0x201A,
  27183. quotesingle: 0x0027,
  27184. quotesinglemonospace: 0xFF07,
  27185. r: 0x0072,
  27186. raarmenian: 0x057C,
  27187. rabengali: 0x09B0,
  27188. racute: 0x0155,
  27189. radeva: 0x0930,
  27190. radical: 0x221A,
  27191. radicalex: 0xF8E5,
  27192. radoverssquare: 0x33AE,
  27193. radoverssquaredsquare: 0x33AF,
  27194. radsquare: 0x33AD,
  27195. rafe: 0x05BF,
  27196. rafehebrew: 0x05BF,
  27197. ragujarati: 0x0AB0,
  27198. ragurmukhi: 0x0A30,
  27199. rahiragana: 0x3089,
  27200. rakatakana: 0x30E9,
  27201. rakatakanahalfwidth: 0xFF97,
  27202. ralowerdiagonalbengali: 0x09F1,
  27203. ramiddlediagonalbengali: 0x09F0,
  27204. ramshorn: 0x0264,
  27205. ratio: 0x2236,
  27206. rbopomofo: 0x3116,
  27207. rcaron: 0x0159,
  27208. rcedilla: 0x0157,
  27209. rcircle: 0x24E1,
  27210. rcommaaccent: 0x0157,
  27211. rdblgrave: 0x0211,
  27212. rdotaccent: 0x1E59,
  27213. rdotbelow: 0x1E5B,
  27214. rdotbelowmacron: 0x1E5D,
  27215. referencemark: 0x203B,
  27216. reflexsubset: 0x2286,
  27217. reflexsuperset: 0x2287,
  27218. registered: 0x00AE,
  27219. registersans: 0xF8E8,
  27220. registerserif: 0xF6DA,
  27221. reharabic: 0x0631,
  27222. reharmenian: 0x0580,
  27223. rehfinalarabic: 0xFEAE,
  27224. rehiragana: 0x308C,
  27225. rekatakana: 0x30EC,
  27226. rekatakanahalfwidth: 0xFF9A,
  27227. resh: 0x05E8,
  27228. reshdageshhebrew: 0xFB48,
  27229. reshhebrew: 0x05E8,
  27230. reversedtilde: 0x223D,
  27231. reviahebrew: 0x0597,
  27232. reviamugrashhebrew: 0x0597,
  27233. revlogicalnot: 0x2310,
  27234. rfishhook: 0x027E,
  27235. rfishhookreversed: 0x027F,
  27236. rhabengali: 0x09DD,
  27237. rhadeva: 0x095D,
  27238. rho: 0x03C1,
  27239. rhook: 0x027D,
  27240. rhookturned: 0x027B,
  27241. rhookturnedsuperior: 0x02B5,
  27242. rhosymbolgreek: 0x03F1,
  27243. rhotichookmod: 0x02DE,
  27244. rieulacirclekorean: 0x3271,
  27245. rieulaparenkorean: 0x3211,
  27246. rieulcirclekorean: 0x3263,
  27247. rieulhieuhkorean: 0x3140,
  27248. rieulkiyeokkorean: 0x313A,
  27249. rieulkiyeoksioskorean: 0x3169,
  27250. rieulkorean: 0x3139,
  27251. rieulmieumkorean: 0x313B,
  27252. rieulpansioskorean: 0x316C,
  27253. rieulparenkorean: 0x3203,
  27254. rieulphieuphkorean: 0x313F,
  27255. rieulpieupkorean: 0x313C,
  27256. rieulpieupsioskorean: 0x316B,
  27257. rieulsioskorean: 0x313D,
  27258. rieulthieuthkorean: 0x313E,
  27259. rieultikeutkorean: 0x316A,
  27260. rieulyeorinhieuhkorean: 0x316D,
  27261. rightangle: 0x221F,
  27262. righttackbelowcmb: 0x0319,
  27263. righttriangle: 0x22BF,
  27264. rihiragana: 0x308A,
  27265. rikatakana: 0x30EA,
  27266. rikatakanahalfwidth: 0xFF98,
  27267. ring: 0x02DA,
  27268. ringbelowcmb: 0x0325,
  27269. ringcmb: 0x030A,
  27270. ringhalfleft: 0x02BF,
  27271. ringhalfleftarmenian: 0x0559,
  27272. ringhalfleftbelowcmb: 0x031C,
  27273. ringhalfleftcentered: 0x02D3,
  27274. ringhalfright: 0x02BE,
  27275. ringhalfrightbelowcmb: 0x0339,
  27276. ringhalfrightcentered: 0x02D2,
  27277. rinvertedbreve: 0x0213,
  27278. rittorusquare: 0x3351,
  27279. rlinebelow: 0x1E5F,
  27280. rlongleg: 0x027C,
  27281. rlonglegturned: 0x027A,
  27282. rmonospace: 0xFF52,
  27283. rohiragana: 0x308D,
  27284. rokatakana: 0x30ED,
  27285. rokatakanahalfwidth: 0xFF9B,
  27286. roruathai: 0x0E23,
  27287. rparen: 0x24AD,
  27288. rrabengali: 0x09DC,
  27289. rradeva: 0x0931,
  27290. rragurmukhi: 0x0A5C,
  27291. rreharabic: 0x0691,
  27292. rrehfinalarabic: 0xFB8D,
  27293. rrvocalicbengali: 0x09E0,
  27294. rrvocalicdeva: 0x0960,
  27295. rrvocalicgujarati: 0x0AE0,
  27296. rrvocalicvowelsignbengali: 0x09C4,
  27297. rrvocalicvowelsigndeva: 0x0944,
  27298. rrvocalicvowelsigngujarati: 0x0AC4,
  27299. rsuperior: 0xF6F1,
  27300. rtblock: 0x2590,
  27301. rturned: 0x0279,
  27302. rturnedsuperior: 0x02B4,
  27303. ruhiragana: 0x308B,
  27304. rukatakana: 0x30EB,
  27305. rukatakanahalfwidth: 0xFF99,
  27306. rupeemarkbengali: 0x09F2,
  27307. rupeesignbengali: 0x09F3,
  27308. rupiah: 0xF6DD,
  27309. ruthai: 0x0E24,
  27310. rvocalicbengali: 0x098B,
  27311. rvocalicdeva: 0x090B,
  27312. rvocalicgujarati: 0x0A8B,
  27313. rvocalicvowelsignbengali: 0x09C3,
  27314. rvocalicvowelsigndeva: 0x0943,
  27315. rvocalicvowelsigngujarati: 0x0AC3,
  27316. s: 0x0073,
  27317. sabengali: 0x09B8,
  27318. sacute: 0x015B,
  27319. sacutedotaccent: 0x1E65,
  27320. sadarabic: 0x0635,
  27321. sadeva: 0x0938,
  27322. sadfinalarabic: 0xFEBA,
  27323. sadinitialarabic: 0xFEBB,
  27324. sadmedialarabic: 0xFEBC,
  27325. sagujarati: 0x0AB8,
  27326. sagurmukhi: 0x0A38,
  27327. sahiragana: 0x3055,
  27328. sakatakana: 0x30B5,
  27329. sakatakanahalfwidth: 0xFF7B,
  27330. sallallahoualayhewasallamarabic: 0xFDFA,
  27331. samekh: 0x05E1,
  27332. samekhdagesh: 0xFB41,
  27333. samekhdageshhebrew: 0xFB41,
  27334. samekhhebrew: 0x05E1,
  27335. saraaathai: 0x0E32,
  27336. saraaethai: 0x0E41,
  27337. saraaimaimalaithai: 0x0E44,
  27338. saraaimaimuanthai: 0x0E43,
  27339. saraamthai: 0x0E33,
  27340. saraathai: 0x0E30,
  27341. saraethai: 0x0E40,
  27342. saraiileftthai: 0xF886,
  27343. saraiithai: 0x0E35,
  27344. saraileftthai: 0xF885,
  27345. saraithai: 0x0E34,
  27346. saraothai: 0x0E42,
  27347. saraueeleftthai: 0xF888,
  27348. saraueethai: 0x0E37,
  27349. saraueleftthai: 0xF887,
  27350. sarauethai: 0x0E36,
  27351. sarauthai: 0x0E38,
  27352. sarauuthai: 0x0E39,
  27353. sbopomofo: 0x3119,
  27354. scaron: 0x0161,
  27355. scarondotaccent: 0x1E67,
  27356. scedilla: 0x015F,
  27357. schwa: 0x0259,
  27358. schwacyrillic: 0x04D9,
  27359. schwadieresiscyrillic: 0x04DB,
  27360. schwahook: 0x025A,
  27361. scircle: 0x24E2,
  27362. scircumflex: 0x015D,
  27363. scommaaccent: 0x0219,
  27364. sdotaccent: 0x1E61,
  27365. sdotbelow: 0x1E63,
  27366. sdotbelowdotaccent: 0x1E69,
  27367. seagullbelowcmb: 0x033C,
  27368. second: 0x2033,
  27369. secondtonechinese: 0x02CA,
  27370. section: 0x00A7,
  27371. seenarabic: 0x0633,
  27372. seenfinalarabic: 0xFEB2,
  27373. seeninitialarabic: 0xFEB3,
  27374. seenmedialarabic: 0xFEB4,
  27375. segol: 0x05B6,
  27376. segol13: 0x05B6,
  27377. segol1f: 0x05B6,
  27378. segol2c: 0x05B6,
  27379. segolhebrew: 0x05B6,
  27380. segolnarrowhebrew: 0x05B6,
  27381. segolquarterhebrew: 0x05B6,
  27382. segoltahebrew: 0x0592,
  27383. segolwidehebrew: 0x05B6,
  27384. seharmenian: 0x057D,
  27385. sehiragana: 0x305B,
  27386. sekatakana: 0x30BB,
  27387. sekatakanahalfwidth: 0xFF7E,
  27388. semicolon: 0x003B,
  27389. semicolonarabic: 0x061B,
  27390. semicolonmonospace: 0xFF1B,
  27391. semicolonsmall: 0xFE54,
  27392. semivoicedmarkkana: 0x309C,
  27393. semivoicedmarkkanahalfwidth: 0xFF9F,
  27394. sentisquare: 0x3322,
  27395. sentosquare: 0x3323,
  27396. seven: 0x0037,
  27397. sevenarabic: 0x0667,
  27398. sevenbengali: 0x09ED,
  27399. sevencircle: 0x2466,
  27400. sevencircleinversesansserif: 0x2790,
  27401. sevendeva: 0x096D,
  27402. seveneighths: 0x215E,
  27403. sevengujarati: 0x0AED,
  27404. sevengurmukhi: 0x0A6D,
  27405. sevenhackarabic: 0x0667,
  27406. sevenhangzhou: 0x3027,
  27407. sevenideographicparen: 0x3226,
  27408. seveninferior: 0x2087,
  27409. sevenmonospace: 0xFF17,
  27410. sevenoldstyle: 0xF737,
  27411. sevenparen: 0x247A,
  27412. sevenperiod: 0x248E,
  27413. sevenpersian: 0x06F7,
  27414. sevenroman: 0x2176,
  27415. sevensuperior: 0x2077,
  27416. seventeencircle: 0x2470,
  27417. seventeenparen: 0x2484,
  27418. seventeenperiod: 0x2498,
  27419. seventhai: 0x0E57,
  27420. sfthyphen: 0x00AD,
  27421. shaarmenian: 0x0577,
  27422. shabengali: 0x09B6,
  27423. shacyrillic: 0x0448,
  27424. shaddaarabic: 0x0651,
  27425. shaddadammaarabic: 0xFC61,
  27426. shaddadammatanarabic: 0xFC5E,
  27427. shaddafathaarabic: 0xFC60,
  27428. shaddakasraarabic: 0xFC62,
  27429. shaddakasratanarabic: 0xFC5F,
  27430. shade: 0x2592,
  27431. shadedark: 0x2593,
  27432. shadelight: 0x2591,
  27433. shademedium: 0x2592,
  27434. shadeva: 0x0936,
  27435. shagujarati: 0x0AB6,
  27436. shagurmukhi: 0x0A36,
  27437. shalshelethebrew: 0x0593,
  27438. shbopomofo: 0x3115,
  27439. shchacyrillic: 0x0449,
  27440. sheenarabic: 0x0634,
  27441. sheenfinalarabic: 0xFEB6,
  27442. sheeninitialarabic: 0xFEB7,
  27443. sheenmedialarabic: 0xFEB8,
  27444. sheicoptic: 0x03E3,
  27445. sheqel: 0x20AA,
  27446. sheqelhebrew: 0x20AA,
  27447. sheva: 0x05B0,
  27448. sheva115: 0x05B0,
  27449. sheva15: 0x05B0,
  27450. sheva22: 0x05B0,
  27451. sheva2e: 0x05B0,
  27452. shevahebrew: 0x05B0,
  27453. shevanarrowhebrew: 0x05B0,
  27454. shevaquarterhebrew: 0x05B0,
  27455. shevawidehebrew: 0x05B0,
  27456. shhacyrillic: 0x04BB,
  27457. shimacoptic: 0x03ED,
  27458. shin: 0x05E9,
  27459. shindagesh: 0xFB49,
  27460. shindageshhebrew: 0xFB49,
  27461. shindageshshindot: 0xFB2C,
  27462. shindageshshindothebrew: 0xFB2C,
  27463. shindageshsindot: 0xFB2D,
  27464. shindageshsindothebrew: 0xFB2D,
  27465. shindothebrew: 0x05C1,
  27466. shinhebrew: 0x05E9,
  27467. shinshindot: 0xFB2A,
  27468. shinshindothebrew: 0xFB2A,
  27469. shinsindot: 0xFB2B,
  27470. shinsindothebrew: 0xFB2B,
  27471. shook: 0x0282,
  27472. sigma: 0x03C3,
  27473. sigma1: 0x03C2,
  27474. sigmafinal: 0x03C2,
  27475. sigmalunatesymbolgreek: 0x03F2,
  27476. sihiragana: 0x3057,
  27477. sikatakana: 0x30B7,
  27478. sikatakanahalfwidth: 0xFF7C,
  27479. siluqhebrew: 0x05BD,
  27480. siluqlefthebrew: 0x05BD,
  27481. similar: 0x223C,
  27482. sindothebrew: 0x05C2,
  27483. siosacirclekorean: 0x3274,
  27484. siosaparenkorean: 0x3214,
  27485. sioscieuckorean: 0x317E,
  27486. sioscirclekorean: 0x3266,
  27487. sioskiyeokkorean: 0x317A,
  27488. sioskorean: 0x3145,
  27489. siosnieunkorean: 0x317B,
  27490. siosparenkorean: 0x3206,
  27491. siospieupkorean: 0x317D,
  27492. siostikeutkorean: 0x317C,
  27493. six: 0x0036,
  27494. sixarabic: 0x0666,
  27495. sixbengali: 0x09EC,
  27496. sixcircle: 0x2465,
  27497. sixcircleinversesansserif: 0x278F,
  27498. sixdeva: 0x096C,
  27499. sixgujarati: 0x0AEC,
  27500. sixgurmukhi: 0x0A6C,
  27501. sixhackarabic: 0x0666,
  27502. sixhangzhou: 0x3026,
  27503. sixideographicparen: 0x3225,
  27504. sixinferior: 0x2086,
  27505. sixmonospace: 0xFF16,
  27506. sixoldstyle: 0xF736,
  27507. sixparen: 0x2479,
  27508. sixperiod: 0x248D,
  27509. sixpersian: 0x06F6,
  27510. sixroman: 0x2175,
  27511. sixsuperior: 0x2076,
  27512. sixteencircle: 0x246F,
  27513. sixteencurrencydenominatorbengali: 0x09F9,
  27514. sixteenparen: 0x2483,
  27515. sixteenperiod: 0x2497,
  27516. sixthai: 0x0E56,
  27517. slash: 0x002F,
  27518. slashmonospace: 0xFF0F,
  27519. slong: 0x017F,
  27520. slongdotaccent: 0x1E9B,
  27521. smileface: 0x263A,
  27522. smonospace: 0xFF53,
  27523. sofpasuqhebrew: 0x05C3,
  27524. softhyphen: 0x00AD,
  27525. softsigncyrillic: 0x044C,
  27526. sohiragana: 0x305D,
  27527. sokatakana: 0x30BD,
  27528. sokatakanahalfwidth: 0xFF7F,
  27529. soliduslongoverlaycmb: 0x0338,
  27530. solidusshortoverlaycmb: 0x0337,
  27531. sorusithai: 0x0E29,
  27532. sosalathai: 0x0E28,
  27533. sosothai: 0x0E0B,
  27534. sosuathai: 0x0E2A,
  27535. space: 0x0020,
  27536. spacehackarabic: 0x0020,
  27537. spade: 0x2660,
  27538. spadesuitblack: 0x2660,
  27539. spadesuitwhite: 0x2664,
  27540. sparen: 0x24AE,
  27541. squarebelowcmb: 0x033B,
  27542. squarecc: 0x33C4,
  27543. squarecm: 0x339D,
  27544. squarediagonalcrosshatchfill: 0x25A9,
  27545. squarehorizontalfill: 0x25A4,
  27546. squarekg: 0x338F,
  27547. squarekm: 0x339E,
  27548. squarekmcapital: 0x33CE,
  27549. squareln: 0x33D1,
  27550. squarelog: 0x33D2,
  27551. squaremg: 0x338E,
  27552. squaremil: 0x33D5,
  27553. squaremm: 0x339C,
  27554. squaremsquared: 0x33A1,
  27555. squareorthogonalcrosshatchfill: 0x25A6,
  27556. squareupperlefttolowerrightfill: 0x25A7,
  27557. squareupperrighttolowerleftfill: 0x25A8,
  27558. squareverticalfill: 0x25A5,
  27559. squarewhitewithsmallblack: 0x25A3,
  27560. srsquare: 0x33DB,
  27561. ssabengali: 0x09B7,
  27562. ssadeva: 0x0937,
  27563. ssagujarati: 0x0AB7,
  27564. ssangcieuckorean: 0x3149,
  27565. ssanghieuhkorean: 0x3185,
  27566. ssangieungkorean: 0x3180,
  27567. ssangkiyeokkorean: 0x3132,
  27568. ssangnieunkorean: 0x3165,
  27569. ssangpieupkorean: 0x3143,
  27570. ssangsioskorean: 0x3146,
  27571. ssangtikeutkorean: 0x3138,
  27572. ssuperior: 0xF6F2,
  27573. sterling: 0x00A3,
  27574. sterlingmonospace: 0xFFE1,
  27575. strokelongoverlaycmb: 0x0336,
  27576. strokeshortoverlaycmb: 0x0335,
  27577. subset: 0x2282,
  27578. subsetnotequal: 0x228A,
  27579. subsetorequal: 0x2286,
  27580. succeeds: 0x227B,
  27581. suchthat: 0x220B,
  27582. suhiragana: 0x3059,
  27583. sukatakana: 0x30B9,
  27584. sukatakanahalfwidth: 0xFF7D,
  27585. sukunarabic: 0x0652,
  27586. summation: 0x2211,
  27587. sun: 0x263C,
  27588. superset: 0x2283,
  27589. supersetnotequal: 0x228B,
  27590. supersetorequal: 0x2287,
  27591. svsquare: 0x33DC,
  27592. syouwaerasquare: 0x337C,
  27593. t: 0x0074,
  27594. tabengali: 0x09A4,
  27595. tackdown: 0x22A4,
  27596. tackleft: 0x22A3,
  27597. tadeva: 0x0924,
  27598. tagujarati: 0x0AA4,
  27599. tagurmukhi: 0x0A24,
  27600. taharabic: 0x0637,
  27601. tahfinalarabic: 0xFEC2,
  27602. tahinitialarabic: 0xFEC3,
  27603. tahiragana: 0x305F,
  27604. tahmedialarabic: 0xFEC4,
  27605. taisyouerasquare: 0x337D,
  27606. takatakana: 0x30BF,
  27607. takatakanahalfwidth: 0xFF80,
  27608. tatweelarabic: 0x0640,
  27609. tau: 0x03C4,
  27610. tav: 0x05EA,
  27611. tavdages: 0xFB4A,
  27612. tavdagesh: 0xFB4A,
  27613. tavdageshhebrew: 0xFB4A,
  27614. tavhebrew: 0x05EA,
  27615. tbar: 0x0167,
  27616. tbopomofo: 0x310A,
  27617. tcaron: 0x0165,
  27618. tccurl: 0x02A8,
  27619. tcedilla: 0x0163,
  27620. tcheharabic: 0x0686,
  27621. tchehfinalarabic: 0xFB7B,
  27622. tchehinitialarabic: 0xFB7C,
  27623. tchehmedialarabic: 0xFB7D,
  27624. tcircle: 0x24E3,
  27625. tcircumflexbelow: 0x1E71,
  27626. tcommaaccent: 0x0163,
  27627. tdieresis: 0x1E97,
  27628. tdotaccent: 0x1E6B,
  27629. tdotbelow: 0x1E6D,
  27630. tecyrillic: 0x0442,
  27631. tedescendercyrillic: 0x04AD,
  27632. teharabic: 0x062A,
  27633. tehfinalarabic: 0xFE96,
  27634. tehhahinitialarabic: 0xFCA2,
  27635. tehhahisolatedarabic: 0xFC0C,
  27636. tehinitialarabic: 0xFE97,
  27637. tehiragana: 0x3066,
  27638. tehjeeminitialarabic: 0xFCA1,
  27639. tehjeemisolatedarabic: 0xFC0B,
  27640. tehmarbutaarabic: 0x0629,
  27641. tehmarbutafinalarabic: 0xFE94,
  27642. tehmedialarabic: 0xFE98,
  27643. tehmeeminitialarabic: 0xFCA4,
  27644. tehmeemisolatedarabic: 0xFC0E,
  27645. tehnoonfinalarabic: 0xFC73,
  27646. tekatakana: 0x30C6,
  27647. tekatakanahalfwidth: 0xFF83,
  27648. telephone: 0x2121,
  27649. telephoneblack: 0x260E,
  27650. telishagedolahebrew: 0x05A0,
  27651. telishaqetanahebrew: 0x05A9,
  27652. tencircle: 0x2469,
  27653. tenideographicparen: 0x3229,
  27654. tenparen: 0x247D,
  27655. tenperiod: 0x2491,
  27656. tenroman: 0x2179,
  27657. tesh: 0x02A7,
  27658. tet: 0x05D8,
  27659. tetdagesh: 0xFB38,
  27660. tetdageshhebrew: 0xFB38,
  27661. tethebrew: 0x05D8,
  27662. tetsecyrillic: 0x04B5,
  27663. tevirhebrew: 0x059B,
  27664. tevirlefthebrew: 0x059B,
  27665. thabengali: 0x09A5,
  27666. thadeva: 0x0925,
  27667. thagujarati: 0x0AA5,
  27668. thagurmukhi: 0x0A25,
  27669. thalarabic: 0x0630,
  27670. thalfinalarabic: 0xFEAC,
  27671. thanthakhatlowleftthai: 0xF898,
  27672. thanthakhatlowrightthai: 0xF897,
  27673. thanthakhatthai: 0x0E4C,
  27674. thanthakhatupperleftthai: 0xF896,
  27675. theharabic: 0x062B,
  27676. thehfinalarabic: 0xFE9A,
  27677. thehinitialarabic: 0xFE9B,
  27678. thehmedialarabic: 0xFE9C,
  27679. thereexists: 0x2203,
  27680. therefore: 0x2234,
  27681. theta: 0x03B8,
  27682. theta1: 0x03D1,
  27683. thetasymbolgreek: 0x03D1,
  27684. thieuthacirclekorean: 0x3279,
  27685. thieuthaparenkorean: 0x3219,
  27686. thieuthcirclekorean: 0x326B,
  27687. thieuthkorean: 0x314C,
  27688. thieuthparenkorean: 0x320B,
  27689. thirteencircle: 0x246C,
  27690. thirteenparen: 0x2480,
  27691. thirteenperiod: 0x2494,
  27692. thonangmonthothai: 0x0E11,
  27693. thook: 0x01AD,
  27694. thophuthaothai: 0x0E12,
  27695. thorn: 0x00FE,
  27696. thothahanthai: 0x0E17,
  27697. thothanthai: 0x0E10,
  27698. thothongthai: 0x0E18,
  27699. thothungthai: 0x0E16,
  27700. thousandcyrillic: 0x0482,
  27701. thousandsseparatorarabic: 0x066C,
  27702. thousandsseparatorpersian: 0x066C,
  27703. three: 0x0033,
  27704. threearabic: 0x0663,
  27705. threebengali: 0x09E9,
  27706. threecircle: 0x2462,
  27707. threecircleinversesansserif: 0x278C,
  27708. threedeva: 0x0969,
  27709. threeeighths: 0x215C,
  27710. threegujarati: 0x0AE9,
  27711. threegurmukhi: 0x0A69,
  27712. threehackarabic: 0x0663,
  27713. threehangzhou: 0x3023,
  27714. threeideographicparen: 0x3222,
  27715. threeinferior: 0x2083,
  27716. threemonospace: 0xFF13,
  27717. threenumeratorbengali: 0x09F6,
  27718. threeoldstyle: 0xF733,
  27719. threeparen: 0x2476,
  27720. threeperiod: 0x248A,
  27721. threepersian: 0x06F3,
  27722. threequarters: 0x00BE,
  27723. threequartersemdash: 0xF6DE,
  27724. threeroman: 0x2172,
  27725. threesuperior: 0x00B3,
  27726. threethai: 0x0E53,
  27727. thzsquare: 0x3394,
  27728. tihiragana: 0x3061,
  27729. tikatakana: 0x30C1,
  27730. tikatakanahalfwidth: 0xFF81,
  27731. tikeutacirclekorean: 0x3270,
  27732. tikeutaparenkorean: 0x3210,
  27733. tikeutcirclekorean: 0x3262,
  27734. tikeutkorean: 0x3137,
  27735. tikeutparenkorean: 0x3202,
  27736. tilde: 0x02DC,
  27737. tildebelowcmb: 0x0330,
  27738. tildecmb: 0x0303,
  27739. tildecomb: 0x0303,
  27740. tildedoublecmb: 0x0360,
  27741. tildeoperator: 0x223C,
  27742. tildeoverlaycmb: 0x0334,
  27743. tildeverticalcmb: 0x033E,
  27744. timescircle: 0x2297,
  27745. tipehahebrew: 0x0596,
  27746. tipehalefthebrew: 0x0596,
  27747. tippigurmukhi: 0x0A70,
  27748. titlocyrilliccmb: 0x0483,
  27749. tiwnarmenian: 0x057F,
  27750. tlinebelow: 0x1E6F,
  27751. tmonospace: 0xFF54,
  27752. toarmenian: 0x0569,
  27753. tohiragana: 0x3068,
  27754. tokatakana: 0x30C8,
  27755. tokatakanahalfwidth: 0xFF84,
  27756. tonebarextrahighmod: 0x02E5,
  27757. tonebarextralowmod: 0x02E9,
  27758. tonebarhighmod: 0x02E6,
  27759. tonebarlowmod: 0x02E8,
  27760. tonebarmidmod: 0x02E7,
  27761. tonefive: 0x01BD,
  27762. tonesix: 0x0185,
  27763. tonetwo: 0x01A8,
  27764. tonos: 0x0384,
  27765. tonsquare: 0x3327,
  27766. topatakthai: 0x0E0F,
  27767. tortoiseshellbracketleft: 0x3014,
  27768. tortoiseshellbracketleftsmall: 0xFE5D,
  27769. tortoiseshellbracketleftvertical: 0xFE39,
  27770. tortoiseshellbracketright: 0x3015,
  27771. tortoiseshellbracketrightsmall: 0xFE5E,
  27772. tortoiseshellbracketrightvertical: 0xFE3A,
  27773. totaothai: 0x0E15,
  27774. tpalatalhook: 0x01AB,
  27775. tparen: 0x24AF,
  27776. trademark: 0x2122,
  27777. trademarksans: 0xF8EA,
  27778. trademarkserif: 0xF6DB,
  27779. tretroflexhook: 0x0288,
  27780. triagdn: 0x25BC,
  27781. triaglf: 0x25C4,
  27782. triagrt: 0x25BA,
  27783. triagup: 0x25B2,
  27784. ts: 0x02A6,
  27785. tsadi: 0x05E6,
  27786. tsadidagesh: 0xFB46,
  27787. tsadidageshhebrew: 0xFB46,
  27788. tsadihebrew: 0x05E6,
  27789. tsecyrillic: 0x0446,
  27790. tsere: 0x05B5,
  27791. tsere12: 0x05B5,
  27792. tsere1e: 0x05B5,
  27793. tsere2b: 0x05B5,
  27794. tserehebrew: 0x05B5,
  27795. tserenarrowhebrew: 0x05B5,
  27796. tserequarterhebrew: 0x05B5,
  27797. tserewidehebrew: 0x05B5,
  27798. tshecyrillic: 0x045B,
  27799. tsuperior: 0xF6F3,
  27800. ttabengali: 0x099F,
  27801. ttadeva: 0x091F,
  27802. ttagujarati: 0x0A9F,
  27803. ttagurmukhi: 0x0A1F,
  27804. tteharabic: 0x0679,
  27805. ttehfinalarabic: 0xFB67,
  27806. ttehinitialarabic: 0xFB68,
  27807. ttehmedialarabic: 0xFB69,
  27808. tthabengali: 0x09A0,
  27809. tthadeva: 0x0920,
  27810. tthagujarati: 0x0AA0,
  27811. tthagurmukhi: 0x0A20,
  27812. tturned: 0x0287,
  27813. tuhiragana: 0x3064,
  27814. tukatakana: 0x30C4,
  27815. tukatakanahalfwidth: 0xFF82,
  27816. tusmallhiragana: 0x3063,
  27817. tusmallkatakana: 0x30C3,
  27818. tusmallkatakanahalfwidth: 0xFF6F,
  27819. twelvecircle: 0x246B,
  27820. twelveparen: 0x247F,
  27821. twelveperiod: 0x2493,
  27822. twelveroman: 0x217B,
  27823. twentycircle: 0x2473,
  27824. twentyhangzhou: 0x5344,
  27825. twentyparen: 0x2487,
  27826. twentyperiod: 0x249B,
  27827. two: 0x0032,
  27828. twoarabic: 0x0662,
  27829. twobengali: 0x09E8,
  27830. twocircle: 0x2461,
  27831. twocircleinversesansserif: 0x278B,
  27832. twodeva: 0x0968,
  27833. twodotenleader: 0x2025,
  27834. twodotleader: 0x2025,
  27835. twodotleadervertical: 0xFE30,
  27836. twogujarati: 0x0AE8,
  27837. twogurmukhi: 0x0A68,
  27838. twohackarabic: 0x0662,
  27839. twohangzhou: 0x3022,
  27840. twoideographicparen: 0x3221,
  27841. twoinferior: 0x2082,
  27842. twomonospace: 0xFF12,
  27843. twonumeratorbengali: 0x09F5,
  27844. twooldstyle: 0xF732,
  27845. twoparen: 0x2475,
  27846. twoperiod: 0x2489,
  27847. twopersian: 0x06F2,
  27848. tworoman: 0x2171,
  27849. twostroke: 0x01BB,
  27850. twosuperior: 0x00B2,
  27851. twothai: 0x0E52,
  27852. twothirds: 0x2154,
  27853. u: 0x0075,
  27854. uacute: 0x00FA,
  27855. ubar: 0x0289,
  27856. ubengali: 0x0989,
  27857. ubopomofo: 0x3128,
  27858. ubreve: 0x016D,
  27859. ucaron: 0x01D4,
  27860. ucircle: 0x24E4,
  27861. ucircumflex: 0x00FB,
  27862. ucircumflexbelow: 0x1E77,
  27863. ucyrillic: 0x0443,
  27864. udattadeva: 0x0951,
  27865. udblacute: 0x0171,
  27866. udblgrave: 0x0215,
  27867. udeva: 0x0909,
  27868. udieresis: 0x00FC,
  27869. udieresisacute: 0x01D8,
  27870. udieresisbelow: 0x1E73,
  27871. udieresiscaron: 0x01DA,
  27872. udieresiscyrillic: 0x04F1,
  27873. udieresisgrave: 0x01DC,
  27874. udieresismacron: 0x01D6,
  27875. udotbelow: 0x1EE5,
  27876. ugrave: 0x00F9,
  27877. ugujarati: 0x0A89,
  27878. ugurmukhi: 0x0A09,
  27879. uhiragana: 0x3046,
  27880. uhookabove: 0x1EE7,
  27881. uhorn: 0x01B0,
  27882. uhornacute: 0x1EE9,
  27883. uhorndotbelow: 0x1EF1,
  27884. uhorngrave: 0x1EEB,
  27885. uhornhookabove: 0x1EED,
  27886. uhorntilde: 0x1EEF,
  27887. uhungarumlaut: 0x0171,
  27888. uhungarumlautcyrillic: 0x04F3,
  27889. uinvertedbreve: 0x0217,
  27890. ukatakana: 0x30A6,
  27891. ukatakanahalfwidth: 0xFF73,
  27892. ukcyrillic: 0x0479,
  27893. ukorean: 0x315C,
  27894. umacron: 0x016B,
  27895. umacroncyrillic: 0x04EF,
  27896. umacrondieresis: 0x1E7B,
  27897. umatragurmukhi: 0x0A41,
  27898. umonospace: 0xFF55,
  27899. underscore: 0x005F,
  27900. underscoredbl: 0x2017,
  27901. underscoremonospace: 0xFF3F,
  27902. underscorevertical: 0xFE33,
  27903. underscorewavy: 0xFE4F,
  27904. union: 0x222A,
  27905. universal: 0x2200,
  27906. uogonek: 0x0173,
  27907. uparen: 0x24B0,
  27908. upblock: 0x2580,
  27909. upperdothebrew: 0x05C4,
  27910. upsilon: 0x03C5,
  27911. upsilondieresis: 0x03CB,
  27912. upsilondieresistonos: 0x03B0,
  27913. upsilonlatin: 0x028A,
  27914. upsilontonos: 0x03CD,
  27915. uptackbelowcmb: 0x031D,
  27916. uptackmod: 0x02D4,
  27917. uragurmukhi: 0x0A73,
  27918. uring: 0x016F,
  27919. ushortcyrillic: 0x045E,
  27920. usmallhiragana: 0x3045,
  27921. usmallkatakana: 0x30A5,
  27922. usmallkatakanahalfwidth: 0xFF69,
  27923. ustraightcyrillic: 0x04AF,
  27924. ustraightstrokecyrillic: 0x04B1,
  27925. utilde: 0x0169,
  27926. utildeacute: 0x1E79,
  27927. utildebelow: 0x1E75,
  27928. uubengali: 0x098A,
  27929. uudeva: 0x090A,
  27930. uugujarati: 0x0A8A,
  27931. uugurmukhi: 0x0A0A,
  27932. uumatragurmukhi: 0x0A42,
  27933. uuvowelsignbengali: 0x09C2,
  27934. uuvowelsigndeva: 0x0942,
  27935. uuvowelsigngujarati: 0x0AC2,
  27936. uvowelsignbengali: 0x09C1,
  27937. uvowelsigndeva: 0x0941,
  27938. uvowelsigngujarati: 0x0AC1,
  27939. v: 0x0076,
  27940. vadeva: 0x0935,
  27941. vagujarati: 0x0AB5,
  27942. vagurmukhi: 0x0A35,
  27943. vakatakana: 0x30F7,
  27944. vav: 0x05D5,
  27945. vavdagesh: 0xFB35,
  27946. vavdagesh65: 0xFB35,
  27947. vavdageshhebrew: 0xFB35,
  27948. vavhebrew: 0x05D5,
  27949. vavholam: 0xFB4B,
  27950. vavholamhebrew: 0xFB4B,
  27951. vavvavhebrew: 0x05F0,
  27952. vavyodhebrew: 0x05F1,
  27953. vcircle: 0x24E5,
  27954. vdotbelow: 0x1E7F,
  27955. vecyrillic: 0x0432,
  27956. veharabic: 0x06A4,
  27957. vehfinalarabic: 0xFB6B,
  27958. vehinitialarabic: 0xFB6C,
  27959. vehmedialarabic: 0xFB6D,
  27960. vekatakana: 0x30F9,
  27961. venus: 0x2640,
  27962. verticalbar: 0x007C,
  27963. verticallineabovecmb: 0x030D,
  27964. verticallinebelowcmb: 0x0329,
  27965. verticallinelowmod: 0x02CC,
  27966. verticallinemod: 0x02C8,
  27967. vewarmenian: 0x057E,
  27968. vhook: 0x028B,
  27969. vikatakana: 0x30F8,
  27970. viramabengali: 0x09CD,
  27971. viramadeva: 0x094D,
  27972. viramagujarati: 0x0ACD,
  27973. visargabengali: 0x0983,
  27974. visargadeva: 0x0903,
  27975. visargagujarati: 0x0A83,
  27976. vmonospace: 0xFF56,
  27977. voarmenian: 0x0578,
  27978. voicediterationhiragana: 0x309E,
  27979. voicediterationkatakana: 0x30FE,
  27980. voicedmarkkana: 0x309B,
  27981. voicedmarkkanahalfwidth: 0xFF9E,
  27982. vokatakana: 0x30FA,
  27983. vparen: 0x24B1,
  27984. vtilde: 0x1E7D,
  27985. vturned: 0x028C,
  27986. vuhiragana: 0x3094,
  27987. vukatakana: 0x30F4,
  27988. w: 0x0077,
  27989. wacute: 0x1E83,
  27990. waekorean: 0x3159,
  27991. wahiragana: 0x308F,
  27992. wakatakana: 0x30EF,
  27993. wakatakanahalfwidth: 0xFF9C,
  27994. wakorean: 0x3158,
  27995. wasmallhiragana: 0x308E,
  27996. wasmallkatakana: 0x30EE,
  27997. wattosquare: 0x3357,
  27998. wavedash: 0x301C,
  27999. wavyunderscorevertical: 0xFE34,
  28000. wawarabic: 0x0648,
  28001. wawfinalarabic: 0xFEEE,
  28002. wawhamzaabovearabic: 0x0624,
  28003. wawhamzaabovefinalarabic: 0xFE86,
  28004. wbsquare: 0x33DD,
  28005. wcircle: 0x24E6,
  28006. wcircumflex: 0x0175,
  28007. wdieresis: 0x1E85,
  28008. wdotaccent: 0x1E87,
  28009. wdotbelow: 0x1E89,
  28010. wehiragana: 0x3091,
  28011. weierstrass: 0x2118,
  28012. wekatakana: 0x30F1,
  28013. wekorean: 0x315E,
  28014. weokorean: 0x315D,
  28015. wgrave: 0x1E81,
  28016. whitebullet: 0x25E6,
  28017. whitecircle: 0x25CB,
  28018. whitecircleinverse: 0x25D9,
  28019. whitecornerbracketleft: 0x300E,
  28020. whitecornerbracketleftvertical: 0xFE43,
  28021. whitecornerbracketright: 0x300F,
  28022. whitecornerbracketrightvertical: 0xFE44,
  28023. whitediamond: 0x25C7,
  28024. whitediamondcontainingblacksmalldiamond: 0x25C8,
  28025. whitedownpointingsmalltriangle: 0x25BF,
  28026. whitedownpointingtriangle: 0x25BD,
  28027. whiteleftpointingsmalltriangle: 0x25C3,
  28028. whiteleftpointingtriangle: 0x25C1,
  28029. whitelenticularbracketleft: 0x3016,
  28030. whitelenticularbracketright: 0x3017,
  28031. whiterightpointingsmalltriangle: 0x25B9,
  28032. whiterightpointingtriangle: 0x25B7,
  28033. whitesmallsquare: 0x25AB,
  28034. whitesmilingface: 0x263A,
  28035. whitesquare: 0x25A1,
  28036. whitestar: 0x2606,
  28037. whitetelephone: 0x260F,
  28038. whitetortoiseshellbracketleft: 0x3018,
  28039. whitetortoiseshellbracketright: 0x3019,
  28040. whiteuppointingsmalltriangle: 0x25B5,
  28041. whiteuppointingtriangle: 0x25B3,
  28042. wihiragana: 0x3090,
  28043. wikatakana: 0x30F0,
  28044. wikorean: 0x315F,
  28045. wmonospace: 0xFF57,
  28046. wohiragana: 0x3092,
  28047. wokatakana: 0x30F2,
  28048. wokatakanahalfwidth: 0xFF66,
  28049. won: 0x20A9,
  28050. wonmonospace: 0xFFE6,
  28051. wowaenthai: 0x0E27,
  28052. wparen: 0x24B2,
  28053. wring: 0x1E98,
  28054. wsuperior: 0x02B7,
  28055. wturned: 0x028D,
  28056. wynn: 0x01BF,
  28057. x: 0x0078,
  28058. xabovecmb: 0x033D,
  28059. xbopomofo: 0x3112,
  28060. xcircle: 0x24E7,
  28061. xdieresis: 0x1E8D,
  28062. xdotaccent: 0x1E8B,
  28063. xeharmenian: 0x056D,
  28064. xi: 0x03BE,
  28065. xmonospace: 0xFF58,
  28066. xparen: 0x24B3,
  28067. xsuperior: 0x02E3,
  28068. y: 0x0079,
  28069. yaadosquare: 0x334E,
  28070. yabengali: 0x09AF,
  28071. yacute: 0x00FD,
  28072. yadeva: 0x092F,
  28073. yaekorean: 0x3152,
  28074. yagujarati: 0x0AAF,
  28075. yagurmukhi: 0x0A2F,
  28076. yahiragana: 0x3084,
  28077. yakatakana: 0x30E4,
  28078. yakatakanahalfwidth: 0xFF94,
  28079. yakorean: 0x3151,
  28080. yamakkanthai: 0x0E4E,
  28081. yasmallhiragana: 0x3083,
  28082. yasmallkatakana: 0x30E3,
  28083. yasmallkatakanahalfwidth: 0xFF6C,
  28084. yatcyrillic: 0x0463,
  28085. ycircle: 0x24E8,
  28086. ycircumflex: 0x0177,
  28087. ydieresis: 0x00FF,
  28088. ydotaccent: 0x1E8F,
  28089. ydotbelow: 0x1EF5,
  28090. yeharabic: 0x064A,
  28091. yehbarreearabic: 0x06D2,
  28092. yehbarreefinalarabic: 0xFBAF,
  28093. yehfinalarabic: 0xFEF2,
  28094. yehhamzaabovearabic: 0x0626,
  28095. yehhamzaabovefinalarabic: 0xFE8A,
  28096. yehhamzaaboveinitialarabic: 0xFE8B,
  28097. yehhamzaabovemedialarabic: 0xFE8C,
  28098. yehinitialarabic: 0xFEF3,
  28099. yehmedialarabic: 0xFEF4,
  28100. yehmeeminitialarabic: 0xFCDD,
  28101. yehmeemisolatedarabic: 0xFC58,
  28102. yehnoonfinalarabic: 0xFC94,
  28103. yehthreedotsbelowarabic: 0x06D1,
  28104. yekorean: 0x3156,
  28105. yen: 0x00A5,
  28106. yenmonospace: 0xFFE5,
  28107. yeokorean: 0x3155,
  28108. yeorinhieuhkorean: 0x3186,
  28109. yerahbenyomohebrew: 0x05AA,
  28110. yerahbenyomolefthebrew: 0x05AA,
  28111. yericyrillic: 0x044B,
  28112. yerudieresiscyrillic: 0x04F9,
  28113. yesieungkorean: 0x3181,
  28114. yesieungpansioskorean: 0x3183,
  28115. yesieungsioskorean: 0x3182,
  28116. yetivhebrew: 0x059A,
  28117. ygrave: 0x1EF3,
  28118. yhook: 0x01B4,
  28119. yhookabove: 0x1EF7,
  28120. yiarmenian: 0x0575,
  28121. yicyrillic: 0x0457,
  28122. yikorean: 0x3162,
  28123. yinyang: 0x262F,
  28124. yiwnarmenian: 0x0582,
  28125. ymonospace: 0xFF59,
  28126. yod: 0x05D9,
  28127. yoddagesh: 0xFB39,
  28128. yoddageshhebrew: 0xFB39,
  28129. yodhebrew: 0x05D9,
  28130. yodyodhebrew: 0x05F2,
  28131. yodyodpatahhebrew: 0xFB1F,
  28132. yohiragana: 0x3088,
  28133. yoikorean: 0x3189,
  28134. yokatakana: 0x30E8,
  28135. yokatakanahalfwidth: 0xFF96,
  28136. yokorean: 0x315B,
  28137. yosmallhiragana: 0x3087,
  28138. yosmallkatakana: 0x30E7,
  28139. yosmallkatakanahalfwidth: 0xFF6E,
  28140. yotgreek: 0x03F3,
  28141. yoyaekorean: 0x3188,
  28142. yoyakorean: 0x3187,
  28143. yoyakthai: 0x0E22,
  28144. yoyingthai: 0x0E0D,
  28145. yparen: 0x24B4,
  28146. ypogegrammeni: 0x037A,
  28147. ypogegrammenigreekcmb: 0x0345,
  28148. yr: 0x01A6,
  28149. yring: 0x1E99,
  28150. ysuperior: 0x02B8,
  28151. ytilde: 0x1EF9,
  28152. yturned: 0x028E,
  28153. yuhiragana: 0x3086,
  28154. yuikorean: 0x318C,
  28155. yukatakana: 0x30E6,
  28156. yukatakanahalfwidth: 0xFF95,
  28157. yukorean: 0x3160,
  28158. yusbigcyrillic: 0x046B,
  28159. yusbigiotifiedcyrillic: 0x046D,
  28160. yuslittlecyrillic: 0x0467,
  28161. yuslittleiotifiedcyrillic: 0x0469,
  28162. yusmallhiragana: 0x3085,
  28163. yusmallkatakana: 0x30E5,
  28164. yusmallkatakanahalfwidth: 0xFF6D,
  28165. yuyekorean: 0x318B,
  28166. yuyeokorean: 0x318A,
  28167. yyabengali: 0x09DF,
  28168. yyadeva: 0x095F,
  28169. z: 0x007A,
  28170. zaarmenian: 0x0566,
  28171. zacute: 0x017A,
  28172. zadeva: 0x095B,
  28173. zagurmukhi: 0x0A5B,
  28174. zaharabic: 0x0638,
  28175. zahfinalarabic: 0xFEC6,
  28176. zahinitialarabic: 0xFEC7,
  28177. zahiragana: 0x3056,
  28178. zahmedialarabic: 0xFEC8,
  28179. zainarabic: 0x0632,
  28180. zainfinalarabic: 0xFEB0,
  28181. zakatakana: 0x30B6,
  28182. zaqefgadolhebrew: 0x0595,
  28183. zaqefqatanhebrew: 0x0594,
  28184. zarqahebrew: 0x0598,
  28185. zayin: 0x05D6,
  28186. zayindagesh: 0xFB36,
  28187. zayindageshhebrew: 0xFB36,
  28188. zayinhebrew: 0x05D6,
  28189. zbopomofo: 0x3117,
  28190. zcaron: 0x017E,
  28191. zcircle: 0x24E9,
  28192. zcircumflex: 0x1E91,
  28193. zcurl: 0x0291,
  28194. zdot: 0x017C,
  28195. zdotaccent: 0x017C,
  28196. zdotbelow: 0x1E93,
  28197. zecyrillic: 0x0437,
  28198. zedescendercyrillic: 0x0499,
  28199. zedieresiscyrillic: 0x04DF,
  28200. zehiragana: 0x305C,
  28201. zekatakana: 0x30BC,
  28202. zero: 0x0030,
  28203. zeroarabic: 0x0660,
  28204. zerobengali: 0x09E6,
  28205. zerodeva: 0x0966,
  28206. zerogujarati: 0x0AE6,
  28207. zerogurmukhi: 0x0A66,
  28208. zerohackarabic: 0x0660,
  28209. zeroinferior: 0x2080,
  28210. zeromonospace: 0xFF10,
  28211. zerooldstyle: 0xF730,
  28212. zeropersian: 0x06F0,
  28213. zerosuperior: 0x2070,
  28214. zerothai: 0x0E50,
  28215. zerowidthjoiner: 0xFEFF,
  28216. zerowidthnonjoiner: 0x200C,
  28217. zerowidthspace: 0x200B,
  28218. zeta: 0x03B6,
  28219. zhbopomofo: 0x3113,
  28220. zhearmenian: 0x056A,
  28221. zhebrevecyrillic: 0x04C2,
  28222. zhecyrillic: 0x0436,
  28223. zhedescendercyrillic: 0x0497,
  28224. zhedieresiscyrillic: 0x04DD,
  28225. zihiragana: 0x3058,
  28226. zikatakana: 0x30B8,
  28227. zinorhebrew: 0x05AE,
  28228. zlinebelow: 0x1E95,
  28229. zmonospace: 0xFF5A,
  28230. zohiragana: 0x305E,
  28231. zokatakana: 0x30BE,
  28232. zparen: 0x24B5,
  28233. zretroflexhook: 0x0290,
  28234. zstroke: 0x01B6,
  28235. zuhiragana: 0x305A,
  28236. zukatakana: 0x30BA,
  28237. '.notdef': 0x0000
  28238. };
  28239. var PDFImage = (function PDFImageClosure() {
  28240. /**
  28241. * Decode the image in the main thread if it supported. Resovles the promise
  28242. * when the image data is ready.
  28243. */
  28244. function handleImageData(handler, xref, res, image) {
  28245. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  28246. // For natively supported jpegs send them to the main thread for decoding.
  28247. var dict = image.dict;
  28248. var colorSpace = dict.get('ColorSpace', 'CS');
  28249. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28250. var numComps = colorSpace.numComps;
  28251. var decodePromise = handler.sendWithPromise('JpegDecode',
  28252. [image.getIR(), numComps]);
  28253. return decodePromise.then(function (message) {
  28254. var data = message.data;
  28255. return new Stream(data, 0, data.length, image.dict);
  28256. });
  28257. } else {
  28258. return Promise.resolve(image);
  28259. }
  28260. }
  28261. /**
  28262. * Decode and clamp a value. The formula is different from the spec because we
  28263. * don't decode to float range [0,1], we decode it in the [0,max] range.
  28264. */
  28265. function decodeAndClamp(value, addend, coefficient, max) {
  28266. value = addend + value * coefficient;
  28267. // Clamp the value to the range
  28268. return (value < 0 ? 0 : (value > max ? max : value));
  28269. }
  28270. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  28271. this.image = image;
  28272. var dict = image.dict;
  28273. if (dict.has('Filter')) {
  28274. var filter = dict.get('Filter').name;
  28275. if (filter === 'JPXDecode') {
  28276. var jpxImage = new JpxImage();
  28277. jpxImage.parseImageProperties(image.stream);
  28278. image.stream.reset();
  28279. image.bitsPerComponent = jpxImage.bitsPerComponent;
  28280. image.numComps = jpxImage.componentsCount;
  28281. } else if (filter === 'JBIG2Decode') {
  28282. image.bitsPerComponent = 1;
  28283. image.numComps = 1;
  28284. }
  28285. }
  28286. // TODO cache rendered images?
  28287. this.width = dict.get('Width', 'W');
  28288. this.height = dict.get('Height', 'H');
  28289. if (this.width < 1 || this.height < 1) {
  28290. error('Invalid image width: ' + this.width + ' or height: ' +
  28291. this.height);
  28292. }
  28293. this.interpolate = dict.get('Interpolate', 'I') || false;
  28294. this.imageMask = dict.get('ImageMask', 'IM') || false;
  28295. this.matte = dict.get('Matte') || false;
  28296. var bitsPerComponent = image.bitsPerComponent;
  28297. if (!bitsPerComponent) {
  28298. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  28299. if (!bitsPerComponent) {
  28300. if (this.imageMask) {
  28301. bitsPerComponent = 1;
  28302. } else {
  28303. error('Bits per component missing in image: ' + this.imageMask);
  28304. }
  28305. }
  28306. }
  28307. this.bpc = bitsPerComponent;
  28308. if (!this.imageMask) {
  28309. var colorSpace = dict.get('ColorSpace', 'CS');
  28310. if (!colorSpace) {
  28311. info('JPX images (which do not require color spaces)');
  28312. switch (image.numComps) {
  28313. case 1:
  28314. colorSpace = Name.get('DeviceGray');
  28315. break;
  28316. case 3:
  28317. colorSpace = Name.get('DeviceRGB');
  28318. break;
  28319. case 4:
  28320. colorSpace = Name.get('DeviceCMYK');
  28321. break;
  28322. default:
  28323. error('JPX images with ' + this.numComps +
  28324. ' color components not supported.');
  28325. }
  28326. }
  28327. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28328. this.numComps = this.colorSpace.numComps;
  28329. }
  28330. this.decode = dict.get('Decode', 'D');
  28331. this.needsDecode = false;
  28332. if (this.decode &&
  28333. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  28334. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  28335. this.needsDecode = true;
  28336. // Do some preprocessing to avoid more math.
  28337. var max = (1 << bitsPerComponent) - 1;
  28338. this.decodeCoefficients = [];
  28339. this.decodeAddends = [];
  28340. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  28341. var dmin = this.decode[i];
  28342. var dmax = this.decode[i + 1];
  28343. this.decodeCoefficients[j] = dmax - dmin;
  28344. this.decodeAddends[j] = max * dmin;
  28345. }
  28346. }
  28347. if (smask) {
  28348. this.smask = new PDFImage(xref, res, smask, false);
  28349. } else if (mask) {
  28350. if (isStream(mask)) {
  28351. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  28352. } else {
  28353. // Color key mask (just an array).
  28354. this.mask = mask;
  28355. }
  28356. }
  28357. }
  28358. /**
  28359. * Handles processing of image data and returns the Promise that is resolved
  28360. * with a PDFImage when the image is ready to be used.
  28361. */
  28362. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  28363. res, image, inline) {
  28364. var imagePromise = handleImageData(handler, xref, res, image);
  28365. var smaskPromise;
  28366. var maskPromise;
  28367. var smask = image.dict.get('SMask');
  28368. var mask = image.dict.get('Mask');
  28369. if (smask) {
  28370. smaskPromise = handleImageData(handler, xref, res, smask);
  28371. maskPromise = Promise.resolve(null);
  28372. } else {
  28373. smaskPromise = Promise.resolve(null);
  28374. if (mask) {
  28375. if (isStream(mask)) {
  28376. maskPromise = handleImageData(handler, xref, res, mask);
  28377. } else if (isArray(mask)) {
  28378. maskPromise = Promise.resolve(mask);
  28379. } else {
  28380. warn('Unsupported mask format.');
  28381. maskPromise = Promise.resolve(null);
  28382. }
  28383. } else {
  28384. maskPromise = Promise.resolve(null);
  28385. }
  28386. }
  28387. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  28388. function(results) {
  28389. var imageData = results[0];
  28390. var smaskData = results[1];
  28391. var maskData = results[2];
  28392. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  28393. });
  28394. };
  28395. /**
  28396. * Resize an image using the nearest neighbor algorithm. Currently only
  28397. * supports one and three component images.
  28398. * @param {TypedArray} pixels The original image with one component.
  28399. * @param {Number} bpc Number of bits per component.
  28400. * @param {Number} components Number of color components, 1 or 3 is supported.
  28401. * @param {Number} w1 Original width.
  28402. * @param {Number} h1 Original height.
  28403. * @param {Number} w2 New width.
  28404. * @param {Number} h2 New height.
  28405. * @param {TypedArray} dest (Optional) The destination buffer.
  28406. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  28407. * @return {TypedArray} Resized image data.
  28408. */
  28409. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  28410. w1, h1, w2, h2, dest, alpha01) {
  28411. if (components !== 1 && components !== 3) {
  28412. error('Unsupported component count for resizing.');
  28413. }
  28414. var length = w2 * h2 * components;
  28415. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  28416. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28417. var xRatio = w1 / w2;
  28418. var yRatio = h1 / h2;
  28419. var i, j, py, newIndex = 0, oldIndex;
  28420. var xScaled = new Uint16Array(w2);
  28421. var w1Scanline = w1 * components;
  28422. if (alpha01 !== 1) {
  28423. alpha01 = 0;
  28424. }
  28425. for (j = 0; j < w2; j++) {
  28426. xScaled[j] = Math.floor(j * xRatio) * components;
  28427. }
  28428. if (components === 1) {
  28429. for (i = 0; i < h2; i++) {
  28430. py = Math.floor(i * yRatio) * w1Scanline;
  28431. for (j = 0; j < w2; j++) {
  28432. oldIndex = py + xScaled[j];
  28433. temp[newIndex++] = pixels[oldIndex];
  28434. }
  28435. }
  28436. } else if (components === 3) {
  28437. for (i = 0; i < h2; i++) {
  28438. py = Math.floor(i * yRatio) * w1Scanline;
  28439. for (j = 0; j < w2; j++) {
  28440. oldIndex = py + xScaled[j];
  28441. temp[newIndex++] = pixels[oldIndex++];
  28442. temp[newIndex++] = pixels[oldIndex++];
  28443. temp[newIndex++] = pixels[oldIndex++];
  28444. newIndex += alpha01;
  28445. }
  28446. }
  28447. }
  28448. return temp;
  28449. };
  28450. PDFImage.createMask =
  28451. function PDFImage_createMask(imgArray, width, height,
  28452. imageIsFromDecodeStream, inverseDecode) {
  28453. // |imgArray| might not contain full data for every pixel of the mask, so
  28454. // we need to distinguish between |computedLength| and |actualLength|.
  28455. // In particular, if inverseDecode is true, then the array we return must
  28456. // have a length of |computedLength|.
  28457. var computedLength = ((width + 7) >> 3) * height;
  28458. var actualLength = imgArray.byteLength;
  28459. var haveFullData = computedLength === actualLength;
  28460. var data, i;
  28461. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  28462. // imgArray came from a DecodeStream and its data is in an appropriate
  28463. // form, so we can just transfer it.
  28464. data = imgArray;
  28465. } else if (!inverseDecode) {
  28466. data = new Uint8Array(actualLength);
  28467. data.set(imgArray);
  28468. } else {
  28469. data = new Uint8Array(computedLength);
  28470. data.set(imgArray);
  28471. for (i = actualLength; i < computedLength; i++) {
  28472. data[i] = 0xff;
  28473. }
  28474. }
  28475. // If necessary, invert the original mask data (but not any extra we might
  28476. // have added above). It's safe to modify the array -- whether it's the
  28477. // original or a copy, we're about to transfer it anyway, so nothing else
  28478. // in this thread can be relying on its contents.
  28479. if (inverseDecode) {
  28480. for (i = 0; i < actualLength; i++) {
  28481. data[i] = ~data[i];
  28482. }
  28483. }
  28484. return {data: data, width: width, height: height};
  28485. };
  28486. PDFImage.prototype = {
  28487. get drawWidth() {
  28488. return Math.max(this.width,
  28489. this.smask && this.smask.width || 0,
  28490. this.mask && this.mask.width || 0);
  28491. },
  28492. get drawHeight() {
  28493. return Math.max(this.height,
  28494. this.smask && this.smask.height || 0,
  28495. this.mask && this.mask.height || 0);
  28496. },
  28497. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  28498. var bpc = this.bpc;
  28499. var numComps = this.numComps;
  28500. var decodeAddends = this.decodeAddends;
  28501. var decodeCoefficients = this.decodeCoefficients;
  28502. var max = (1 << bpc) - 1;
  28503. var i, ii;
  28504. if (bpc === 1) {
  28505. // If the buffer needed decode that means it just needs to be inverted.
  28506. for (i = 0, ii = buffer.length; i < ii; i++) {
  28507. buffer[i] = +!(buffer[i]);
  28508. }
  28509. return;
  28510. }
  28511. var index = 0;
  28512. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  28513. for (var j = 0; j < numComps; j++) {
  28514. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  28515. decodeCoefficients[j], max);
  28516. index++;
  28517. }
  28518. }
  28519. },
  28520. getComponents: function PDFImage_getComponents(buffer) {
  28521. var bpc = this.bpc;
  28522. // This image doesn't require any extra work.
  28523. if (bpc === 8) {
  28524. return buffer;
  28525. }
  28526. var width = this.width;
  28527. var height = this.height;
  28528. var numComps = this.numComps;
  28529. var length = width * height * numComps;
  28530. var bufferPos = 0;
  28531. var output = (bpc <= 8 ? new Uint8Array(length) :
  28532. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28533. var rowComps = width * numComps;
  28534. var max = (1 << bpc) - 1;
  28535. var i = 0, ii, buf;
  28536. if (bpc === 1) {
  28537. // Optimization for reading 1 bpc images.
  28538. var mask, loop1End, loop2End;
  28539. for (var j = 0; j < height; j++) {
  28540. loop1End = i + (rowComps & ~7);
  28541. loop2End = i + rowComps;
  28542. // unroll loop for all full bytes
  28543. while (i < loop1End) {
  28544. buf = buffer[bufferPos++];
  28545. output[i] = (buf >> 7) & 1;
  28546. output[i + 1] = (buf >> 6) & 1;
  28547. output[i + 2] = (buf >> 5) & 1;
  28548. output[i + 3] = (buf >> 4) & 1;
  28549. output[i + 4] = (buf >> 3) & 1;
  28550. output[i + 5] = (buf >> 2) & 1;
  28551. output[i + 6] = (buf >> 1) & 1;
  28552. output[i + 7] = buf & 1;
  28553. i += 8;
  28554. }
  28555. // handle remaing bits
  28556. if (i < loop2End) {
  28557. buf = buffer[bufferPos++];
  28558. mask = 128;
  28559. while (i < loop2End) {
  28560. output[i++] = +!!(buf & mask);
  28561. mask >>= 1;
  28562. }
  28563. }
  28564. }
  28565. } else {
  28566. // The general case that handles all other bpc values.
  28567. var bits = 0;
  28568. buf = 0;
  28569. for (i = 0, ii = length; i < ii; ++i) {
  28570. if (i % rowComps === 0) {
  28571. buf = 0;
  28572. bits = 0;
  28573. }
  28574. while (bits < bpc) {
  28575. buf = (buf << 8) | buffer[bufferPos++];
  28576. bits += 8;
  28577. }
  28578. var remainingBits = bits - bpc;
  28579. var value = buf >> remainingBits;
  28580. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  28581. buf = buf & ((1 << remainingBits) - 1);
  28582. bits = remainingBits;
  28583. }
  28584. }
  28585. return output;
  28586. },
  28587. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  28588. actualHeight, image) {
  28589. var smask = this.smask;
  28590. var mask = this.mask;
  28591. var alphaBuf, sw, sh, i, ii, j;
  28592. if (smask) {
  28593. sw = smask.width;
  28594. sh = smask.height;
  28595. alphaBuf = new Uint8Array(sw * sh);
  28596. smask.fillGrayBuffer(alphaBuf);
  28597. if (sw !== width || sh !== height) {
  28598. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  28599. height);
  28600. }
  28601. } else if (mask) {
  28602. if (mask instanceof PDFImage) {
  28603. sw = mask.width;
  28604. sh = mask.height;
  28605. alphaBuf = new Uint8Array(sw * sh);
  28606. mask.numComps = 1;
  28607. mask.fillGrayBuffer(alphaBuf);
  28608. // Need to invert values in rgbaBuf
  28609. for (i = 0, ii = sw * sh; i < ii; ++i) {
  28610. alphaBuf[i] = 255 - alphaBuf[i];
  28611. }
  28612. if (sw !== width || sh !== height) {
  28613. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  28614. height);
  28615. }
  28616. } else if (isArray(mask)) {
  28617. // Color key mask: if any of the compontents are outside the range
  28618. // then they should be painted.
  28619. alphaBuf = new Uint8Array(width * height);
  28620. var numComps = this.numComps;
  28621. for (i = 0, ii = width * height; i < ii; ++i) {
  28622. var opacity = 0;
  28623. var imageOffset = i * numComps;
  28624. for (j = 0; j < numComps; ++j) {
  28625. var color = image[imageOffset + j];
  28626. var maskOffset = j * 2;
  28627. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  28628. opacity = 255;
  28629. break;
  28630. }
  28631. }
  28632. alphaBuf[i] = opacity;
  28633. }
  28634. } else {
  28635. error('Unknown mask format.');
  28636. }
  28637. }
  28638. if (alphaBuf) {
  28639. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28640. rgbaBuf[j] = alphaBuf[i];
  28641. }
  28642. } else {
  28643. // No mask.
  28644. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28645. rgbaBuf[j] = 255;
  28646. }
  28647. }
  28648. },
  28649. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  28650. var matte = this.smask && this.smask.matte;
  28651. if (!matte) {
  28652. return;
  28653. }
  28654. var matteRgb = this.colorSpace.getRgb(matte, 0);
  28655. var matteR = matteRgb[0];
  28656. var matteG = matteRgb[1];
  28657. var matteB = matteRgb[2];
  28658. var length = width * height * 4;
  28659. var r, g, b;
  28660. for (var i = 0; i < length; i += 4) {
  28661. var alpha = buffer[i + 3];
  28662. if (alpha === 0) {
  28663. // according formula we have to get Infinity in all components
  28664. // making it white (typical paper color) should be okay
  28665. buffer[i] = 255;
  28666. buffer[i + 1] = 255;
  28667. buffer[i + 2] = 255;
  28668. continue;
  28669. }
  28670. var k = 255 / alpha;
  28671. r = (buffer[i] - matteR) * k + matteR;
  28672. g = (buffer[i + 1] - matteG) * k + matteG;
  28673. b = (buffer[i + 2] - matteB) * k + matteB;
  28674. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  28675. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  28676. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  28677. }
  28678. },
  28679. createImageData: function PDFImage_createImageData(forceRGBA) {
  28680. var drawWidth = this.drawWidth;
  28681. var drawHeight = this.drawHeight;
  28682. var imgData = { // other fields are filled in below
  28683. width: drawWidth,
  28684. height: drawHeight
  28685. };
  28686. var numComps = this.numComps;
  28687. var originalWidth = this.width;
  28688. var originalHeight = this.height;
  28689. var bpc = this.bpc;
  28690. // Rows start at byte boundary.
  28691. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  28692. var imgArray;
  28693. if (!forceRGBA) {
  28694. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  28695. // without any complications, we pass a same-sized copy to the main
  28696. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  28697. // of memory for many scanned documents. It's also much faster.
  28698. //
  28699. // Similarly, if it is a 24-bit-per pixel RGB image without any
  28700. // complications, we avoid expanding by 1.333x to RGBA form.
  28701. var kind;
  28702. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  28703. kind = ImageKind.GRAYSCALE_1BPP;
  28704. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  28705. kind = ImageKind.RGB_24BPP;
  28706. }
  28707. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  28708. drawWidth === originalWidth && drawHeight === originalHeight) {
  28709. imgData.kind = kind;
  28710. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28711. // If imgArray came from a DecodeStream, we're safe to transfer it
  28712. // (and thus neuter it) because it will constitute the entire
  28713. // DecodeStream's data. But if it came from a Stream, we need to
  28714. // copy it because it'll only be a portion of the Stream's data, and
  28715. // the rest will be read later on.
  28716. if (this.image instanceof DecodeStream) {
  28717. imgData.data = imgArray;
  28718. } else {
  28719. var newArray = new Uint8Array(imgArray.length);
  28720. newArray.set(imgArray);
  28721. imgData.data = newArray;
  28722. }
  28723. return imgData;
  28724. }
  28725. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  28726. imgData.kind = ImageKind.RGB_24BPP;
  28727. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  28728. drawWidth, drawHeight, true);
  28729. return imgData;
  28730. }
  28731. }
  28732. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28733. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  28734. var actualHeight = 0 | (imgArray.length / rowBytes *
  28735. drawHeight / originalHeight);
  28736. var comps = this.getComponents(imgArray);
  28737. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  28738. // more compact RGB_24BPP form if allowable.
  28739. var alpha01, maybeUndoPreblend;
  28740. if (!forceRGBA && !this.smask && !this.mask) {
  28741. imgData.kind = ImageKind.RGB_24BPP;
  28742. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  28743. alpha01 = 0;
  28744. maybeUndoPreblend = false;
  28745. } else {
  28746. imgData.kind = ImageKind.RGBA_32BPP;
  28747. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  28748. alpha01 = 1;
  28749. maybeUndoPreblend = true;
  28750. // Color key masking (opacity) must be performed before decoding.
  28751. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  28752. comps);
  28753. }
  28754. if (this.needsDecode) {
  28755. this.decodeBuffer(comps);
  28756. }
  28757. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  28758. drawWidth, drawHeight, actualHeight, bpc, comps,
  28759. alpha01);
  28760. if (maybeUndoPreblend) {
  28761. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  28762. }
  28763. return imgData;
  28764. },
  28765. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  28766. var numComps = this.numComps;
  28767. if (numComps !== 1) {
  28768. error('Reading gray scale from a color image: ' + numComps);
  28769. }
  28770. var width = this.width;
  28771. var height = this.height;
  28772. var bpc = this.bpc;
  28773. // rows start at byte boundary
  28774. var rowBytes = (width * numComps * bpc + 7) >> 3;
  28775. var imgArray = this.getImageBytes(height * rowBytes);
  28776. var comps = this.getComponents(imgArray);
  28777. var i, length;
  28778. if (bpc === 1) {
  28779. // inline decoding (= inversion) for 1 bpc images
  28780. length = width * height;
  28781. if (this.needsDecode) {
  28782. // invert and scale to {0, 255}
  28783. for (i = 0; i < length; ++i) {
  28784. buffer[i] = (comps[i] - 1) & 255;
  28785. }
  28786. } else {
  28787. // scale to {0, 255}
  28788. for (i = 0; i < length; ++i) {
  28789. buffer[i] = (-comps[i]) & 255;
  28790. }
  28791. }
  28792. return;
  28793. }
  28794. if (this.needsDecode) {
  28795. this.decodeBuffer(comps);
  28796. }
  28797. length = width * height;
  28798. // we aren't using a colorspace so we need to scale the value
  28799. var scale = 255 / ((1 << bpc) - 1);
  28800. for (i = 0; i < length; ++i) {
  28801. buffer[i] = (scale * comps[i]) | 0;
  28802. }
  28803. },
  28804. getImageBytes: function PDFImage_getImageBytes(length,
  28805. drawWidth, drawHeight,
  28806. forceRGB) {
  28807. this.image.reset();
  28808. this.image.drawWidth = drawWidth || this.width;
  28809. this.image.drawHeight = drawHeight || this.height;
  28810. this.image.forceRGB = !!forceRGB;
  28811. return this.image.getBytes(length);
  28812. }
  28813. };
  28814. return PDFImage;
  28815. })();
  28816. // The Metrics object contains glyph widths (in glyph space units).
  28817. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  28818. // space unit corresponds to 1/1000th of text space unit.
  28819. var Metrics = {
  28820. 'Courier': 600,
  28821. 'Courier-Bold': 600,
  28822. 'Courier-BoldOblique': 600,
  28823. 'Courier-Oblique': 600,
  28824. 'Helvetica' : {
  28825. 'space': 278,
  28826. 'exclam': 278,
  28827. 'quotedbl': 355,
  28828. 'numbersign': 556,
  28829. 'dollar': 556,
  28830. 'percent': 889,
  28831. 'ampersand': 667,
  28832. 'quoteright': 222,
  28833. 'parenleft': 333,
  28834. 'parenright': 333,
  28835. 'asterisk': 389,
  28836. 'plus': 584,
  28837. 'comma': 278,
  28838. 'hyphen': 333,
  28839. 'period': 278,
  28840. 'slash': 278,
  28841. 'zero': 556,
  28842. 'one': 556,
  28843. 'two': 556,
  28844. 'three': 556,
  28845. 'four': 556,
  28846. 'five': 556,
  28847. 'six': 556,
  28848. 'seven': 556,
  28849. 'eight': 556,
  28850. 'nine': 556,
  28851. 'colon': 278,
  28852. 'semicolon': 278,
  28853. 'less': 584,
  28854. 'equal': 584,
  28855. 'greater': 584,
  28856. 'question': 556,
  28857. 'at': 1015,
  28858. 'A': 667,
  28859. 'B': 667,
  28860. 'C': 722,
  28861. 'D': 722,
  28862. 'E': 667,
  28863. 'F': 611,
  28864. 'G': 778,
  28865. 'H': 722,
  28866. 'I': 278,
  28867. 'J': 500,
  28868. 'K': 667,
  28869. 'L': 556,
  28870. 'M': 833,
  28871. 'N': 722,
  28872. 'O': 778,
  28873. 'P': 667,
  28874. 'Q': 778,
  28875. 'R': 722,
  28876. 'S': 667,
  28877. 'T': 611,
  28878. 'U': 722,
  28879. 'V': 667,
  28880. 'W': 944,
  28881. 'X': 667,
  28882. 'Y': 667,
  28883. 'Z': 611,
  28884. 'bracketleft': 278,
  28885. 'backslash': 278,
  28886. 'bracketright': 278,
  28887. 'asciicircum': 469,
  28888. 'underscore': 556,
  28889. 'quoteleft': 222,
  28890. 'a': 556,
  28891. 'b': 556,
  28892. 'c': 500,
  28893. 'd': 556,
  28894. 'e': 556,
  28895. 'f': 278,
  28896. 'g': 556,
  28897. 'h': 556,
  28898. 'i': 222,
  28899. 'j': 222,
  28900. 'k': 500,
  28901. 'l': 222,
  28902. 'm': 833,
  28903. 'n': 556,
  28904. 'o': 556,
  28905. 'p': 556,
  28906. 'q': 556,
  28907. 'r': 333,
  28908. 's': 500,
  28909. 't': 278,
  28910. 'u': 556,
  28911. 'v': 500,
  28912. 'w': 722,
  28913. 'x': 500,
  28914. 'y': 500,
  28915. 'z': 500,
  28916. 'braceleft': 334,
  28917. 'bar': 260,
  28918. 'braceright': 334,
  28919. 'asciitilde': 584,
  28920. 'exclamdown': 333,
  28921. 'cent': 556,
  28922. 'sterling': 556,
  28923. 'fraction': 167,
  28924. 'yen': 556,
  28925. 'florin': 556,
  28926. 'section': 556,
  28927. 'currency': 556,
  28928. 'quotesingle': 191,
  28929. 'quotedblleft': 333,
  28930. 'guillemotleft': 556,
  28931. 'guilsinglleft': 333,
  28932. 'guilsinglright': 333,
  28933. 'fi': 500,
  28934. 'fl': 500,
  28935. 'endash': 556,
  28936. 'dagger': 556,
  28937. 'daggerdbl': 556,
  28938. 'periodcentered': 278,
  28939. 'paragraph': 537,
  28940. 'bullet': 350,
  28941. 'quotesinglbase': 222,
  28942. 'quotedblbase': 333,
  28943. 'quotedblright': 333,
  28944. 'guillemotright': 556,
  28945. 'ellipsis': 1000,
  28946. 'perthousand': 1000,
  28947. 'questiondown': 611,
  28948. 'grave': 333,
  28949. 'acute': 333,
  28950. 'circumflex': 333,
  28951. 'tilde': 333,
  28952. 'macron': 333,
  28953. 'breve': 333,
  28954. 'dotaccent': 333,
  28955. 'dieresis': 333,
  28956. 'ring': 333,
  28957. 'cedilla': 333,
  28958. 'hungarumlaut': 333,
  28959. 'ogonek': 333,
  28960. 'caron': 333,
  28961. 'emdash': 1000,
  28962. 'AE': 1000,
  28963. 'ordfeminine': 370,
  28964. 'Lslash': 556,
  28965. 'Oslash': 778,
  28966. 'OE': 1000,
  28967. 'ordmasculine': 365,
  28968. 'ae': 889,
  28969. 'dotlessi': 278,
  28970. 'lslash': 222,
  28971. 'oslash': 611,
  28972. 'oe': 944,
  28973. 'germandbls': 611,
  28974. 'Idieresis': 278,
  28975. 'eacute': 556,
  28976. 'abreve': 556,
  28977. 'uhungarumlaut': 556,
  28978. 'ecaron': 556,
  28979. 'Ydieresis': 667,
  28980. 'divide': 584,
  28981. 'Yacute': 667,
  28982. 'Acircumflex': 667,
  28983. 'aacute': 556,
  28984. 'Ucircumflex': 722,
  28985. 'yacute': 500,
  28986. 'scommaaccent': 500,
  28987. 'ecircumflex': 556,
  28988. 'Uring': 722,
  28989. 'Udieresis': 722,
  28990. 'aogonek': 556,
  28991. 'Uacute': 722,
  28992. 'uogonek': 556,
  28993. 'Edieresis': 667,
  28994. 'Dcroat': 722,
  28995. 'commaaccent': 250,
  28996. 'copyright': 737,
  28997. 'Emacron': 667,
  28998. 'ccaron': 500,
  28999. 'aring': 556,
  29000. 'Ncommaaccent': 722,
  29001. 'lacute': 222,
  29002. 'agrave': 556,
  29003. 'Tcommaaccent': 611,
  29004. 'Cacute': 722,
  29005. 'atilde': 556,
  29006. 'Edotaccent': 667,
  29007. 'scaron': 500,
  29008. 'scedilla': 500,
  29009. 'iacute': 278,
  29010. 'lozenge': 471,
  29011. 'Rcaron': 722,
  29012. 'Gcommaaccent': 778,
  29013. 'ucircumflex': 556,
  29014. 'acircumflex': 556,
  29015. 'Amacron': 667,
  29016. 'rcaron': 333,
  29017. 'ccedilla': 500,
  29018. 'Zdotaccent': 611,
  29019. 'Thorn': 667,
  29020. 'Omacron': 778,
  29021. 'Racute': 722,
  29022. 'Sacute': 667,
  29023. 'dcaron': 643,
  29024. 'Umacron': 722,
  29025. 'uring': 556,
  29026. 'threesuperior': 333,
  29027. 'Ograve': 778,
  29028. 'Agrave': 667,
  29029. 'Abreve': 667,
  29030. 'multiply': 584,
  29031. 'uacute': 556,
  29032. 'Tcaron': 611,
  29033. 'partialdiff': 476,
  29034. 'ydieresis': 500,
  29035. 'Nacute': 722,
  29036. 'icircumflex': 278,
  29037. 'Ecircumflex': 667,
  29038. 'adieresis': 556,
  29039. 'edieresis': 556,
  29040. 'cacute': 500,
  29041. 'nacute': 556,
  29042. 'umacron': 556,
  29043. 'Ncaron': 722,
  29044. 'Iacute': 278,
  29045. 'plusminus': 584,
  29046. 'brokenbar': 260,
  29047. 'registered': 737,
  29048. 'Gbreve': 778,
  29049. 'Idotaccent': 278,
  29050. 'summation': 600,
  29051. 'Egrave': 667,
  29052. 'racute': 333,
  29053. 'omacron': 556,
  29054. 'Zacute': 611,
  29055. 'Zcaron': 611,
  29056. 'greaterequal': 549,
  29057. 'Eth': 722,
  29058. 'Ccedilla': 722,
  29059. 'lcommaaccent': 222,
  29060. 'tcaron': 317,
  29061. 'eogonek': 556,
  29062. 'Uogonek': 722,
  29063. 'Aacute': 667,
  29064. 'Adieresis': 667,
  29065. 'egrave': 556,
  29066. 'zacute': 500,
  29067. 'iogonek': 222,
  29068. 'Oacute': 778,
  29069. 'oacute': 556,
  29070. 'amacron': 556,
  29071. 'sacute': 500,
  29072. 'idieresis': 278,
  29073. 'Ocircumflex': 778,
  29074. 'Ugrave': 722,
  29075. 'Delta': 612,
  29076. 'thorn': 556,
  29077. 'twosuperior': 333,
  29078. 'Odieresis': 778,
  29079. 'mu': 556,
  29080. 'igrave': 278,
  29081. 'ohungarumlaut': 556,
  29082. 'Eogonek': 667,
  29083. 'dcroat': 556,
  29084. 'threequarters': 834,
  29085. 'Scedilla': 667,
  29086. 'lcaron': 299,
  29087. 'Kcommaaccent': 667,
  29088. 'Lacute': 556,
  29089. 'trademark': 1000,
  29090. 'edotaccent': 556,
  29091. 'Igrave': 278,
  29092. 'Imacron': 278,
  29093. 'Lcaron': 556,
  29094. 'onehalf': 834,
  29095. 'lessequal': 549,
  29096. 'ocircumflex': 556,
  29097. 'ntilde': 556,
  29098. 'Uhungarumlaut': 722,
  29099. 'Eacute': 667,
  29100. 'emacron': 556,
  29101. 'gbreve': 556,
  29102. 'onequarter': 834,
  29103. 'Scaron': 667,
  29104. 'Scommaaccent': 667,
  29105. 'Ohungarumlaut': 778,
  29106. 'degree': 400,
  29107. 'ograve': 556,
  29108. 'Ccaron': 722,
  29109. 'ugrave': 556,
  29110. 'radical': 453,
  29111. 'Dcaron': 722,
  29112. 'rcommaaccent': 333,
  29113. 'Ntilde': 722,
  29114. 'otilde': 556,
  29115. 'Rcommaaccent': 722,
  29116. 'Lcommaaccent': 556,
  29117. 'Atilde': 667,
  29118. 'Aogonek': 667,
  29119. 'Aring': 667,
  29120. 'Otilde': 778,
  29121. 'zdotaccent': 500,
  29122. 'Ecaron': 667,
  29123. 'Iogonek': 278,
  29124. 'kcommaaccent': 500,
  29125. 'minus': 584,
  29126. 'Icircumflex': 278,
  29127. 'ncaron': 556,
  29128. 'tcommaaccent': 278,
  29129. 'logicalnot': 584,
  29130. 'odieresis': 556,
  29131. 'udieresis': 556,
  29132. 'notequal': 549,
  29133. 'gcommaaccent': 556,
  29134. 'eth': 556,
  29135. 'zcaron': 500,
  29136. 'ncommaaccent': 556,
  29137. 'onesuperior': 333,
  29138. 'imacron': 278,
  29139. 'Euro': 556
  29140. },
  29141. 'Helvetica-Bold': {
  29142. 'space': 278,
  29143. 'exclam': 333,
  29144. 'quotedbl': 474,
  29145. 'numbersign': 556,
  29146. 'dollar': 556,
  29147. 'percent': 889,
  29148. 'ampersand': 722,
  29149. 'quoteright': 278,
  29150. 'parenleft': 333,
  29151. 'parenright': 333,
  29152. 'asterisk': 389,
  29153. 'plus': 584,
  29154. 'comma': 278,
  29155. 'hyphen': 333,
  29156. 'period': 278,
  29157. 'slash': 278,
  29158. 'zero': 556,
  29159. 'one': 556,
  29160. 'two': 556,
  29161. 'three': 556,
  29162. 'four': 556,
  29163. 'five': 556,
  29164. 'six': 556,
  29165. 'seven': 556,
  29166. 'eight': 556,
  29167. 'nine': 556,
  29168. 'colon': 333,
  29169. 'semicolon': 333,
  29170. 'less': 584,
  29171. 'equal': 584,
  29172. 'greater': 584,
  29173. 'question': 611,
  29174. 'at': 975,
  29175. 'A': 722,
  29176. 'B': 722,
  29177. 'C': 722,
  29178. 'D': 722,
  29179. 'E': 667,
  29180. 'F': 611,
  29181. 'G': 778,
  29182. 'H': 722,
  29183. 'I': 278,
  29184. 'J': 556,
  29185. 'K': 722,
  29186. 'L': 611,
  29187. 'M': 833,
  29188. 'N': 722,
  29189. 'O': 778,
  29190. 'P': 667,
  29191. 'Q': 778,
  29192. 'R': 722,
  29193. 'S': 667,
  29194. 'T': 611,
  29195. 'U': 722,
  29196. 'V': 667,
  29197. 'W': 944,
  29198. 'X': 667,
  29199. 'Y': 667,
  29200. 'Z': 611,
  29201. 'bracketleft': 333,
  29202. 'backslash': 278,
  29203. 'bracketright': 333,
  29204. 'asciicircum': 584,
  29205. 'underscore': 556,
  29206. 'quoteleft': 278,
  29207. 'a': 556,
  29208. 'b': 611,
  29209. 'c': 556,
  29210. 'd': 611,
  29211. 'e': 556,
  29212. 'f': 333,
  29213. 'g': 611,
  29214. 'h': 611,
  29215. 'i': 278,
  29216. 'j': 278,
  29217. 'k': 556,
  29218. 'l': 278,
  29219. 'm': 889,
  29220. 'n': 611,
  29221. 'o': 611,
  29222. 'p': 611,
  29223. 'q': 611,
  29224. 'r': 389,
  29225. 's': 556,
  29226. 't': 333,
  29227. 'u': 611,
  29228. 'v': 556,
  29229. 'w': 778,
  29230. 'x': 556,
  29231. 'y': 556,
  29232. 'z': 500,
  29233. 'braceleft': 389,
  29234. 'bar': 280,
  29235. 'braceright': 389,
  29236. 'asciitilde': 584,
  29237. 'exclamdown': 333,
  29238. 'cent': 556,
  29239. 'sterling': 556,
  29240. 'fraction': 167,
  29241. 'yen': 556,
  29242. 'florin': 556,
  29243. 'section': 556,
  29244. 'currency': 556,
  29245. 'quotesingle': 238,
  29246. 'quotedblleft': 500,
  29247. 'guillemotleft': 556,
  29248. 'guilsinglleft': 333,
  29249. 'guilsinglright': 333,
  29250. 'fi': 611,
  29251. 'fl': 611,
  29252. 'endash': 556,
  29253. 'dagger': 556,
  29254. 'daggerdbl': 556,
  29255. 'periodcentered': 278,
  29256. 'paragraph': 556,
  29257. 'bullet': 350,
  29258. 'quotesinglbase': 278,
  29259. 'quotedblbase': 500,
  29260. 'quotedblright': 500,
  29261. 'guillemotright': 556,
  29262. 'ellipsis': 1000,
  29263. 'perthousand': 1000,
  29264. 'questiondown': 611,
  29265. 'grave': 333,
  29266. 'acute': 333,
  29267. 'circumflex': 333,
  29268. 'tilde': 333,
  29269. 'macron': 333,
  29270. 'breve': 333,
  29271. 'dotaccent': 333,
  29272. 'dieresis': 333,
  29273. 'ring': 333,
  29274. 'cedilla': 333,
  29275. 'hungarumlaut': 333,
  29276. 'ogonek': 333,
  29277. 'caron': 333,
  29278. 'emdash': 1000,
  29279. 'AE': 1000,
  29280. 'ordfeminine': 370,
  29281. 'Lslash': 611,
  29282. 'Oslash': 778,
  29283. 'OE': 1000,
  29284. 'ordmasculine': 365,
  29285. 'ae': 889,
  29286. 'dotlessi': 278,
  29287. 'lslash': 278,
  29288. 'oslash': 611,
  29289. 'oe': 944,
  29290. 'germandbls': 611,
  29291. 'Idieresis': 278,
  29292. 'eacute': 556,
  29293. 'abreve': 556,
  29294. 'uhungarumlaut': 611,
  29295. 'ecaron': 556,
  29296. 'Ydieresis': 667,
  29297. 'divide': 584,
  29298. 'Yacute': 667,
  29299. 'Acircumflex': 722,
  29300. 'aacute': 556,
  29301. 'Ucircumflex': 722,
  29302. 'yacute': 556,
  29303. 'scommaaccent': 556,
  29304. 'ecircumflex': 556,
  29305. 'Uring': 722,
  29306. 'Udieresis': 722,
  29307. 'aogonek': 556,
  29308. 'Uacute': 722,
  29309. 'uogonek': 611,
  29310. 'Edieresis': 667,
  29311. 'Dcroat': 722,
  29312. 'commaaccent': 250,
  29313. 'copyright': 737,
  29314. 'Emacron': 667,
  29315. 'ccaron': 556,
  29316. 'aring': 556,
  29317. 'Ncommaaccent': 722,
  29318. 'lacute': 278,
  29319. 'agrave': 556,
  29320. 'Tcommaaccent': 611,
  29321. 'Cacute': 722,
  29322. 'atilde': 556,
  29323. 'Edotaccent': 667,
  29324. 'scaron': 556,
  29325. 'scedilla': 556,
  29326. 'iacute': 278,
  29327. 'lozenge': 494,
  29328. 'Rcaron': 722,
  29329. 'Gcommaaccent': 778,
  29330. 'ucircumflex': 611,
  29331. 'acircumflex': 556,
  29332. 'Amacron': 722,
  29333. 'rcaron': 389,
  29334. 'ccedilla': 556,
  29335. 'Zdotaccent': 611,
  29336. 'Thorn': 667,
  29337. 'Omacron': 778,
  29338. 'Racute': 722,
  29339. 'Sacute': 667,
  29340. 'dcaron': 743,
  29341. 'Umacron': 722,
  29342. 'uring': 611,
  29343. 'threesuperior': 333,
  29344. 'Ograve': 778,
  29345. 'Agrave': 722,
  29346. 'Abreve': 722,
  29347. 'multiply': 584,
  29348. 'uacute': 611,
  29349. 'Tcaron': 611,
  29350. 'partialdiff': 494,
  29351. 'ydieresis': 556,
  29352. 'Nacute': 722,
  29353. 'icircumflex': 278,
  29354. 'Ecircumflex': 667,
  29355. 'adieresis': 556,
  29356. 'edieresis': 556,
  29357. 'cacute': 556,
  29358. 'nacute': 611,
  29359. 'umacron': 611,
  29360. 'Ncaron': 722,
  29361. 'Iacute': 278,
  29362. 'plusminus': 584,
  29363. 'brokenbar': 280,
  29364. 'registered': 737,
  29365. 'Gbreve': 778,
  29366. 'Idotaccent': 278,
  29367. 'summation': 600,
  29368. 'Egrave': 667,
  29369. 'racute': 389,
  29370. 'omacron': 611,
  29371. 'Zacute': 611,
  29372. 'Zcaron': 611,
  29373. 'greaterequal': 549,
  29374. 'Eth': 722,
  29375. 'Ccedilla': 722,
  29376. 'lcommaaccent': 278,
  29377. 'tcaron': 389,
  29378. 'eogonek': 556,
  29379. 'Uogonek': 722,
  29380. 'Aacute': 722,
  29381. 'Adieresis': 722,
  29382. 'egrave': 556,
  29383. 'zacute': 500,
  29384. 'iogonek': 278,
  29385. 'Oacute': 778,
  29386. 'oacute': 611,
  29387. 'amacron': 556,
  29388. 'sacute': 556,
  29389. 'idieresis': 278,
  29390. 'Ocircumflex': 778,
  29391. 'Ugrave': 722,
  29392. 'Delta': 612,
  29393. 'thorn': 611,
  29394. 'twosuperior': 333,
  29395. 'Odieresis': 778,
  29396. 'mu': 611,
  29397. 'igrave': 278,
  29398. 'ohungarumlaut': 611,
  29399. 'Eogonek': 667,
  29400. 'dcroat': 611,
  29401. 'threequarters': 834,
  29402. 'Scedilla': 667,
  29403. 'lcaron': 400,
  29404. 'Kcommaaccent': 722,
  29405. 'Lacute': 611,
  29406. 'trademark': 1000,
  29407. 'edotaccent': 556,
  29408. 'Igrave': 278,
  29409. 'Imacron': 278,
  29410. 'Lcaron': 611,
  29411. 'onehalf': 834,
  29412. 'lessequal': 549,
  29413. 'ocircumflex': 611,
  29414. 'ntilde': 611,
  29415. 'Uhungarumlaut': 722,
  29416. 'Eacute': 667,
  29417. 'emacron': 556,
  29418. 'gbreve': 611,
  29419. 'onequarter': 834,
  29420. 'Scaron': 667,
  29421. 'Scommaaccent': 667,
  29422. 'Ohungarumlaut': 778,
  29423. 'degree': 400,
  29424. 'ograve': 611,
  29425. 'Ccaron': 722,
  29426. 'ugrave': 611,
  29427. 'radical': 549,
  29428. 'Dcaron': 722,
  29429. 'rcommaaccent': 389,
  29430. 'Ntilde': 722,
  29431. 'otilde': 611,
  29432. 'Rcommaaccent': 722,
  29433. 'Lcommaaccent': 611,
  29434. 'Atilde': 722,
  29435. 'Aogonek': 722,
  29436. 'Aring': 722,
  29437. 'Otilde': 778,
  29438. 'zdotaccent': 500,
  29439. 'Ecaron': 667,
  29440. 'Iogonek': 278,
  29441. 'kcommaaccent': 556,
  29442. 'minus': 584,
  29443. 'Icircumflex': 278,
  29444. 'ncaron': 611,
  29445. 'tcommaaccent': 333,
  29446. 'logicalnot': 584,
  29447. 'odieresis': 611,
  29448. 'udieresis': 611,
  29449. 'notequal': 549,
  29450. 'gcommaaccent': 611,
  29451. 'eth': 611,
  29452. 'zcaron': 500,
  29453. 'ncommaaccent': 611,
  29454. 'onesuperior': 333,
  29455. 'imacron': 278,
  29456. 'Euro': 556
  29457. },
  29458. 'Helvetica-BoldOblique': {
  29459. 'space': 278,
  29460. 'exclam': 333,
  29461. 'quotedbl': 474,
  29462. 'numbersign': 556,
  29463. 'dollar': 556,
  29464. 'percent': 889,
  29465. 'ampersand': 722,
  29466. 'quoteright': 278,
  29467. 'parenleft': 333,
  29468. 'parenright': 333,
  29469. 'asterisk': 389,
  29470. 'plus': 584,
  29471. 'comma': 278,
  29472. 'hyphen': 333,
  29473. 'period': 278,
  29474. 'slash': 278,
  29475. 'zero': 556,
  29476. 'one': 556,
  29477. 'two': 556,
  29478. 'three': 556,
  29479. 'four': 556,
  29480. 'five': 556,
  29481. 'six': 556,
  29482. 'seven': 556,
  29483. 'eight': 556,
  29484. 'nine': 556,
  29485. 'colon': 333,
  29486. 'semicolon': 333,
  29487. 'less': 584,
  29488. 'equal': 584,
  29489. 'greater': 584,
  29490. 'question': 611,
  29491. 'at': 975,
  29492. 'A': 722,
  29493. 'B': 722,
  29494. 'C': 722,
  29495. 'D': 722,
  29496. 'E': 667,
  29497. 'F': 611,
  29498. 'G': 778,
  29499. 'H': 722,
  29500. 'I': 278,
  29501. 'J': 556,
  29502. 'K': 722,
  29503. 'L': 611,
  29504. 'M': 833,
  29505. 'N': 722,
  29506. 'O': 778,
  29507. 'P': 667,
  29508. 'Q': 778,
  29509. 'R': 722,
  29510. 'S': 667,
  29511. 'T': 611,
  29512. 'U': 722,
  29513. 'V': 667,
  29514. 'W': 944,
  29515. 'X': 667,
  29516. 'Y': 667,
  29517. 'Z': 611,
  29518. 'bracketleft': 333,
  29519. 'backslash': 278,
  29520. 'bracketright': 333,
  29521. 'asciicircum': 584,
  29522. 'underscore': 556,
  29523. 'quoteleft': 278,
  29524. 'a': 556,
  29525. 'b': 611,
  29526. 'c': 556,
  29527. 'd': 611,
  29528. 'e': 556,
  29529. 'f': 333,
  29530. 'g': 611,
  29531. 'h': 611,
  29532. 'i': 278,
  29533. 'j': 278,
  29534. 'k': 556,
  29535. 'l': 278,
  29536. 'm': 889,
  29537. 'n': 611,
  29538. 'o': 611,
  29539. 'p': 611,
  29540. 'q': 611,
  29541. 'r': 389,
  29542. 's': 556,
  29543. 't': 333,
  29544. 'u': 611,
  29545. 'v': 556,
  29546. 'w': 778,
  29547. 'x': 556,
  29548. 'y': 556,
  29549. 'z': 500,
  29550. 'braceleft': 389,
  29551. 'bar': 280,
  29552. 'braceright': 389,
  29553. 'asciitilde': 584,
  29554. 'exclamdown': 333,
  29555. 'cent': 556,
  29556. 'sterling': 556,
  29557. 'fraction': 167,
  29558. 'yen': 556,
  29559. 'florin': 556,
  29560. 'section': 556,
  29561. 'currency': 556,
  29562. 'quotesingle': 238,
  29563. 'quotedblleft': 500,
  29564. 'guillemotleft': 556,
  29565. 'guilsinglleft': 333,
  29566. 'guilsinglright': 333,
  29567. 'fi': 611,
  29568. 'fl': 611,
  29569. 'endash': 556,
  29570. 'dagger': 556,
  29571. 'daggerdbl': 556,
  29572. 'periodcentered': 278,
  29573. 'paragraph': 556,
  29574. 'bullet': 350,
  29575. 'quotesinglbase': 278,
  29576. 'quotedblbase': 500,
  29577. 'quotedblright': 500,
  29578. 'guillemotright': 556,
  29579. 'ellipsis': 1000,
  29580. 'perthousand': 1000,
  29581. 'questiondown': 611,
  29582. 'grave': 333,
  29583. 'acute': 333,
  29584. 'circumflex': 333,
  29585. 'tilde': 333,
  29586. 'macron': 333,
  29587. 'breve': 333,
  29588. 'dotaccent': 333,
  29589. 'dieresis': 333,
  29590. 'ring': 333,
  29591. 'cedilla': 333,
  29592. 'hungarumlaut': 333,
  29593. 'ogonek': 333,
  29594. 'caron': 333,
  29595. 'emdash': 1000,
  29596. 'AE': 1000,
  29597. 'ordfeminine': 370,
  29598. 'Lslash': 611,
  29599. 'Oslash': 778,
  29600. 'OE': 1000,
  29601. 'ordmasculine': 365,
  29602. 'ae': 889,
  29603. 'dotlessi': 278,
  29604. 'lslash': 278,
  29605. 'oslash': 611,
  29606. 'oe': 944,
  29607. 'germandbls': 611,
  29608. 'Idieresis': 278,
  29609. 'eacute': 556,
  29610. 'abreve': 556,
  29611. 'uhungarumlaut': 611,
  29612. 'ecaron': 556,
  29613. 'Ydieresis': 667,
  29614. 'divide': 584,
  29615. 'Yacute': 667,
  29616. 'Acircumflex': 722,
  29617. 'aacute': 556,
  29618. 'Ucircumflex': 722,
  29619. 'yacute': 556,
  29620. 'scommaaccent': 556,
  29621. 'ecircumflex': 556,
  29622. 'Uring': 722,
  29623. 'Udieresis': 722,
  29624. 'aogonek': 556,
  29625. 'Uacute': 722,
  29626. 'uogonek': 611,
  29627. 'Edieresis': 667,
  29628. 'Dcroat': 722,
  29629. 'commaaccent': 250,
  29630. 'copyright': 737,
  29631. 'Emacron': 667,
  29632. 'ccaron': 556,
  29633. 'aring': 556,
  29634. 'Ncommaaccent': 722,
  29635. 'lacute': 278,
  29636. 'agrave': 556,
  29637. 'Tcommaaccent': 611,
  29638. 'Cacute': 722,
  29639. 'atilde': 556,
  29640. 'Edotaccent': 667,
  29641. 'scaron': 556,
  29642. 'scedilla': 556,
  29643. 'iacute': 278,
  29644. 'lozenge': 494,
  29645. 'Rcaron': 722,
  29646. 'Gcommaaccent': 778,
  29647. 'ucircumflex': 611,
  29648. 'acircumflex': 556,
  29649. 'Amacron': 722,
  29650. 'rcaron': 389,
  29651. 'ccedilla': 556,
  29652. 'Zdotaccent': 611,
  29653. 'Thorn': 667,
  29654. 'Omacron': 778,
  29655. 'Racute': 722,
  29656. 'Sacute': 667,
  29657. 'dcaron': 743,
  29658. 'Umacron': 722,
  29659. 'uring': 611,
  29660. 'threesuperior': 333,
  29661. 'Ograve': 778,
  29662. 'Agrave': 722,
  29663. 'Abreve': 722,
  29664. 'multiply': 584,
  29665. 'uacute': 611,
  29666. 'Tcaron': 611,
  29667. 'partialdiff': 494,
  29668. 'ydieresis': 556,
  29669. 'Nacute': 722,
  29670. 'icircumflex': 278,
  29671. 'Ecircumflex': 667,
  29672. 'adieresis': 556,
  29673. 'edieresis': 556,
  29674. 'cacute': 556,
  29675. 'nacute': 611,
  29676. 'umacron': 611,
  29677. 'Ncaron': 722,
  29678. 'Iacute': 278,
  29679. 'plusminus': 584,
  29680. 'brokenbar': 280,
  29681. 'registered': 737,
  29682. 'Gbreve': 778,
  29683. 'Idotaccent': 278,
  29684. 'summation': 600,
  29685. 'Egrave': 667,
  29686. 'racute': 389,
  29687. 'omacron': 611,
  29688. 'Zacute': 611,
  29689. 'Zcaron': 611,
  29690. 'greaterequal': 549,
  29691. 'Eth': 722,
  29692. 'Ccedilla': 722,
  29693. 'lcommaaccent': 278,
  29694. 'tcaron': 389,
  29695. 'eogonek': 556,
  29696. 'Uogonek': 722,
  29697. 'Aacute': 722,
  29698. 'Adieresis': 722,
  29699. 'egrave': 556,
  29700. 'zacute': 500,
  29701. 'iogonek': 278,
  29702. 'Oacute': 778,
  29703. 'oacute': 611,
  29704. 'amacron': 556,
  29705. 'sacute': 556,
  29706. 'idieresis': 278,
  29707. 'Ocircumflex': 778,
  29708. 'Ugrave': 722,
  29709. 'Delta': 612,
  29710. 'thorn': 611,
  29711. 'twosuperior': 333,
  29712. 'Odieresis': 778,
  29713. 'mu': 611,
  29714. 'igrave': 278,
  29715. 'ohungarumlaut': 611,
  29716. 'Eogonek': 667,
  29717. 'dcroat': 611,
  29718. 'threequarters': 834,
  29719. 'Scedilla': 667,
  29720. 'lcaron': 400,
  29721. 'Kcommaaccent': 722,
  29722. 'Lacute': 611,
  29723. 'trademark': 1000,
  29724. 'edotaccent': 556,
  29725. 'Igrave': 278,
  29726. 'Imacron': 278,
  29727. 'Lcaron': 611,
  29728. 'onehalf': 834,
  29729. 'lessequal': 549,
  29730. 'ocircumflex': 611,
  29731. 'ntilde': 611,
  29732. 'Uhungarumlaut': 722,
  29733. 'Eacute': 667,
  29734. 'emacron': 556,
  29735. 'gbreve': 611,
  29736. 'onequarter': 834,
  29737. 'Scaron': 667,
  29738. 'Scommaaccent': 667,
  29739. 'Ohungarumlaut': 778,
  29740. 'degree': 400,
  29741. 'ograve': 611,
  29742. 'Ccaron': 722,
  29743. 'ugrave': 611,
  29744. 'radical': 549,
  29745. 'Dcaron': 722,
  29746. 'rcommaaccent': 389,
  29747. 'Ntilde': 722,
  29748. 'otilde': 611,
  29749. 'Rcommaaccent': 722,
  29750. 'Lcommaaccent': 611,
  29751. 'Atilde': 722,
  29752. 'Aogonek': 722,
  29753. 'Aring': 722,
  29754. 'Otilde': 778,
  29755. 'zdotaccent': 500,
  29756. 'Ecaron': 667,
  29757. 'Iogonek': 278,
  29758. 'kcommaaccent': 556,
  29759. 'minus': 584,
  29760. 'Icircumflex': 278,
  29761. 'ncaron': 611,
  29762. 'tcommaaccent': 333,
  29763. 'logicalnot': 584,
  29764. 'odieresis': 611,
  29765. 'udieresis': 611,
  29766. 'notequal': 549,
  29767. 'gcommaaccent': 611,
  29768. 'eth': 611,
  29769. 'zcaron': 500,
  29770. 'ncommaaccent': 611,
  29771. 'onesuperior': 333,
  29772. 'imacron': 278,
  29773. 'Euro': 556
  29774. },
  29775. 'Helvetica-Oblique' : {
  29776. 'space': 278,
  29777. 'exclam': 278,
  29778. 'quotedbl': 355,
  29779. 'numbersign': 556,
  29780. 'dollar': 556,
  29781. 'percent': 889,
  29782. 'ampersand': 667,
  29783. 'quoteright': 222,
  29784. 'parenleft': 333,
  29785. 'parenright': 333,
  29786. 'asterisk': 389,
  29787. 'plus': 584,
  29788. 'comma': 278,
  29789. 'hyphen': 333,
  29790. 'period': 278,
  29791. 'slash': 278,
  29792. 'zero': 556,
  29793. 'one': 556,
  29794. 'two': 556,
  29795. 'three': 556,
  29796. 'four': 556,
  29797. 'five': 556,
  29798. 'six': 556,
  29799. 'seven': 556,
  29800. 'eight': 556,
  29801. 'nine': 556,
  29802. 'colon': 278,
  29803. 'semicolon': 278,
  29804. 'less': 584,
  29805. 'equal': 584,
  29806. 'greater': 584,
  29807. 'question': 556,
  29808. 'at': 1015,
  29809. 'A': 667,
  29810. 'B': 667,
  29811. 'C': 722,
  29812. 'D': 722,
  29813. 'E': 667,
  29814. 'F': 611,
  29815. 'G': 778,
  29816. 'H': 722,
  29817. 'I': 278,
  29818. 'J': 500,
  29819. 'K': 667,
  29820. 'L': 556,
  29821. 'M': 833,
  29822. 'N': 722,
  29823. 'O': 778,
  29824. 'P': 667,
  29825. 'Q': 778,
  29826. 'R': 722,
  29827. 'S': 667,
  29828. 'T': 611,
  29829. 'U': 722,
  29830. 'V': 667,
  29831. 'W': 944,
  29832. 'X': 667,
  29833. 'Y': 667,
  29834. 'Z': 611,
  29835. 'bracketleft': 278,
  29836. 'backslash': 278,
  29837. 'bracketright': 278,
  29838. 'asciicircum': 469,
  29839. 'underscore': 556,
  29840. 'quoteleft': 222,
  29841. 'a': 556,
  29842. 'b': 556,
  29843. 'c': 500,
  29844. 'd': 556,
  29845. 'e': 556,
  29846. 'f': 278,
  29847. 'g': 556,
  29848. 'h': 556,
  29849. 'i': 222,
  29850. 'j': 222,
  29851. 'k': 500,
  29852. 'l': 222,
  29853. 'm': 833,
  29854. 'n': 556,
  29855. 'o': 556,
  29856. 'p': 556,
  29857. 'q': 556,
  29858. 'r': 333,
  29859. 's': 500,
  29860. 't': 278,
  29861. 'u': 556,
  29862. 'v': 500,
  29863. 'w': 722,
  29864. 'x': 500,
  29865. 'y': 500,
  29866. 'z': 500,
  29867. 'braceleft': 334,
  29868. 'bar': 260,
  29869. 'braceright': 334,
  29870. 'asciitilde': 584,
  29871. 'exclamdown': 333,
  29872. 'cent': 556,
  29873. 'sterling': 556,
  29874. 'fraction': 167,
  29875. 'yen': 556,
  29876. 'florin': 556,
  29877. 'section': 556,
  29878. 'currency': 556,
  29879. 'quotesingle': 191,
  29880. 'quotedblleft': 333,
  29881. 'guillemotleft': 556,
  29882. 'guilsinglleft': 333,
  29883. 'guilsinglright': 333,
  29884. 'fi': 500,
  29885. 'fl': 500,
  29886. 'endash': 556,
  29887. 'dagger': 556,
  29888. 'daggerdbl': 556,
  29889. 'periodcentered': 278,
  29890. 'paragraph': 537,
  29891. 'bullet': 350,
  29892. 'quotesinglbase': 222,
  29893. 'quotedblbase': 333,
  29894. 'quotedblright': 333,
  29895. 'guillemotright': 556,
  29896. 'ellipsis': 1000,
  29897. 'perthousand': 1000,
  29898. 'questiondown': 611,
  29899. 'grave': 333,
  29900. 'acute': 333,
  29901. 'circumflex': 333,
  29902. 'tilde': 333,
  29903. 'macron': 333,
  29904. 'breve': 333,
  29905. 'dotaccent': 333,
  29906. 'dieresis': 333,
  29907. 'ring': 333,
  29908. 'cedilla': 333,
  29909. 'hungarumlaut': 333,
  29910. 'ogonek': 333,
  29911. 'caron': 333,
  29912. 'emdash': 1000,
  29913. 'AE': 1000,
  29914. 'ordfeminine': 370,
  29915. 'Lslash': 556,
  29916. 'Oslash': 778,
  29917. 'OE': 1000,
  29918. 'ordmasculine': 365,
  29919. 'ae': 889,
  29920. 'dotlessi': 278,
  29921. 'lslash': 222,
  29922. 'oslash': 611,
  29923. 'oe': 944,
  29924. 'germandbls': 611,
  29925. 'Idieresis': 278,
  29926. 'eacute': 556,
  29927. 'abreve': 556,
  29928. 'uhungarumlaut': 556,
  29929. 'ecaron': 556,
  29930. 'Ydieresis': 667,
  29931. 'divide': 584,
  29932. 'Yacute': 667,
  29933. 'Acircumflex': 667,
  29934. 'aacute': 556,
  29935. 'Ucircumflex': 722,
  29936. 'yacute': 500,
  29937. 'scommaaccent': 500,
  29938. 'ecircumflex': 556,
  29939. 'Uring': 722,
  29940. 'Udieresis': 722,
  29941. 'aogonek': 556,
  29942. 'Uacute': 722,
  29943. 'uogonek': 556,
  29944. 'Edieresis': 667,
  29945. 'Dcroat': 722,
  29946. 'commaaccent': 250,
  29947. 'copyright': 737,
  29948. 'Emacron': 667,
  29949. 'ccaron': 500,
  29950. 'aring': 556,
  29951. 'Ncommaaccent': 722,
  29952. 'lacute': 222,
  29953. 'agrave': 556,
  29954. 'Tcommaaccent': 611,
  29955. 'Cacute': 722,
  29956. 'atilde': 556,
  29957. 'Edotaccent': 667,
  29958. 'scaron': 500,
  29959. 'scedilla': 500,
  29960. 'iacute': 278,
  29961. 'lozenge': 471,
  29962. 'Rcaron': 722,
  29963. 'Gcommaaccent': 778,
  29964. 'ucircumflex': 556,
  29965. 'acircumflex': 556,
  29966. 'Amacron': 667,
  29967. 'rcaron': 333,
  29968. 'ccedilla': 500,
  29969. 'Zdotaccent': 611,
  29970. 'Thorn': 667,
  29971. 'Omacron': 778,
  29972. 'Racute': 722,
  29973. 'Sacute': 667,
  29974. 'dcaron': 643,
  29975. 'Umacron': 722,
  29976. 'uring': 556,
  29977. 'threesuperior': 333,
  29978. 'Ograve': 778,
  29979. 'Agrave': 667,
  29980. 'Abreve': 667,
  29981. 'multiply': 584,
  29982. 'uacute': 556,
  29983. 'Tcaron': 611,
  29984. 'partialdiff': 476,
  29985. 'ydieresis': 500,
  29986. 'Nacute': 722,
  29987. 'icircumflex': 278,
  29988. 'Ecircumflex': 667,
  29989. 'adieresis': 556,
  29990. 'edieresis': 556,
  29991. 'cacute': 500,
  29992. 'nacute': 556,
  29993. 'umacron': 556,
  29994. 'Ncaron': 722,
  29995. 'Iacute': 278,
  29996. 'plusminus': 584,
  29997. 'brokenbar': 260,
  29998. 'registered': 737,
  29999. 'Gbreve': 778,
  30000. 'Idotaccent': 278,
  30001. 'summation': 600,
  30002. 'Egrave': 667,
  30003. 'racute': 333,
  30004. 'omacron': 556,
  30005. 'Zacute': 611,
  30006. 'Zcaron': 611,
  30007. 'greaterequal': 549,
  30008. 'Eth': 722,
  30009. 'Ccedilla': 722,
  30010. 'lcommaaccent': 222,
  30011. 'tcaron': 317,
  30012. 'eogonek': 556,
  30013. 'Uogonek': 722,
  30014. 'Aacute': 667,
  30015. 'Adieresis': 667,
  30016. 'egrave': 556,
  30017. 'zacute': 500,
  30018. 'iogonek': 222,
  30019. 'Oacute': 778,
  30020. 'oacute': 556,
  30021. 'amacron': 556,
  30022. 'sacute': 500,
  30023. 'idieresis': 278,
  30024. 'Ocircumflex': 778,
  30025. 'Ugrave': 722,
  30026. 'Delta': 612,
  30027. 'thorn': 556,
  30028. 'twosuperior': 333,
  30029. 'Odieresis': 778,
  30030. 'mu': 556,
  30031. 'igrave': 278,
  30032. 'ohungarumlaut': 556,
  30033. 'Eogonek': 667,
  30034. 'dcroat': 556,
  30035. 'threequarters': 834,
  30036. 'Scedilla': 667,
  30037. 'lcaron': 299,
  30038. 'Kcommaaccent': 667,
  30039. 'Lacute': 556,
  30040. 'trademark': 1000,
  30041. 'edotaccent': 556,
  30042. 'Igrave': 278,
  30043. 'Imacron': 278,
  30044. 'Lcaron': 556,
  30045. 'onehalf': 834,
  30046. 'lessequal': 549,
  30047. 'ocircumflex': 556,
  30048. 'ntilde': 556,
  30049. 'Uhungarumlaut': 722,
  30050. 'Eacute': 667,
  30051. 'emacron': 556,
  30052. 'gbreve': 556,
  30053. 'onequarter': 834,
  30054. 'Scaron': 667,
  30055. 'Scommaaccent': 667,
  30056. 'Ohungarumlaut': 778,
  30057. 'degree': 400,
  30058. 'ograve': 556,
  30059. 'Ccaron': 722,
  30060. 'ugrave': 556,
  30061. 'radical': 453,
  30062. 'Dcaron': 722,
  30063. 'rcommaaccent': 333,
  30064. 'Ntilde': 722,
  30065. 'otilde': 556,
  30066. 'Rcommaaccent': 722,
  30067. 'Lcommaaccent': 556,
  30068. 'Atilde': 667,
  30069. 'Aogonek': 667,
  30070. 'Aring': 667,
  30071. 'Otilde': 778,
  30072. 'zdotaccent': 500,
  30073. 'Ecaron': 667,
  30074. 'Iogonek': 278,
  30075. 'kcommaaccent': 500,
  30076. 'minus': 584,
  30077. 'Icircumflex': 278,
  30078. 'ncaron': 556,
  30079. 'tcommaaccent': 278,
  30080. 'logicalnot': 584,
  30081. 'odieresis': 556,
  30082. 'udieresis': 556,
  30083. 'notequal': 549,
  30084. 'gcommaaccent': 556,
  30085. 'eth': 556,
  30086. 'zcaron': 500,
  30087. 'ncommaaccent': 556,
  30088. 'onesuperior': 333,
  30089. 'imacron': 278,
  30090. 'Euro': 556
  30091. },
  30092. 'Symbol': {
  30093. 'space': 250,
  30094. 'exclam': 333,
  30095. 'universal': 713,
  30096. 'numbersign': 500,
  30097. 'existential': 549,
  30098. 'percent': 833,
  30099. 'ampersand': 778,
  30100. 'suchthat': 439,
  30101. 'parenleft': 333,
  30102. 'parenright': 333,
  30103. 'asteriskmath': 500,
  30104. 'plus': 549,
  30105. 'comma': 250,
  30106. 'minus': 549,
  30107. 'period': 250,
  30108. 'slash': 278,
  30109. 'zero': 500,
  30110. 'one': 500,
  30111. 'two': 500,
  30112. 'three': 500,
  30113. 'four': 500,
  30114. 'five': 500,
  30115. 'six': 500,
  30116. 'seven': 500,
  30117. 'eight': 500,
  30118. 'nine': 500,
  30119. 'colon': 278,
  30120. 'semicolon': 278,
  30121. 'less': 549,
  30122. 'equal': 549,
  30123. 'greater': 549,
  30124. 'question': 444,
  30125. 'congruent': 549,
  30126. 'Alpha': 722,
  30127. 'Beta': 667,
  30128. 'Chi': 722,
  30129. 'Delta': 612,
  30130. 'Epsilon': 611,
  30131. 'Phi': 763,
  30132. 'Gamma': 603,
  30133. 'Eta': 722,
  30134. 'Iota': 333,
  30135. 'theta1': 631,
  30136. 'Kappa': 722,
  30137. 'Lambda': 686,
  30138. 'Mu': 889,
  30139. 'Nu': 722,
  30140. 'Omicron': 722,
  30141. 'Pi': 768,
  30142. 'Theta': 741,
  30143. 'Rho': 556,
  30144. 'Sigma': 592,
  30145. 'Tau': 611,
  30146. 'Upsilon': 690,
  30147. 'sigma1': 439,
  30148. 'Omega': 768,
  30149. 'Xi': 645,
  30150. 'Psi': 795,
  30151. 'Zeta': 611,
  30152. 'bracketleft': 333,
  30153. 'therefore': 863,
  30154. 'bracketright': 333,
  30155. 'perpendicular': 658,
  30156. 'underscore': 500,
  30157. 'radicalex': 500,
  30158. 'alpha': 631,
  30159. 'beta': 549,
  30160. 'chi': 549,
  30161. 'delta': 494,
  30162. 'epsilon': 439,
  30163. 'phi': 521,
  30164. 'gamma': 411,
  30165. 'eta': 603,
  30166. 'iota': 329,
  30167. 'phi1': 603,
  30168. 'kappa': 549,
  30169. 'lambda': 549,
  30170. 'mu': 576,
  30171. 'nu': 521,
  30172. 'omicron': 549,
  30173. 'pi': 549,
  30174. 'theta': 521,
  30175. 'rho': 549,
  30176. 'sigma': 603,
  30177. 'tau': 439,
  30178. 'upsilon': 576,
  30179. 'omega1': 713,
  30180. 'omega': 686,
  30181. 'xi': 493,
  30182. 'psi': 686,
  30183. 'zeta': 494,
  30184. 'braceleft': 480,
  30185. 'bar': 200,
  30186. 'braceright': 480,
  30187. 'similar': 549,
  30188. 'Euro': 750,
  30189. 'Upsilon1': 620,
  30190. 'minute': 247,
  30191. 'lessequal': 549,
  30192. 'fraction': 167,
  30193. 'infinity': 713,
  30194. 'florin': 500,
  30195. 'club': 753,
  30196. 'diamond': 753,
  30197. 'heart': 753,
  30198. 'spade': 753,
  30199. 'arrowboth': 1042,
  30200. 'arrowleft': 987,
  30201. 'arrowup': 603,
  30202. 'arrowright': 987,
  30203. 'arrowdown': 603,
  30204. 'degree': 400,
  30205. 'plusminus': 549,
  30206. 'second': 411,
  30207. 'greaterequal': 549,
  30208. 'multiply': 549,
  30209. 'proportional': 713,
  30210. 'partialdiff': 494,
  30211. 'bullet': 460,
  30212. 'divide': 549,
  30213. 'notequal': 549,
  30214. 'equivalence': 549,
  30215. 'approxequal': 549,
  30216. 'ellipsis': 1000,
  30217. 'arrowvertex': 603,
  30218. 'arrowhorizex': 1000,
  30219. 'carriagereturn': 658,
  30220. 'aleph': 823,
  30221. 'Ifraktur': 686,
  30222. 'Rfraktur': 795,
  30223. 'weierstrass': 987,
  30224. 'circlemultiply': 768,
  30225. 'circleplus': 768,
  30226. 'emptyset': 823,
  30227. 'intersection': 768,
  30228. 'union': 768,
  30229. 'propersuperset': 713,
  30230. 'reflexsuperset': 713,
  30231. 'notsubset': 713,
  30232. 'propersubset': 713,
  30233. 'reflexsubset': 713,
  30234. 'element': 713,
  30235. 'notelement': 713,
  30236. 'angle': 768,
  30237. 'gradient': 713,
  30238. 'registerserif': 790,
  30239. 'copyrightserif': 790,
  30240. 'trademarkserif': 890,
  30241. 'product': 823,
  30242. 'radical': 549,
  30243. 'dotmath': 250,
  30244. 'logicalnot': 713,
  30245. 'logicaland': 603,
  30246. 'logicalor': 603,
  30247. 'arrowdblboth': 1042,
  30248. 'arrowdblleft': 987,
  30249. 'arrowdblup': 603,
  30250. 'arrowdblright': 987,
  30251. 'arrowdbldown': 603,
  30252. 'lozenge': 494,
  30253. 'angleleft': 329,
  30254. 'registersans': 790,
  30255. 'copyrightsans': 790,
  30256. 'trademarksans': 786,
  30257. 'summation': 713,
  30258. 'parenlefttp': 384,
  30259. 'parenleftex': 384,
  30260. 'parenleftbt': 384,
  30261. 'bracketlefttp': 384,
  30262. 'bracketleftex': 384,
  30263. 'bracketleftbt': 384,
  30264. 'bracelefttp': 494,
  30265. 'braceleftmid': 494,
  30266. 'braceleftbt': 494,
  30267. 'braceex': 494,
  30268. 'angleright': 329,
  30269. 'integral': 274,
  30270. 'integraltp': 686,
  30271. 'integralex': 686,
  30272. 'integralbt': 686,
  30273. 'parenrighttp': 384,
  30274. 'parenrightex': 384,
  30275. 'parenrightbt': 384,
  30276. 'bracketrighttp': 384,
  30277. 'bracketrightex': 384,
  30278. 'bracketrightbt': 384,
  30279. 'bracerighttp': 494,
  30280. 'bracerightmid': 494,
  30281. 'bracerightbt': 494,
  30282. 'apple': 790
  30283. },
  30284. 'Times-Roman': {
  30285. 'space': 250,
  30286. 'exclam': 333,
  30287. 'quotedbl': 408,
  30288. 'numbersign': 500,
  30289. 'dollar': 500,
  30290. 'percent': 833,
  30291. 'ampersand': 778,
  30292. 'quoteright': 333,
  30293. 'parenleft': 333,
  30294. 'parenright': 333,
  30295. 'asterisk': 500,
  30296. 'plus': 564,
  30297. 'comma': 250,
  30298. 'hyphen': 333,
  30299. 'period': 250,
  30300. 'slash': 278,
  30301. 'zero': 500,
  30302. 'one': 500,
  30303. 'two': 500,
  30304. 'three': 500,
  30305. 'four': 500,
  30306. 'five': 500,
  30307. 'six': 500,
  30308. 'seven': 500,
  30309. 'eight': 500,
  30310. 'nine': 500,
  30311. 'colon': 278,
  30312. 'semicolon': 278,
  30313. 'less': 564,
  30314. 'equal': 564,
  30315. 'greater': 564,
  30316. 'question': 444,
  30317. 'at': 921,
  30318. 'A': 722,
  30319. 'B': 667,
  30320. 'C': 667,
  30321. 'D': 722,
  30322. 'E': 611,
  30323. 'F': 556,
  30324. 'G': 722,
  30325. 'H': 722,
  30326. 'I': 333,
  30327. 'J': 389,
  30328. 'K': 722,
  30329. 'L': 611,
  30330. 'M': 889,
  30331. 'N': 722,
  30332. 'O': 722,
  30333. 'P': 556,
  30334. 'Q': 722,
  30335. 'R': 667,
  30336. 'S': 556,
  30337. 'T': 611,
  30338. 'U': 722,
  30339. 'V': 722,
  30340. 'W': 944,
  30341. 'X': 722,
  30342. 'Y': 722,
  30343. 'Z': 611,
  30344. 'bracketleft': 333,
  30345. 'backslash': 278,
  30346. 'bracketright': 333,
  30347. 'asciicircum': 469,
  30348. 'underscore': 500,
  30349. 'quoteleft': 333,
  30350. 'a': 444,
  30351. 'b': 500,
  30352. 'c': 444,
  30353. 'd': 500,
  30354. 'e': 444,
  30355. 'f': 333,
  30356. 'g': 500,
  30357. 'h': 500,
  30358. 'i': 278,
  30359. 'j': 278,
  30360. 'k': 500,
  30361. 'l': 278,
  30362. 'm': 778,
  30363. 'n': 500,
  30364. 'o': 500,
  30365. 'p': 500,
  30366. 'q': 500,
  30367. 'r': 333,
  30368. 's': 389,
  30369. 't': 278,
  30370. 'u': 500,
  30371. 'v': 500,
  30372. 'w': 722,
  30373. 'x': 500,
  30374. 'y': 500,
  30375. 'z': 444,
  30376. 'braceleft': 480,
  30377. 'bar': 200,
  30378. 'braceright': 480,
  30379. 'asciitilde': 541,
  30380. 'exclamdown': 333,
  30381. 'cent': 500,
  30382. 'sterling': 500,
  30383. 'fraction': 167,
  30384. 'yen': 500,
  30385. 'florin': 500,
  30386. 'section': 500,
  30387. 'currency': 500,
  30388. 'quotesingle': 180,
  30389. 'quotedblleft': 444,
  30390. 'guillemotleft': 500,
  30391. 'guilsinglleft': 333,
  30392. 'guilsinglright': 333,
  30393. 'fi': 556,
  30394. 'fl': 556,
  30395. 'endash': 500,
  30396. 'dagger': 500,
  30397. 'daggerdbl': 500,
  30398. 'periodcentered': 250,
  30399. 'paragraph': 453,
  30400. 'bullet': 350,
  30401. 'quotesinglbase': 333,
  30402. 'quotedblbase': 444,
  30403. 'quotedblright': 444,
  30404. 'guillemotright': 500,
  30405. 'ellipsis': 1000,
  30406. 'perthousand': 1000,
  30407. 'questiondown': 444,
  30408. 'grave': 333,
  30409. 'acute': 333,
  30410. 'circumflex': 333,
  30411. 'tilde': 333,
  30412. 'macron': 333,
  30413. 'breve': 333,
  30414. 'dotaccent': 333,
  30415. 'dieresis': 333,
  30416. 'ring': 333,
  30417. 'cedilla': 333,
  30418. 'hungarumlaut': 333,
  30419. 'ogonek': 333,
  30420. 'caron': 333,
  30421. 'emdash': 1000,
  30422. 'AE': 889,
  30423. 'ordfeminine': 276,
  30424. 'Lslash': 611,
  30425. 'Oslash': 722,
  30426. 'OE': 889,
  30427. 'ordmasculine': 310,
  30428. 'ae': 667,
  30429. 'dotlessi': 278,
  30430. 'lslash': 278,
  30431. 'oslash': 500,
  30432. 'oe': 722,
  30433. 'germandbls': 500,
  30434. 'Idieresis': 333,
  30435. 'eacute': 444,
  30436. 'abreve': 444,
  30437. 'uhungarumlaut': 500,
  30438. 'ecaron': 444,
  30439. 'Ydieresis': 722,
  30440. 'divide': 564,
  30441. 'Yacute': 722,
  30442. 'Acircumflex': 722,
  30443. 'aacute': 444,
  30444. 'Ucircumflex': 722,
  30445. 'yacute': 500,
  30446. 'scommaaccent': 389,
  30447. 'ecircumflex': 444,
  30448. 'Uring': 722,
  30449. 'Udieresis': 722,
  30450. 'aogonek': 444,
  30451. 'Uacute': 722,
  30452. 'uogonek': 500,
  30453. 'Edieresis': 611,
  30454. 'Dcroat': 722,
  30455. 'commaaccent': 250,
  30456. 'copyright': 760,
  30457. 'Emacron': 611,
  30458. 'ccaron': 444,
  30459. 'aring': 444,
  30460. 'Ncommaaccent': 722,
  30461. 'lacute': 278,
  30462. 'agrave': 444,
  30463. 'Tcommaaccent': 611,
  30464. 'Cacute': 667,
  30465. 'atilde': 444,
  30466. 'Edotaccent': 611,
  30467. 'scaron': 389,
  30468. 'scedilla': 389,
  30469. 'iacute': 278,
  30470. 'lozenge': 471,
  30471. 'Rcaron': 667,
  30472. 'Gcommaaccent': 722,
  30473. 'ucircumflex': 500,
  30474. 'acircumflex': 444,
  30475. 'Amacron': 722,
  30476. 'rcaron': 333,
  30477. 'ccedilla': 444,
  30478. 'Zdotaccent': 611,
  30479. 'Thorn': 556,
  30480. 'Omacron': 722,
  30481. 'Racute': 667,
  30482. 'Sacute': 556,
  30483. 'dcaron': 588,
  30484. 'Umacron': 722,
  30485. 'uring': 500,
  30486. 'threesuperior': 300,
  30487. 'Ograve': 722,
  30488. 'Agrave': 722,
  30489. 'Abreve': 722,
  30490. 'multiply': 564,
  30491. 'uacute': 500,
  30492. 'Tcaron': 611,
  30493. 'partialdiff': 476,
  30494. 'ydieresis': 500,
  30495. 'Nacute': 722,
  30496. 'icircumflex': 278,
  30497. 'Ecircumflex': 611,
  30498. 'adieresis': 444,
  30499. 'edieresis': 444,
  30500. 'cacute': 444,
  30501. 'nacute': 500,
  30502. 'umacron': 500,
  30503. 'Ncaron': 722,
  30504. 'Iacute': 333,
  30505. 'plusminus': 564,
  30506. 'brokenbar': 200,
  30507. 'registered': 760,
  30508. 'Gbreve': 722,
  30509. 'Idotaccent': 333,
  30510. 'summation': 600,
  30511. 'Egrave': 611,
  30512. 'racute': 333,
  30513. 'omacron': 500,
  30514. 'Zacute': 611,
  30515. 'Zcaron': 611,
  30516. 'greaterequal': 549,
  30517. 'Eth': 722,
  30518. 'Ccedilla': 667,
  30519. 'lcommaaccent': 278,
  30520. 'tcaron': 326,
  30521. 'eogonek': 444,
  30522. 'Uogonek': 722,
  30523. 'Aacute': 722,
  30524. 'Adieresis': 722,
  30525. 'egrave': 444,
  30526. 'zacute': 444,
  30527. 'iogonek': 278,
  30528. 'Oacute': 722,
  30529. 'oacute': 500,
  30530. 'amacron': 444,
  30531. 'sacute': 389,
  30532. 'idieresis': 278,
  30533. 'Ocircumflex': 722,
  30534. 'Ugrave': 722,
  30535. 'Delta': 612,
  30536. 'thorn': 500,
  30537. 'twosuperior': 300,
  30538. 'Odieresis': 722,
  30539. 'mu': 500,
  30540. 'igrave': 278,
  30541. 'ohungarumlaut': 500,
  30542. 'Eogonek': 611,
  30543. 'dcroat': 500,
  30544. 'threequarters': 750,
  30545. 'Scedilla': 556,
  30546. 'lcaron': 344,
  30547. 'Kcommaaccent': 722,
  30548. 'Lacute': 611,
  30549. 'trademark': 980,
  30550. 'edotaccent': 444,
  30551. 'Igrave': 333,
  30552. 'Imacron': 333,
  30553. 'Lcaron': 611,
  30554. 'onehalf': 750,
  30555. 'lessequal': 549,
  30556. 'ocircumflex': 500,
  30557. 'ntilde': 500,
  30558. 'Uhungarumlaut': 722,
  30559. 'Eacute': 611,
  30560. 'emacron': 444,
  30561. 'gbreve': 500,
  30562. 'onequarter': 750,
  30563. 'Scaron': 556,
  30564. 'Scommaaccent': 556,
  30565. 'Ohungarumlaut': 722,
  30566. 'degree': 400,
  30567. 'ograve': 500,
  30568. 'Ccaron': 667,
  30569. 'ugrave': 500,
  30570. 'radical': 453,
  30571. 'Dcaron': 722,
  30572. 'rcommaaccent': 333,
  30573. 'Ntilde': 722,
  30574. 'otilde': 500,
  30575. 'Rcommaaccent': 667,
  30576. 'Lcommaaccent': 611,
  30577. 'Atilde': 722,
  30578. 'Aogonek': 722,
  30579. 'Aring': 722,
  30580. 'Otilde': 722,
  30581. 'zdotaccent': 444,
  30582. 'Ecaron': 611,
  30583. 'Iogonek': 333,
  30584. 'kcommaaccent': 500,
  30585. 'minus': 564,
  30586. 'Icircumflex': 333,
  30587. 'ncaron': 500,
  30588. 'tcommaaccent': 278,
  30589. 'logicalnot': 564,
  30590. 'odieresis': 500,
  30591. 'udieresis': 500,
  30592. 'notequal': 549,
  30593. 'gcommaaccent': 500,
  30594. 'eth': 500,
  30595. 'zcaron': 444,
  30596. 'ncommaaccent': 500,
  30597. 'onesuperior': 300,
  30598. 'imacron': 278,
  30599. 'Euro': 500
  30600. },
  30601. 'Times-Bold': {
  30602. 'space': 250,
  30603. 'exclam': 333,
  30604. 'quotedbl': 555,
  30605. 'numbersign': 500,
  30606. 'dollar': 500,
  30607. 'percent': 1000,
  30608. 'ampersand': 833,
  30609. 'quoteright': 333,
  30610. 'parenleft': 333,
  30611. 'parenright': 333,
  30612. 'asterisk': 500,
  30613. 'plus': 570,
  30614. 'comma': 250,
  30615. 'hyphen': 333,
  30616. 'period': 250,
  30617. 'slash': 278,
  30618. 'zero': 500,
  30619. 'one': 500,
  30620. 'two': 500,
  30621. 'three': 500,
  30622. 'four': 500,
  30623. 'five': 500,
  30624. 'six': 500,
  30625. 'seven': 500,
  30626. 'eight': 500,
  30627. 'nine': 500,
  30628. 'colon': 333,
  30629. 'semicolon': 333,
  30630. 'less': 570,
  30631. 'equal': 570,
  30632. 'greater': 570,
  30633. 'question': 500,
  30634. 'at': 930,
  30635. 'A': 722,
  30636. 'B': 667,
  30637. 'C': 722,
  30638. 'D': 722,
  30639. 'E': 667,
  30640. 'F': 611,
  30641. 'G': 778,
  30642. 'H': 778,
  30643. 'I': 389,
  30644. 'J': 500,
  30645. 'K': 778,
  30646. 'L': 667,
  30647. 'M': 944,
  30648. 'N': 722,
  30649. 'O': 778,
  30650. 'P': 611,
  30651. 'Q': 778,
  30652. 'R': 722,
  30653. 'S': 556,
  30654. 'T': 667,
  30655. 'U': 722,
  30656. 'V': 722,
  30657. 'W': 1000,
  30658. 'X': 722,
  30659. 'Y': 722,
  30660. 'Z': 667,
  30661. 'bracketleft': 333,
  30662. 'backslash': 278,
  30663. 'bracketright': 333,
  30664. 'asciicircum': 581,
  30665. 'underscore': 500,
  30666. 'quoteleft': 333,
  30667. 'a': 500,
  30668. 'b': 556,
  30669. 'c': 444,
  30670. 'd': 556,
  30671. 'e': 444,
  30672. 'f': 333,
  30673. 'g': 500,
  30674. 'h': 556,
  30675. 'i': 278,
  30676. 'j': 333,
  30677. 'k': 556,
  30678. 'l': 278,
  30679. 'm': 833,
  30680. 'n': 556,
  30681. 'o': 500,
  30682. 'p': 556,
  30683. 'q': 556,
  30684. 'r': 444,
  30685. 's': 389,
  30686. 't': 333,
  30687. 'u': 556,
  30688. 'v': 500,
  30689. 'w': 722,
  30690. 'x': 500,
  30691. 'y': 500,
  30692. 'z': 444,
  30693. 'braceleft': 394,
  30694. 'bar': 220,
  30695. 'braceright': 394,
  30696. 'asciitilde': 520,
  30697. 'exclamdown': 333,
  30698. 'cent': 500,
  30699. 'sterling': 500,
  30700. 'fraction': 167,
  30701. 'yen': 500,
  30702. 'florin': 500,
  30703. 'section': 500,
  30704. 'currency': 500,
  30705. 'quotesingle': 278,
  30706. 'quotedblleft': 500,
  30707. 'guillemotleft': 500,
  30708. 'guilsinglleft': 333,
  30709. 'guilsinglright': 333,
  30710. 'fi': 556,
  30711. 'fl': 556,
  30712. 'endash': 500,
  30713. 'dagger': 500,
  30714. 'daggerdbl': 500,
  30715. 'periodcentered': 250,
  30716. 'paragraph': 540,
  30717. 'bullet': 350,
  30718. 'quotesinglbase': 333,
  30719. 'quotedblbase': 500,
  30720. 'quotedblright': 500,
  30721. 'guillemotright': 500,
  30722. 'ellipsis': 1000,
  30723. 'perthousand': 1000,
  30724. 'questiondown': 500,
  30725. 'grave': 333,
  30726. 'acute': 333,
  30727. 'circumflex': 333,
  30728. 'tilde': 333,
  30729. 'macron': 333,
  30730. 'breve': 333,
  30731. 'dotaccent': 333,
  30732. 'dieresis': 333,
  30733. 'ring': 333,
  30734. 'cedilla': 333,
  30735. 'hungarumlaut': 333,
  30736. 'ogonek': 333,
  30737. 'caron': 333,
  30738. 'emdash': 1000,
  30739. 'AE': 1000,
  30740. 'ordfeminine': 300,
  30741. 'Lslash': 667,
  30742. 'Oslash': 778,
  30743. 'OE': 1000,
  30744. 'ordmasculine': 330,
  30745. 'ae': 722,
  30746. 'dotlessi': 278,
  30747. 'lslash': 278,
  30748. 'oslash': 500,
  30749. 'oe': 722,
  30750. 'germandbls': 556,
  30751. 'Idieresis': 389,
  30752. 'eacute': 444,
  30753. 'abreve': 500,
  30754. 'uhungarumlaut': 556,
  30755. 'ecaron': 444,
  30756. 'Ydieresis': 722,
  30757. 'divide': 570,
  30758. 'Yacute': 722,
  30759. 'Acircumflex': 722,
  30760. 'aacute': 500,
  30761. 'Ucircumflex': 722,
  30762. 'yacute': 500,
  30763. 'scommaaccent': 389,
  30764. 'ecircumflex': 444,
  30765. 'Uring': 722,
  30766. 'Udieresis': 722,
  30767. 'aogonek': 500,
  30768. 'Uacute': 722,
  30769. 'uogonek': 556,
  30770. 'Edieresis': 667,
  30771. 'Dcroat': 722,
  30772. 'commaaccent': 250,
  30773. 'copyright': 747,
  30774. 'Emacron': 667,
  30775. 'ccaron': 444,
  30776. 'aring': 500,
  30777. 'Ncommaaccent': 722,
  30778. 'lacute': 278,
  30779. 'agrave': 500,
  30780. 'Tcommaaccent': 667,
  30781. 'Cacute': 722,
  30782. 'atilde': 500,
  30783. 'Edotaccent': 667,
  30784. 'scaron': 389,
  30785. 'scedilla': 389,
  30786. 'iacute': 278,
  30787. 'lozenge': 494,
  30788. 'Rcaron': 722,
  30789. 'Gcommaaccent': 778,
  30790. 'ucircumflex': 556,
  30791. 'acircumflex': 500,
  30792. 'Amacron': 722,
  30793. 'rcaron': 444,
  30794. 'ccedilla': 444,
  30795. 'Zdotaccent': 667,
  30796. 'Thorn': 611,
  30797. 'Omacron': 778,
  30798. 'Racute': 722,
  30799. 'Sacute': 556,
  30800. 'dcaron': 672,
  30801. 'Umacron': 722,
  30802. 'uring': 556,
  30803. 'threesuperior': 300,
  30804. 'Ograve': 778,
  30805. 'Agrave': 722,
  30806. 'Abreve': 722,
  30807. 'multiply': 570,
  30808. 'uacute': 556,
  30809. 'Tcaron': 667,
  30810. 'partialdiff': 494,
  30811. 'ydieresis': 500,
  30812. 'Nacute': 722,
  30813. 'icircumflex': 278,
  30814. 'Ecircumflex': 667,
  30815. 'adieresis': 500,
  30816. 'edieresis': 444,
  30817. 'cacute': 444,
  30818. 'nacute': 556,
  30819. 'umacron': 556,
  30820. 'Ncaron': 722,
  30821. 'Iacute': 389,
  30822. 'plusminus': 570,
  30823. 'brokenbar': 220,
  30824. 'registered': 747,
  30825. 'Gbreve': 778,
  30826. 'Idotaccent': 389,
  30827. 'summation': 600,
  30828. 'Egrave': 667,
  30829. 'racute': 444,
  30830. 'omacron': 500,
  30831. 'Zacute': 667,
  30832. 'Zcaron': 667,
  30833. 'greaterequal': 549,
  30834. 'Eth': 722,
  30835. 'Ccedilla': 722,
  30836. 'lcommaaccent': 278,
  30837. 'tcaron': 416,
  30838. 'eogonek': 444,
  30839. 'Uogonek': 722,
  30840. 'Aacute': 722,
  30841. 'Adieresis': 722,
  30842. 'egrave': 444,
  30843. 'zacute': 444,
  30844. 'iogonek': 278,
  30845. 'Oacute': 778,
  30846. 'oacute': 500,
  30847. 'amacron': 500,
  30848. 'sacute': 389,
  30849. 'idieresis': 278,
  30850. 'Ocircumflex': 778,
  30851. 'Ugrave': 722,
  30852. 'Delta': 612,
  30853. 'thorn': 556,
  30854. 'twosuperior': 300,
  30855. 'Odieresis': 778,
  30856. 'mu': 556,
  30857. 'igrave': 278,
  30858. 'ohungarumlaut': 500,
  30859. 'Eogonek': 667,
  30860. 'dcroat': 556,
  30861. 'threequarters': 750,
  30862. 'Scedilla': 556,
  30863. 'lcaron': 394,
  30864. 'Kcommaaccent': 778,
  30865. 'Lacute': 667,
  30866. 'trademark': 1000,
  30867. 'edotaccent': 444,
  30868. 'Igrave': 389,
  30869. 'Imacron': 389,
  30870. 'Lcaron': 667,
  30871. 'onehalf': 750,
  30872. 'lessequal': 549,
  30873. 'ocircumflex': 500,
  30874. 'ntilde': 556,
  30875. 'Uhungarumlaut': 722,
  30876. 'Eacute': 667,
  30877. 'emacron': 444,
  30878. 'gbreve': 500,
  30879. 'onequarter': 750,
  30880. 'Scaron': 556,
  30881. 'Scommaaccent': 556,
  30882. 'Ohungarumlaut': 778,
  30883. 'degree': 400,
  30884. 'ograve': 500,
  30885. 'Ccaron': 722,
  30886. 'ugrave': 556,
  30887. 'radical': 549,
  30888. 'Dcaron': 722,
  30889. 'rcommaaccent': 444,
  30890. 'Ntilde': 722,
  30891. 'otilde': 500,
  30892. 'Rcommaaccent': 722,
  30893. 'Lcommaaccent': 667,
  30894. 'Atilde': 722,
  30895. 'Aogonek': 722,
  30896. 'Aring': 722,
  30897. 'Otilde': 778,
  30898. 'zdotaccent': 444,
  30899. 'Ecaron': 667,
  30900. 'Iogonek': 389,
  30901. 'kcommaaccent': 556,
  30902. 'minus': 570,
  30903. 'Icircumflex': 389,
  30904. 'ncaron': 556,
  30905. 'tcommaaccent': 333,
  30906. 'logicalnot': 570,
  30907. 'odieresis': 500,
  30908. 'udieresis': 556,
  30909. 'notequal': 549,
  30910. 'gcommaaccent': 500,
  30911. 'eth': 500,
  30912. 'zcaron': 444,
  30913. 'ncommaaccent': 556,
  30914. 'onesuperior': 300,
  30915. 'imacron': 278,
  30916. 'Euro': 500
  30917. },
  30918. 'Times-BoldItalic': {
  30919. 'space': 250,
  30920. 'exclam': 389,
  30921. 'quotedbl': 555,
  30922. 'numbersign': 500,
  30923. 'dollar': 500,
  30924. 'percent': 833,
  30925. 'ampersand': 778,
  30926. 'quoteright': 333,
  30927. 'parenleft': 333,
  30928. 'parenright': 333,
  30929. 'asterisk': 500,
  30930. 'plus': 570,
  30931. 'comma': 250,
  30932. 'hyphen': 333,
  30933. 'period': 250,
  30934. 'slash': 278,
  30935. 'zero': 500,
  30936. 'one': 500,
  30937. 'two': 500,
  30938. 'three': 500,
  30939. 'four': 500,
  30940. 'five': 500,
  30941. 'six': 500,
  30942. 'seven': 500,
  30943. 'eight': 500,
  30944. 'nine': 500,
  30945. 'colon': 333,
  30946. 'semicolon': 333,
  30947. 'less': 570,
  30948. 'equal': 570,
  30949. 'greater': 570,
  30950. 'question': 500,
  30951. 'at': 832,
  30952. 'A': 667,
  30953. 'B': 667,
  30954. 'C': 667,
  30955. 'D': 722,
  30956. 'E': 667,
  30957. 'F': 667,
  30958. 'G': 722,
  30959. 'H': 778,
  30960. 'I': 389,
  30961. 'J': 500,
  30962. 'K': 667,
  30963. 'L': 611,
  30964. 'M': 889,
  30965. 'N': 722,
  30966. 'O': 722,
  30967. 'P': 611,
  30968. 'Q': 722,
  30969. 'R': 667,
  30970. 'S': 556,
  30971. 'T': 611,
  30972. 'U': 722,
  30973. 'V': 667,
  30974. 'W': 889,
  30975. 'X': 667,
  30976. 'Y': 611,
  30977. 'Z': 611,
  30978. 'bracketleft': 333,
  30979. 'backslash': 278,
  30980. 'bracketright': 333,
  30981. 'asciicircum': 570,
  30982. 'underscore': 500,
  30983. 'quoteleft': 333,
  30984. 'a': 500,
  30985. 'b': 500,
  30986. 'c': 444,
  30987. 'd': 500,
  30988. 'e': 444,
  30989. 'f': 333,
  30990. 'g': 500,
  30991. 'h': 556,
  30992. 'i': 278,
  30993. 'j': 278,
  30994. 'k': 500,
  30995. 'l': 278,
  30996. 'm': 778,
  30997. 'n': 556,
  30998. 'o': 500,
  30999. 'p': 500,
  31000. 'q': 500,
  31001. 'r': 389,
  31002. 's': 389,
  31003. 't': 278,
  31004. 'u': 556,
  31005. 'v': 444,
  31006. 'w': 667,
  31007. 'x': 500,
  31008. 'y': 444,
  31009. 'z': 389,
  31010. 'braceleft': 348,
  31011. 'bar': 220,
  31012. 'braceright': 348,
  31013. 'asciitilde': 570,
  31014. 'exclamdown': 389,
  31015. 'cent': 500,
  31016. 'sterling': 500,
  31017. 'fraction': 167,
  31018. 'yen': 500,
  31019. 'florin': 500,
  31020. 'section': 500,
  31021. 'currency': 500,
  31022. 'quotesingle': 278,
  31023. 'quotedblleft': 500,
  31024. 'guillemotleft': 500,
  31025. 'guilsinglleft': 333,
  31026. 'guilsinglright': 333,
  31027. 'fi': 556,
  31028. 'fl': 556,
  31029. 'endash': 500,
  31030. 'dagger': 500,
  31031. 'daggerdbl': 500,
  31032. 'periodcentered': 250,
  31033. 'paragraph': 500,
  31034. 'bullet': 350,
  31035. 'quotesinglbase': 333,
  31036. 'quotedblbase': 500,
  31037. 'quotedblright': 500,
  31038. 'guillemotright': 500,
  31039. 'ellipsis': 1000,
  31040. 'perthousand': 1000,
  31041. 'questiondown': 500,
  31042. 'grave': 333,
  31043. 'acute': 333,
  31044. 'circumflex': 333,
  31045. 'tilde': 333,
  31046. 'macron': 333,
  31047. 'breve': 333,
  31048. 'dotaccent': 333,
  31049. 'dieresis': 333,
  31050. 'ring': 333,
  31051. 'cedilla': 333,
  31052. 'hungarumlaut': 333,
  31053. 'ogonek': 333,
  31054. 'caron': 333,
  31055. 'emdash': 1000,
  31056. 'AE': 944,
  31057. 'ordfeminine': 266,
  31058. 'Lslash': 611,
  31059. 'Oslash': 722,
  31060. 'OE': 944,
  31061. 'ordmasculine': 300,
  31062. 'ae': 722,
  31063. 'dotlessi': 278,
  31064. 'lslash': 278,
  31065. 'oslash': 500,
  31066. 'oe': 722,
  31067. 'germandbls': 500,
  31068. 'Idieresis': 389,
  31069. 'eacute': 444,
  31070. 'abreve': 500,
  31071. 'uhungarumlaut': 556,
  31072. 'ecaron': 444,
  31073. 'Ydieresis': 611,
  31074. 'divide': 570,
  31075. 'Yacute': 611,
  31076. 'Acircumflex': 667,
  31077. 'aacute': 500,
  31078. 'Ucircumflex': 722,
  31079. 'yacute': 444,
  31080. 'scommaaccent': 389,
  31081. 'ecircumflex': 444,
  31082. 'Uring': 722,
  31083. 'Udieresis': 722,
  31084. 'aogonek': 500,
  31085. 'Uacute': 722,
  31086. 'uogonek': 556,
  31087. 'Edieresis': 667,
  31088. 'Dcroat': 722,
  31089. 'commaaccent': 250,
  31090. 'copyright': 747,
  31091. 'Emacron': 667,
  31092. 'ccaron': 444,
  31093. 'aring': 500,
  31094. 'Ncommaaccent': 722,
  31095. 'lacute': 278,
  31096. 'agrave': 500,
  31097. 'Tcommaaccent': 611,
  31098. 'Cacute': 667,
  31099. 'atilde': 500,
  31100. 'Edotaccent': 667,
  31101. 'scaron': 389,
  31102. 'scedilla': 389,
  31103. 'iacute': 278,
  31104. 'lozenge': 494,
  31105. 'Rcaron': 667,
  31106. 'Gcommaaccent': 722,
  31107. 'ucircumflex': 556,
  31108. 'acircumflex': 500,
  31109. 'Amacron': 667,
  31110. 'rcaron': 389,
  31111. 'ccedilla': 444,
  31112. 'Zdotaccent': 611,
  31113. 'Thorn': 611,
  31114. 'Omacron': 722,
  31115. 'Racute': 667,
  31116. 'Sacute': 556,
  31117. 'dcaron': 608,
  31118. 'Umacron': 722,
  31119. 'uring': 556,
  31120. 'threesuperior': 300,
  31121. 'Ograve': 722,
  31122. 'Agrave': 667,
  31123. 'Abreve': 667,
  31124. 'multiply': 570,
  31125. 'uacute': 556,
  31126. 'Tcaron': 611,
  31127. 'partialdiff': 494,
  31128. 'ydieresis': 444,
  31129. 'Nacute': 722,
  31130. 'icircumflex': 278,
  31131. 'Ecircumflex': 667,
  31132. 'adieresis': 500,
  31133. 'edieresis': 444,
  31134. 'cacute': 444,
  31135. 'nacute': 556,
  31136. 'umacron': 556,
  31137. 'Ncaron': 722,
  31138. 'Iacute': 389,
  31139. 'plusminus': 570,
  31140. 'brokenbar': 220,
  31141. 'registered': 747,
  31142. 'Gbreve': 722,
  31143. 'Idotaccent': 389,
  31144. 'summation': 600,
  31145. 'Egrave': 667,
  31146. 'racute': 389,
  31147. 'omacron': 500,
  31148. 'Zacute': 611,
  31149. 'Zcaron': 611,
  31150. 'greaterequal': 549,
  31151. 'Eth': 722,
  31152. 'Ccedilla': 667,
  31153. 'lcommaaccent': 278,
  31154. 'tcaron': 366,
  31155. 'eogonek': 444,
  31156. 'Uogonek': 722,
  31157. 'Aacute': 667,
  31158. 'Adieresis': 667,
  31159. 'egrave': 444,
  31160. 'zacute': 389,
  31161. 'iogonek': 278,
  31162. 'Oacute': 722,
  31163. 'oacute': 500,
  31164. 'amacron': 500,
  31165. 'sacute': 389,
  31166. 'idieresis': 278,
  31167. 'Ocircumflex': 722,
  31168. 'Ugrave': 722,
  31169. 'Delta': 612,
  31170. 'thorn': 500,
  31171. 'twosuperior': 300,
  31172. 'Odieresis': 722,
  31173. 'mu': 576,
  31174. 'igrave': 278,
  31175. 'ohungarumlaut': 500,
  31176. 'Eogonek': 667,
  31177. 'dcroat': 500,
  31178. 'threequarters': 750,
  31179. 'Scedilla': 556,
  31180. 'lcaron': 382,
  31181. 'Kcommaaccent': 667,
  31182. 'Lacute': 611,
  31183. 'trademark': 1000,
  31184. 'edotaccent': 444,
  31185. 'Igrave': 389,
  31186. 'Imacron': 389,
  31187. 'Lcaron': 611,
  31188. 'onehalf': 750,
  31189. 'lessequal': 549,
  31190. 'ocircumflex': 500,
  31191. 'ntilde': 556,
  31192. 'Uhungarumlaut': 722,
  31193. 'Eacute': 667,
  31194. 'emacron': 444,
  31195. 'gbreve': 500,
  31196. 'onequarter': 750,
  31197. 'Scaron': 556,
  31198. 'Scommaaccent': 556,
  31199. 'Ohungarumlaut': 722,
  31200. 'degree': 400,
  31201. 'ograve': 500,
  31202. 'Ccaron': 667,
  31203. 'ugrave': 556,
  31204. 'radical': 549,
  31205. 'Dcaron': 722,
  31206. 'rcommaaccent': 389,
  31207. 'Ntilde': 722,
  31208. 'otilde': 500,
  31209. 'Rcommaaccent': 667,
  31210. 'Lcommaaccent': 611,
  31211. 'Atilde': 667,
  31212. 'Aogonek': 667,
  31213. 'Aring': 667,
  31214. 'Otilde': 722,
  31215. 'zdotaccent': 389,
  31216. 'Ecaron': 667,
  31217. 'Iogonek': 389,
  31218. 'kcommaaccent': 500,
  31219. 'minus': 606,
  31220. 'Icircumflex': 389,
  31221. 'ncaron': 556,
  31222. 'tcommaaccent': 278,
  31223. 'logicalnot': 606,
  31224. 'odieresis': 500,
  31225. 'udieresis': 556,
  31226. 'notequal': 549,
  31227. 'gcommaaccent': 500,
  31228. 'eth': 500,
  31229. 'zcaron': 389,
  31230. 'ncommaaccent': 556,
  31231. 'onesuperior': 300,
  31232. 'imacron': 278,
  31233. 'Euro': 500
  31234. },
  31235. 'Times-Italic': {
  31236. 'space': 250,
  31237. 'exclam': 333,
  31238. 'quotedbl': 420,
  31239. 'numbersign': 500,
  31240. 'dollar': 500,
  31241. 'percent': 833,
  31242. 'ampersand': 778,
  31243. 'quoteright': 333,
  31244. 'parenleft': 333,
  31245. 'parenright': 333,
  31246. 'asterisk': 500,
  31247. 'plus': 675,
  31248. 'comma': 250,
  31249. 'hyphen': 333,
  31250. 'period': 250,
  31251. 'slash': 278,
  31252. 'zero': 500,
  31253. 'one': 500,
  31254. 'two': 500,
  31255. 'three': 500,
  31256. 'four': 500,
  31257. 'five': 500,
  31258. 'six': 500,
  31259. 'seven': 500,
  31260. 'eight': 500,
  31261. 'nine': 500,
  31262. 'colon': 333,
  31263. 'semicolon': 333,
  31264. 'less': 675,
  31265. 'equal': 675,
  31266. 'greater': 675,
  31267. 'question': 500,
  31268. 'at': 920,
  31269. 'A': 611,
  31270. 'B': 611,
  31271. 'C': 667,
  31272. 'D': 722,
  31273. 'E': 611,
  31274. 'F': 611,
  31275. 'G': 722,
  31276. 'H': 722,
  31277. 'I': 333,
  31278. 'J': 444,
  31279. 'K': 667,
  31280. 'L': 556,
  31281. 'M': 833,
  31282. 'N': 667,
  31283. 'O': 722,
  31284. 'P': 611,
  31285. 'Q': 722,
  31286. 'R': 611,
  31287. 'S': 500,
  31288. 'T': 556,
  31289. 'U': 722,
  31290. 'V': 611,
  31291. 'W': 833,
  31292. 'X': 611,
  31293. 'Y': 556,
  31294. 'Z': 556,
  31295. 'bracketleft': 389,
  31296. 'backslash': 278,
  31297. 'bracketright': 389,
  31298. 'asciicircum': 422,
  31299. 'underscore': 500,
  31300. 'quoteleft': 333,
  31301. 'a': 500,
  31302. 'b': 500,
  31303. 'c': 444,
  31304. 'd': 500,
  31305. 'e': 444,
  31306. 'f': 278,
  31307. 'g': 500,
  31308. 'h': 500,
  31309. 'i': 278,
  31310. 'j': 278,
  31311. 'k': 444,
  31312. 'l': 278,
  31313. 'm': 722,
  31314. 'n': 500,
  31315. 'o': 500,
  31316. 'p': 500,
  31317. 'q': 500,
  31318. 'r': 389,
  31319. 's': 389,
  31320. 't': 278,
  31321. 'u': 500,
  31322. 'v': 444,
  31323. 'w': 667,
  31324. 'x': 444,
  31325. 'y': 444,
  31326. 'z': 389,
  31327. 'braceleft': 400,
  31328. 'bar': 275,
  31329. 'braceright': 400,
  31330. 'asciitilde': 541,
  31331. 'exclamdown': 389,
  31332. 'cent': 500,
  31333. 'sterling': 500,
  31334. 'fraction': 167,
  31335. 'yen': 500,
  31336. 'florin': 500,
  31337. 'section': 500,
  31338. 'currency': 500,
  31339. 'quotesingle': 214,
  31340. 'quotedblleft': 556,
  31341. 'guillemotleft': 500,
  31342. 'guilsinglleft': 333,
  31343. 'guilsinglright': 333,
  31344. 'fi': 500,
  31345. 'fl': 500,
  31346. 'endash': 500,
  31347. 'dagger': 500,
  31348. 'daggerdbl': 500,
  31349. 'periodcentered': 250,
  31350. 'paragraph': 523,
  31351. 'bullet': 350,
  31352. 'quotesinglbase': 333,
  31353. 'quotedblbase': 556,
  31354. 'quotedblright': 556,
  31355. 'guillemotright': 500,
  31356. 'ellipsis': 889,
  31357. 'perthousand': 1000,
  31358. 'questiondown': 500,
  31359. 'grave': 333,
  31360. 'acute': 333,
  31361. 'circumflex': 333,
  31362. 'tilde': 333,
  31363. 'macron': 333,
  31364. 'breve': 333,
  31365. 'dotaccent': 333,
  31366. 'dieresis': 333,
  31367. 'ring': 333,
  31368. 'cedilla': 333,
  31369. 'hungarumlaut': 333,
  31370. 'ogonek': 333,
  31371. 'caron': 333,
  31372. 'emdash': 889,
  31373. 'AE': 889,
  31374. 'ordfeminine': 276,
  31375. 'Lslash': 556,
  31376. 'Oslash': 722,
  31377. 'OE': 944,
  31378. 'ordmasculine': 310,
  31379. 'ae': 667,
  31380. 'dotlessi': 278,
  31381. 'lslash': 278,
  31382. 'oslash': 500,
  31383. 'oe': 667,
  31384. 'germandbls': 500,
  31385. 'Idieresis': 333,
  31386. 'eacute': 444,
  31387. 'abreve': 500,
  31388. 'uhungarumlaut': 500,
  31389. 'ecaron': 444,
  31390. 'Ydieresis': 556,
  31391. 'divide': 675,
  31392. 'Yacute': 556,
  31393. 'Acircumflex': 611,
  31394. 'aacute': 500,
  31395. 'Ucircumflex': 722,
  31396. 'yacute': 444,
  31397. 'scommaaccent': 389,
  31398. 'ecircumflex': 444,
  31399. 'Uring': 722,
  31400. 'Udieresis': 722,
  31401. 'aogonek': 500,
  31402. 'Uacute': 722,
  31403. 'uogonek': 500,
  31404. 'Edieresis': 611,
  31405. 'Dcroat': 722,
  31406. 'commaaccent': 250,
  31407. 'copyright': 760,
  31408. 'Emacron': 611,
  31409. 'ccaron': 444,
  31410. 'aring': 500,
  31411. 'Ncommaaccent': 667,
  31412. 'lacute': 278,
  31413. 'agrave': 500,
  31414. 'Tcommaaccent': 556,
  31415. 'Cacute': 667,
  31416. 'atilde': 500,
  31417. 'Edotaccent': 611,
  31418. 'scaron': 389,
  31419. 'scedilla': 389,
  31420. 'iacute': 278,
  31421. 'lozenge': 471,
  31422. 'Rcaron': 611,
  31423. 'Gcommaaccent': 722,
  31424. 'ucircumflex': 500,
  31425. 'acircumflex': 500,
  31426. 'Amacron': 611,
  31427. 'rcaron': 389,
  31428. 'ccedilla': 444,
  31429. 'Zdotaccent': 556,
  31430. 'Thorn': 611,
  31431. 'Omacron': 722,
  31432. 'Racute': 611,
  31433. 'Sacute': 500,
  31434. 'dcaron': 544,
  31435. 'Umacron': 722,
  31436. 'uring': 500,
  31437. 'threesuperior': 300,
  31438. 'Ograve': 722,
  31439. 'Agrave': 611,
  31440. 'Abreve': 611,
  31441. 'multiply': 675,
  31442. 'uacute': 500,
  31443. 'Tcaron': 556,
  31444. 'partialdiff': 476,
  31445. 'ydieresis': 444,
  31446. 'Nacute': 667,
  31447. 'icircumflex': 278,
  31448. 'Ecircumflex': 611,
  31449. 'adieresis': 500,
  31450. 'edieresis': 444,
  31451. 'cacute': 444,
  31452. 'nacute': 500,
  31453. 'umacron': 500,
  31454. 'Ncaron': 667,
  31455. 'Iacute': 333,
  31456. 'plusminus': 675,
  31457. 'brokenbar': 275,
  31458. 'registered': 760,
  31459. 'Gbreve': 722,
  31460. 'Idotaccent': 333,
  31461. 'summation': 600,
  31462. 'Egrave': 611,
  31463. 'racute': 389,
  31464. 'omacron': 500,
  31465. 'Zacute': 556,
  31466. 'Zcaron': 556,
  31467. 'greaterequal': 549,
  31468. 'Eth': 722,
  31469. 'Ccedilla': 667,
  31470. 'lcommaaccent': 278,
  31471. 'tcaron': 300,
  31472. 'eogonek': 444,
  31473. 'Uogonek': 722,
  31474. 'Aacute': 611,
  31475. 'Adieresis': 611,
  31476. 'egrave': 444,
  31477. 'zacute': 389,
  31478. 'iogonek': 278,
  31479. 'Oacute': 722,
  31480. 'oacute': 500,
  31481. 'amacron': 500,
  31482. 'sacute': 389,
  31483. 'idieresis': 278,
  31484. 'Ocircumflex': 722,
  31485. 'Ugrave': 722,
  31486. 'Delta': 612,
  31487. 'thorn': 500,
  31488. 'twosuperior': 300,
  31489. 'Odieresis': 722,
  31490. 'mu': 500,
  31491. 'igrave': 278,
  31492. 'ohungarumlaut': 500,
  31493. 'Eogonek': 611,
  31494. 'dcroat': 500,
  31495. 'threequarters': 750,
  31496. 'Scedilla': 500,
  31497. 'lcaron': 300,
  31498. 'Kcommaaccent': 667,
  31499. 'Lacute': 556,
  31500. 'trademark': 980,
  31501. 'edotaccent': 444,
  31502. 'Igrave': 333,
  31503. 'Imacron': 333,
  31504. 'Lcaron': 611,
  31505. 'onehalf': 750,
  31506. 'lessequal': 549,
  31507. 'ocircumflex': 500,
  31508. 'ntilde': 500,
  31509. 'Uhungarumlaut': 722,
  31510. 'Eacute': 611,
  31511. 'emacron': 444,
  31512. 'gbreve': 500,
  31513. 'onequarter': 750,
  31514. 'Scaron': 500,
  31515. 'Scommaaccent': 500,
  31516. 'Ohungarumlaut': 722,
  31517. 'degree': 400,
  31518. 'ograve': 500,
  31519. 'Ccaron': 667,
  31520. 'ugrave': 500,
  31521. 'radical': 453,
  31522. 'Dcaron': 722,
  31523. 'rcommaaccent': 389,
  31524. 'Ntilde': 667,
  31525. 'otilde': 500,
  31526. 'Rcommaaccent': 611,
  31527. 'Lcommaaccent': 556,
  31528. 'Atilde': 611,
  31529. 'Aogonek': 611,
  31530. 'Aring': 611,
  31531. 'Otilde': 722,
  31532. 'zdotaccent': 389,
  31533. 'Ecaron': 611,
  31534. 'Iogonek': 333,
  31535. 'kcommaaccent': 444,
  31536. 'minus': 675,
  31537. 'Icircumflex': 333,
  31538. 'ncaron': 500,
  31539. 'tcommaaccent': 278,
  31540. 'logicalnot': 675,
  31541. 'odieresis': 500,
  31542. 'udieresis': 500,
  31543. 'notequal': 549,
  31544. 'gcommaaccent': 500,
  31545. 'eth': 500,
  31546. 'zcaron': 389,
  31547. 'ncommaaccent': 500,
  31548. 'onesuperior': 300,
  31549. 'imacron': 278,
  31550. 'Euro': 500
  31551. },
  31552. 'ZapfDingbats': {
  31553. 'space': 278,
  31554. 'a1': 974,
  31555. 'a2': 961,
  31556. 'a202': 974,
  31557. 'a3': 980,
  31558. 'a4': 719,
  31559. 'a5': 789,
  31560. 'a119': 790,
  31561. 'a118': 791,
  31562. 'a117': 690,
  31563. 'a11': 960,
  31564. 'a12': 939,
  31565. 'a13': 549,
  31566. 'a14': 855,
  31567. 'a15': 911,
  31568. 'a16': 933,
  31569. 'a105': 911,
  31570. 'a17': 945,
  31571. 'a18': 974,
  31572. 'a19': 755,
  31573. 'a20': 846,
  31574. 'a21': 762,
  31575. 'a22': 761,
  31576. 'a23': 571,
  31577. 'a24': 677,
  31578. 'a25': 763,
  31579. 'a26': 760,
  31580. 'a27': 759,
  31581. 'a28': 754,
  31582. 'a6': 494,
  31583. 'a7': 552,
  31584. 'a8': 537,
  31585. 'a9': 577,
  31586. 'a10': 692,
  31587. 'a29': 786,
  31588. 'a30': 788,
  31589. 'a31': 788,
  31590. 'a32': 790,
  31591. 'a33': 793,
  31592. 'a34': 794,
  31593. 'a35': 816,
  31594. 'a36': 823,
  31595. 'a37': 789,
  31596. 'a38': 841,
  31597. 'a39': 823,
  31598. 'a40': 833,
  31599. 'a41': 816,
  31600. 'a42': 831,
  31601. 'a43': 923,
  31602. 'a44': 744,
  31603. 'a45': 723,
  31604. 'a46': 749,
  31605. 'a47': 790,
  31606. 'a48': 792,
  31607. 'a49': 695,
  31608. 'a50': 776,
  31609. 'a51': 768,
  31610. 'a52': 792,
  31611. 'a53': 759,
  31612. 'a54': 707,
  31613. 'a55': 708,
  31614. 'a56': 682,
  31615. 'a57': 701,
  31616. 'a58': 826,
  31617. 'a59': 815,
  31618. 'a60': 789,
  31619. 'a61': 789,
  31620. 'a62': 707,
  31621. 'a63': 687,
  31622. 'a64': 696,
  31623. 'a65': 689,
  31624. 'a66': 786,
  31625. 'a67': 787,
  31626. 'a68': 713,
  31627. 'a69': 791,
  31628. 'a70': 785,
  31629. 'a71': 791,
  31630. 'a72': 873,
  31631. 'a73': 761,
  31632. 'a74': 762,
  31633. 'a203': 762,
  31634. 'a75': 759,
  31635. 'a204': 759,
  31636. 'a76': 892,
  31637. 'a77': 892,
  31638. 'a78': 788,
  31639. 'a79': 784,
  31640. 'a81': 438,
  31641. 'a82': 138,
  31642. 'a83': 277,
  31643. 'a84': 415,
  31644. 'a97': 392,
  31645. 'a98': 392,
  31646. 'a99': 668,
  31647. 'a100': 668,
  31648. 'a89': 390,
  31649. 'a90': 390,
  31650. 'a93': 317,
  31651. 'a94': 317,
  31652. 'a91': 276,
  31653. 'a92': 276,
  31654. 'a205': 509,
  31655. 'a85': 509,
  31656. 'a206': 410,
  31657. 'a86': 410,
  31658. 'a87': 234,
  31659. 'a88': 234,
  31660. 'a95': 334,
  31661. 'a96': 334,
  31662. 'a101': 732,
  31663. 'a102': 544,
  31664. 'a103': 544,
  31665. 'a104': 910,
  31666. 'a106': 667,
  31667. 'a107': 760,
  31668. 'a108': 760,
  31669. 'a112': 776,
  31670. 'a111': 595,
  31671. 'a110': 694,
  31672. 'a109': 626,
  31673. 'a120': 788,
  31674. 'a121': 788,
  31675. 'a122': 788,
  31676. 'a123': 788,
  31677. 'a124': 788,
  31678. 'a125': 788,
  31679. 'a126': 788,
  31680. 'a127': 788,
  31681. 'a128': 788,
  31682. 'a129': 788,
  31683. 'a130': 788,
  31684. 'a131': 788,
  31685. 'a132': 788,
  31686. 'a133': 788,
  31687. 'a134': 788,
  31688. 'a135': 788,
  31689. 'a136': 788,
  31690. 'a137': 788,
  31691. 'a138': 788,
  31692. 'a139': 788,
  31693. 'a140': 788,
  31694. 'a141': 788,
  31695. 'a142': 788,
  31696. 'a143': 788,
  31697. 'a144': 788,
  31698. 'a145': 788,
  31699. 'a146': 788,
  31700. 'a147': 788,
  31701. 'a148': 788,
  31702. 'a149': 788,
  31703. 'a150': 788,
  31704. 'a151': 788,
  31705. 'a152': 788,
  31706. 'a153': 788,
  31707. 'a154': 788,
  31708. 'a155': 788,
  31709. 'a156': 788,
  31710. 'a157': 788,
  31711. 'a158': 788,
  31712. 'a159': 788,
  31713. 'a160': 894,
  31714. 'a161': 838,
  31715. 'a163': 1016,
  31716. 'a164': 458,
  31717. 'a196': 748,
  31718. 'a165': 924,
  31719. 'a192': 748,
  31720. 'a166': 918,
  31721. 'a167': 927,
  31722. 'a168': 928,
  31723. 'a169': 928,
  31724. 'a170': 834,
  31725. 'a171': 873,
  31726. 'a172': 828,
  31727. 'a173': 924,
  31728. 'a162': 924,
  31729. 'a174': 917,
  31730. 'a175': 930,
  31731. 'a176': 931,
  31732. 'a177': 463,
  31733. 'a178': 883,
  31734. 'a179': 836,
  31735. 'a193': 836,
  31736. 'a180': 867,
  31737. 'a199': 867,
  31738. 'a181': 696,
  31739. 'a200': 696,
  31740. 'a182': 874,
  31741. 'a201': 874,
  31742. 'a183': 760,
  31743. 'a184': 946,
  31744. 'a197': 771,
  31745. 'a185': 865,
  31746. 'a194': 771,
  31747. 'a198': 888,
  31748. 'a186': 967,
  31749. 'a195': 888,
  31750. 'a187': 831,
  31751. 'a188': 873,
  31752. 'a189': 927,
  31753. 'a190': 970,
  31754. 'a191': 918
  31755. }
  31756. };
  31757. var EOF = {};
  31758. function isEOF(v) {
  31759. return (v === EOF);
  31760. }
  31761. var Parser = (function ParserClosure() {
  31762. function Parser(lexer, allowStreams, xref) {
  31763. this.lexer = lexer;
  31764. this.allowStreams = allowStreams;
  31765. this.xref = xref;
  31766. this.imageCache = {
  31767. length: 0,
  31768. adler32: 0,
  31769. stream: null
  31770. };
  31771. this.refill();
  31772. }
  31773. Parser.prototype = {
  31774. refill: function Parser_refill() {
  31775. this.buf1 = this.lexer.getObj();
  31776. this.buf2 = this.lexer.getObj();
  31777. },
  31778. shift: function Parser_shift() {
  31779. if (isCmd(this.buf2, 'ID')) {
  31780. this.buf1 = this.buf2;
  31781. this.buf2 = null;
  31782. } else {
  31783. this.buf1 = this.buf2;
  31784. this.buf2 = this.lexer.getObj();
  31785. }
  31786. },
  31787. getObj: function Parser_getObj(cipherTransform) {
  31788. var buf1 = this.buf1;
  31789. this.shift();
  31790. if (buf1 instanceof Cmd) {
  31791. switch (buf1.cmd) {
  31792. case 'BI': // inline image
  31793. return this.makeInlineImage(cipherTransform);
  31794. case '[': // array
  31795. var array = [];
  31796. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  31797. array.push(this.getObj(cipherTransform));
  31798. }
  31799. if (isEOF(this.buf1)) {
  31800. error('End of file inside array');
  31801. }
  31802. this.shift();
  31803. return array;
  31804. case '<<': // dictionary or stream
  31805. var dict = new Dict(this.xref);
  31806. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  31807. if (!isName(this.buf1)) {
  31808. info('Malformed dictionary: key must be a name object');
  31809. this.shift();
  31810. continue;
  31811. }
  31812. var key = this.buf1.name;
  31813. this.shift();
  31814. if (isEOF(this.buf1)) {
  31815. break;
  31816. }
  31817. dict.set(key, this.getObj(cipherTransform));
  31818. }
  31819. if (isEOF(this.buf1)) {
  31820. error('End of file inside dictionary');
  31821. }
  31822. // Stream objects are not allowed inside content streams or
  31823. // object streams.
  31824. if (isCmd(this.buf2, 'stream')) {
  31825. return (this.allowStreams ?
  31826. this.makeStream(dict, cipherTransform) : dict);
  31827. }
  31828. this.shift();
  31829. return dict;
  31830. default: // simple object
  31831. return buf1;
  31832. }
  31833. }
  31834. if (isInt(buf1)) { // indirect reference or integer
  31835. var num = buf1;
  31836. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  31837. var ref = new Ref(num, this.buf1);
  31838. this.shift();
  31839. this.shift();
  31840. return ref;
  31841. }
  31842. return num;
  31843. }
  31844. if (isString(buf1)) { // string
  31845. var str = buf1;
  31846. if (cipherTransform) {
  31847. str = cipherTransform.decryptString(str);
  31848. }
  31849. return str;
  31850. }
  31851. // simple object
  31852. return buf1;
  31853. },
  31854. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  31855. var lexer = this.lexer;
  31856. var stream = lexer.stream;
  31857. // parse dictionary
  31858. var dict = new Dict(null);
  31859. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  31860. if (!isName(this.buf1)) {
  31861. error('Dictionary key must be a name object');
  31862. }
  31863. var key = this.buf1.name;
  31864. this.shift();
  31865. if (isEOF(this.buf1)) {
  31866. break;
  31867. }
  31868. dict.set(key, this.getObj(cipherTransform));
  31869. }
  31870. // parse image stream
  31871. var startPos = stream.pos;
  31872. // searching for the /EI\s/
  31873. var state = 0, ch, i, ii;
  31874. while (state !== 4 && (ch = stream.getByte()) !== -1) {
  31875. switch (ch | 0) {
  31876. case 0x20:
  31877. case 0x0D:
  31878. case 0x0A:
  31879. // let's check next five bytes to be ASCII... just be sure
  31880. var followingBytes = stream.peekBytes(5);
  31881. for (i = 0, ii = followingBytes.length; i < ii; i++) {
  31882. ch = followingBytes[i];
  31883. if (ch !== 0x0A && ch !== 0x0D && (ch < 0x20 || ch > 0x7F)) {
  31884. // not a LF, CR, SPACE or any visible ASCII character
  31885. state = 0;
  31886. break; // some binary stuff found, resetting the state
  31887. }
  31888. }
  31889. state = (state === 3 ? 4 : 0);
  31890. break;
  31891. case 0x45:
  31892. state = 2;
  31893. break;
  31894. case 0x49:
  31895. state = (state === 2 ? 3 : 0);
  31896. break;
  31897. default:
  31898. state = 0;
  31899. break;
  31900. }
  31901. }
  31902. var length = (stream.pos - 4) - startPos;
  31903. var imageStream = stream.makeSubStream(startPos, length, dict);
  31904. // trying to cache repeat images, first we are trying to "warm up" caching
  31905. // using length, then comparing adler32
  31906. var MAX_LENGTH_TO_CACHE = 1000;
  31907. var cacheImage = false, adler32;
  31908. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  31909. var imageBytes = imageStream.getBytes();
  31910. imageStream.reset();
  31911. var a = 1;
  31912. var b = 0;
  31913. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  31914. a = (a + (imageBytes[i] & 0xff)) % 65521;
  31915. b = (b + a) % 65521;
  31916. }
  31917. adler32 = (b << 16) | a;
  31918. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  31919. this.buf2 = Cmd.get('EI');
  31920. this.shift();
  31921. this.imageCache.stream.reset();
  31922. return this.imageCache.stream;
  31923. }
  31924. cacheImage = true;
  31925. }
  31926. if (!cacheImage && !this.imageCache.stream) {
  31927. this.imageCache.length = length;
  31928. this.imageCache.stream = null;
  31929. }
  31930. if (cipherTransform) {
  31931. imageStream = cipherTransform.createStream(imageStream, length);
  31932. }
  31933. imageStream = this.filter(imageStream, dict, length);
  31934. imageStream.dict = dict;
  31935. if (cacheImage) {
  31936. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  31937. this.imageCache.adler32 = adler32;
  31938. this.imageCache.stream = imageStream;
  31939. }
  31940. this.buf2 = Cmd.get('EI');
  31941. this.shift();
  31942. return imageStream;
  31943. },
  31944. fetchIfRef: function Parser_fetchIfRef(obj) {
  31945. // not relying on the xref.fetchIfRef -- xref might not be set
  31946. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  31947. },
  31948. makeStream: function Parser_makeStream(dict, cipherTransform) {
  31949. var lexer = this.lexer;
  31950. var stream = lexer.stream;
  31951. // get stream start position
  31952. lexer.skipToNextLine();
  31953. var pos = stream.pos - 1;
  31954. // get length
  31955. var length = this.fetchIfRef(dict.get('Length'));
  31956. if (!isInt(length)) {
  31957. info('Bad ' + length + ' attribute in stream');
  31958. length = 0;
  31959. }
  31960. // skip over the stream data
  31961. stream.pos = pos + length;
  31962. lexer.nextChar();
  31963. this.shift(); // '>>'
  31964. this.shift(); // 'stream'
  31965. if (!isCmd(this.buf1, 'endstream')) {
  31966. // bad stream length, scanning for endstream
  31967. stream.pos = pos;
  31968. var SCAN_BLOCK_SIZE = 2048;
  31969. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  31970. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  31971. 0x61, 0x6D];
  31972. var skipped = 0, found = false, i, j;
  31973. while (stream.pos < stream.end) {
  31974. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  31975. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  31976. if (scanLength <= 0) {
  31977. break;
  31978. }
  31979. found = false;
  31980. for (i = 0, j = 0; i < scanLength; i++) {
  31981. var b = scanBytes[i];
  31982. if (b !== ENDSTREAM_SIGNATURE[j]) {
  31983. i -= j;
  31984. j = 0;
  31985. } else {
  31986. j++;
  31987. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  31988. i++;
  31989. found = true;
  31990. break;
  31991. }
  31992. }
  31993. }
  31994. if (found) {
  31995. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  31996. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  31997. break;
  31998. }
  31999. skipped += scanLength;
  32000. stream.pos += scanLength;
  32001. }
  32002. if (!found) {
  32003. error('Missing endstream');
  32004. }
  32005. length = skipped;
  32006. lexer.nextChar();
  32007. this.shift();
  32008. this.shift();
  32009. }
  32010. this.shift(); // 'endstream'
  32011. stream = stream.makeSubStream(pos, length, dict);
  32012. if (cipherTransform) {
  32013. stream = cipherTransform.createStream(stream, length);
  32014. }
  32015. stream = this.filter(stream, dict, length);
  32016. stream.dict = dict;
  32017. return stream;
  32018. },
  32019. filter: function Parser_filter(stream, dict, length) {
  32020. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  32021. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  32022. if (isName(filter)) {
  32023. return this.makeFilter(stream, filter.name, length, params);
  32024. }
  32025. var maybeLength = length;
  32026. if (isArray(filter)) {
  32027. var filterArray = filter;
  32028. var paramsArray = params;
  32029. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  32030. filter = filterArray[i];
  32031. if (!isName(filter)) {
  32032. error('Bad filter name: ' + filter);
  32033. }
  32034. params = null;
  32035. if (isArray(paramsArray) && (i in paramsArray)) {
  32036. params = paramsArray[i];
  32037. }
  32038. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  32039. // after the first stream the length variable is invalid
  32040. maybeLength = null;
  32041. }
  32042. }
  32043. return stream;
  32044. },
  32045. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  32046. if (stream.dict.get('Length') === 0) {
  32047. return new NullStream(stream);
  32048. }
  32049. try {
  32050. var xrefStreamStats = this.xref.stats.streamTypes;
  32051. if (name === 'FlateDecode' || name === 'Fl') {
  32052. xrefStreamStats[StreamType.FLATE] = true;
  32053. if (params) {
  32054. return new PredictorStream(new FlateStream(stream, maybeLength),
  32055. maybeLength, params);
  32056. }
  32057. return new FlateStream(stream, maybeLength);
  32058. }
  32059. if (name === 'LZWDecode' || name === 'LZW') {
  32060. xrefStreamStats[StreamType.LZW] = true;
  32061. var earlyChange = 1;
  32062. if (params) {
  32063. if (params.has('EarlyChange')) {
  32064. earlyChange = params.get('EarlyChange');
  32065. }
  32066. return new PredictorStream(
  32067. new LZWStream(stream, maybeLength, earlyChange),
  32068. maybeLength, params);
  32069. }
  32070. return new LZWStream(stream, maybeLength, earlyChange);
  32071. }
  32072. if (name === 'DCTDecode' || name === 'DCT') {
  32073. xrefStreamStats[StreamType.DCT] = true;
  32074. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  32075. }
  32076. if (name === 'JPXDecode' || name === 'JPX') {
  32077. xrefStreamStats[StreamType.JPX] = true;
  32078. return new JpxStream(stream, maybeLength, stream.dict);
  32079. }
  32080. if (name === 'ASCII85Decode' || name === 'A85') {
  32081. xrefStreamStats[StreamType.A85] = true;
  32082. return new Ascii85Stream(stream, maybeLength);
  32083. }
  32084. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  32085. xrefStreamStats[StreamType.AHX] = true;
  32086. return new AsciiHexStream(stream, maybeLength);
  32087. }
  32088. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  32089. xrefStreamStats[StreamType.CCF] = true;
  32090. return new CCITTFaxStream(stream, maybeLength, params);
  32091. }
  32092. if (name === 'RunLengthDecode' || name === 'RL') {
  32093. xrefStreamStats[StreamType.RL] = true;
  32094. return new RunLengthStream(stream, maybeLength);
  32095. }
  32096. if (name === 'JBIG2Decode') {
  32097. xrefStreamStats[StreamType.JBIG] = true;
  32098. return new Jbig2Stream(stream, maybeLength, stream.dict);
  32099. }
  32100. warn('filter "' + name + '" not supported yet');
  32101. return stream;
  32102. } catch (ex) {
  32103. if (ex instanceof MissingDataException) {
  32104. throw ex;
  32105. }
  32106. warn('Invalid stream: \"' + ex + '\"');
  32107. return new NullStream(stream);
  32108. }
  32109. }
  32110. };
  32111. return Parser;
  32112. })();
  32113. var Lexer = (function LexerClosure() {
  32114. function Lexer(stream, knownCommands) {
  32115. this.stream = stream;
  32116. this.nextChar();
  32117. // While lexing, we build up many strings one char at a time. Using += for
  32118. // this can result in lots of garbage strings. It's better to build an
  32119. // array of single-char strings and then join() them together at the end.
  32120. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  32121. // purpose uses less memory than using a new array for each string.
  32122. this.strBuf = [];
  32123. // The PDFs might have "glued" commands with other commands, operands or
  32124. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  32125. // commands and their prefixes. The prefixes are built the following way:
  32126. // if there a command that is a prefix of the other valid command or
  32127. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  32128. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  32129. // other commands or literals as a prefix. The knowCommands is optional.
  32130. this.knownCommands = knownCommands;
  32131. }
  32132. Lexer.isSpace = function Lexer_isSpace(ch) {
  32133. // Space is one of the following characters: SPACE, TAB, CR or LF.
  32134. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  32135. };
  32136. // A '1' in this array means the character is white space. A '1' or
  32137. // '2' means the character ends a name or command.
  32138. var specialChars = [
  32139. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  32140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  32141. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  32142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  32143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  32144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  32145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  32146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  32147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  32148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  32149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  32150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  32151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  32152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  32153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  32154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  32155. ];
  32156. function toHexDigit(ch) {
  32157. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  32158. return ch & 0x0F;
  32159. }
  32160. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  32161. // 'A'-'F', 'a'-'f'
  32162. return (ch & 0x0F) + 9;
  32163. }
  32164. return -1;
  32165. }
  32166. Lexer.prototype = {
  32167. nextChar: function Lexer_nextChar() {
  32168. return (this.currentChar = this.stream.getByte());
  32169. },
  32170. peekChar: function Lexer_peekChar() {
  32171. return this.stream.peekBytes(1)[0];
  32172. },
  32173. getNumber: function Lexer_getNumber() {
  32174. var ch = this.currentChar;
  32175. var eNotation = false;
  32176. var divideBy = 0; // different from 0 if it's a floating point value
  32177. var sign = 1;
  32178. if (ch === 0x2D) { // '-'
  32179. sign = -1;
  32180. ch = this.nextChar();
  32181. } else if (ch === 0x2B) { // '+'
  32182. ch = this.nextChar();
  32183. }
  32184. if (ch === 0x2E) { // '.'
  32185. divideBy = 10;
  32186. ch = this.nextChar();
  32187. }
  32188. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32189. error('Invalid number: ' + String.fromCharCode(ch));
  32190. return 0;
  32191. }
  32192. var baseValue = ch - 0x30; // '0'
  32193. var powerValue = 0;
  32194. var powerValueSign = 1;
  32195. while ((ch = this.nextChar()) >= 0) {
  32196. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  32197. var currentDigit = ch - 0x30; // '0'
  32198. if (eNotation) { // We are after an 'e' or 'E'
  32199. powerValue = powerValue * 10 + currentDigit;
  32200. } else {
  32201. if (divideBy !== 0) { // We are after a point
  32202. divideBy *= 10;
  32203. }
  32204. baseValue = baseValue * 10 + currentDigit;
  32205. }
  32206. } else if (ch === 0x2E) { // '.'
  32207. if (divideBy === 0) {
  32208. divideBy = 1;
  32209. } else {
  32210. // A number can have only one '.'
  32211. break;
  32212. }
  32213. } else if (ch === 0x2D) { // '-'
  32214. // ignore minus signs in the middle of numbers to match
  32215. // Adobe's behavior
  32216. warn('Badly formated number');
  32217. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  32218. // 'E' can be either a scientific notation or the beginning of a new
  32219. // operator
  32220. ch = this.peekChar();
  32221. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  32222. powerValueSign = (ch === 0x2D) ? -1 : 1;
  32223. this.nextChar(); // Consume the sign character
  32224. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32225. // The 'E' must be the beginning of a new operator
  32226. break;
  32227. }
  32228. eNotation = true;
  32229. } else {
  32230. // the last character doesn't belong to us
  32231. break;
  32232. }
  32233. }
  32234. if (divideBy !== 0) {
  32235. baseValue /= divideBy;
  32236. }
  32237. if (eNotation) {
  32238. baseValue *= Math.pow(10, powerValueSign * powerValue);
  32239. }
  32240. return sign * baseValue;
  32241. },
  32242. getString: function Lexer_getString() {
  32243. var numParen = 1;
  32244. var done = false;
  32245. var strBuf = this.strBuf;
  32246. strBuf.length = 0;
  32247. var ch = this.nextChar();
  32248. while (true) {
  32249. var charBuffered = false;
  32250. switch (ch | 0) {
  32251. case -1:
  32252. warn('Unterminated string');
  32253. done = true;
  32254. break;
  32255. case 0x28: // '('
  32256. ++numParen;
  32257. strBuf.push('(');
  32258. break;
  32259. case 0x29: // ')'
  32260. if (--numParen === 0) {
  32261. this.nextChar(); // consume strings ')'
  32262. done = true;
  32263. } else {
  32264. strBuf.push(')');
  32265. }
  32266. break;
  32267. case 0x5C: // '\\'
  32268. ch = this.nextChar();
  32269. switch (ch) {
  32270. case -1:
  32271. warn('Unterminated string');
  32272. done = true;
  32273. break;
  32274. case 0x6E: // 'n'
  32275. strBuf.push('\n');
  32276. break;
  32277. case 0x72: // 'r'
  32278. strBuf.push('\r');
  32279. break;
  32280. case 0x74: // 't'
  32281. strBuf.push('\t');
  32282. break;
  32283. case 0x62: // 'b'
  32284. strBuf.push('\b');
  32285. break;
  32286. case 0x66: // 'f'
  32287. strBuf.push('\f');
  32288. break;
  32289. case 0x5C: // '\'
  32290. case 0x28: // '('
  32291. case 0x29: // ')'
  32292. strBuf.push(String.fromCharCode(ch));
  32293. break;
  32294. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  32295. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  32296. var x = ch & 0x0F;
  32297. ch = this.nextChar();
  32298. charBuffered = true;
  32299. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32300. x = (x << 3) + (ch & 0x0F);
  32301. ch = this.nextChar();
  32302. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32303. charBuffered = false;
  32304. x = (x << 3) + (ch & 0x0F);
  32305. }
  32306. }
  32307. strBuf.push(String.fromCharCode(x));
  32308. break;
  32309. case 0x0D: // CR
  32310. if (this.peekChar() === 0x0A) { // LF
  32311. this.nextChar();
  32312. }
  32313. break;
  32314. case 0x0A: // LF
  32315. break;
  32316. default:
  32317. strBuf.push(String.fromCharCode(ch));
  32318. break;
  32319. }
  32320. break;
  32321. default:
  32322. strBuf.push(String.fromCharCode(ch));
  32323. break;
  32324. }
  32325. if (done) {
  32326. break;
  32327. }
  32328. if (!charBuffered) {
  32329. ch = this.nextChar();
  32330. }
  32331. }
  32332. return strBuf.join('');
  32333. },
  32334. getName: function Lexer_getName() {
  32335. var ch;
  32336. var strBuf = this.strBuf;
  32337. strBuf.length = 0;
  32338. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32339. if (ch === 0x23) { // '#'
  32340. ch = this.nextChar();
  32341. var x = toHexDigit(ch);
  32342. if (x !== -1) {
  32343. var x2 = toHexDigit(this.nextChar());
  32344. if (x2 === -1) {
  32345. error('Illegal digit in hex char in name: ' + x2);
  32346. }
  32347. strBuf.push(String.fromCharCode((x << 4) | x2));
  32348. } else {
  32349. strBuf.push('#', String.fromCharCode(ch));
  32350. }
  32351. } else {
  32352. strBuf.push(String.fromCharCode(ch));
  32353. }
  32354. }
  32355. if (strBuf.length > 128) {
  32356. error('Warning: name token is longer than allowed by the spec: ' +
  32357. strBuf.length);
  32358. }
  32359. return Name.get(strBuf.join(''));
  32360. },
  32361. getHexString: function Lexer_getHexString() {
  32362. var strBuf = this.strBuf;
  32363. strBuf.length = 0;
  32364. var ch = this.currentChar;
  32365. var isFirstHex = true;
  32366. var firstDigit;
  32367. var secondDigit;
  32368. while (true) {
  32369. if (ch < 0) {
  32370. warn('Unterminated hex string');
  32371. break;
  32372. } else if (ch === 0x3E) { // '>'
  32373. this.nextChar();
  32374. break;
  32375. } else if (specialChars[ch] === 1) {
  32376. ch = this.nextChar();
  32377. continue;
  32378. } else {
  32379. if (isFirstHex) {
  32380. firstDigit = toHexDigit(ch);
  32381. if (firstDigit === -1) {
  32382. warn('Ignoring invalid character "' + ch + '" in hex string');
  32383. ch = this.nextChar();
  32384. continue;
  32385. }
  32386. } else {
  32387. secondDigit = toHexDigit(ch);
  32388. if (secondDigit === -1) {
  32389. warn('Ignoring invalid character "' + ch + '" in hex string');
  32390. ch = this.nextChar();
  32391. continue;
  32392. }
  32393. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  32394. }
  32395. isFirstHex = !isFirstHex;
  32396. ch = this.nextChar();
  32397. }
  32398. }
  32399. return strBuf.join('');
  32400. },
  32401. getObj: function Lexer_getObj() {
  32402. // skip whitespace and comments
  32403. var comment = false;
  32404. var ch = this.currentChar;
  32405. while (true) {
  32406. if (ch < 0) {
  32407. return EOF;
  32408. }
  32409. if (comment) {
  32410. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  32411. comment = false;
  32412. }
  32413. } else if (ch === 0x25) { // '%'
  32414. comment = true;
  32415. } else if (specialChars[ch] !== 1) {
  32416. break;
  32417. }
  32418. ch = this.nextChar();
  32419. }
  32420. // start reading token
  32421. switch (ch | 0) {
  32422. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32423. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32424. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32425. return this.getNumber();
  32426. case 0x28: // '('
  32427. return this.getString();
  32428. case 0x2F: // '/'
  32429. return this.getName();
  32430. // array punctuation
  32431. case 0x5B: // '['
  32432. this.nextChar();
  32433. return Cmd.get('[');
  32434. case 0x5D: // ']'
  32435. this.nextChar();
  32436. return Cmd.get(']');
  32437. // hex string or dict punctuation
  32438. case 0x3C: // '<'
  32439. ch = this.nextChar();
  32440. if (ch === 0x3C) {
  32441. // dict punctuation
  32442. this.nextChar();
  32443. return Cmd.get('<<');
  32444. }
  32445. return this.getHexString();
  32446. // dict punctuation
  32447. case 0x3E: // '>'
  32448. ch = this.nextChar();
  32449. if (ch === 0x3E) {
  32450. this.nextChar();
  32451. return Cmd.get('>>');
  32452. }
  32453. return Cmd.get('>');
  32454. case 0x7B: // '{'
  32455. this.nextChar();
  32456. return Cmd.get('{');
  32457. case 0x7D: // '}'
  32458. this.nextChar();
  32459. return Cmd.get('}');
  32460. case 0x29: // ')'
  32461. error('Illegal character: ' + ch);
  32462. break;
  32463. }
  32464. // command
  32465. var str = String.fromCharCode(ch);
  32466. var knownCommands = this.knownCommands;
  32467. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32468. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32469. // stop if known command is found and next character does not make
  32470. // the str a command
  32471. var possibleCommand = str + String.fromCharCode(ch);
  32472. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  32473. break;
  32474. }
  32475. if (str.length === 128) {
  32476. error('Command token too long: ' + str.length);
  32477. }
  32478. str = possibleCommand;
  32479. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32480. }
  32481. if (str === 'true') {
  32482. return true;
  32483. }
  32484. if (str === 'false') {
  32485. return false;
  32486. }
  32487. if (str === 'null') {
  32488. return null;
  32489. }
  32490. return Cmd.get(str);
  32491. },
  32492. skipToNextLine: function Lexer_skipToNextLine() {
  32493. var ch = this.currentChar;
  32494. while (ch >= 0) {
  32495. if (ch === 0x0D) { // CR
  32496. ch = this.nextChar();
  32497. if (ch === 0x0A) { // LF
  32498. this.nextChar();
  32499. }
  32500. break;
  32501. } else if (ch === 0x0A) { // LF
  32502. this.nextChar();
  32503. break;
  32504. }
  32505. ch = this.nextChar();
  32506. }
  32507. }
  32508. };
  32509. return Lexer;
  32510. })();
  32511. var Linearization = {
  32512. create: function LinearizationCreate(stream) {
  32513. function getInt(name, allowZeroValue) {
  32514. var obj = linDict.get(name);
  32515. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  32516. return obj;
  32517. }
  32518. throw new Error('The "' + name + '" parameter in the linearization ' +
  32519. 'dictionary is invalid.');
  32520. }
  32521. function getHints() {
  32522. var hints = linDict.get('H'), hintsLength, item;
  32523. if (isArray(hints) &&
  32524. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  32525. for (var index = 0; index < hintsLength; index++) {
  32526. if (!(isInt(item = hints[index]) && item > 0)) {
  32527. throw new Error('Hint (' + index +
  32528. ') in the linearization dictionary is invalid.');
  32529. }
  32530. }
  32531. return hints;
  32532. }
  32533. throw new Error('Hint array in the linearization dictionary is invalid.');
  32534. }
  32535. var parser = new Parser(new Lexer(stream), false, null);
  32536. var obj1 = parser.getObj();
  32537. var obj2 = parser.getObj();
  32538. var obj3 = parser.getObj();
  32539. var linDict = parser.getObj();
  32540. var obj, length;
  32541. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  32542. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  32543. return null; // No valid linearization dictionary found.
  32544. } else if ((length = getInt('L')) !== stream.length) {
  32545. throw new Error('The "L" parameter in the linearization dictionary ' +
  32546. 'does not equal the stream length.');
  32547. }
  32548. return {
  32549. length: length,
  32550. hints: getHints(),
  32551. objectNumberFirst: getInt('O'),
  32552. endFirst: getInt('E'),
  32553. numPages: getInt('N'),
  32554. mainXRefEntriesOffset: getInt('T'),
  32555. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  32556. };
  32557. }
  32558. };
  32559. var PostScriptParser = (function PostScriptParserClosure() {
  32560. function PostScriptParser(lexer) {
  32561. this.lexer = lexer;
  32562. this.operators = [];
  32563. this.token = null;
  32564. this.prev = null;
  32565. }
  32566. PostScriptParser.prototype = {
  32567. nextToken: function PostScriptParser_nextToken() {
  32568. this.prev = this.token;
  32569. this.token = this.lexer.getToken();
  32570. },
  32571. accept: function PostScriptParser_accept(type) {
  32572. if (this.token.type === type) {
  32573. this.nextToken();
  32574. return true;
  32575. }
  32576. return false;
  32577. },
  32578. expect: function PostScriptParser_expect(type) {
  32579. if (this.accept(type)) {
  32580. return true;
  32581. }
  32582. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  32583. type + '.');
  32584. },
  32585. parse: function PostScriptParser_parse() {
  32586. this.nextToken();
  32587. this.expect(PostScriptTokenTypes.LBRACE);
  32588. this.parseBlock();
  32589. this.expect(PostScriptTokenTypes.RBRACE);
  32590. return this.operators;
  32591. },
  32592. parseBlock: function PostScriptParser_parseBlock() {
  32593. while (true) {
  32594. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  32595. this.operators.push(this.prev.value);
  32596. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  32597. this.operators.push(this.prev.value);
  32598. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32599. this.parseCondition();
  32600. } else {
  32601. return;
  32602. }
  32603. }
  32604. },
  32605. parseCondition: function PostScriptParser_parseCondition() {
  32606. // Add two place holders that will be updated later
  32607. var conditionLocation = this.operators.length;
  32608. this.operators.push(null, null);
  32609. this.parseBlock();
  32610. this.expect(PostScriptTokenTypes.RBRACE);
  32611. if (this.accept(PostScriptTokenTypes.IF)) {
  32612. // The true block is right after the 'if' so it just falls through on
  32613. // true else it jumps and skips the true block.
  32614. this.operators[conditionLocation] = this.operators.length;
  32615. this.operators[conditionLocation + 1] = 'jz';
  32616. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32617. var jumpLocation = this.operators.length;
  32618. this.operators.push(null, null);
  32619. var endOfTrue = this.operators.length;
  32620. this.parseBlock();
  32621. this.expect(PostScriptTokenTypes.RBRACE);
  32622. this.expect(PostScriptTokenTypes.IFELSE);
  32623. // The jump is added at the end of the true block to skip the false
  32624. // block.
  32625. this.operators[jumpLocation] = this.operators.length;
  32626. this.operators[jumpLocation + 1] = 'j';
  32627. this.operators[conditionLocation] = endOfTrue;
  32628. this.operators[conditionLocation + 1] = 'jz';
  32629. } else {
  32630. error('PS Function: error parsing conditional.');
  32631. }
  32632. }
  32633. };
  32634. return PostScriptParser;
  32635. })();
  32636. var PostScriptTokenTypes = {
  32637. LBRACE: 0,
  32638. RBRACE: 1,
  32639. NUMBER: 2,
  32640. OPERATOR: 3,
  32641. IF: 4,
  32642. IFELSE: 5
  32643. };
  32644. var PostScriptToken = (function PostScriptTokenClosure() {
  32645. function PostScriptToken(type, value) {
  32646. this.type = type;
  32647. this.value = value;
  32648. }
  32649. var opCache = {};
  32650. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  32651. var opValue = opCache[op];
  32652. if (opValue) {
  32653. return opValue;
  32654. }
  32655. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  32656. };
  32657. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  32658. '{');
  32659. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  32660. '}');
  32661. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  32662. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  32663. 'IFELSE');
  32664. return PostScriptToken;
  32665. })();
  32666. var PostScriptLexer = (function PostScriptLexerClosure() {
  32667. function PostScriptLexer(stream) {
  32668. this.stream = stream;
  32669. this.nextChar();
  32670. this.strBuf = [];
  32671. }
  32672. PostScriptLexer.prototype = {
  32673. nextChar: function PostScriptLexer_nextChar() {
  32674. return (this.currentChar = this.stream.getByte());
  32675. },
  32676. getToken: function PostScriptLexer_getToken() {
  32677. var comment = false;
  32678. var ch = this.currentChar;
  32679. // skip comments
  32680. while (true) {
  32681. if (ch < 0) {
  32682. return EOF;
  32683. }
  32684. if (comment) {
  32685. if (ch === 0x0A || ch === 0x0D) {
  32686. comment = false;
  32687. }
  32688. } else if (ch === 0x25) { // '%'
  32689. comment = true;
  32690. } else if (!Lexer.isSpace(ch)) {
  32691. break;
  32692. }
  32693. ch = this.nextChar();
  32694. }
  32695. switch (ch | 0) {
  32696. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32697. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32698. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32699. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  32700. this.getNumber());
  32701. case 0x7B: // '{'
  32702. this.nextChar();
  32703. return PostScriptToken.LBRACE;
  32704. case 0x7D: // '}'
  32705. this.nextChar();
  32706. return PostScriptToken.RBRACE;
  32707. }
  32708. // operator
  32709. var strBuf = this.strBuf;
  32710. strBuf.length = 0;
  32711. strBuf[0] = String.fromCharCode(ch);
  32712. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  32713. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  32714. strBuf.push(String.fromCharCode(ch));
  32715. }
  32716. var str = strBuf.join('');
  32717. switch (str.toLowerCase()) {
  32718. case 'if':
  32719. return PostScriptToken.IF;
  32720. case 'ifelse':
  32721. return PostScriptToken.IFELSE;
  32722. default:
  32723. return PostScriptToken.getOperator(str);
  32724. }
  32725. },
  32726. getNumber: function PostScriptLexer_getNumber() {
  32727. var ch = this.currentChar;
  32728. var strBuf = this.strBuf;
  32729. strBuf.length = 0;
  32730. strBuf[0] = String.fromCharCode(ch);
  32731. while ((ch = this.nextChar()) >= 0) {
  32732. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  32733. ch === 0x2D || ch === 0x2E) { // '-', '.'
  32734. strBuf.push(String.fromCharCode(ch));
  32735. } else {
  32736. break;
  32737. }
  32738. }
  32739. var value = parseFloat(strBuf.join(''));
  32740. if (isNaN(value)) {
  32741. error('Invalid floating point number: ' + value);
  32742. }
  32743. return value;
  32744. }
  32745. };
  32746. return PostScriptLexer;
  32747. })();
  32748. var Stream = (function StreamClosure() {
  32749. function Stream(arrayBuffer, start, length, dict) {
  32750. this.bytes = (arrayBuffer instanceof Uint8Array ?
  32751. arrayBuffer : new Uint8Array(arrayBuffer));
  32752. this.start = start || 0;
  32753. this.pos = this.start;
  32754. this.end = (start + length) || this.bytes.length;
  32755. this.dict = dict;
  32756. }
  32757. // required methods for a stream. if a particular stream does not
  32758. // implement these, an error should be thrown
  32759. Stream.prototype = {
  32760. get length() {
  32761. return this.end - this.start;
  32762. },
  32763. get isEmpty() {
  32764. return this.length === 0;
  32765. },
  32766. getByte: function Stream_getByte() {
  32767. if (this.pos >= this.end) {
  32768. return -1;
  32769. }
  32770. return this.bytes[this.pos++];
  32771. },
  32772. getUint16: function Stream_getUint16() {
  32773. var b0 = this.getByte();
  32774. var b1 = this.getByte();
  32775. return (b0 << 8) + b1;
  32776. },
  32777. getInt32: function Stream_getInt32() {
  32778. var b0 = this.getByte();
  32779. var b1 = this.getByte();
  32780. var b2 = this.getByte();
  32781. var b3 = this.getByte();
  32782. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32783. },
  32784. // returns subarray of original buffer
  32785. // should only be read
  32786. getBytes: function Stream_getBytes(length) {
  32787. var bytes = this.bytes;
  32788. var pos = this.pos;
  32789. var strEnd = this.end;
  32790. if (!length) {
  32791. return bytes.subarray(pos, strEnd);
  32792. }
  32793. var end = pos + length;
  32794. if (end > strEnd) {
  32795. end = strEnd;
  32796. }
  32797. this.pos = end;
  32798. return bytes.subarray(pos, end);
  32799. },
  32800. peekBytes: function Stream_peekBytes(length) {
  32801. var bytes = this.getBytes(length);
  32802. this.pos -= bytes.length;
  32803. return bytes;
  32804. },
  32805. skip: function Stream_skip(n) {
  32806. if (!n) {
  32807. n = 1;
  32808. }
  32809. this.pos += n;
  32810. },
  32811. reset: function Stream_reset() {
  32812. this.pos = this.start;
  32813. },
  32814. moveStart: function Stream_moveStart() {
  32815. this.start = this.pos;
  32816. },
  32817. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  32818. return new Stream(this.bytes.buffer, start, length, dict);
  32819. },
  32820. isStream: true
  32821. };
  32822. return Stream;
  32823. })();
  32824. var StringStream = (function StringStreamClosure() {
  32825. function StringStream(str) {
  32826. var length = str.length;
  32827. var bytes = new Uint8Array(length);
  32828. for (var n = 0; n < length; ++n) {
  32829. bytes[n] = str.charCodeAt(n);
  32830. }
  32831. Stream.call(this, bytes);
  32832. }
  32833. StringStream.prototype = Stream.prototype;
  32834. return StringStream;
  32835. })();
  32836. // super class for the decoding streams
  32837. var DecodeStream = (function DecodeStreamClosure() {
  32838. // Lots of DecodeStreams are created whose buffers are never used. For these
  32839. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  32840. // having special cases that would be required if we used |null| for an empty
  32841. // buffer.
  32842. var emptyBuffer = new Uint8Array(0);
  32843. function DecodeStream(maybeMinBufferLength) {
  32844. this.pos = 0;
  32845. this.bufferLength = 0;
  32846. this.eof = false;
  32847. this.buffer = emptyBuffer;
  32848. this.minBufferLength = 512;
  32849. if (maybeMinBufferLength) {
  32850. // Compute the first power of two that is as big as maybeMinBufferLength.
  32851. while (this.minBufferLength < maybeMinBufferLength) {
  32852. this.minBufferLength *= 2;
  32853. }
  32854. }
  32855. }
  32856. DecodeStream.prototype = {
  32857. get isEmpty() {
  32858. while (!this.eof && this.bufferLength === 0) {
  32859. this.readBlock();
  32860. }
  32861. return this.bufferLength === 0;
  32862. },
  32863. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  32864. var buffer = this.buffer;
  32865. if (requested <= buffer.byteLength) {
  32866. return buffer;
  32867. }
  32868. var size = this.minBufferLength;
  32869. while (size < requested) {
  32870. size *= 2;
  32871. }
  32872. var buffer2 = new Uint8Array(size);
  32873. buffer2.set(buffer);
  32874. return (this.buffer = buffer2);
  32875. },
  32876. getByte: function DecodeStream_getByte() {
  32877. var pos = this.pos;
  32878. while (this.bufferLength <= pos) {
  32879. if (this.eof) {
  32880. return -1;
  32881. }
  32882. this.readBlock();
  32883. }
  32884. return this.buffer[this.pos++];
  32885. },
  32886. getUint16: function DecodeStream_getUint16() {
  32887. var b0 = this.getByte();
  32888. var b1 = this.getByte();
  32889. return (b0 << 8) + b1;
  32890. },
  32891. getInt32: function DecodeStream_getInt32() {
  32892. var b0 = this.getByte();
  32893. var b1 = this.getByte();
  32894. var b2 = this.getByte();
  32895. var b3 = this.getByte();
  32896. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32897. },
  32898. getBytes: function DecodeStream_getBytes(length) {
  32899. var end, pos = this.pos;
  32900. if (length) {
  32901. this.ensureBuffer(pos + length);
  32902. end = pos + length;
  32903. while (!this.eof && this.bufferLength < end) {
  32904. this.readBlock();
  32905. }
  32906. var bufEnd = this.bufferLength;
  32907. if (end > bufEnd) {
  32908. end = bufEnd;
  32909. }
  32910. } else {
  32911. while (!this.eof) {
  32912. this.readBlock();
  32913. }
  32914. end = this.bufferLength;
  32915. }
  32916. this.pos = end;
  32917. return this.buffer.subarray(pos, end);
  32918. },
  32919. peekBytes: function DecodeStream_peekBytes(length) {
  32920. var bytes = this.getBytes(length);
  32921. this.pos -= bytes.length;
  32922. return bytes;
  32923. },
  32924. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  32925. var end = start + length;
  32926. while (this.bufferLength <= end && !this.eof) {
  32927. this.readBlock();
  32928. }
  32929. return new Stream(this.buffer, start, length, dict);
  32930. },
  32931. skip: function DecodeStream_skip(n) {
  32932. if (!n) {
  32933. n = 1;
  32934. }
  32935. this.pos += n;
  32936. },
  32937. reset: function DecodeStream_reset() {
  32938. this.pos = 0;
  32939. },
  32940. getBaseStreams: function DecodeStream_getBaseStreams() {
  32941. if (this.str && this.str.getBaseStreams) {
  32942. return this.str.getBaseStreams();
  32943. }
  32944. return [];
  32945. }
  32946. };
  32947. return DecodeStream;
  32948. })();
  32949. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  32950. function StreamsSequenceStream(streams) {
  32951. this.streams = streams;
  32952. DecodeStream.call(this, /* maybeLength = */ null);
  32953. }
  32954. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  32955. StreamsSequenceStream.prototype.readBlock =
  32956. function streamSequenceStreamReadBlock() {
  32957. var streams = this.streams;
  32958. if (streams.length === 0) {
  32959. this.eof = true;
  32960. return;
  32961. }
  32962. var stream = streams.shift();
  32963. var chunk = stream.getBytes();
  32964. var bufferLength = this.bufferLength;
  32965. var newLength = bufferLength + chunk.length;
  32966. var buffer = this.ensureBuffer(newLength);
  32967. buffer.set(chunk, bufferLength);
  32968. this.bufferLength = newLength;
  32969. };
  32970. StreamsSequenceStream.prototype.getBaseStreams =
  32971. function StreamsSequenceStream_getBaseStreams() {
  32972. var baseStreams = [];
  32973. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  32974. var stream = this.streams[i];
  32975. if (stream.getBaseStreams) {
  32976. Util.appendToArray(baseStreams, stream.getBaseStreams());
  32977. }
  32978. }
  32979. return baseStreams;
  32980. };
  32981. return StreamsSequenceStream;
  32982. })();
  32983. var FlateStream = (function FlateStreamClosure() {
  32984. var codeLenCodeMap = new Uint32Array([
  32985. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  32986. ]);
  32987. var lengthDecode = new Uint32Array([
  32988. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  32989. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  32990. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  32991. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  32992. ]);
  32993. var distDecode = new Uint32Array([
  32994. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  32995. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  32996. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  32997. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  32998. ]);
  32999. var fixedLitCodeTab = [new Uint32Array([
  33000. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  33001. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  33002. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  33003. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  33004. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  33005. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  33006. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  33007. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  33008. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  33009. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  33010. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  33011. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  33012. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  33013. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  33014. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  33015. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  33016. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  33017. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  33018. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  33019. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  33020. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  33021. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  33022. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  33023. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  33024. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  33025. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  33026. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  33027. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  33028. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  33029. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  33030. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  33031. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  33032. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  33033. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  33034. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  33035. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  33036. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  33037. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  33038. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  33039. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  33040. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  33041. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  33042. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  33043. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  33044. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  33045. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  33046. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  33047. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  33048. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  33049. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  33050. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  33051. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  33052. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  33053. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  33054. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  33055. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  33056. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  33057. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  33058. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  33059. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  33060. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  33061. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  33062. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  33063. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  33064. ]), 9];
  33065. var fixedDistCodeTab = [new Uint32Array([
  33066. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  33067. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  33068. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  33069. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  33070. ]), 5];
  33071. function FlateStream(str, maybeLength) {
  33072. this.str = str;
  33073. this.dict = str.dict;
  33074. var cmf = str.getByte();
  33075. var flg = str.getByte();
  33076. if (cmf === -1 || flg === -1) {
  33077. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  33078. }
  33079. if ((cmf & 0x0f) !== 0x08) {
  33080. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  33081. }
  33082. if ((((cmf << 8) + flg) % 31) !== 0) {
  33083. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  33084. }
  33085. if (flg & 0x20) {
  33086. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  33087. }
  33088. this.codeSize = 0;
  33089. this.codeBuf = 0;
  33090. DecodeStream.call(this, maybeLength);
  33091. }
  33092. FlateStream.prototype = Object.create(DecodeStream.prototype);
  33093. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  33094. var str = this.str;
  33095. var codeSize = this.codeSize;
  33096. var codeBuf = this.codeBuf;
  33097. var b;
  33098. while (codeSize < bits) {
  33099. if ((b = str.getByte()) === -1) {
  33100. error('Bad encoding in flate stream');
  33101. }
  33102. codeBuf |= b << codeSize;
  33103. codeSize += 8;
  33104. }
  33105. b = codeBuf & ((1 << bits) - 1);
  33106. this.codeBuf = codeBuf >> bits;
  33107. this.codeSize = codeSize -= bits;
  33108. return b;
  33109. };
  33110. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  33111. var str = this.str;
  33112. var codes = table[0];
  33113. var maxLen = table[1];
  33114. var codeSize = this.codeSize;
  33115. var codeBuf = this.codeBuf;
  33116. var b;
  33117. while (codeSize < maxLen) {
  33118. if ((b = str.getByte()) === -1) {
  33119. // premature end of stream. code might however still be valid.
  33120. // codeSize < codeLen check below guards against incomplete codeVal.
  33121. break;
  33122. }
  33123. codeBuf |= (b << codeSize);
  33124. codeSize += 8;
  33125. }
  33126. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  33127. var codeLen = code >> 16;
  33128. var codeVal = code & 0xffff;
  33129. if (codeLen < 1 || codeSize < codeLen) {
  33130. error('Bad encoding in flate stream');
  33131. }
  33132. this.codeBuf = (codeBuf >> codeLen);
  33133. this.codeSize = (codeSize - codeLen);
  33134. return codeVal;
  33135. };
  33136. FlateStream.prototype.generateHuffmanTable =
  33137. function flateStreamGenerateHuffmanTable(lengths) {
  33138. var n = lengths.length;
  33139. // find max code length
  33140. var maxLen = 0;
  33141. var i;
  33142. for (i = 0; i < n; ++i) {
  33143. if (lengths[i] > maxLen) {
  33144. maxLen = lengths[i];
  33145. }
  33146. }
  33147. // build the table
  33148. var size = 1 << maxLen;
  33149. var codes = new Uint32Array(size);
  33150. for (var len = 1, code = 0, skip = 2;
  33151. len <= maxLen;
  33152. ++len, code <<= 1, skip <<= 1) {
  33153. for (var val = 0; val < n; ++val) {
  33154. if (lengths[val] === len) {
  33155. // bit-reverse the code
  33156. var code2 = 0;
  33157. var t = code;
  33158. for (i = 0; i < len; ++i) {
  33159. code2 = (code2 << 1) | (t & 1);
  33160. t >>= 1;
  33161. }
  33162. // fill the table entries
  33163. for (i = code2; i < size; i += skip) {
  33164. codes[i] = (len << 16) | val;
  33165. }
  33166. ++code;
  33167. }
  33168. }
  33169. }
  33170. return [codes, maxLen];
  33171. };
  33172. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  33173. var buffer, len;
  33174. var str = this.str;
  33175. // read block header
  33176. var hdr = this.getBits(3);
  33177. if (hdr & 1) {
  33178. this.eof = true;
  33179. }
  33180. hdr >>= 1;
  33181. if (hdr === 0) { // uncompressed block
  33182. var b;
  33183. if ((b = str.getByte()) === -1) {
  33184. error('Bad block header in flate stream');
  33185. }
  33186. var blockLen = b;
  33187. if ((b = str.getByte()) === -1) {
  33188. error('Bad block header in flate stream');
  33189. }
  33190. blockLen |= (b << 8);
  33191. if ((b = str.getByte()) === -1) {
  33192. error('Bad block header in flate stream');
  33193. }
  33194. var check = b;
  33195. if ((b = str.getByte()) === -1) {
  33196. error('Bad block header in flate stream');
  33197. }
  33198. check |= (b << 8);
  33199. if (check !== (~blockLen & 0xffff) &&
  33200. (blockLen !== 0 || check !== 0)) {
  33201. // Ignoring error for bad "empty" block (see issue 1277)
  33202. error('Bad uncompressed block length in flate stream');
  33203. }
  33204. this.codeBuf = 0;
  33205. this.codeSize = 0;
  33206. var bufferLength = this.bufferLength;
  33207. buffer = this.ensureBuffer(bufferLength + blockLen);
  33208. var end = bufferLength + blockLen;
  33209. this.bufferLength = end;
  33210. if (blockLen === 0) {
  33211. if (str.peekBytes(1).length === 0) {
  33212. this.eof = true;
  33213. }
  33214. } else {
  33215. for (var n = bufferLength; n < end; ++n) {
  33216. if ((b = str.getByte()) === -1) {
  33217. this.eof = true;
  33218. break;
  33219. }
  33220. buffer[n] = b;
  33221. }
  33222. }
  33223. return;
  33224. }
  33225. var litCodeTable;
  33226. var distCodeTable;
  33227. if (hdr === 1) { // compressed block, fixed codes
  33228. litCodeTable = fixedLitCodeTab;
  33229. distCodeTable = fixedDistCodeTab;
  33230. } else if (hdr === 2) { // compressed block, dynamic codes
  33231. var numLitCodes = this.getBits(5) + 257;
  33232. var numDistCodes = this.getBits(5) + 1;
  33233. var numCodeLenCodes = this.getBits(4) + 4;
  33234. // build the code lengths code table
  33235. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  33236. var i;
  33237. for (i = 0; i < numCodeLenCodes; ++i) {
  33238. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  33239. }
  33240. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  33241. // build the literal and distance code tables
  33242. len = 0;
  33243. i = 0;
  33244. var codes = numLitCodes + numDistCodes;
  33245. var codeLengths = new Uint8Array(codes);
  33246. var bitsLength, bitsOffset, what;
  33247. while (i < codes) {
  33248. var code = this.getCode(codeLenCodeTab);
  33249. if (code === 16) {
  33250. bitsLength = 2; bitsOffset = 3; what = len;
  33251. } else if (code === 17) {
  33252. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  33253. } else if (code === 18) {
  33254. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  33255. } else {
  33256. codeLengths[i++] = len = code;
  33257. continue;
  33258. }
  33259. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  33260. while (repeatLength-- > 0) {
  33261. codeLengths[i++] = what;
  33262. }
  33263. }
  33264. litCodeTable =
  33265. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  33266. distCodeTable =
  33267. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  33268. } else {
  33269. error('Unknown block type in flate stream');
  33270. }
  33271. buffer = this.buffer;
  33272. var limit = buffer ? buffer.length : 0;
  33273. var pos = this.bufferLength;
  33274. while (true) {
  33275. var code1 = this.getCode(litCodeTable);
  33276. if (code1 < 256) {
  33277. if (pos + 1 >= limit) {
  33278. buffer = this.ensureBuffer(pos + 1);
  33279. limit = buffer.length;
  33280. }
  33281. buffer[pos++] = code1;
  33282. continue;
  33283. }
  33284. if (code1 === 256) {
  33285. this.bufferLength = pos;
  33286. return;
  33287. }
  33288. code1 -= 257;
  33289. code1 = lengthDecode[code1];
  33290. var code2 = code1 >> 16;
  33291. if (code2 > 0) {
  33292. code2 = this.getBits(code2);
  33293. }
  33294. len = (code1 & 0xffff) + code2;
  33295. code1 = this.getCode(distCodeTable);
  33296. code1 = distDecode[code1];
  33297. code2 = code1 >> 16;
  33298. if (code2 > 0) {
  33299. code2 = this.getBits(code2);
  33300. }
  33301. var dist = (code1 & 0xffff) + code2;
  33302. if (pos + len >= limit) {
  33303. buffer = this.ensureBuffer(pos + len);
  33304. limit = buffer.length;
  33305. }
  33306. for (var k = 0; k < len; ++k, ++pos) {
  33307. buffer[pos] = buffer[pos - dist];
  33308. }
  33309. }
  33310. };
  33311. return FlateStream;
  33312. })();
  33313. var PredictorStream = (function PredictorStreamClosure() {
  33314. function PredictorStream(str, maybeLength, params) {
  33315. var predictor = this.predictor = params.get('Predictor') || 1;
  33316. if (predictor <= 1) {
  33317. return str; // no prediction
  33318. }
  33319. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  33320. error('Unsupported predictor: ' + predictor);
  33321. }
  33322. if (predictor === 2) {
  33323. this.readBlock = this.readBlockTiff;
  33324. } else {
  33325. this.readBlock = this.readBlockPng;
  33326. }
  33327. this.str = str;
  33328. this.dict = str.dict;
  33329. var colors = this.colors = params.get('Colors') || 1;
  33330. var bits = this.bits = params.get('BitsPerComponent') || 8;
  33331. var columns = this.columns = params.get('Columns') || 1;
  33332. this.pixBytes = (colors * bits + 7) >> 3;
  33333. this.rowBytes = (columns * colors * bits + 7) >> 3;
  33334. DecodeStream.call(this, maybeLength);
  33335. return this;
  33336. }
  33337. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  33338. PredictorStream.prototype.readBlockTiff =
  33339. function predictorStreamReadBlockTiff() {
  33340. var rowBytes = this.rowBytes;
  33341. var bufferLength = this.bufferLength;
  33342. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33343. var bits = this.bits;
  33344. var colors = this.colors;
  33345. var rawBytes = this.str.getBytes(rowBytes);
  33346. this.eof = !rawBytes.length;
  33347. if (this.eof) {
  33348. return;
  33349. }
  33350. var inbuf = 0, outbuf = 0;
  33351. var inbits = 0, outbits = 0;
  33352. var pos = bufferLength;
  33353. var i;
  33354. if (bits === 1) {
  33355. for (i = 0; i < rowBytes; ++i) {
  33356. var c = rawBytes[i];
  33357. inbuf = (inbuf << 8) | c;
  33358. // bitwise addition is exclusive or
  33359. // first shift inbuf and then add
  33360. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  33361. // truncate inbuf (assumes colors < 16)
  33362. inbuf &= 0xFFFF;
  33363. }
  33364. } else if (bits === 8) {
  33365. for (i = 0; i < colors; ++i) {
  33366. buffer[pos++] = rawBytes[i];
  33367. }
  33368. for (; i < rowBytes; ++i) {
  33369. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  33370. pos++;
  33371. }
  33372. } else {
  33373. var compArray = new Uint8Array(colors + 1);
  33374. var bitMask = (1 << bits) - 1;
  33375. var j = 0, k = bufferLength;
  33376. var columns = this.columns;
  33377. for (i = 0; i < columns; ++i) {
  33378. for (var kk = 0; kk < colors; ++kk) {
  33379. if (inbits < bits) {
  33380. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  33381. inbits += 8;
  33382. }
  33383. compArray[kk] = (compArray[kk] +
  33384. (inbuf >> (inbits - bits))) & bitMask;
  33385. inbits -= bits;
  33386. outbuf = (outbuf << bits) | compArray[kk];
  33387. outbits += bits;
  33388. if (outbits >= 8) {
  33389. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  33390. outbits -= 8;
  33391. }
  33392. }
  33393. }
  33394. if (outbits > 0) {
  33395. buffer[k++] = (outbuf << (8 - outbits)) +
  33396. (inbuf & ((1 << (8 - outbits)) - 1));
  33397. }
  33398. }
  33399. this.bufferLength += rowBytes;
  33400. };
  33401. PredictorStream.prototype.readBlockPng =
  33402. function predictorStreamReadBlockPng() {
  33403. var rowBytes = this.rowBytes;
  33404. var pixBytes = this.pixBytes;
  33405. var predictor = this.str.getByte();
  33406. var rawBytes = this.str.getBytes(rowBytes);
  33407. this.eof = !rawBytes.length;
  33408. if (this.eof) {
  33409. return;
  33410. }
  33411. var bufferLength = this.bufferLength;
  33412. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33413. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  33414. if (prevRow.length === 0) {
  33415. prevRow = new Uint8Array(rowBytes);
  33416. }
  33417. var i, j = bufferLength, up, c;
  33418. switch (predictor) {
  33419. case 0:
  33420. for (i = 0; i < rowBytes; ++i) {
  33421. buffer[j++] = rawBytes[i];
  33422. }
  33423. break;
  33424. case 1:
  33425. for (i = 0; i < pixBytes; ++i) {
  33426. buffer[j++] = rawBytes[i];
  33427. }
  33428. for (; i < rowBytes; ++i) {
  33429. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  33430. j++;
  33431. }
  33432. break;
  33433. case 2:
  33434. for (i = 0; i < rowBytes; ++i) {
  33435. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  33436. }
  33437. break;
  33438. case 3:
  33439. for (i = 0; i < pixBytes; ++i) {
  33440. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  33441. }
  33442. for (; i < rowBytes; ++i) {
  33443. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  33444. rawBytes[i]) & 0xFF;
  33445. j++;
  33446. }
  33447. break;
  33448. case 4:
  33449. // we need to save the up left pixels values. the simplest way
  33450. // is to create a new buffer
  33451. for (i = 0; i < pixBytes; ++i) {
  33452. up = prevRow[i];
  33453. c = rawBytes[i];
  33454. buffer[j++] = up + c;
  33455. }
  33456. for (; i < rowBytes; ++i) {
  33457. up = prevRow[i];
  33458. var upLeft = prevRow[i - pixBytes];
  33459. var left = buffer[j - pixBytes];
  33460. var p = left + up - upLeft;
  33461. var pa = p - left;
  33462. if (pa < 0) {
  33463. pa = -pa;
  33464. }
  33465. var pb = p - up;
  33466. if (pb < 0) {
  33467. pb = -pb;
  33468. }
  33469. var pc = p - upLeft;
  33470. if (pc < 0) {
  33471. pc = -pc;
  33472. }
  33473. c = rawBytes[i];
  33474. if (pa <= pb && pa <= pc) {
  33475. buffer[j++] = left + c;
  33476. } else if (pb <= pc) {
  33477. buffer[j++] = up + c;
  33478. } else {
  33479. buffer[j++] = upLeft + c;
  33480. }
  33481. }
  33482. break;
  33483. default:
  33484. error('Unsupported predictor: ' + predictor);
  33485. }
  33486. this.bufferLength += rowBytes;
  33487. };
  33488. return PredictorStream;
  33489. })();
  33490. /**
  33491. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  33492. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  33493. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  33494. * a library to decode these images and the stream behaves like all the other
  33495. * DecodeStreams.
  33496. */
  33497. var JpegStream = (function JpegStreamClosure() {
  33498. function JpegStream(stream, maybeLength, dict, xref) {
  33499. // TODO: per poppler, some images may have 'junk' before that
  33500. // need to be removed
  33501. this.stream = stream;
  33502. this.maybeLength = maybeLength;
  33503. this.dict = dict;
  33504. DecodeStream.call(this, maybeLength);
  33505. }
  33506. JpegStream.prototype = Object.create(DecodeStream.prototype);
  33507. Object.defineProperty(JpegStream.prototype, 'bytes', {
  33508. get: function JpegStream_bytes() {
  33509. // If this.maybeLength is null, we'll get the entire stream.
  33510. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33511. },
  33512. configurable: true
  33513. });
  33514. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  33515. if (this.bufferLength) {
  33516. return;
  33517. }
  33518. try {
  33519. var jpegImage = new JpegImage();
  33520. // checking if values needs to be transformed before conversion
  33521. if (this.dict && isArray(this.dict.get('Decode'))) {
  33522. var decodeArr = this.dict.get('Decode');
  33523. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  33524. var decodeArrLength = decodeArr.length;
  33525. var transform = new Int32Array(decodeArrLength);
  33526. var transformNeeded = false;
  33527. var maxValue = (1 << bitsPerComponent) - 1;
  33528. for (var i = 0; i < decodeArrLength; i += 2) {
  33529. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  33530. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  33531. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  33532. transformNeeded = true;
  33533. }
  33534. }
  33535. if (transformNeeded) {
  33536. jpegImage.decodeTransform = transform;
  33537. }
  33538. }
  33539. jpegImage.parse(this.bytes);
  33540. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  33541. this.forceRGB);
  33542. this.buffer = data;
  33543. this.bufferLength = data.length;
  33544. this.eof = true;
  33545. } catch (e) {
  33546. error('JPEG error: ' + e);
  33547. }
  33548. };
  33549. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  33550. this.ensureBuffer();
  33551. return this.buffer;
  33552. };
  33553. JpegStream.prototype.getIR = function JpegStream_getIR() {
  33554. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  33555. };
  33556. /**
  33557. * Checks if the image can be decoded and displayed by the browser without any
  33558. * further processing such as color space conversions.
  33559. */
  33560. JpegStream.prototype.isNativelySupported =
  33561. function JpegStream_isNativelySupported(xref, res) {
  33562. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33563. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  33564. };
  33565. /**
  33566. * Checks if the image can be decoded by the browser.
  33567. */
  33568. JpegStream.prototype.isNativelyDecodable =
  33569. function JpegStream_isNativelyDecodable(xref, res) {
  33570. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33571. var numComps = cs.numComps;
  33572. return numComps === 1 || numComps === 3;
  33573. };
  33574. return JpegStream;
  33575. })();
  33576. /**
  33577. * For JPEG 2000's we use a library to decode these images and
  33578. * the stream behaves like all the other DecodeStreams.
  33579. */
  33580. var JpxStream = (function JpxStreamClosure() {
  33581. function JpxStream(stream, maybeLength, dict) {
  33582. this.stream = stream;
  33583. this.maybeLength = maybeLength;
  33584. this.dict = dict;
  33585. DecodeStream.call(this, maybeLength);
  33586. }
  33587. JpxStream.prototype = Object.create(DecodeStream.prototype);
  33588. Object.defineProperty(JpxStream.prototype, 'bytes', {
  33589. get: function JpxStream_bytes() {
  33590. // If this.maybeLength is null, we'll get the entire stream.
  33591. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33592. },
  33593. configurable: true
  33594. });
  33595. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  33596. if (this.bufferLength) {
  33597. return;
  33598. }
  33599. var jpxImage = new JpxImage();
  33600. jpxImage.parse(this.bytes);
  33601. var width = jpxImage.width;
  33602. var height = jpxImage.height;
  33603. var componentsCount = jpxImage.componentsCount;
  33604. var tileCount = jpxImage.tiles.length;
  33605. if (tileCount === 1) {
  33606. this.buffer = jpxImage.tiles[0].items;
  33607. } else {
  33608. var data = new Uint8Array(width * height * componentsCount);
  33609. for (var k = 0; k < tileCount; k++) {
  33610. var tileComponents = jpxImage.tiles[k];
  33611. var tileWidth = tileComponents.width;
  33612. var tileHeight = tileComponents.height;
  33613. var tileLeft = tileComponents.left;
  33614. var tileTop = tileComponents.top;
  33615. var src = tileComponents.items;
  33616. var srcPosition = 0;
  33617. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  33618. var imgRowSize = width * componentsCount;
  33619. var tileRowSize = tileWidth * componentsCount;
  33620. for (var j = 0; j < tileHeight; j++) {
  33621. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  33622. data.set(rowBytes, dataPosition);
  33623. srcPosition += tileRowSize;
  33624. dataPosition += imgRowSize;
  33625. }
  33626. }
  33627. this.buffer = data;
  33628. }
  33629. this.bufferLength = this.buffer.length;
  33630. this.eof = true;
  33631. };
  33632. return JpxStream;
  33633. })();
  33634. /**
  33635. * For JBIG2's we use a library to decode these images and
  33636. * the stream behaves like all the other DecodeStreams.
  33637. */
  33638. var Jbig2Stream = (function Jbig2StreamClosure() {
  33639. function Jbig2Stream(stream, maybeLength, dict) {
  33640. this.stream = stream;
  33641. this.maybeLength = maybeLength;
  33642. this.dict = dict;
  33643. DecodeStream.call(this, maybeLength);
  33644. }
  33645. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  33646. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  33647. get: function Jbig2Stream_bytes() {
  33648. // If this.maybeLength is null, we'll get the entire stream.
  33649. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33650. },
  33651. configurable: true
  33652. });
  33653. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  33654. if (this.bufferLength) {
  33655. return;
  33656. }
  33657. var jbig2Image = new Jbig2Image();
  33658. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  33659. // According to the PDF specification, DecodeParms can be either
  33660. // a dictionary, or an array whose elements are dictionaries.
  33661. if (isArray(decodeParams)) {
  33662. if (decodeParams.length > 1) {
  33663. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  33664. 'not supported.');
  33665. }
  33666. decodeParams = decodeParams[0];
  33667. }
  33668. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  33669. var globalsStream = decodeParams.get('JBIG2Globals');
  33670. var globals = globalsStream.getBytes();
  33671. chunks.push({data: globals, start: 0, end: globals.length});
  33672. }
  33673. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  33674. var data = jbig2Image.parseChunks(chunks);
  33675. var dataLength = data.length;
  33676. // JBIG2 had black as 1 and white as 0, inverting the colors
  33677. for (var i = 0; i < dataLength; i++) {
  33678. data[i] ^= 0xFF;
  33679. }
  33680. this.buffer = data;
  33681. this.bufferLength = dataLength;
  33682. this.eof = true;
  33683. };
  33684. return Jbig2Stream;
  33685. })();
  33686. var DecryptStream = (function DecryptStreamClosure() {
  33687. function DecryptStream(str, maybeLength, decrypt) {
  33688. this.str = str;
  33689. this.dict = str.dict;
  33690. this.decrypt = decrypt;
  33691. this.nextChunk = null;
  33692. this.initialized = false;
  33693. DecodeStream.call(this, maybeLength);
  33694. }
  33695. var chunkSize = 512;
  33696. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  33697. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  33698. var chunk;
  33699. if (this.initialized) {
  33700. chunk = this.nextChunk;
  33701. } else {
  33702. chunk = this.str.getBytes(chunkSize);
  33703. this.initialized = true;
  33704. }
  33705. if (!chunk || chunk.length === 0) {
  33706. this.eof = true;
  33707. return;
  33708. }
  33709. this.nextChunk = this.str.getBytes(chunkSize);
  33710. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  33711. var decrypt = this.decrypt;
  33712. chunk = decrypt(chunk, !hasMoreData);
  33713. var bufferLength = this.bufferLength;
  33714. var i, n = chunk.length;
  33715. var buffer = this.ensureBuffer(bufferLength + n);
  33716. for (i = 0; i < n; i++) {
  33717. buffer[bufferLength++] = chunk[i];
  33718. }
  33719. this.bufferLength = bufferLength;
  33720. };
  33721. return DecryptStream;
  33722. })();
  33723. var Ascii85Stream = (function Ascii85StreamClosure() {
  33724. function Ascii85Stream(str, maybeLength) {
  33725. this.str = str;
  33726. this.dict = str.dict;
  33727. this.input = new Uint8Array(5);
  33728. // Most streams increase in size when decoded, but Ascii85 streams
  33729. // typically shrink by ~20%.
  33730. if (maybeLength) {
  33731. maybeLength = 0.8 * maybeLength;
  33732. }
  33733. DecodeStream.call(this, maybeLength);
  33734. }
  33735. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  33736. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  33737. var TILDA_CHAR = 0x7E; // '~'
  33738. var Z_LOWER_CHAR = 0x7A; // 'z'
  33739. var EOF = -1;
  33740. var str = this.str;
  33741. var c = str.getByte();
  33742. while (Lexer.isSpace(c)) {
  33743. c = str.getByte();
  33744. }
  33745. if (c === EOF || c === TILDA_CHAR) {
  33746. this.eof = true;
  33747. return;
  33748. }
  33749. var bufferLength = this.bufferLength, buffer;
  33750. var i;
  33751. // special code for z
  33752. if (c === Z_LOWER_CHAR) {
  33753. buffer = this.ensureBuffer(bufferLength + 4);
  33754. for (i = 0; i < 4; ++i) {
  33755. buffer[bufferLength + i] = 0;
  33756. }
  33757. this.bufferLength += 4;
  33758. } else {
  33759. var input = this.input;
  33760. input[0] = c;
  33761. for (i = 1; i < 5; ++i) {
  33762. c = str.getByte();
  33763. while (Lexer.isSpace(c)) {
  33764. c = str.getByte();
  33765. }
  33766. input[i] = c;
  33767. if (c === EOF || c === TILDA_CHAR) {
  33768. break;
  33769. }
  33770. }
  33771. buffer = this.ensureBuffer(bufferLength + i - 1);
  33772. this.bufferLength += i - 1;
  33773. // partial ending;
  33774. if (i < 5) {
  33775. for (; i < 5; ++i) {
  33776. input[i] = 0x21 + 84;
  33777. }
  33778. this.eof = true;
  33779. }
  33780. var t = 0;
  33781. for (i = 0; i < 5; ++i) {
  33782. t = t * 85 + (input[i] - 0x21);
  33783. }
  33784. for (i = 3; i >= 0; --i) {
  33785. buffer[bufferLength + i] = t & 0xFF;
  33786. t >>= 8;
  33787. }
  33788. }
  33789. };
  33790. return Ascii85Stream;
  33791. })();
  33792. var AsciiHexStream = (function AsciiHexStreamClosure() {
  33793. function AsciiHexStream(str, maybeLength) {
  33794. this.str = str;
  33795. this.dict = str.dict;
  33796. this.firstDigit = -1;
  33797. // Most streams increase in size when decoded, but AsciiHex streams shrink
  33798. // by 50%.
  33799. if (maybeLength) {
  33800. maybeLength = 0.5 * maybeLength;
  33801. }
  33802. DecodeStream.call(this, maybeLength);
  33803. }
  33804. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  33805. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  33806. var UPSTREAM_BLOCK_SIZE = 8000;
  33807. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  33808. if (!bytes.length) {
  33809. this.eof = true;
  33810. return;
  33811. }
  33812. var maxDecodeLength = (bytes.length + 1) >> 1;
  33813. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  33814. var bufferLength = this.bufferLength;
  33815. var firstDigit = this.firstDigit;
  33816. for (var i = 0, ii = bytes.length; i < ii; i++) {
  33817. var ch = bytes[i], digit;
  33818. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  33819. digit = ch & 0x0F;
  33820. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  33821. // 'A'-'Z', 'a'-'z'
  33822. digit = (ch & 0x0F) + 9;
  33823. } else if (ch === 0x3E) { // '>'
  33824. this.eof = true;
  33825. break;
  33826. } else { // probably whitespace
  33827. continue; // ignoring
  33828. }
  33829. if (firstDigit < 0) {
  33830. firstDigit = digit;
  33831. } else {
  33832. buffer[bufferLength++] = (firstDigit << 4) | digit;
  33833. firstDigit = -1;
  33834. }
  33835. }
  33836. if (firstDigit >= 0 && this.eof) {
  33837. // incomplete byte
  33838. buffer[bufferLength++] = (firstDigit << 4);
  33839. firstDigit = -1;
  33840. }
  33841. this.firstDigit = firstDigit;
  33842. this.bufferLength = bufferLength;
  33843. };
  33844. return AsciiHexStream;
  33845. })();
  33846. var RunLengthStream = (function RunLengthStreamClosure() {
  33847. function RunLengthStream(str, maybeLength) {
  33848. this.str = str;
  33849. this.dict = str.dict;
  33850. DecodeStream.call(this, maybeLength);
  33851. }
  33852. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  33853. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  33854. // The repeatHeader has following format. The first byte defines type of run
  33855. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  33856. // (in addition to the second byte from the header), n = 129 through 255 -
  33857. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  33858. var repeatHeader = this.str.getBytes(2);
  33859. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  33860. this.eof = true;
  33861. return;
  33862. }
  33863. var buffer;
  33864. var bufferLength = this.bufferLength;
  33865. var n = repeatHeader[0];
  33866. if (n < 128) {
  33867. // copy n bytes
  33868. buffer = this.ensureBuffer(bufferLength + n + 1);
  33869. buffer[bufferLength++] = repeatHeader[1];
  33870. if (n > 0) {
  33871. var source = this.str.getBytes(n);
  33872. buffer.set(source, bufferLength);
  33873. bufferLength += n;
  33874. }
  33875. } else {
  33876. n = 257 - n;
  33877. var b = repeatHeader[1];
  33878. buffer = this.ensureBuffer(bufferLength + n + 1);
  33879. for (var i = 0; i < n; i++) {
  33880. buffer[bufferLength++] = b;
  33881. }
  33882. }
  33883. this.bufferLength = bufferLength;
  33884. };
  33885. return RunLengthStream;
  33886. })();
  33887. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  33888. var ccittEOL = -2;
  33889. var twoDimPass = 0;
  33890. var twoDimHoriz = 1;
  33891. var twoDimVert0 = 2;
  33892. var twoDimVertR1 = 3;
  33893. var twoDimVertL1 = 4;
  33894. var twoDimVertR2 = 5;
  33895. var twoDimVertL2 = 6;
  33896. var twoDimVertR3 = 7;
  33897. var twoDimVertL3 = 8;
  33898. var twoDimTable = [
  33899. [-1, -1], [-1, -1], // 000000x
  33900. [7, twoDimVertL3], // 0000010
  33901. [7, twoDimVertR3], // 0000011
  33902. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  33903. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  33904. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  33905. [4, twoDimPass], [4, twoDimPass],
  33906. [4, twoDimPass], [4, twoDimPass],
  33907. [4, twoDimPass], [4, twoDimPass],
  33908. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  33909. [3, twoDimHoriz], [3, twoDimHoriz],
  33910. [3, twoDimHoriz], [3, twoDimHoriz],
  33911. [3, twoDimHoriz], [3, twoDimHoriz],
  33912. [3, twoDimHoriz], [3, twoDimHoriz],
  33913. [3, twoDimHoriz], [3, twoDimHoriz],
  33914. [3, twoDimHoriz], [3, twoDimHoriz],
  33915. [3, twoDimHoriz], [3, twoDimHoriz],
  33916. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  33917. [3, twoDimVertL1], [3, twoDimVertL1],
  33918. [3, twoDimVertL1], [3, twoDimVertL1],
  33919. [3, twoDimVertL1], [3, twoDimVertL1],
  33920. [3, twoDimVertL1], [3, twoDimVertL1],
  33921. [3, twoDimVertL1], [3, twoDimVertL1],
  33922. [3, twoDimVertL1], [3, twoDimVertL1],
  33923. [3, twoDimVertL1], [3, twoDimVertL1],
  33924. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  33925. [3, twoDimVertR1], [3, twoDimVertR1],
  33926. [3, twoDimVertR1], [3, twoDimVertR1],
  33927. [3, twoDimVertR1], [3, twoDimVertR1],
  33928. [3, twoDimVertR1], [3, twoDimVertR1],
  33929. [3, twoDimVertR1], [3, twoDimVertR1],
  33930. [3, twoDimVertR1], [3, twoDimVertR1],
  33931. [3, twoDimVertR1], [3, twoDimVertR1],
  33932. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  33933. [1, twoDimVert0], [1, twoDimVert0],
  33934. [1, twoDimVert0], [1, twoDimVert0],
  33935. [1, twoDimVert0], [1, twoDimVert0],
  33936. [1, twoDimVert0], [1, twoDimVert0],
  33937. [1, twoDimVert0], [1, twoDimVert0],
  33938. [1, twoDimVert0], [1, twoDimVert0],
  33939. [1, twoDimVert0], [1, twoDimVert0],
  33940. [1, twoDimVert0], [1, twoDimVert0],
  33941. [1, twoDimVert0], [1, twoDimVert0],
  33942. [1, twoDimVert0], [1, twoDimVert0],
  33943. [1, twoDimVert0], [1, twoDimVert0],
  33944. [1, twoDimVert0], [1, twoDimVert0],
  33945. [1, twoDimVert0], [1, twoDimVert0],
  33946. [1, twoDimVert0], [1, twoDimVert0],
  33947. [1, twoDimVert0], [1, twoDimVert0],
  33948. [1, twoDimVert0], [1, twoDimVert0],
  33949. [1, twoDimVert0], [1, twoDimVert0],
  33950. [1, twoDimVert0], [1, twoDimVert0],
  33951. [1, twoDimVert0], [1, twoDimVert0],
  33952. [1, twoDimVert0], [1, twoDimVert0],
  33953. [1, twoDimVert0], [1, twoDimVert0],
  33954. [1, twoDimVert0], [1, twoDimVert0],
  33955. [1, twoDimVert0], [1, twoDimVert0],
  33956. [1, twoDimVert0], [1, twoDimVert0],
  33957. [1, twoDimVert0], [1, twoDimVert0],
  33958. [1, twoDimVert0], [1, twoDimVert0],
  33959. [1, twoDimVert0], [1, twoDimVert0],
  33960. [1, twoDimVert0], [1, twoDimVert0],
  33961. [1, twoDimVert0], [1, twoDimVert0],
  33962. [1, twoDimVert0], [1, twoDimVert0],
  33963. [1, twoDimVert0], [1, twoDimVert0]
  33964. ];
  33965. var whiteTable1 = [
  33966. [-1, -1], // 00000
  33967. [12, ccittEOL], // 00001
  33968. [-1, -1], [-1, -1], // 0001x
  33969. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  33970. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  33971. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  33972. [11, 1792], [11, 1792], // 1000x
  33973. [12, 1984], // 10010
  33974. [12, 2048], // 10011
  33975. [12, 2112], // 10100
  33976. [12, 2176], // 10101
  33977. [12, 2240], // 10110
  33978. [12, 2304], // 10111
  33979. [11, 1856], [11, 1856], // 1100x
  33980. [11, 1920], [11, 1920], // 1101x
  33981. [12, 2368], // 11100
  33982. [12, 2432], // 11101
  33983. [12, 2496], // 11110
  33984. [12, 2560] // 11111
  33985. ];
  33986. var whiteTable2 = [
  33987. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  33988. [8, 29], [8, 29], // 00000010x
  33989. [8, 30], [8, 30], // 00000011x
  33990. [8, 45], [8, 45], // 00000100x
  33991. [8, 46], [8, 46], // 00000101x
  33992. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  33993. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  33994. [8, 47], [8, 47], // 00001010x
  33995. [8, 48], [8, 48], // 00001011x
  33996. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  33997. [6, 13], [6, 13], [6, 13], [6, 13],
  33998. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  33999. [8, 33], [8, 33], // 00010010x
  34000. [8, 34], [8, 34], // 00010011x
  34001. [8, 35], [8, 35], // 00010100x
  34002. [8, 36], [8, 36], // 00010101x
  34003. [8, 37], [8, 37], // 00010110x
  34004. [8, 38], [8, 38], // 00010111x
  34005. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  34006. [8, 31], [8, 31], // 00011010x
  34007. [8, 32], [8, 32], // 00011011x
  34008. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  34009. [6, 1], [6, 1], [6, 1], [6, 1],
  34010. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  34011. [6, 12], [6, 12], [6, 12], [6, 12],
  34012. [8, 53], [8, 53], // 00100100x
  34013. [8, 54], [8, 54], // 00100101x
  34014. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  34015. [8, 39], [8, 39], // 00101000x
  34016. [8, 40], [8, 40], // 00101001x
  34017. [8, 41], [8, 41], // 00101010x
  34018. [8, 42], [8, 42], // 00101011x
  34019. [8, 43], [8, 43], // 00101100x
  34020. [8, 44], [8, 44], // 00101101x
  34021. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  34022. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  34023. [8, 61], [8, 61], // 00110010x
  34024. [8, 62], [8, 62], // 00110011x
  34025. [8, 63], [8, 63], // 00110100x
  34026. [8, 0], [8, 0], // 00110101x
  34027. [8, 320], [8, 320], // 00110110x
  34028. [8, 384], [8, 384], // 00110111x
  34029. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  34030. [5, 10], [5, 10], [5, 10], [5, 10],
  34031. [5, 10], [5, 10], [5, 10], [5, 10],
  34032. [5, 10], [5, 10], [5, 10], [5, 10],
  34033. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  34034. [5, 11], [5, 11], [5, 11], [5, 11],
  34035. [5, 11], [5, 11], [5, 11], [5, 11],
  34036. [5, 11], [5, 11], [5, 11], [5, 11],
  34037. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  34038. [8, 59], [8, 59], // 01001010x
  34039. [8, 60], [8, 60], // 01001011x
  34040. [9, 1472], // 010011000
  34041. [9, 1536], // 010011001
  34042. [9, 1600], // 010011010
  34043. [9, 1728], // 010011011
  34044. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  34045. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  34046. [8, 49], [8, 49], // 01010010x
  34047. [8, 50], [8, 50], // 01010011x
  34048. [8, 51], [8, 51], // 01010100x
  34049. [8, 52], [8, 52], // 01010101x
  34050. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  34051. [8, 55], [8, 55], // 01011000x
  34052. [8, 56], [8, 56], // 01011001x
  34053. [8, 57], [8, 57], // 01011010x
  34054. [8, 58], [8, 58], // 01011011x
  34055. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  34056. [6, 192], [6, 192], [6, 192], [6, 192],
  34057. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  34058. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  34059. [8, 448], [8, 448], // 01100100x
  34060. [8, 512], [8, 512], // 01100101x
  34061. [9, 704], // 011001100
  34062. [9, 768], // 011001101
  34063. [8, 640], [8, 640], // 01100111x
  34064. [8, 576], [8, 576], // 01101000x
  34065. [9, 832], // 011010010
  34066. [9, 896], // 011010011
  34067. [9, 960], // 011010100
  34068. [9, 1024], // 011010101
  34069. [9, 1088], // 011010110
  34070. [9, 1152], // 011010111
  34071. [9, 1216], // 011011000
  34072. [9, 1280], // 011011001
  34073. [9, 1344], // 011011010
  34074. [9, 1408], // 011011011
  34075. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  34076. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  34077. [4, 2], [4, 2], [4, 2], [4, 2],
  34078. [4, 2], [4, 2], [4, 2], [4, 2],
  34079. [4, 2], [4, 2], [4, 2], [4, 2],
  34080. [4, 2], [4, 2], [4, 2], [4, 2],
  34081. [4, 2], [4, 2], [4, 2], [4, 2],
  34082. [4, 2], [4, 2], [4, 2], [4, 2],
  34083. [4, 2], [4, 2], [4, 2], [4, 2],
  34084. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  34085. [4, 3], [4, 3], [4, 3], [4, 3],
  34086. [4, 3], [4, 3], [4, 3], [4, 3],
  34087. [4, 3], [4, 3], [4, 3], [4, 3],
  34088. [4, 3], [4, 3], [4, 3], [4, 3],
  34089. [4, 3], [4, 3], [4, 3], [4, 3],
  34090. [4, 3], [4, 3], [4, 3], [4, 3],
  34091. [4, 3], [4, 3], [4, 3], [4, 3],
  34092. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  34093. [5, 128], [5, 128], [5, 128], [5, 128],
  34094. [5, 128], [5, 128], [5, 128], [5, 128],
  34095. [5, 128], [5, 128], [5, 128], [5, 128],
  34096. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  34097. [5, 8], [5, 8], [5, 8], [5, 8],
  34098. [5, 8], [5, 8], [5, 8], [5, 8],
  34099. [5, 8], [5, 8], [5, 8], [5, 8],
  34100. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  34101. [5, 9], [5, 9], [5, 9], [5, 9],
  34102. [5, 9], [5, 9], [5, 9], [5, 9],
  34103. [5, 9], [5, 9], [5, 9], [5, 9],
  34104. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  34105. [6, 16], [6, 16], [6, 16], [6, 16],
  34106. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  34107. [6, 17], [6, 17], [6, 17], [6, 17],
  34108. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  34109. [4, 4], [4, 4], [4, 4], [4, 4],
  34110. [4, 4], [4, 4], [4, 4], [4, 4],
  34111. [4, 4], [4, 4], [4, 4], [4, 4],
  34112. [4, 4], [4, 4], [4, 4], [4, 4],
  34113. [4, 4], [4, 4], [4, 4], [4, 4],
  34114. [4, 4], [4, 4], [4, 4], [4, 4],
  34115. [4, 4], [4, 4], [4, 4], [4, 4],
  34116. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  34117. [4, 5], [4, 5], [4, 5], [4, 5],
  34118. [4, 5], [4, 5], [4, 5], [4, 5],
  34119. [4, 5], [4, 5], [4, 5], [4, 5],
  34120. [4, 5], [4, 5], [4, 5], [4, 5],
  34121. [4, 5], [4, 5], [4, 5], [4, 5],
  34122. [4, 5], [4, 5], [4, 5], [4, 5],
  34123. [4, 5], [4, 5], [4, 5], [4, 5],
  34124. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  34125. [6, 14], [6, 14], [6, 14], [6, 14],
  34126. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  34127. [6, 15], [6, 15], [6, 15], [6, 15],
  34128. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  34129. [5, 64], [5, 64], [5, 64], [5, 64],
  34130. [5, 64], [5, 64], [5, 64], [5, 64],
  34131. [5, 64], [5, 64], [5, 64], [5, 64],
  34132. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  34133. [4, 6], [4, 6], [4, 6], [4, 6],
  34134. [4, 6], [4, 6], [4, 6], [4, 6],
  34135. [4, 6], [4, 6], [4, 6], [4, 6],
  34136. [4, 6], [4, 6], [4, 6], [4, 6],
  34137. [4, 6], [4, 6], [4, 6], [4, 6],
  34138. [4, 6], [4, 6], [4, 6], [4, 6],
  34139. [4, 6], [4, 6], [4, 6], [4, 6],
  34140. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  34141. [4, 7], [4, 7], [4, 7], [4, 7],
  34142. [4, 7], [4, 7], [4, 7], [4, 7],
  34143. [4, 7], [4, 7], [4, 7], [4, 7],
  34144. [4, 7], [4, 7], [4, 7], [4, 7],
  34145. [4, 7], [4, 7], [4, 7], [4, 7],
  34146. [4, 7], [4, 7], [4, 7], [4, 7],
  34147. [4, 7], [4, 7], [4, 7], [4, 7]
  34148. ];
  34149. var blackTable1 = [
  34150. [-1, -1], [-1, -1], // 000000000000x
  34151. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  34152. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  34153. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  34154. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  34155. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  34156. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  34157. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  34158. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  34159. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  34160. [12, 1984], [12, 1984], // 000000010010x
  34161. [12, 2048], [12, 2048], // 000000010011x
  34162. [12, 2112], [12, 2112], // 000000010100x
  34163. [12, 2176], [12, 2176], // 000000010101x
  34164. [12, 2240], [12, 2240], // 000000010110x
  34165. [12, 2304], [12, 2304], // 000000010111x
  34166. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  34167. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  34168. [12, 2368], [12, 2368], // 000000011100x
  34169. [12, 2432], [12, 2432], // 000000011101x
  34170. [12, 2496], [12, 2496], // 000000011110x
  34171. [12, 2560], [12, 2560], // 000000011111x
  34172. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  34173. [10, 18], [10, 18], [10, 18], [10, 18],
  34174. [12, 52], [12, 52], // 000000100100x
  34175. [13, 640], // 0000001001010
  34176. [13, 704], // 0000001001011
  34177. [13, 768], // 0000001001100
  34178. [13, 832], // 0000001001101
  34179. [12, 55], [12, 55], // 000000100111x
  34180. [12, 56], [12, 56], // 000000101000x
  34181. [13, 1280], // 0000001010010
  34182. [13, 1344], // 0000001010011
  34183. [13, 1408], // 0000001010100
  34184. [13, 1472], // 0000001010101
  34185. [12, 59], [12, 59], // 000000101011x
  34186. [12, 60], [12, 60], // 000000101100x
  34187. [13, 1536], // 0000001011010
  34188. [13, 1600], // 0000001011011
  34189. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  34190. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  34191. [13, 1664], // 0000001100100
  34192. [13, 1728], // 0000001100101
  34193. [12, 320], [12, 320], // 000000110011x
  34194. [12, 384], [12, 384], // 000000110100x
  34195. [12, 448], [12, 448], // 000000110101x
  34196. [13, 512], // 0000001101100
  34197. [13, 576], // 0000001101101
  34198. [12, 53], [12, 53], // 000000110111x
  34199. [12, 54], [12, 54], // 000000111000x
  34200. [13, 896], // 0000001110010
  34201. [13, 960], // 0000001110011
  34202. [13, 1024], // 0000001110100
  34203. [13, 1088], // 0000001110101
  34204. [13, 1152], // 0000001110110
  34205. [13, 1216], // 0000001110111
  34206. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  34207. [10, 64], [10, 64], [10, 64], [10, 64]
  34208. ];
  34209. var blackTable2 = [
  34210. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  34211. [8, 13], [8, 13], [8, 13], [8, 13],
  34212. [8, 13], [8, 13], [8, 13], [8, 13],
  34213. [8, 13], [8, 13], [8, 13], [8, 13],
  34214. [11, 23], [11, 23], // 00000101000x
  34215. [12, 50], // 000001010010
  34216. [12, 51], // 000001010011
  34217. [12, 44], // 000001010100
  34218. [12, 45], // 000001010101
  34219. [12, 46], // 000001010110
  34220. [12, 47], // 000001010111
  34221. [12, 57], // 000001011000
  34222. [12, 58], // 000001011001
  34223. [12, 61], // 000001011010
  34224. [12, 256], // 000001011011
  34225. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  34226. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  34227. [12, 48], // 000001100100
  34228. [12, 49], // 000001100101
  34229. [12, 62], // 000001100110
  34230. [12, 63], // 000001100111
  34231. [12, 30], // 000001101000
  34232. [12, 31], // 000001101001
  34233. [12, 32], // 000001101010
  34234. [12, 33], // 000001101011
  34235. [12, 40], // 000001101100
  34236. [12, 41], // 000001101101
  34237. [11, 22], [11, 22], // 00000110111x
  34238. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  34239. [8, 14], [8, 14], [8, 14], [8, 14],
  34240. [8, 14], [8, 14], [8, 14], [8, 14],
  34241. [8, 14], [8, 14], [8, 14], [8, 14],
  34242. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  34243. [7, 10], [7, 10], [7, 10], [7, 10],
  34244. [7, 10], [7, 10], [7, 10], [7, 10],
  34245. [7, 10], [7, 10], [7, 10], [7, 10],
  34246. [7, 10], [7, 10], [7, 10], [7, 10],
  34247. [7, 10], [7, 10], [7, 10], [7, 10],
  34248. [7, 10], [7, 10], [7, 10], [7, 10],
  34249. [7, 10], [7, 10], [7, 10], [7, 10],
  34250. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  34251. [7, 11], [7, 11], [7, 11], [7, 11],
  34252. [7, 11], [7, 11], [7, 11], [7, 11],
  34253. [7, 11], [7, 11], [7, 11], [7, 11],
  34254. [7, 11], [7, 11], [7, 11], [7, 11],
  34255. [7, 11], [7, 11], [7, 11], [7, 11],
  34256. [7, 11], [7, 11], [7, 11], [7, 11],
  34257. [7, 11], [7, 11], [7, 11], [7, 11],
  34258. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  34259. [9, 15], [9, 15], [9, 15], [9, 15],
  34260. [12, 128], // 000011001000
  34261. [12, 192], // 000011001001
  34262. [12, 26], // 000011001010
  34263. [12, 27], // 000011001011
  34264. [12, 28], // 000011001100
  34265. [12, 29], // 000011001101
  34266. [11, 19], [11, 19], // 00001100111x
  34267. [11, 20], [11, 20], // 00001101000x
  34268. [12, 34], // 000011010010
  34269. [12, 35], // 000011010011
  34270. [12, 36], // 000011010100
  34271. [12, 37], // 000011010101
  34272. [12, 38], // 000011010110
  34273. [12, 39], // 000011010111
  34274. [11, 21], [11, 21], // 00001101100x
  34275. [12, 42], // 000011011010
  34276. [12, 43], // 000011011011
  34277. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  34278. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  34279. [7, 12], [7, 12], [7, 12], [7, 12],
  34280. [7, 12], [7, 12], [7, 12], [7, 12],
  34281. [7, 12], [7, 12], [7, 12], [7, 12],
  34282. [7, 12], [7, 12], [7, 12], [7, 12],
  34283. [7, 12], [7, 12], [7, 12], [7, 12],
  34284. [7, 12], [7, 12], [7, 12], [7, 12],
  34285. [7, 12], [7, 12], [7, 12], [7, 12]
  34286. ];
  34287. var blackTable3 = [
  34288. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  34289. [6, 9], // 000100
  34290. [6, 8], // 000101
  34291. [5, 7], [5, 7], // 00011x
  34292. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  34293. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  34294. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  34295. [3, 1], [3, 1], [3, 1], [3, 1],
  34296. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  34297. [3, 4], [3, 4], [3, 4], [3, 4],
  34298. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  34299. [2, 3], [2, 3], [2, 3], [2, 3],
  34300. [2, 3], [2, 3], [2, 3], [2, 3],
  34301. [2, 3], [2, 3], [2, 3], [2, 3],
  34302. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  34303. [2, 2], [2, 2], [2, 2], [2, 2],
  34304. [2, 2], [2, 2], [2, 2], [2, 2],
  34305. [2, 2], [2, 2], [2, 2], [2, 2]
  34306. ];
  34307. function CCITTFaxStream(str, maybeLength, params) {
  34308. this.str = str;
  34309. this.dict = str.dict;
  34310. params = params || Dict.empty;
  34311. this.encoding = params.get('K') || 0;
  34312. this.eoline = params.get('EndOfLine') || false;
  34313. this.byteAlign = params.get('EncodedByteAlign') || false;
  34314. this.columns = params.get('Columns') || 1728;
  34315. this.rows = params.get('Rows') || 0;
  34316. var eoblock = params.get('EndOfBlock');
  34317. if (eoblock === null || eoblock === undefined) {
  34318. eoblock = true;
  34319. }
  34320. this.eoblock = eoblock;
  34321. this.black = params.get('BlackIs1') || false;
  34322. this.codingLine = new Uint32Array(this.columns + 1);
  34323. this.refLine = new Uint32Array(this.columns + 2);
  34324. this.codingLine[0] = this.columns;
  34325. this.codingPos = 0;
  34326. this.row = 0;
  34327. this.nextLine2D = this.encoding < 0;
  34328. this.inputBits = 0;
  34329. this.inputBuf = 0;
  34330. this.outputBits = 0;
  34331. var code1;
  34332. while ((code1 = this.lookBits(12)) === 0) {
  34333. this.eatBits(1);
  34334. }
  34335. if (code1 === 1) {
  34336. this.eatBits(12);
  34337. }
  34338. if (this.encoding > 0) {
  34339. this.nextLine2D = !this.lookBits(1);
  34340. this.eatBits(1);
  34341. }
  34342. DecodeStream.call(this, maybeLength);
  34343. }
  34344. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  34345. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  34346. while (!this.eof) {
  34347. var c = this.lookChar();
  34348. this.ensureBuffer(this.bufferLength + 1);
  34349. this.buffer[this.bufferLength++] = c;
  34350. }
  34351. };
  34352. CCITTFaxStream.prototype.addPixels =
  34353. function ccittFaxStreamAddPixels(a1, blackPixels) {
  34354. var codingLine = this.codingLine;
  34355. var codingPos = this.codingPos;
  34356. if (a1 > codingLine[codingPos]) {
  34357. if (a1 > this.columns) {
  34358. info('row is wrong length');
  34359. this.err = true;
  34360. a1 = this.columns;
  34361. }
  34362. if ((codingPos & 1) ^ blackPixels) {
  34363. ++codingPos;
  34364. }
  34365. codingLine[codingPos] = a1;
  34366. }
  34367. this.codingPos = codingPos;
  34368. };
  34369. CCITTFaxStream.prototype.addPixelsNeg =
  34370. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  34371. var codingLine = this.codingLine;
  34372. var codingPos = this.codingPos;
  34373. if (a1 > codingLine[codingPos]) {
  34374. if (a1 > this.columns) {
  34375. info('row is wrong length');
  34376. this.err = true;
  34377. a1 = this.columns;
  34378. }
  34379. if ((codingPos & 1) ^ blackPixels) {
  34380. ++codingPos;
  34381. }
  34382. codingLine[codingPos] = a1;
  34383. } else if (a1 < codingLine[codingPos]) {
  34384. if (a1 < 0) {
  34385. info('invalid code');
  34386. this.err = true;
  34387. a1 = 0;
  34388. }
  34389. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  34390. --codingPos;
  34391. }
  34392. codingLine[codingPos] = a1;
  34393. }
  34394. this.codingPos = codingPos;
  34395. };
  34396. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  34397. var refLine = this.refLine;
  34398. var codingLine = this.codingLine;
  34399. var columns = this.columns;
  34400. var refPos, blackPixels, bits, i;
  34401. if (this.outputBits === 0) {
  34402. if (this.eof) {
  34403. return null;
  34404. }
  34405. this.err = false;
  34406. var code1, code2, code3;
  34407. if (this.nextLine2D) {
  34408. for (i = 0; codingLine[i] < columns; ++i) {
  34409. refLine[i] = codingLine[i];
  34410. }
  34411. refLine[i++] = columns;
  34412. refLine[i] = columns;
  34413. codingLine[0] = 0;
  34414. this.codingPos = 0;
  34415. refPos = 0;
  34416. blackPixels = 0;
  34417. while (codingLine[this.codingPos] < columns) {
  34418. code1 = this.getTwoDimCode();
  34419. switch (code1) {
  34420. case twoDimPass:
  34421. this.addPixels(refLine[refPos + 1], blackPixels);
  34422. if (refLine[refPos + 1] < columns) {
  34423. refPos += 2;
  34424. }
  34425. break;
  34426. case twoDimHoriz:
  34427. code1 = code2 = 0;
  34428. if (blackPixels) {
  34429. do {
  34430. code1 += (code3 = this.getBlackCode());
  34431. } while (code3 >= 64);
  34432. do {
  34433. code2 += (code3 = this.getWhiteCode());
  34434. } while (code3 >= 64);
  34435. } else {
  34436. do {
  34437. code1 += (code3 = this.getWhiteCode());
  34438. } while (code3 >= 64);
  34439. do {
  34440. code2 += (code3 = this.getBlackCode());
  34441. } while (code3 >= 64);
  34442. }
  34443. this.addPixels(codingLine[this.codingPos] +
  34444. code1, blackPixels);
  34445. if (codingLine[this.codingPos] < columns) {
  34446. this.addPixels(codingLine[this.codingPos] + code2,
  34447. blackPixels ^ 1);
  34448. }
  34449. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34450. refLine[refPos] < columns) {
  34451. refPos += 2;
  34452. }
  34453. break;
  34454. case twoDimVertR3:
  34455. this.addPixels(refLine[refPos] + 3, blackPixels);
  34456. blackPixels ^= 1;
  34457. if (codingLine[this.codingPos] < columns) {
  34458. ++refPos;
  34459. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34460. refLine[refPos] < columns) {
  34461. refPos += 2;
  34462. }
  34463. }
  34464. break;
  34465. case twoDimVertR2:
  34466. this.addPixels(refLine[refPos] + 2, blackPixels);
  34467. blackPixels ^= 1;
  34468. if (codingLine[this.codingPos] < columns) {
  34469. ++refPos;
  34470. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34471. refLine[refPos] < columns) {
  34472. refPos += 2;
  34473. }
  34474. }
  34475. break;
  34476. case twoDimVertR1:
  34477. this.addPixels(refLine[refPos] + 1, blackPixels);
  34478. blackPixels ^= 1;
  34479. if (codingLine[this.codingPos] < columns) {
  34480. ++refPos;
  34481. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34482. refLine[refPos] < columns) {
  34483. refPos += 2;
  34484. }
  34485. }
  34486. break;
  34487. case twoDimVert0:
  34488. this.addPixels(refLine[refPos], blackPixels);
  34489. blackPixels ^= 1;
  34490. if (codingLine[this.codingPos] < columns) {
  34491. ++refPos;
  34492. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34493. refLine[refPos] < columns) {
  34494. refPos += 2;
  34495. }
  34496. }
  34497. break;
  34498. case twoDimVertL3:
  34499. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  34500. blackPixels ^= 1;
  34501. if (codingLine[this.codingPos] < columns) {
  34502. if (refPos > 0) {
  34503. --refPos;
  34504. } else {
  34505. ++refPos;
  34506. }
  34507. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34508. refLine[refPos] < columns) {
  34509. refPos += 2;
  34510. }
  34511. }
  34512. break;
  34513. case twoDimVertL2:
  34514. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  34515. blackPixels ^= 1;
  34516. if (codingLine[this.codingPos] < columns) {
  34517. if (refPos > 0) {
  34518. --refPos;
  34519. } else {
  34520. ++refPos;
  34521. }
  34522. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34523. refLine[refPos] < columns) {
  34524. refPos += 2;
  34525. }
  34526. }
  34527. break;
  34528. case twoDimVertL1:
  34529. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  34530. blackPixels ^= 1;
  34531. if (codingLine[this.codingPos] < columns) {
  34532. if (refPos > 0) {
  34533. --refPos;
  34534. } else {
  34535. ++refPos;
  34536. }
  34537. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34538. refLine[refPos] < columns) {
  34539. refPos += 2;
  34540. }
  34541. }
  34542. break;
  34543. case EOF:
  34544. this.addPixels(columns, 0);
  34545. this.eof = true;
  34546. break;
  34547. default:
  34548. info('bad 2d code');
  34549. this.addPixels(columns, 0);
  34550. this.err = true;
  34551. }
  34552. }
  34553. } else {
  34554. codingLine[0] = 0;
  34555. this.codingPos = 0;
  34556. blackPixels = 0;
  34557. while (codingLine[this.codingPos] < columns) {
  34558. code1 = 0;
  34559. if (blackPixels) {
  34560. do {
  34561. code1 += (code3 = this.getBlackCode());
  34562. } while (code3 >= 64);
  34563. } else {
  34564. do {
  34565. code1 += (code3 = this.getWhiteCode());
  34566. } while (code3 >= 64);
  34567. }
  34568. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  34569. blackPixels ^= 1;
  34570. }
  34571. }
  34572. var gotEOL = false;
  34573. if (!this.eoblock && this.row === this.rows - 1) {
  34574. this.eof = true;
  34575. } else if (this.eoline || !this.byteAlign) {
  34576. code1 = this.lookBits(12);
  34577. if (this.eoline) {
  34578. while (code1 !== EOF && code1 !== 1) {
  34579. this.eatBits(1);
  34580. code1 = this.lookBits(12);
  34581. }
  34582. } else {
  34583. while (code1 === 0) {
  34584. this.eatBits(1);
  34585. code1 = this.lookBits(12);
  34586. }
  34587. }
  34588. if (code1 === 1) {
  34589. this.eatBits(12);
  34590. gotEOL = true;
  34591. } else if (code1 === EOF) {
  34592. this.eof = true;
  34593. }
  34594. }
  34595. if (this.byteAlign && !gotEOL) {
  34596. this.inputBits &= ~7;
  34597. }
  34598. if (!this.eof && this.encoding > 0) {
  34599. this.nextLine2D = !this.lookBits(1);
  34600. this.eatBits(1);
  34601. }
  34602. if (this.eoblock && gotEOL && this.byteAlign) {
  34603. code1 = this.lookBits(12);
  34604. if (code1 === 1) {
  34605. this.eatBits(12);
  34606. if (this.encoding > 0) {
  34607. this.lookBits(1);
  34608. this.eatBits(1);
  34609. }
  34610. if (this.encoding >= 0) {
  34611. for (i = 0; i < 4; ++i) {
  34612. code1 = this.lookBits(12);
  34613. if (code1 !== 1) {
  34614. info('bad rtc code: ' + code1);
  34615. }
  34616. this.eatBits(12);
  34617. if (this.encoding > 0) {
  34618. this.lookBits(1);
  34619. this.eatBits(1);
  34620. }
  34621. }
  34622. }
  34623. this.eof = true;
  34624. }
  34625. } else if (this.err && this.eoline) {
  34626. while (true) {
  34627. code1 = this.lookBits(13);
  34628. if (code1 === EOF) {
  34629. this.eof = true;
  34630. return null;
  34631. }
  34632. if ((code1 >> 1) === 1) {
  34633. break;
  34634. }
  34635. this.eatBits(1);
  34636. }
  34637. this.eatBits(12);
  34638. if (this.encoding > 0) {
  34639. this.eatBits(1);
  34640. this.nextLine2D = !(code1 & 1);
  34641. }
  34642. }
  34643. if (codingLine[0] > 0) {
  34644. this.outputBits = codingLine[this.codingPos = 0];
  34645. } else {
  34646. this.outputBits = codingLine[this.codingPos = 1];
  34647. }
  34648. this.row++;
  34649. }
  34650. var c;
  34651. if (this.outputBits >= 8) {
  34652. c = (this.codingPos & 1) ? 0 : 0xFF;
  34653. this.outputBits -= 8;
  34654. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  34655. this.codingPos++;
  34656. this.outputBits = (codingLine[this.codingPos] -
  34657. codingLine[this.codingPos - 1]);
  34658. }
  34659. } else {
  34660. bits = 8;
  34661. c = 0;
  34662. do {
  34663. if (this.outputBits > bits) {
  34664. c <<= bits;
  34665. if (!(this.codingPos & 1)) {
  34666. c |= 0xFF >> (8 - bits);
  34667. }
  34668. this.outputBits -= bits;
  34669. bits = 0;
  34670. } else {
  34671. c <<= this.outputBits;
  34672. if (!(this.codingPos & 1)) {
  34673. c |= 0xFF >> (8 - this.outputBits);
  34674. }
  34675. bits -= this.outputBits;
  34676. this.outputBits = 0;
  34677. if (codingLine[this.codingPos] < columns) {
  34678. this.codingPos++;
  34679. this.outputBits = (codingLine[this.codingPos] -
  34680. codingLine[this.codingPos - 1]);
  34681. } else if (bits > 0) {
  34682. c <<= bits;
  34683. bits = 0;
  34684. }
  34685. }
  34686. } while (bits);
  34687. }
  34688. if (this.black) {
  34689. c ^= 0xFF;
  34690. }
  34691. return c;
  34692. };
  34693. // This functions returns the code found from the table.
  34694. // The start and end parameters set the boundaries for searching the table.
  34695. // The limit parameter is optional. Function returns an array with three
  34696. // values. The first array element indicates whether a valid code is being
  34697. // returned. The second array element is the actual code. The third array
  34698. // element indicates whether EOF was reached.
  34699. CCITTFaxStream.prototype.findTableCode =
  34700. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  34701. var limitValue = limit || 0;
  34702. for (var i = start; i <= end; ++i) {
  34703. var code = this.lookBits(i);
  34704. if (code === EOF) {
  34705. return [true, 1, false];
  34706. }
  34707. if (i < end) {
  34708. code <<= end - i;
  34709. }
  34710. if (!limitValue || code >= limitValue) {
  34711. var p = table[code - limitValue];
  34712. if (p[0] === i) {
  34713. this.eatBits(i);
  34714. return [true, p[1], true];
  34715. }
  34716. }
  34717. }
  34718. return [false, 0, false];
  34719. };
  34720. CCITTFaxStream.prototype.getTwoDimCode =
  34721. function ccittFaxStreamGetTwoDimCode() {
  34722. var code = 0;
  34723. var p;
  34724. if (this.eoblock) {
  34725. code = this.lookBits(7);
  34726. p = twoDimTable[code];
  34727. if (p && p[0] > 0) {
  34728. this.eatBits(p[0]);
  34729. return p[1];
  34730. }
  34731. } else {
  34732. var result = this.findTableCode(1, 7, twoDimTable);
  34733. if (result[0] && result[2]) {
  34734. return result[1];
  34735. }
  34736. }
  34737. info('Bad two dim code');
  34738. return EOF;
  34739. };
  34740. CCITTFaxStream.prototype.getWhiteCode =
  34741. function ccittFaxStreamGetWhiteCode() {
  34742. var code = 0;
  34743. var p;
  34744. if (this.eoblock) {
  34745. code = this.lookBits(12);
  34746. if (code === EOF) {
  34747. return 1;
  34748. }
  34749. if ((code >> 5) === 0) {
  34750. p = whiteTable1[code];
  34751. } else {
  34752. p = whiteTable2[code >> 3];
  34753. }
  34754. if (p[0] > 0) {
  34755. this.eatBits(p[0]);
  34756. return p[1];
  34757. }
  34758. } else {
  34759. var result = this.findTableCode(1, 9, whiteTable2);
  34760. if (result[0]) {
  34761. return result[1];
  34762. }
  34763. result = this.findTableCode(11, 12, whiteTable1);
  34764. if (result[0]) {
  34765. return result[1];
  34766. }
  34767. }
  34768. info('bad white code');
  34769. this.eatBits(1);
  34770. return 1;
  34771. };
  34772. CCITTFaxStream.prototype.getBlackCode =
  34773. function ccittFaxStreamGetBlackCode() {
  34774. var code, p;
  34775. if (this.eoblock) {
  34776. code = this.lookBits(13);
  34777. if (code === EOF) {
  34778. return 1;
  34779. }
  34780. if ((code >> 7) === 0) {
  34781. p = blackTable1[code];
  34782. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  34783. p = blackTable2[(code >> 1) - 64];
  34784. } else {
  34785. p = blackTable3[code >> 7];
  34786. }
  34787. if (p[0] > 0) {
  34788. this.eatBits(p[0]);
  34789. return p[1];
  34790. }
  34791. } else {
  34792. var result = this.findTableCode(2, 6, blackTable3);
  34793. if (result[0]) {
  34794. return result[1];
  34795. }
  34796. result = this.findTableCode(7, 12, blackTable2, 64);
  34797. if (result[0]) {
  34798. return result[1];
  34799. }
  34800. result = this.findTableCode(10, 13, blackTable1);
  34801. if (result[0]) {
  34802. return result[1];
  34803. }
  34804. }
  34805. info('bad black code');
  34806. this.eatBits(1);
  34807. return 1;
  34808. };
  34809. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  34810. var c;
  34811. while (this.inputBits < n) {
  34812. if ((c = this.str.getByte()) === -1) {
  34813. if (this.inputBits === 0) {
  34814. return EOF;
  34815. }
  34816. return ((this.inputBuf << (n - this.inputBits)) &
  34817. (0xFFFF >> (16 - n)));
  34818. }
  34819. this.inputBuf = (this.inputBuf << 8) + c;
  34820. this.inputBits += 8;
  34821. }
  34822. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  34823. };
  34824. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  34825. if ((this.inputBits -= n) < 0) {
  34826. this.inputBits = 0;
  34827. }
  34828. };
  34829. return CCITTFaxStream;
  34830. })();
  34831. var LZWStream = (function LZWStreamClosure() {
  34832. function LZWStream(str, maybeLength, earlyChange) {
  34833. this.str = str;
  34834. this.dict = str.dict;
  34835. this.cachedData = 0;
  34836. this.bitsCached = 0;
  34837. var maxLzwDictionarySize = 4096;
  34838. var lzwState = {
  34839. earlyChange: earlyChange,
  34840. codeLength: 9,
  34841. nextCode: 258,
  34842. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  34843. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  34844. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  34845. currentSequence: new Uint8Array(maxLzwDictionarySize),
  34846. currentSequenceLength: 0
  34847. };
  34848. for (var i = 0; i < 256; ++i) {
  34849. lzwState.dictionaryValues[i] = i;
  34850. lzwState.dictionaryLengths[i] = 1;
  34851. }
  34852. this.lzwState = lzwState;
  34853. DecodeStream.call(this, maybeLength);
  34854. }
  34855. LZWStream.prototype = Object.create(DecodeStream.prototype);
  34856. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  34857. var bitsCached = this.bitsCached;
  34858. var cachedData = this.cachedData;
  34859. while (bitsCached < n) {
  34860. var c = this.str.getByte();
  34861. if (c === -1) {
  34862. this.eof = true;
  34863. return null;
  34864. }
  34865. cachedData = (cachedData << 8) | c;
  34866. bitsCached += 8;
  34867. }
  34868. this.bitsCached = (bitsCached -= n);
  34869. this.cachedData = cachedData;
  34870. this.lastCode = null;
  34871. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  34872. };
  34873. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  34874. var blockSize = 512;
  34875. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  34876. var i, j, q;
  34877. var lzwState = this.lzwState;
  34878. if (!lzwState) {
  34879. return; // eof was found
  34880. }
  34881. var earlyChange = lzwState.earlyChange;
  34882. var nextCode = lzwState.nextCode;
  34883. var dictionaryValues = lzwState.dictionaryValues;
  34884. var dictionaryLengths = lzwState.dictionaryLengths;
  34885. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  34886. var codeLength = lzwState.codeLength;
  34887. var prevCode = lzwState.prevCode;
  34888. var currentSequence = lzwState.currentSequence;
  34889. var currentSequenceLength = lzwState.currentSequenceLength;
  34890. var decodedLength = 0;
  34891. var currentBufferLength = this.bufferLength;
  34892. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34893. for (i = 0; i < blockSize; i++) {
  34894. var code = this.readBits(codeLength);
  34895. var hasPrev = currentSequenceLength > 0;
  34896. if (code < 256) {
  34897. currentSequence[0] = code;
  34898. currentSequenceLength = 1;
  34899. } else if (code >= 258) {
  34900. if (code < nextCode) {
  34901. currentSequenceLength = dictionaryLengths[code];
  34902. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  34903. currentSequence[j] = dictionaryValues[q];
  34904. q = dictionaryPrevCodes[q];
  34905. }
  34906. } else {
  34907. currentSequence[currentSequenceLength++] = currentSequence[0];
  34908. }
  34909. } else if (code === 256) {
  34910. codeLength = 9;
  34911. nextCode = 258;
  34912. currentSequenceLength = 0;
  34913. continue;
  34914. } else {
  34915. this.eof = true;
  34916. delete this.lzwState;
  34917. break;
  34918. }
  34919. if (hasPrev) {
  34920. dictionaryPrevCodes[nextCode] = prevCode;
  34921. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  34922. dictionaryValues[nextCode] = currentSequence[0];
  34923. nextCode++;
  34924. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  34925. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  34926. 0.6931471805599453 + 1, 12) | 0;
  34927. }
  34928. prevCode = code;
  34929. decodedLength += currentSequenceLength;
  34930. if (estimatedDecodedSize < decodedLength) {
  34931. do {
  34932. estimatedDecodedSize += decodedSizeDelta;
  34933. } while (estimatedDecodedSize < decodedLength);
  34934. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34935. }
  34936. for (j = 0; j < currentSequenceLength; j++) {
  34937. buffer[currentBufferLength++] = currentSequence[j];
  34938. }
  34939. }
  34940. lzwState.nextCode = nextCode;
  34941. lzwState.codeLength = codeLength;
  34942. lzwState.prevCode = prevCode;
  34943. lzwState.currentSequenceLength = currentSequenceLength;
  34944. this.bufferLength = currentBufferLength;
  34945. };
  34946. return LZWStream;
  34947. })();
  34948. var NullStream = (function NullStreamClosure() {
  34949. function NullStream() {
  34950. Stream.call(this, new Uint8Array(0));
  34951. }
  34952. NullStream.prototype = Stream.prototype;
  34953. return NullStream;
  34954. })();
  34955. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  34956. setup: function wphSetup(handler) {
  34957. var pdfManager;
  34958. function loadDocument(recoveryMode) {
  34959. var loadDocumentCapability = createPromiseCapability();
  34960. var parseSuccess = function parseSuccess() {
  34961. var numPagesPromise = pdfManager.ensureDoc('numPages');
  34962. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  34963. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  34964. Promise.all([numPagesPromise, fingerprintPromise,
  34965. encryptedPromise]).then(function onDocReady(results) {
  34966. var doc = {
  34967. numPages: results[0],
  34968. fingerprint: results[1],
  34969. encrypted: !!results[2],
  34970. };
  34971. loadDocumentCapability.resolve(doc);
  34972. },
  34973. parseFailure);
  34974. };
  34975. var parseFailure = function parseFailure(e) {
  34976. loadDocumentCapability.reject(e);
  34977. };
  34978. pdfManager.ensureDoc('checkHeader', []).then(function() {
  34979. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  34980. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  34981. parseSuccess, parseFailure);
  34982. }, parseFailure);
  34983. }, parseFailure);
  34984. return loadDocumentCapability.promise;
  34985. }
  34986. function getPdfManager(data) {
  34987. var pdfManagerCapability = createPromiseCapability();
  34988. var source = data.source;
  34989. var disableRange = data.disableRange;
  34990. if (source.data) {
  34991. try {
  34992. pdfManager = new LocalPdfManager(source.data, source.password);
  34993. pdfManagerCapability.resolve();
  34994. } catch (ex) {
  34995. pdfManagerCapability.reject(ex);
  34996. }
  34997. return pdfManagerCapability.promise;
  34998. } else if (source.chunkedViewerLoading) {
  34999. try {
  35000. pdfManager = new NetworkPdfManager(source, handler);
  35001. pdfManagerCapability.resolve();
  35002. } catch (ex) {
  35003. pdfManagerCapability.reject(ex);
  35004. }
  35005. return pdfManagerCapability.promise;
  35006. }
  35007. var networkManager = new NetworkManager(source.url, {
  35008. httpHeaders: source.httpHeaders,
  35009. withCredentials: source.withCredentials
  35010. });
  35011. var fullRequestXhrId = networkManager.requestFull({
  35012. onHeadersReceived: function onHeadersReceived() {
  35013. if (disableRange) {
  35014. return;
  35015. }
  35016. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  35017. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  35018. return;
  35019. }
  35020. var contentEncoding =
  35021. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  35022. if (contentEncoding !== 'identity') {
  35023. return;
  35024. }
  35025. var length = fullRequestXhr.getResponseHeader('Content-Length');
  35026. length = parseInt(length, 10);
  35027. if (!isInt(length)) {
  35028. return;
  35029. }
  35030. source.length = length;
  35031. if (length <= 2 * RANGE_CHUNK_SIZE) {
  35032. // The file size is smaller than the size of two chunks, so it does
  35033. // not make any sense to abort the request and retry with a range
  35034. // request.
  35035. return;
  35036. }
  35037. // NOTE: by cancelling the full request, and then issuing range
  35038. // requests, there will be an issue for sites where you can only
  35039. // request the pdf once. However, if this is the case, then the
  35040. // server should not be returning that it can support range requests.
  35041. networkManager.abortRequest(fullRequestXhrId);
  35042. try {
  35043. pdfManager = new NetworkPdfManager(source, handler);
  35044. pdfManagerCapability.resolve(pdfManager);
  35045. } catch (ex) {
  35046. pdfManagerCapability.reject(ex);
  35047. }
  35048. },
  35049. onDone: function onDone(args) {
  35050. // the data is array, instantiating directly from it
  35051. try {
  35052. pdfManager = new LocalPdfManager(args.chunk, source.password);
  35053. pdfManagerCapability.resolve();
  35054. } catch (ex) {
  35055. pdfManagerCapability.reject(ex);
  35056. }
  35057. },
  35058. onError: function onError(status) {
  35059. if (status === 404) {
  35060. var exception = new MissingPDFException('Missing PDF "' +
  35061. source.url + '".');
  35062. handler.send('MissingPDF', { exception: exception });
  35063. } else {
  35064. handler.send('DocError', 'Unexpected server response (' +
  35065. status + ') while retrieving PDF "' +
  35066. source.url + '".');
  35067. }
  35068. },
  35069. onProgress: function onProgress(evt) {
  35070. handler.send('DocProgress', {
  35071. loaded: evt.loaded,
  35072. total: evt.lengthComputable ? evt.total : source.length
  35073. });
  35074. }
  35075. });
  35076. return pdfManagerCapability.promise;
  35077. }
  35078. handler.on('test', function wphSetupTest(data) {
  35079. // check if Uint8Array can be sent to worker
  35080. if (!(data instanceof Uint8Array)) {
  35081. handler.send('test', false);
  35082. return;
  35083. }
  35084. // making sure postMessage transfers are working
  35085. var supportTransfers = data[0] === 255;
  35086. handler.postMessageTransfers = supportTransfers;
  35087. // check if the response property is supported by xhr
  35088. var xhr = new XMLHttpRequest();
  35089. var responseExists = 'response' in xhr;
  35090. // check if the property is actually implemented
  35091. try {
  35092. var dummy = xhr.responseType;
  35093. } catch (e) {
  35094. responseExists = false;
  35095. }
  35096. if (!responseExists) {
  35097. handler.send('test', false);
  35098. return;
  35099. }
  35100. handler.send('test', {
  35101. supportTypedArray: true,
  35102. supportTransfers: supportTransfers
  35103. });
  35104. });
  35105. handler.on('GetDocRequest', function wphSetupDoc(data) {
  35106. var onSuccess = function(doc) {
  35107. handler.send('GetDoc', { pdfInfo: doc });
  35108. };
  35109. var onFailure = function(e) {
  35110. if (e instanceof PasswordException) {
  35111. if (e.code === PasswordResponses.NEED_PASSWORD) {
  35112. handler.send('NeedPassword', {
  35113. exception: e
  35114. });
  35115. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  35116. handler.send('IncorrectPassword', {
  35117. exception: e
  35118. });
  35119. }
  35120. } else if (e instanceof InvalidPDFException) {
  35121. handler.send('InvalidPDF', {
  35122. exception: e
  35123. });
  35124. } else if (e instanceof MissingPDFException) {
  35125. handler.send('MissingPDF', {
  35126. exception: e
  35127. });
  35128. } else {
  35129. handler.send('UnknownError', {
  35130. exception: new UnknownErrorException(e.message, e.toString())
  35131. });
  35132. }
  35133. };
  35134. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  35135. -1 : data.maxImageSize;
  35136. PDFJS.disableFontFace = data.disableFontFace;
  35137. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  35138. PDFJS.verbosity = data.verbosity;
  35139. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  35140. null : data.cMapUrl;
  35141. PDFJS.cMapPacked = data.cMapPacked === true;
  35142. getPdfManager(data).then(function () {
  35143. pdfManager.onLoadedStream().then(function(stream) {
  35144. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  35145. });
  35146. }).then(function pdfManagerReady() {
  35147. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  35148. // Try again with recoveryMode == true
  35149. if (!(ex instanceof XRefParseException)) {
  35150. if (ex instanceof PasswordException) {
  35151. // after password exception prepare to receive a new password
  35152. // to repeat loading
  35153. pdfManager.passwordChanged().then(pdfManagerReady);
  35154. }
  35155. onFailure(ex);
  35156. return;
  35157. }
  35158. pdfManager.requestLoadedStream();
  35159. pdfManager.onLoadedStream().then(function() {
  35160. loadDocument(true).then(onSuccess, onFailure);
  35161. });
  35162. }, onFailure);
  35163. }, onFailure);
  35164. });
  35165. handler.on('GetPage', function wphSetupGetPage(data) {
  35166. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35167. var rotatePromise = pdfManager.ensure(page, 'rotate');
  35168. var refPromise = pdfManager.ensure(page, 'ref');
  35169. var viewPromise = pdfManager.ensure(page, 'view');
  35170. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  35171. function(results) {
  35172. return {
  35173. rotate: results[0],
  35174. ref: results[1],
  35175. view: results[2]
  35176. };
  35177. });
  35178. });
  35179. });
  35180. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  35181. var ref = new Ref(data.ref.num, data.ref.gen);
  35182. var catalog = pdfManager.pdfDocument.catalog;
  35183. return catalog.getPageIndex(ref);
  35184. });
  35185. handler.on('GetDestinations',
  35186. function wphSetupGetDestinations(data) {
  35187. return pdfManager.ensureCatalog('destinations');
  35188. }
  35189. );
  35190. handler.on('GetAttachments',
  35191. function wphSetupGetAttachments(data) {
  35192. return pdfManager.ensureCatalog('attachments');
  35193. }
  35194. );
  35195. handler.on('GetJavaScript',
  35196. function wphSetupGetJavaScript(data) {
  35197. return pdfManager.ensureCatalog('javaScript');
  35198. }
  35199. );
  35200. handler.on('GetOutline',
  35201. function wphSetupGetOutline(data) {
  35202. return pdfManager.ensureCatalog('documentOutline');
  35203. }
  35204. );
  35205. handler.on('GetMetadata',
  35206. function wphSetupGetMetadata(data) {
  35207. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  35208. pdfManager.ensureCatalog('metadata')]);
  35209. }
  35210. );
  35211. handler.on('GetData', function wphSetupGetData(data) {
  35212. pdfManager.requestLoadedStream();
  35213. return pdfManager.onLoadedStream().then(function(stream) {
  35214. return stream.bytes;
  35215. });
  35216. });
  35217. handler.on('GetStats',
  35218. function wphSetupGetStats(data) {
  35219. return pdfManager.pdfDocument.xref.stats;
  35220. }
  35221. );
  35222. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  35223. pdfManager.updatePassword(data);
  35224. });
  35225. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  35226. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35227. return pdfManager.ensure(page, 'getAnnotationsData', []);
  35228. });
  35229. });
  35230. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  35231. pdfManager.getPage(data.pageIndex).then(function(page) {
  35232. var pageNum = data.pageIndex + 1;
  35233. var start = Date.now();
  35234. // Pre compile the pdf page and fetch the fonts/images.
  35235. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  35236. info('page=' + pageNum + ' - getOperatorList: time=' +
  35237. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  35238. }, function(e) {
  35239. var minimumStackMessage =
  35240. 'worker.js: while trying to getPage() and getOperatorList()';
  35241. var wrappedException;
  35242. // Turn the error into an obj that can be serialized
  35243. if (typeof e === 'string') {
  35244. wrappedException = {
  35245. message: e,
  35246. stack: minimumStackMessage
  35247. };
  35248. } else if (typeof e === 'object') {
  35249. wrappedException = {
  35250. message: e.message || e.toString(),
  35251. stack: e.stack || minimumStackMessage
  35252. };
  35253. } else {
  35254. wrappedException = {
  35255. message: 'Unknown exception type: ' + (typeof e),
  35256. stack: minimumStackMessage
  35257. };
  35258. }
  35259. handler.send('PageError', {
  35260. pageNum: pageNum,
  35261. error: wrappedException,
  35262. intent: data.intent
  35263. });
  35264. });
  35265. });
  35266. }, this);
  35267. handler.on('GetTextContent', function wphExtractText(data) {
  35268. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35269. var pageNum = data.pageIndex + 1;
  35270. var start = Date.now();
  35271. return page.extractTextContent().then(function(textContent) {
  35272. info('text indexing: page=' + pageNum + ' - time=' +
  35273. (Date.now() - start) + 'ms');
  35274. return textContent;
  35275. });
  35276. });
  35277. });
  35278. handler.on('Cleanup', function wphCleanup(data) {
  35279. return pdfManager.cleanup();
  35280. });
  35281. handler.on('Terminate', function wphTerminate(data) {
  35282. pdfManager.terminate();
  35283. });
  35284. }
  35285. };
  35286. var consoleTimer = {};
  35287. var workerConsole = {
  35288. log: function log() {
  35289. var args = Array.prototype.slice.call(arguments);
  35290. globalScope.postMessage({
  35291. action: 'console_log',
  35292. data: args
  35293. });
  35294. },
  35295. error: function error() {
  35296. var args = Array.prototype.slice.call(arguments);
  35297. globalScope.postMessage({
  35298. action: 'console_error',
  35299. data: args
  35300. });
  35301. throw 'pdf.js execution error';
  35302. },
  35303. time: function time(name) {
  35304. consoleTimer[name] = Date.now();
  35305. },
  35306. timeEnd: function timeEnd(name) {
  35307. var time = consoleTimer[name];
  35308. if (!time) {
  35309. error('Unknown timer name ' + name);
  35310. }
  35311. this.log('Timer:', name, Date.now() - time);
  35312. }
  35313. };
  35314. // Worker thread?
  35315. if (typeof window === 'undefined') {
  35316. if (!('console' in globalScope)) {
  35317. globalScope.console = workerConsole;
  35318. }
  35319. // Listen for unsupported features so we can pass them on to the main thread.
  35320. PDFJS.UnsupportedManager.listen(function (msg) {
  35321. globalScope.postMessage({
  35322. action: '_unsupported_feature',
  35323. data: msg
  35324. });
  35325. });
  35326. var handler = new MessageHandler('worker_processor', this);
  35327. WorkerMessageHandler.setup(handler);
  35328. }
  35329. /* This class implements the QM Coder decoding as defined in
  35330. * JPEG 2000 Part I Final Committee Draft Version 1.0
  35331. * Annex C.3 Arithmetic decoding procedure
  35332. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  35333. *
  35334. * The arithmetic decoder is used in conjunction with context models to decode
  35335. * JPEG2000 and JBIG2 streams.
  35336. */
  35337. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  35338. // Table C-2
  35339. var QeTable = [
  35340. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  35341. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  35342. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  35343. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  35344. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  35345. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  35346. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  35347. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  35348. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  35349. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  35350. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  35351. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  35352. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  35353. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  35354. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  35355. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  35356. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  35357. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  35358. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  35359. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  35360. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  35361. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  35362. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  35363. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  35364. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  35365. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  35366. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  35367. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  35368. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  35369. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  35370. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  35371. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  35372. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  35373. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  35374. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  35375. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  35376. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  35377. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  35378. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  35379. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  35380. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  35381. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  35382. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  35383. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  35384. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  35385. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  35386. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  35387. ];
  35388. // C.3.5 Initialisation of the decoder (INITDEC)
  35389. function ArithmeticDecoder(data, start, end) {
  35390. this.data = data;
  35391. this.bp = start;
  35392. this.dataEnd = end;
  35393. this.chigh = data[start];
  35394. this.clow = 0;
  35395. this.byteIn();
  35396. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  35397. this.clow = (this.clow << 7) & 0xFFFF;
  35398. this.ct -= 7;
  35399. this.a = 0x8000;
  35400. }
  35401. ArithmeticDecoder.prototype = {
  35402. // C.3.4 Compressed data input (BYTEIN)
  35403. byteIn: function ArithmeticDecoder_byteIn() {
  35404. var data = this.data;
  35405. var bp = this.bp;
  35406. if (data[bp] === 0xFF) {
  35407. var b1 = data[bp + 1];
  35408. if (b1 > 0x8F) {
  35409. this.clow += 0xFF00;
  35410. this.ct = 8;
  35411. } else {
  35412. bp++;
  35413. this.clow += (data[bp] << 9);
  35414. this.ct = 7;
  35415. this.bp = bp;
  35416. }
  35417. } else {
  35418. bp++;
  35419. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  35420. this.ct = 8;
  35421. this.bp = bp;
  35422. }
  35423. if (this.clow > 0xFFFF) {
  35424. this.chigh += (this.clow >> 16);
  35425. this.clow &= 0xFFFF;
  35426. }
  35427. },
  35428. // C.3.2 Decoding a decision (DECODE)
  35429. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  35430. // contexts are packed into 1 byte:
  35431. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  35432. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  35433. var qeTableIcx = QeTable[cx_index];
  35434. var qeIcx = qeTableIcx.qe;
  35435. var d;
  35436. var a = this.a - qeIcx;
  35437. if (this.chigh < qeIcx) {
  35438. // exchangeLps
  35439. if (a < qeIcx) {
  35440. a = qeIcx;
  35441. d = cx_mps;
  35442. cx_index = qeTableIcx.nmps;
  35443. } else {
  35444. a = qeIcx;
  35445. d = 1 ^ cx_mps;
  35446. if (qeTableIcx.switchFlag === 1) {
  35447. cx_mps = d;
  35448. }
  35449. cx_index = qeTableIcx.nlps;
  35450. }
  35451. } else {
  35452. this.chigh -= qeIcx;
  35453. if ((a & 0x8000) !== 0) {
  35454. this.a = a;
  35455. return cx_mps;
  35456. }
  35457. // exchangeMps
  35458. if (a < qeIcx) {
  35459. d = 1 ^ cx_mps;
  35460. if (qeTableIcx.switchFlag === 1) {
  35461. cx_mps = d;
  35462. }
  35463. cx_index = qeTableIcx.nlps;
  35464. } else {
  35465. d = cx_mps;
  35466. cx_index = qeTableIcx.nmps;
  35467. }
  35468. }
  35469. // C.3.3 renormD;
  35470. do {
  35471. if (this.ct === 0) {
  35472. this.byteIn();
  35473. }
  35474. a <<= 1;
  35475. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  35476. this.clow = (this.clow << 1) & 0xFFFF;
  35477. this.ct--;
  35478. } while ((a & 0x8000) === 0);
  35479. this.a = a;
  35480. contexts[pos] = cx_index << 1 | cx_mps;
  35481. return d;
  35482. }
  35483. };
  35484. return ArithmeticDecoder;
  35485. })();
  35486. var JpegImage = (function jpegImage() {
  35487. var dctZigZag = new Uint8Array([
  35488. 0,
  35489. 1, 8,
  35490. 16, 9, 2,
  35491. 3, 10, 17, 24,
  35492. 32, 25, 18, 11, 4,
  35493. 5, 12, 19, 26, 33, 40,
  35494. 48, 41, 34, 27, 20, 13, 6,
  35495. 7, 14, 21, 28, 35, 42, 49, 56,
  35496. 57, 50, 43, 36, 29, 22, 15,
  35497. 23, 30, 37, 44, 51, 58,
  35498. 59, 52, 45, 38, 31,
  35499. 39, 46, 53, 60,
  35500. 61, 54, 47,
  35501. 55, 62,
  35502. 63
  35503. ]);
  35504. var dctCos1 = 4017; // cos(pi/16)
  35505. var dctSin1 = 799; // sin(pi/16)
  35506. var dctCos3 = 3406; // cos(3*pi/16)
  35507. var dctSin3 = 2276; // sin(3*pi/16)
  35508. var dctCos6 = 1567; // cos(6*pi/16)
  35509. var dctSin6 = 3784; // sin(6*pi/16)
  35510. var dctSqrt2 = 5793; // sqrt(2)
  35511. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  35512. function constructor() {
  35513. }
  35514. function buildHuffmanTable(codeLengths, values) {
  35515. var k = 0, code = [], i, j, length = 16;
  35516. while (length > 0 && !codeLengths[length - 1]) {
  35517. length--;
  35518. }
  35519. code.push({children: [], index: 0});
  35520. var p = code[0], q;
  35521. for (i = 0; i < length; i++) {
  35522. for (j = 0; j < codeLengths[i]; j++) {
  35523. p = code.pop();
  35524. p.children[p.index] = values[k];
  35525. while (p.index > 0) {
  35526. p = code.pop();
  35527. }
  35528. p.index++;
  35529. code.push(p);
  35530. while (code.length <= i) {
  35531. code.push(q = {children: [], index: 0});
  35532. p.children[p.index] = q.children;
  35533. p = q;
  35534. }
  35535. k++;
  35536. }
  35537. if (i + 1 < length) {
  35538. // p here points to last code
  35539. code.push(q = {children: [], index: 0});
  35540. p.children[p.index] = q.children;
  35541. p = q;
  35542. }
  35543. }
  35544. return code[0].children;
  35545. }
  35546. function getBlockBufferOffset(component, row, col) {
  35547. return 64 * ((component.blocksPerLine + 1) * row + col);
  35548. }
  35549. function decodeScan(data, offset, frame, components, resetInterval,
  35550. spectralStart, spectralEnd, successivePrev, successive) {
  35551. var precision = frame.precision;
  35552. var samplesPerLine = frame.samplesPerLine;
  35553. var scanLines = frame.scanLines;
  35554. var mcusPerLine = frame.mcusPerLine;
  35555. var progressive = frame.progressive;
  35556. var maxH = frame.maxH, maxV = frame.maxV;
  35557. var startOffset = offset, bitsData = 0, bitsCount = 0;
  35558. function readBit() {
  35559. if (bitsCount > 0) {
  35560. bitsCount--;
  35561. return (bitsData >> bitsCount) & 1;
  35562. }
  35563. bitsData = data[offset++];
  35564. if (bitsData === 0xFF) {
  35565. var nextByte = data[offset++];
  35566. if (nextByte) {
  35567. throw 'unexpected marker: ' +
  35568. ((bitsData << 8) | nextByte).toString(16);
  35569. }
  35570. // unstuff 0
  35571. }
  35572. bitsCount = 7;
  35573. return bitsData >>> 7;
  35574. }
  35575. function decodeHuffman(tree) {
  35576. var node = tree;
  35577. var bit;
  35578. while ((bit = readBit()) !== null) {
  35579. node = node[bit];
  35580. if (typeof node === 'number') {
  35581. return node;
  35582. }
  35583. if (typeof node !== 'object') {
  35584. throw 'invalid huffman sequence';
  35585. }
  35586. }
  35587. return null;
  35588. }
  35589. function receive(length) {
  35590. var n = 0;
  35591. while (length > 0) {
  35592. var bit = readBit();
  35593. if (bit === null) {
  35594. return;
  35595. }
  35596. n = (n << 1) | bit;
  35597. length--;
  35598. }
  35599. return n;
  35600. }
  35601. function receiveAndExtend(length) {
  35602. if (length === 1) {
  35603. return readBit() === 1 ? 1 : -1;
  35604. }
  35605. var n = receive(length);
  35606. if (n >= 1 << (length - 1)) {
  35607. return n;
  35608. }
  35609. return n + (-1 << length) + 1;
  35610. }
  35611. function decodeBaseline(component, offset) {
  35612. var t = decodeHuffman(component.huffmanTableDC);
  35613. var diff = t === 0 ? 0 : receiveAndExtend(t);
  35614. component.blockData[offset] = (component.pred += diff);
  35615. var k = 1;
  35616. while (k < 64) {
  35617. var rs = decodeHuffman(component.huffmanTableAC);
  35618. var s = rs & 15, r = rs >> 4;
  35619. if (s === 0) {
  35620. if (r < 15) {
  35621. break;
  35622. }
  35623. k += 16;
  35624. continue;
  35625. }
  35626. k += r;
  35627. var z = dctZigZag[k];
  35628. component.blockData[offset + z] = receiveAndExtend(s);
  35629. k++;
  35630. }
  35631. }
  35632. function decodeDCFirst(component, offset) {
  35633. var t = decodeHuffman(component.huffmanTableDC);
  35634. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  35635. component.blockData[offset] = (component.pred += diff);
  35636. }
  35637. function decodeDCSuccessive(component, offset) {
  35638. component.blockData[offset] |= readBit() << successive;
  35639. }
  35640. var eobrun = 0;
  35641. function decodeACFirst(component, offset) {
  35642. if (eobrun > 0) {
  35643. eobrun--;
  35644. return;
  35645. }
  35646. var k = spectralStart, e = spectralEnd;
  35647. while (k <= e) {
  35648. var rs = decodeHuffman(component.huffmanTableAC);
  35649. var s = rs & 15, r = rs >> 4;
  35650. if (s === 0) {
  35651. if (r < 15) {
  35652. eobrun = receive(r) + (1 << r) - 1;
  35653. break;
  35654. }
  35655. k += 16;
  35656. continue;
  35657. }
  35658. k += r;
  35659. var z = dctZigZag[k];
  35660. component.blockData[offset + z] =
  35661. receiveAndExtend(s) * (1 << successive);
  35662. k++;
  35663. }
  35664. }
  35665. var successiveACState = 0, successiveACNextValue;
  35666. function decodeACSuccessive(component, offset) {
  35667. var k = spectralStart;
  35668. var e = spectralEnd;
  35669. var r = 0;
  35670. var s;
  35671. var rs;
  35672. while (k <= e) {
  35673. var z = dctZigZag[k];
  35674. switch (successiveACState) {
  35675. case 0: // initial state
  35676. rs = decodeHuffman(component.huffmanTableAC);
  35677. s = rs & 15;
  35678. r = rs >> 4;
  35679. if (s === 0) {
  35680. if (r < 15) {
  35681. eobrun = receive(r) + (1 << r);
  35682. successiveACState = 4;
  35683. } else {
  35684. r = 16;
  35685. successiveACState = 1;
  35686. }
  35687. } else {
  35688. if (s !== 1) {
  35689. throw 'invalid ACn encoding';
  35690. }
  35691. successiveACNextValue = receiveAndExtend(s);
  35692. successiveACState = r ? 2 : 3;
  35693. }
  35694. continue;
  35695. case 1: // skipping r zero items
  35696. case 2:
  35697. if (component.blockData[offset + z]) {
  35698. component.blockData[offset + z] += (readBit() << successive);
  35699. } else {
  35700. r--;
  35701. if (r === 0) {
  35702. successiveACState = successiveACState === 2 ? 3 : 0;
  35703. }
  35704. }
  35705. break;
  35706. case 3: // set value for a zero item
  35707. if (component.blockData[offset + z]) {
  35708. component.blockData[offset + z] += (readBit() << successive);
  35709. } else {
  35710. component.blockData[offset + z] =
  35711. successiveACNextValue << successive;
  35712. successiveACState = 0;
  35713. }
  35714. break;
  35715. case 4: // eob
  35716. if (component.blockData[offset + z]) {
  35717. component.blockData[offset + z] += (readBit() << successive);
  35718. }
  35719. break;
  35720. }
  35721. k++;
  35722. }
  35723. if (successiveACState === 4) {
  35724. eobrun--;
  35725. if (eobrun === 0) {
  35726. successiveACState = 0;
  35727. }
  35728. }
  35729. }
  35730. function decodeMcu(component, decode, mcu, row, col) {
  35731. var mcuRow = (mcu / mcusPerLine) | 0;
  35732. var mcuCol = mcu % mcusPerLine;
  35733. var blockRow = mcuRow * component.v + row;
  35734. var blockCol = mcuCol * component.h + col;
  35735. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35736. decode(component, offset);
  35737. }
  35738. function decodeBlock(component, decode, mcu) {
  35739. var blockRow = (mcu / component.blocksPerLine) | 0;
  35740. var blockCol = mcu % component.blocksPerLine;
  35741. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35742. decode(component, offset);
  35743. }
  35744. var componentsLength = components.length;
  35745. var component, i, j, k, n;
  35746. var decodeFn;
  35747. if (progressive) {
  35748. if (spectralStart === 0) {
  35749. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  35750. } else {
  35751. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  35752. }
  35753. } else {
  35754. decodeFn = decodeBaseline;
  35755. }
  35756. var mcu = 0, marker;
  35757. var mcuExpected;
  35758. if (componentsLength === 1) {
  35759. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  35760. } else {
  35761. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  35762. }
  35763. if (!resetInterval) {
  35764. resetInterval = mcuExpected;
  35765. }
  35766. var h, v;
  35767. while (mcu < mcuExpected) {
  35768. // reset interval stuff
  35769. for (i = 0; i < componentsLength; i++) {
  35770. components[i].pred = 0;
  35771. }
  35772. eobrun = 0;
  35773. if (componentsLength === 1) {
  35774. component = components[0];
  35775. for (n = 0; n < resetInterval; n++) {
  35776. decodeBlock(component, decodeFn, mcu);
  35777. mcu++;
  35778. }
  35779. } else {
  35780. for (n = 0; n < resetInterval; n++) {
  35781. for (i = 0; i < componentsLength; i++) {
  35782. component = components[i];
  35783. h = component.h;
  35784. v = component.v;
  35785. for (j = 0; j < v; j++) {
  35786. for (k = 0; k < h; k++) {
  35787. decodeMcu(component, decodeFn, mcu, j, k);
  35788. }
  35789. }
  35790. }
  35791. mcu++;
  35792. }
  35793. }
  35794. // find marker
  35795. bitsCount = 0;
  35796. marker = (data[offset] << 8) | data[offset + 1];
  35797. if (marker <= 0xFF00) {
  35798. throw 'marker was not found';
  35799. }
  35800. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  35801. offset += 2;
  35802. } else {
  35803. break;
  35804. }
  35805. }
  35806. return offset - startOffset;
  35807. }
  35808. // A port of poppler's IDCT method which in turn is taken from:
  35809. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  35810. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  35811. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  35812. // 988-991.
  35813. function quantizeAndInverse(component, blockBufferOffset, p) {
  35814. var qt = component.quantizationTable, blockData = component.blockData;
  35815. var v0, v1, v2, v3, v4, v5, v6, v7;
  35816. var p0, p1, p2, p3, p4, p5, p6, p7;
  35817. var t;
  35818. // inverse DCT on rows
  35819. for (var row = 0; row < 64; row += 8) {
  35820. // gather block data
  35821. p0 = blockData[blockBufferOffset + row];
  35822. p1 = blockData[blockBufferOffset + row + 1];
  35823. p2 = blockData[blockBufferOffset + row + 2];
  35824. p3 = blockData[blockBufferOffset + row + 3];
  35825. p4 = blockData[blockBufferOffset + row + 4];
  35826. p5 = blockData[blockBufferOffset + row + 5];
  35827. p6 = blockData[blockBufferOffset + row + 6];
  35828. p7 = blockData[blockBufferOffset + row + 7];
  35829. // dequant p0
  35830. p0 *= qt[row];
  35831. // check for all-zero AC coefficients
  35832. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35833. t = (dctSqrt2 * p0 + 512) >> 10;
  35834. p[row] = t;
  35835. p[row + 1] = t;
  35836. p[row + 2] = t;
  35837. p[row + 3] = t;
  35838. p[row + 4] = t;
  35839. p[row + 5] = t;
  35840. p[row + 6] = t;
  35841. p[row + 7] = t;
  35842. continue;
  35843. }
  35844. // dequant p1 ... p7
  35845. p1 *= qt[row + 1];
  35846. p2 *= qt[row + 2];
  35847. p3 *= qt[row + 3];
  35848. p4 *= qt[row + 4];
  35849. p5 *= qt[row + 5];
  35850. p6 *= qt[row + 6];
  35851. p7 *= qt[row + 7];
  35852. // stage 4
  35853. v0 = (dctSqrt2 * p0 + 128) >> 8;
  35854. v1 = (dctSqrt2 * p4 + 128) >> 8;
  35855. v2 = p2;
  35856. v3 = p6;
  35857. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  35858. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  35859. v5 = p3 << 4;
  35860. v6 = p5 << 4;
  35861. // stage 3
  35862. v0 = (v0 + v1 + 1) >> 1;
  35863. v1 = v0 - v1;
  35864. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  35865. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  35866. v3 = t;
  35867. v4 = (v4 + v6 + 1) >> 1;
  35868. v6 = v4 - v6;
  35869. v7 = (v7 + v5 + 1) >> 1;
  35870. v5 = v7 - v5;
  35871. // stage 2
  35872. v0 = (v0 + v3 + 1) >> 1;
  35873. v3 = v0 - v3;
  35874. v1 = (v1 + v2 + 1) >> 1;
  35875. v2 = v1 - v2;
  35876. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35877. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35878. v7 = t;
  35879. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35880. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35881. v6 = t;
  35882. // stage 1
  35883. p[row] = v0 + v7;
  35884. p[row + 7] = v0 - v7;
  35885. p[row + 1] = v1 + v6;
  35886. p[row + 6] = v1 - v6;
  35887. p[row + 2] = v2 + v5;
  35888. p[row + 5] = v2 - v5;
  35889. p[row + 3] = v3 + v4;
  35890. p[row + 4] = v3 - v4;
  35891. }
  35892. // inverse DCT on columns
  35893. for (var col = 0; col < 8; ++col) {
  35894. p0 = p[col];
  35895. p1 = p[col + 8];
  35896. p2 = p[col + 16];
  35897. p3 = p[col + 24];
  35898. p4 = p[col + 32];
  35899. p5 = p[col + 40];
  35900. p6 = p[col + 48];
  35901. p7 = p[col + 56];
  35902. // check for all-zero AC coefficients
  35903. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35904. t = (dctSqrt2 * p0 + 8192) >> 14;
  35905. // convert to 8 bit
  35906. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  35907. blockData[blockBufferOffset + col] = t;
  35908. blockData[blockBufferOffset + col + 8] = t;
  35909. blockData[blockBufferOffset + col + 16] = t;
  35910. blockData[blockBufferOffset + col + 24] = t;
  35911. blockData[blockBufferOffset + col + 32] = t;
  35912. blockData[blockBufferOffset + col + 40] = t;
  35913. blockData[blockBufferOffset + col + 48] = t;
  35914. blockData[blockBufferOffset + col + 56] = t;
  35915. continue;
  35916. }
  35917. // stage 4
  35918. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  35919. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  35920. v2 = p2;
  35921. v3 = p6;
  35922. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  35923. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  35924. v5 = p3;
  35925. v6 = p5;
  35926. // stage 3
  35927. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  35928. // converting to UInt8 range later.
  35929. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  35930. v1 = v0 - v1;
  35931. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  35932. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  35933. v3 = t;
  35934. v4 = (v4 + v6 + 1) >> 1;
  35935. v6 = v4 - v6;
  35936. v7 = (v7 + v5 + 1) >> 1;
  35937. v5 = v7 - v5;
  35938. // stage 2
  35939. v0 = (v0 + v3 + 1) >> 1;
  35940. v3 = v0 - v3;
  35941. v1 = (v1 + v2 + 1) >> 1;
  35942. v2 = v1 - v2;
  35943. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35944. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35945. v7 = t;
  35946. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35947. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35948. v6 = t;
  35949. // stage 1
  35950. p0 = v0 + v7;
  35951. p7 = v0 - v7;
  35952. p1 = v1 + v6;
  35953. p6 = v1 - v6;
  35954. p2 = v2 + v5;
  35955. p5 = v2 - v5;
  35956. p3 = v3 + v4;
  35957. p4 = v3 - v4;
  35958. // convert to 8-bit integers
  35959. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  35960. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  35961. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  35962. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  35963. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  35964. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  35965. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  35966. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  35967. // store block data
  35968. blockData[blockBufferOffset + col] = p0;
  35969. blockData[blockBufferOffset + col + 8] = p1;
  35970. blockData[blockBufferOffset + col + 16] = p2;
  35971. blockData[blockBufferOffset + col + 24] = p3;
  35972. blockData[blockBufferOffset + col + 32] = p4;
  35973. blockData[blockBufferOffset + col + 40] = p5;
  35974. blockData[blockBufferOffset + col + 48] = p6;
  35975. blockData[blockBufferOffset + col + 56] = p7;
  35976. }
  35977. }
  35978. function buildComponentData(frame, component) {
  35979. var blocksPerLine = component.blocksPerLine;
  35980. var blocksPerColumn = component.blocksPerColumn;
  35981. var computationBuffer = new Int16Array(64);
  35982. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  35983. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  35984. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35985. quantizeAndInverse(component, offset, computationBuffer);
  35986. }
  35987. }
  35988. return component.blockData;
  35989. }
  35990. function clamp0to255(a) {
  35991. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  35992. }
  35993. constructor.prototype = {
  35994. parse: function parse(data) {
  35995. function readUint16() {
  35996. var value = (data[offset] << 8) | data[offset + 1];
  35997. offset += 2;
  35998. return value;
  35999. }
  36000. function readDataBlock() {
  36001. var length = readUint16();
  36002. var array = data.subarray(offset, offset + length - 2);
  36003. offset += array.length;
  36004. return array;
  36005. }
  36006. function prepareComponents(frame) {
  36007. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  36008. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  36009. for (var i = 0; i < frame.components.length; i++) {
  36010. component = frame.components[i];
  36011. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  36012. component.h / frame.maxH);
  36013. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  36014. component.v / frame.maxV);
  36015. var blocksPerLineForMcu = mcusPerLine * component.h;
  36016. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  36017. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  36018. (blocksPerLineForMcu + 1);
  36019. component.blockData = new Int16Array(blocksBufferSize);
  36020. component.blocksPerLine = blocksPerLine;
  36021. component.blocksPerColumn = blocksPerColumn;
  36022. }
  36023. frame.mcusPerLine = mcusPerLine;
  36024. frame.mcusPerColumn = mcusPerColumn;
  36025. }
  36026. var offset = 0, length = data.length;
  36027. var jfif = null;
  36028. var adobe = null;
  36029. var pixels = null;
  36030. var frame, resetInterval;
  36031. var quantizationTables = [];
  36032. var huffmanTablesAC = [], huffmanTablesDC = [];
  36033. var fileMarker = readUint16();
  36034. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  36035. throw 'SOI not found';
  36036. }
  36037. fileMarker = readUint16();
  36038. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  36039. var i, j, l;
  36040. switch(fileMarker) {
  36041. case 0xFFE0: // APP0 (Application Specific)
  36042. case 0xFFE1: // APP1
  36043. case 0xFFE2: // APP2
  36044. case 0xFFE3: // APP3
  36045. case 0xFFE4: // APP4
  36046. case 0xFFE5: // APP5
  36047. case 0xFFE6: // APP6
  36048. case 0xFFE7: // APP7
  36049. case 0xFFE8: // APP8
  36050. case 0xFFE9: // APP9
  36051. case 0xFFEA: // APP10
  36052. case 0xFFEB: // APP11
  36053. case 0xFFEC: // APP12
  36054. case 0xFFED: // APP13
  36055. case 0xFFEE: // APP14
  36056. case 0xFFEF: // APP15
  36057. case 0xFFFE: // COM (Comment)
  36058. var appData = readDataBlock();
  36059. if (fileMarker === 0xFFE0) {
  36060. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  36061. appData[2] === 0x49 && appData[3] === 0x46 &&
  36062. appData[4] === 0) { // 'JFIF\x00'
  36063. jfif = {
  36064. version: { major: appData[5], minor: appData[6] },
  36065. densityUnits: appData[7],
  36066. xDensity: (appData[8] << 8) | appData[9],
  36067. yDensity: (appData[10] << 8) | appData[11],
  36068. thumbWidth: appData[12],
  36069. thumbHeight: appData[13],
  36070. thumbData: appData.subarray(14, 14 +
  36071. 3 * appData[12] * appData[13])
  36072. };
  36073. }
  36074. }
  36075. // TODO APP1 - Exif
  36076. if (fileMarker === 0xFFEE) {
  36077. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  36078. appData[2] === 0x6F && appData[3] === 0x62 &&
  36079. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  36080. adobe = {
  36081. version: appData[6],
  36082. flags0: (appData[7] << 8) | appData[8],
  36083. flags1: (appData[9] << 8) | appData[10],
  36084. transformCode: appData[11]
  36085. };
  36086. }
  36087. }
  36088. break;
  36089. case 0xFFDB: // DQT (Define Quantization Tables)
  36090. var quantizationTablesLength = readUint16();
  36091. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  36092. var z;
  36093. while (offset < quantizationTablesEnd) {
  36094. var quantizationTableSpec = data[offset++];
  36095. var tableData = new Uint16Array(64);
  36096. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  36097. for (j = 0; j < 64; j++) {
  36098. z = dctZigZag[j];
  36099. tableData[z] = data[offset++];
  36100. }
  36101. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  36102. for (j = 0; j < 64; j++) {
  36103. z = dctZigZag[j];
  36104. tableData[z] = readUint16();
  36105. }
  36106. } else {
  36107. throw 'DQT: invalid table spec';
  36108. }
  36109. quantizationTables[quantizationTableSpec & 15] = tableData;
  36110. }
  36111. break;
  36112. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  36113. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  36114. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  36115. if (frame) {
  36116. throw 'Only single frame JPEGs supported';
  36117. }
  36118. readUint16(); // skip data length
  36119. frame = {};
  36120. frame.extended = (fileMarker === 0xFFC1);
  36121. frame.progressive = (fileMarker === 0xFFC2);
  36122. frame.precision = data[offset++];
  36123. frame.scanLines = readUint16();
  36124. frame.samplesPerLine = readUint16();
  36125. frame.components = [];
  36126. frame.componentIds = {};
  36127. var componentsCount = data[offset++], componentId;
  36128. var maxH = 0, maxV = 0;
  36129. for (i = 0; i < componentsCount; i++) {
  36130. componentId = data[offset];
  36131. var h = data[offset + 1] >> 4;
  36132. var v = data[offset + 1] & 15;
  36133. if (maxH < h) {
  36134. maxH = h;
  36135. }
  36136. if (maxV < v) {
  36137. maxV = v;
  36138. }
  36139. var qId = data[offset + 2];
  36140. l = frame.components.push({
  36141. h: h,
  36142. v: v,
  36143. quantizationTable: quantizationTables[qId]
  36144. });
  36145. frame.componentIds[componentId] = l - 1;
  36146. offset += 3;
  36147. }
  36148. frame.maxH = maxH;
  36149. frame.maxV = maxV;
  36150. prepareComponents(frame);
  36151. break;
  36152. case 0xFFC4: // DHT (Define Huffman Tables)
  36153. var huffmanLength = readUint16();
  36154. for (i = 2; i < huffmanLength;) {
  36155. var huffmanTableSpec = data[offset++];
  36156. var codeLengths = new Uint8Array(16);
  36157. var codeLengthSum = 0;
  36158. for (j = 0; j < 16; j++, offset++) {
  36159. codeLengthSum += (codeLengths[j] = data[offset]);
  36160. }
  36161. var huffmanValues = new Uint8Array(codeLengthSum);
  36162. for (j = 0; j < codeLengthSum; j++, offset++) {
  36163. huffmanValues[j] = data[offset];
  36164. }
  36165. i += 17 + codeLengthSum;
  36166. ((huffmanTableSpec >> 4) === 0 ?
  36167. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  36168. buildHuffmanTable(codeLengths, huffmanValues);
  36169. }
  36170. break;
  36171. case 0xFFDD: // DRI (Define Restart Interval)
  36172. readUint16(); // skip data length
  36173. resetInterval = readUint16();
  36174. break;
  36175. case 0xFFDA: // SOS (Start of Scan)
  36176. var scanLength = readUint16();
  36177. var selectorsCount = data[offset++];
  36178. var components = [], component;
  36179. for (i = 0; i < selectorsCount; i++) {
  36180. var componentIndex = frame.componentIds[data[offset++]];
  36181. component = frame.components[componentIndex];
  36182. var tableSpec = data[offset++];
  36183. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  36184. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  36185. components.push(component);
  36186. }
  36187. var spectralStart = data[offset++];
  36188. var spectralEnd = data[offset++];
  36189. var successiveApproximation = data[offset++];
  36190. var processed = decodeScan(data, offset,
  36191. frame, components, resetInterval,
  36192. spectralStart, spectralEnd,
  36193. successiveApproximation >> 4, successiveApproximation & 15);
  36194. offset += processed;
  36195. break;
  36196. default:
  36197. if (data[offset - 3] === 0xFF &&
  36198. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  36199. // could be incorrect encoding -- last 0xFF byte of the previous
  36200. // block was eaten by the encoder
  36201. offset -= 3;
  36202. break;
  36203. }
  36204. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  36205. }
  36206. fileMarker = readUint16();
  36207. }
  36208. this.width = frame.samplesPerLine;
  36209. this.height = frame.scanLines;
  36210. this.jfif = jfif;
  36211. this.adobe = adobe;
  36212. this.components = [];
  36213. for (i = 0; i < frame.components.length; i++) {
  36214. component = frame.components[i];
  36215. this.components.push({
  36216. output: buildComponentData(frame, component),
  36217. scaleX: component.h / frame.maxH,
  36218. scaleY: component.v / frame.maxV,
  36219. blocksPerLine: component.blocksPerLine,
  36220. blocksPerColumn: component.blocksPerColumn
  36221. });
  36222. }
  36223. this.numComponents = this.components.length;
  36224. },
  36225. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  36226. var scaleX = this.width / width, scaleY = this.height / height;
  36227. var component, componentScaleX, componentScaleY, blocksPerScanline;
  36228. var x, y, i, j, k;
  36229. var index;
  36230. var offset = 0;
  36231. var output;
  36232. var numComponents = this.components.length;
  36233. var dataLength = width * height * numComponents;
  36234. var data = new Uint8Array(dataLength);
  36235. var xScaleBlockOffset = new Uint32Array(width);
  36236. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  36237. for (i = 0; i < numComponents; i++) {
  36238. component = this.components[i];
  36239. componentScaleX = component.scaleX * scaleX;
  36240. componentScaleY = component.scaleY * scaleY;
  36241. offset = i;
  36242. output = component.output;
  36243. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  36244. // precalculate the xScaleBlockOffset
  36245. for (x = 0; x < width; x++) {
  36246. j = 0 | (x * componentScaleX);
  36247. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  36248. }
  36249. // linearize the blocks of the component
  36250. for (y = 0; y < height; y++) {
  36251. j = 0 | (y * componentScaleY);
  36252. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  36253. for (x = 0; x < width; x++) {
  36254. data[offset] = output[index + xScaleBlockOffset[x]];
  36255. offset += numComponents;
  36256. }
  36257. }
  36258. }
  36259. // decodeTransform will contains pairs of multiplier (-256..256) and
  36260. // additive
  36261. var transform = this.decodeTransform;
  36262. if (transform) {
  36263. for (i = 0; i < dataLength;) {
  36264. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  36265. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  36266. }
  36267. }
  36268. }
  36269. return data;
  36270. },
  36271. _isColorConversionNeeded: function isColorConversionNeeded() {
  36272. if (this.adobe && this.adobe.transformCode) {
  36273. // The adobe transform marker overrides any previous setting
  36274. return true;
  36275. } else if (this.numComponents === 3) {
  36276. return true;
  36277. } else {
  36278. return false;
  36279. }
  36280. },
  36281. _convertYccToRgb: function convertYccToRgb(data) {
  36282. var Y, Cb, Cr;
  36283. for (var i = 0, length = data.length; i < length; i += 3) {
  36284. Y = data[i ];
  36285. Cb = data[i + 1];
  36286. Cr = data[i + 2];
  36287. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  36288. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  36289. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  36290. }
  36291. return data;
  36292. },
  36293. _convertYcckToRgb: function convertYcckToRgb(data) {
  36294. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  36295. var offset = 0;
  36296. for (var i = 0, length = data.length; i < length; i += 4) {
  36297. Y = data[i];
  36298. Cb = data[i + 1];
  36299. Cr = data[i + 2];
  36300. k = data[i + 3];
  36301. CbCb = Cb * Cb;
  36302. CbCr = Cb * Cr;
  36303. CbY = Cb * Y;
  36304. Cbk = Cb * k;
  36305. CrCr = Cr * Cr;
  36306. Crk = Cr * k;
  36307. CrY = Cr * Y;
  36308. YY = Y * Y;
  36309. Yk = Y * k;
  36310. kk = k * k;
  36311. var r = - 122.67195406894 -
  36312. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  36313. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  36314. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  36315. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  36316. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  36317. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  36318. 0.000336197177618394 * kk + 0.484791561490776 * k;
  36319. var g = 107.268039397724 +
  36320. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  36321. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  36322. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  36323. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  36324. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  36325. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  36326. 0.000318913117588328 * kk - 0.213742400323665 * k;
  36327. var b = - 20.810012546947 -
  36328. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  36329. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  36330. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  36331. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  36332. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  36333. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  36334. 0.000343531996510555 * kk + 0.24165260232407 * k;
  36335. data[offset++] = clamp0to255(r);
  36336. data[offset++] = clamp0to255(g);
  36337. data[offset++] = clamp0to255(b);
  36338. }
  36339. return data;
  36340. },
  36341. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  36342. var Y, Cb, Cr;
  36343. for (var i = 0, length = data.length; i < length; i += 4) {
  36344. Y = data[i];
  36345. Cb = data[i + 1];
  36346. Cr = data[i + 2];
  36347. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  36348. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  36349. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  36350. // K in data[i + 3] is unchanged
  36351. }
  36352. return data;
  36353. },
  36354. _convertCmykToRgb: function convertCmykToRgb(data) {
  36355. var c, m, y, k;
  36356. var offset = 0;
  36357. var min = -255 * 255 * 255;
  36358. var scale = 1 / 255 / 255;
  36359. for (var i = 0, length = data.length; i < length; i += 4) {
  36360. c = data[i];
  36361. m = data[i + 1];
  36362. y = data[i + 2];
  36363. k = data[i + 3];
  36364. var r =
  36365. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  36366. 18.82290502165302 * y + 212.25662451639585 * k -
  36367. 72734.4411664936) +
  36368. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  36369. 17.873870861415444 * k - 1401.7366389350734) +
  36370. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  36371. 4465.541406466231) -
  36372. k * (21.86122147463605 * k + 48317.86113160301);
  36373. var g =
  36374. c * (8.841041422036149 * c + 60.118027045597366 * m +
  36375. 6.871425592049007 * y + 31.159100130055922 * k -
  36376. 20220.756542821975) +
  36377. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  36378. 131.35250912493976 * k - 48691.05921601825) +
  36379. y * (4.444339102852739 * y + 9.8632861493405 * k -
  36380. 6341.191035517494) -
  36381. k * (20.737325471181034 * k + 47890.15695978492);
  36382. var b =
  36383. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  36384. 30.89978309703729 * y - 0.23883238689178934 * k -
  36385. 3616.812083916688) +
  36386. m * (10.49593273432072 * m + 63.02378494754052 * y +
  36387. 50.606957656360734 * k - 28620.90484698408) +
  36388. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  36389. 49363.43385999684) -
  36390. k * (22.33816807309886 * k + 45932.16563550634);
  36391. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  36392. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  36393. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  36394. }
  36395. return data;
  36396. },
  36397. getData: function getData(width, height, forceRGBoutput) {
  36398. if (this.numComponents > 4) {
  36399. throw 'Unsupported color mode';
  36400. }
  36401. // type of data: Uint8Array(width * height * numComponents)
  36402. var data = this._getLinearizedBlockData(width, height);
  36403. if (this.numComponents === 3) {
  36404. return this._convertYccToRgb(data);
  36405. } else if (this.numComponents === 4) {
  36406. if (this._isColorConversionNeeded()) {
  36407. if (forceRGBoutput) {
  36408. return this._convertYcckToRgb(data);
  36409. } else {
  36410. return this._convertYcckToCmyk(data);
  36411. }
  36412. } else if (forceRGBoutput) {
  36413. return this._convertCmykToRgb(data);
  36414. }
  36415. }
  36416. return data;
  36417. }
  36418. };
  36419. return constructor;
  36420. })();
  36421. var JpxImage = (function JpxImageClosure() {
  36422. // Table E.1
  36423. var SubbandsGainLog2 = {
  36424. 'LL': 0,
  36425. 'LH': 1,
  36426. 'HL': 1,
  36427. 'HH': 2
  36428. };
  36429. function JpxImage() {
  36430. this.failOnCorruptedImage = false;
  36431. }
  36432. JpxImage.prototype = {
  36433. parse: function JpxImage_parse(data) {
  36434. var head = readUint16(data, 0);
  36435. // No box header, immediate start of codestream (SOC)
  36436. if (head === 0xFF4F) {
  36437. this.parseCodestream(data, 0, data.length);
  36438. return;
  36439. }
  36440. var position = 0, length = data.length;
  36441. while (position < length) {
  36442. var headerSize = 8;
  36443. var lbox = readUint32(data, position);
  36444. var tbox = readUint32(data, position + 4);
  36445. position += headerSize;
  36446. if (lbox === 1) {
  36447. // XLBox: read UInt64 according to spec.
  36448. // JavaScript's int precision of 53 bit should be sufficient here.
  36449. lbox = readUint32(data, position) * 4294967296 +
  36450. readUint32(data, position + 4);
  36451. position += 8;
  36452. headerSize += 8;
  36453. }
  36454. if (lbox === 0) {
  36455. lbox = length - position + headerSize;
  36456. }
  36457. if (lbox < headerSize) {
  36458. throw new Error('JPX Error: Invalid box field size');
  36459. }
  36460. var dataLength = lbox - headerSize;
  36461. var jumpDataLength = true;
  36462. switch (tbox) {
  36463. case 0x6A501A1A: // 'jP\032\032'
  36464. // TODO
  36465. break;
  36466. case 0x6A703268: // 'jp2h'
  36467. jumpDataLength = false; // parsing child boxes
  36468. break;
  36469. case 0x636F6C72: // 'colr'
  36470. // TODO
  36471. break;
  36472. case 0x6A703263: // 'jp2c'
  36473. this.parseCodestream(data, position, position + dataLength);
  36474. break;
  36475. }
  36476. if (jumpDataLength) {
  36477. position += dataLength;
  36478. }
  36479. }
  36480. },
  36481. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  36482. var newByte = stream.getByte();
  36483. while (newByte >= 0) {
  36484. var oldByte = newByte;
  36485. newByte = stream.getByte();
  36486. var code = (oldByte << 8) | newByte;
  36487. // Image and tile size (SIZ)
  36488. if (code === 0xFF51) {
  36489. stream.skip(4);
  36490. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  36491. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  36492. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  36493. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  36494. stream.skip(16);
  36495. var Csiz = stream.getUint16(); // Byte 36
  36496. this.width = Xsiz - XOsiz;
  36497. this.height = Ysiz - YOsiz;
  36498. this.componentsCount = Csiz;
  36499. // Results are always returned as Uint8Arrays
  36500. this.bitsPerComponent = 8;
  36501. return;
  36502. }
  36503. }
  36504. throw new Error('JPX Error: No size marker found in JPX stream');
  36505. },
  36506. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  36507. var context = {};
  36508. try {
  36509. var doNotRecover = false;
  36510. var position = start;
  36511. while (position + 1 < end) {
  36512. var code = readUint16(data, position);
  36513. position += 2;
  36514. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  36515. switch (code) {
  36516. case 0xFF4F: // Start of codestream (SOC)
  36517. context.mainHeader = true;
  36518. break;
  36519. case 0xFFD9: // End of codestream (EOC)
  36520. break;
  36521. case 0xFF51: // Image and tile size (SIZ)
  36522. length = readUint16(data, position);
  36523. var siz = {};
  36524. siz.Xsiz = readUint32(data, position + 4);
  36525. siz.Ysiz = readUint32(data, position + 8);
  36526. siz.XOsiz = readUint32(data, position + 12);
  36527. siz.YOsiz = readUint32(data, position + 16);
  36528. siz.XTsiz = readUint32(data, position + 20);
  36529. siz.YTsiz = readUint32(data, position + 24);
  36530. siz.XTOsiz = readUint32(data, position + 28);
  36531. siz.YTOsiz = readUint32(data, position + 32);
  36532. var componentsCount = readUint16(data, position + 36);
  36533. siz.Csiz = componentsCount;
  36534. var components = [];
  36535. j = position + 38;
  36536. for (var i = 0; i < componentsCount; i++) {
  36537. var component = {
  36538. precision: (data[j] & 0x7F) + 1,
  36539. isSigned: !!(data[j] & 0x80),
  36540. XRsiz: data[j + 1],
  36541. YRsiz: data[j + 1]
  36542. };
  36543. calculateComponentDimensions(component, siz);
  36544. components.push(component);
  36545. }
  36546. context.SIZ = siz;
  36547. context.components = components;
  36548. calculateTileGrids(context, components);
  36549. context.QCC = [];
  36550. context.COC = [];
  36551. break;
  36552. case 0xFF55: // Tile-part lengths, main header (TLM)
  36553. var Ltlm = readUint16(data, position); // Marker segment length
  36554. // Skip tile length markers
  36555. position += Ltlm;
  36556. break;
  36557. case 0xFF5C: // Quantization default (QCD)
  36558. length = readUint16(data, position);
  36559. var qcd = {};
  36560. j = position + 2;
  36561. sqcd = data[j++];
  36562. switch (sqcd & 0x1F) {
  36563. case 0:
  36564. spqcdSize = 8;
  36565. scalarExpounded = true;
  36566. break;
  36567. case 1:
  36568. spqcdSize = 16;
  36569. scalarExpounded = false;
  36570. break;
  36571. case 2:
  36572. spqcdSize = 16;
  36573. scalarExpounded = true;
  36574. break;
  36575. default:
  36576. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36577. }
  36578. qcd.noQuantization = (spqcdSize === 8);
  36579. qcd.scalarExpounded = scalarExpounded;
  36580. qcd.guardBits = sqcd >> 5;
  36581. spqcds = [];
  36582. while (j < length + position) {
  36583. var spqcd = {};
  36584. if (spqcdSize === 8) {
  36585. spqcd.epsilon = data[j++] >> 3;
  36586. spqcd.mu = 0;
  36587. } else {
  36588. spqcd.epsilon = data[j] >> 3;
  36589. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36590. j += 2;
  36591. }
  36592. spqcds.push(spqcd);
  36593. }
  36594. qcd.SPqcds = spqcds;
  36595. if (context.mainHeader) {
  36596. context.QCD = qcd;
  36597. } else {
  36598. context.currentTile.QCD = qcd;
  36599. context.currentTile.QCC = [];
  36600. }
  36601. break;
  36602. case 0xFF5D: // Quantization component (QCC)
  36603. length = readUint16(data, position);
  36604. var qcc = {};
  36605. j = position + 2;
  36606. var cqcc;
  36607. if (context.SIZ.Csiz < 257) {
  36608. cqcc = data[j++];
  36609. } else {
  36610. cqcc = readUint16(data, j);
  36611. j += 2;
  36612. }
  36613. sqcd = data[j++];
  36614. switch (sqcd & 0x1F) {
  36615. case 0:
  36616. spqcdSize = 8;
  36617. scalarExpounded = true;
  36618. break;
  36619. case 1:
  36620. spqcdSize = 16;
  36621. scalarExpounded = false;
  36622. break;
  36623. case 2:
  36624. spqcdSize = 16;
  36625. scalarExpounded = true;
  36626. break;
  36627. default:
  36628. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36629. }
  36630. qcc.noQuantization = (spqcdSize === 8);
  36631. qcc.scalarExpounded = scalarExpounded;
  36632. qcc.guardBits = sqcd >> 5;
  36633. spqcds = [];
  36634. while (j < (length + position)) {
  36635. spqcd = {};
  36636. if (spqcdSize === 8) {
  36637. spqcd.epsilon = data[j++] >> 3;
  36638. spqcd.mu = 0;
  36639. } else {
  36640. spqcd.epsilon = data[j] >> 3;
  36641. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36642. j += 2;
  36643. }
  36644. spqcds.push(spqcd);
  36645. }
  36646. qcc.SPqcds = spqcds;
  36647. if (context.mainHeader) {
  36648. context.QCC[cqcc] = qcc;
  36649. } else {
  36650. context.currentTile.QCC[cqcc] = qcc;
  36651. }
  36652. break;
  36653. case 0xFF52: // Coding style default (COD)
  36654. length = readUint16(data, position);
  36655. var cod = {};
  36656. j = position + 2;
  36657. var scod = data[j++];
  36658. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  36659. cod.sopMarkerUsed = !!(scod & 2);
  36660. cod.ephMarkerUsed = !!(scod & 4);
  36661. cod.progressionOrder = data[j++];
  36662. cod.layersCount = readUint16(data, j);
  36663. j += 2;
  36664. cod.multipleComponentTransform = data[j++];
  36665. cod.decompositionLevelsCount = data[j++];
  36666. cod.xcb = (data[j++] & 0xF) + 2;
  36667. cod.ycb = (data[j++] & 0xF) + 2;
  36668. var blockStyle = data[j++];
  36669. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  36670. cod.resetContextProbabilities = !!(blockStyle & 2);
  36671. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  36672. cod.verticalyStripe = !!(blockStyle & 8);
  36673. cod.predictableTermination = !!(blockStyle & 16);
  36674. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  36675. cod.reversibleTransformation = data[j++];
  36676. if (cod.entropyCoderWithCustomPrecincts) {
  36677. var precinctsSizes = [];
  36678. while (j < length + position) {
  36679. var precinctsSize = data[j++];
  36680. precinctsSizes.push({
  36681. PPx: precinctsSize & 0xF,
  36682. PPy: precinctsSize >> 4
  36683. });
  36684. }
  36685. cod.precinctsSizes = precinctsSizes;
  36686. }
  36687. var unsupported = [];
  36688. if (cod.sopMarkerUsed) {
  36689. unsupported.push('sopMarkerUsed');
  36690. }
  36691. if (cod.ephMarkerUsed) {
  36692. unsupported.push('ephMarkerUsed');
  36693. }
  36694. if (cod.selectiveArithmeticCodingBypass) {
  36695. unsupported.push('selectiveArithmeticCodingBypass');
  36696. }
  36697. if (cod.resetContextProbabilities) {
  36698. unsupported.push('resetContextProbabilities');
  36699. }
  36700. if (cod.terminationOnEachCodingPass) {
  36701. unsupported.push('terminationOnEachCodingPass');
  36702. }
  36703. if (cod.verticalyStripe) {
  36704. unsupported.push('verticalyStripe');
  36705. }
  36706. if (cod.predictableTermination) {
  36707. unsupported.push('predictableTermination');
  36708. }
  36709. if (unsupported.length > 0) {
  36710. doNotRecover = true;
  36711. throw new Error('JPX Error: Unsupported COD options (' +
  36712. unsupported.join(', ') + ')');
  36713. }
  36714. if (context.mainHeader) {
  36715. context.COD = cod;
  36716. } else {
  36717. context.currentTile.COD = cod;
  36718. context.currentTile.COC = [];
  36719. }
  36720. break;
  36721. case 0xFF90: // Start of tile-part (SOT)
  36722. length = readUint16(data, position);
  36723. tile = {};
  36724. tile.index = readUint16(data, position + 2);
  36725. tile.length = readUint32(data, position + 4);
  36726. tile.dataEnd = tile.length + position - 2;
  36727. tile.partIndex = data[position + 8];
  36728. tile.partsCount = data[position + 9];
  36729. context.mainHeader = false;
  36730. if (tile.partIndex === 0) {
  36731. // reset component specific settings
  36732. tile.COD = context.COD;
  36733. tile.COC = context.COC.slice(0); // clone of the global COC
  36734. tile.QCD = context.QCD;
  36735. tile.QCC = context.QCC.slice(0); // clone of the global COC
  36736. }
  36737. context.currentTile = tile;
  36738. break;
  36739. case 0xFF93: // Start of data (SOD)
  36740. tile = context.currentTile;
  36741. if (tile.partIndex === 0) {
  36742. initializeTile(context, tile.index);
  36743. buildPackets(context);
  36744. }
  36745. // moving to the end of the data
  36746. length = tile.dataEnd - position;
  36747. parseTilePackets(context, data, position, length);
  36748. break;
  36749. case 0xFF64: // Comment (COM)
  36750. length = readUint16(data, position);
  36751. // skipping content
  36752. break;
  36753. case 0xFF53: // Coding style component (COC)
  36754. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  36755. 'not implemented');
  36756. default:
  36757. throw new Error('JPX Error: Unknown codestream code: ' +
  36758. code.toString(16));
  36759. }
  36760. position += length;
  36761. }
  36762. } catch (e) {
  36763. if (doNotRecover || this.failOnCorruptedImage) {
  36764. throw e;
  36765. } else {
  36766. warn('Trying to recover from ' + e.message);
  36767. }
  36768. }
  36769. this.tiles = transformComponents(context);
  36770. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  36771. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  36772. this.componentsCount = context.SIZ.Csiz;
  36773. }
  36774. };
  36775. function calculateComponentDimensions(component, siz) {
  36776. // Section B.2 Component mapping
  36777. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  36778. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  36779. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  36780. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  36781. component.width = component.x1 - component.x0;
  36782. component.height = component.y1 - component.y0;
  36783. }
  36784. function calculateTileGrids(context, components) {
  36785. var siz = context.SIZ;
  36786. // Section B.3 Division into tile and tile-components
  36787. var tile, tiles = [];
  36788. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  36789. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  36790. for (var q = 0; q < numYtiles; q++) {
  36791. for (var p = 0; p < numXtiles; p++) {
  36792. tile = {};
  36793. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  36794. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  36795. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  36796. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  36797. tile.width = tile.tx1 - tile.tx0;
  36798. tile.height = tile.ty1 - tile.ty0;
  36799. tile.components = [];
  36800. tiles.push(tile);
  36801. }
  36802. }
  36803. context.tiles = tiles;
  36804. var componentsCount = siz.Csiz;
  36805. for (var i = 0, ii = componentsCount; i < ii; i++) {
  36806. var component = components[i];
  36807. for (var j = 0, jj = tiles.length; j < jj; j++) {
  36808. var tileComponent = {};
  36809. tile = tiles[j];
  36810. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  36811. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  36812. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  36813. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  36814. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  36815. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  36816. tile.components[i] = tileComponent;
  36817. }
  36818. }
  36819. }
  36820. function getBlocksDimensions(context, component, r) {
  36821. var codOrCoc = component.codingStyleParameters;
  36822. var result = {};
  36823. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  36824. result.PPx = 15;
  36825. result.PPy = 15;
  36826. } else {
  36827. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  36828. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  36829. }
  36830. // calculate codeblock size as described in section B.7
  36831. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  36832. Math.min(codOrCoc.xcb, result.PPx));
  36833. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  36834. Math.min(codOrCoc.ycb, result.PPy));
  36835. return result;
  36836. }
  36837. function buildPrecincts(context, resolution, dimensions) {
  36838. // Section B.6 Division resolution to precincts
  36839. var precinctWidth = 1 << dimensions.PPx;
  36840. var precinctHeight = 1 << dimensions.PPy;
  36841. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  36842. Math.ceil(resolution.trx1 / precinctWidth) -
  36843. Math.floor(resolution.trx0 / precinctWidth) : 0);
  36844. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  36845. Math.ceil(resolution.try1 / precinctHeight) -
  36846. Math.floor(resolution.try0 / precinctHeight) : 0);
  36847. var numprecincts = numprecinctswide * numprecinctshigh;
  36848. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  36849. precinctWidth;
  36850. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  36851. precinctHeight;
  36852. resolution.precinctParameters = {
  36853. precinctXOffset: precinctXOffset,
  36854. precinctYOffset: precinctYOffset,
  36855. precinctWidth: precinctWidth,
  36856. precinctHeight: precinctHeight,
  36857. numprecinctswide: numprecinctswide,
  36858. numprecinctshigh: numprecinctshigh,
  36859. numprecincts: numprecincts
  36860. };
  36861. }
  36862. function buildCodeblocks(context, subband, dimensions) {
  36863. // Section B.7 Division sub-band into code-blocks
  36864. var xcb_ = dimensions.xcb_;
  36865. var ycb_ = dimensions.ycb_;
  36866. var codeblockWidth = 1 << xcb_;
  36867. var codeblockHeight = 1 << ycb_;
  36868. var cbx0 = subband.tbx0 >> xcb_;
  36869. var cby0 = subband.tby0 >> ycb_;
  36870. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  36871. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  36872. var precinctParameters = subband.resolution.precinctParameters;
  36873. var codeblocks = [];
  36874. var precincts = [];
  36875. var i, j, codeblock, precinctNumber;
  36876. for (j = cby0; j < cby1; j++) {
  36877. for (i = cbx0; i < cbx1; i++) {
  36878. codeblock = {
  36879. cbx: i,
  36880. cby: j,
  36881. tbx0: codeblockWidth * i,
  36882. tby0: codeblockHeight * j,
  36883. tbx1: codeblockWidth * (i + 1),
  36884. tby1: codeblockHeight * (j + 1)
  36885. };
  36886. // calculate precinct number
  36887. var pi = Math.floor((codeblock.tbx0 -
  36888. precinctParameters.precinctXOffset) /
  36889. precinctParameters.precinctWidth);
  36890. var pj = Math.floor((codeblock.tby0 -
  36891. precinctParameters.precinctYOffset) /
  36892. precinctParameters.precinctHeight);
  36893. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  36894. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  36895. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  36896. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  36897. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  36898. codeblock.precinctNumber = precinctNumber;
  36899. codeblock.subbandType = subband.type;
  36900. codeblock.Lblock = 3;
  36901. codeblocks.push(codeblock);
  36902. // building precinct for the sub-band
  36903. var precinct = precincts[precinctNumber];
  36904. if (precinct !== undefined) {
  36905. if (i < precinct.cbxMin) {
  36906. precinct.cbxMin = i;
  36907. } else if (i > precinct.cbxMax) {
  36908. precinct.cbxMax = i;
  36909. }
  36910. if (j < precinct.cbyMin) {
  36911. precinct.cbxMin = j;
  36912. } else if (j > precinct.cbyMax) {
  36913. precinct.cbyMax = j;
  36914. }
  36915. } else {
  36916. precincts[precinctNumber] = precinct = {
  36917. cbxMin: i,
  36918. cbyMin: j,
  36919. cbxMax: i,
  36920. cbyMax: j
  36921. };
  36922. }
  36923. codeblock.precinct = precinct;
  36924. }
  36925. }
  36926. subband.codeblockParameters = {
  36927. codeblockWidth: xcb_,
  36928. codeblockHeight: ycb_,
  36929. numcodeblockwide: cbx1 - cbx0 + 1,
  36930. numcodeblockhigh: cby1 - cby1 + 1
  36931. };
  36932. subband.codeblocks = codeblocks;
  36933. subband.precincts = precincts;
  36934. }
  36935. function createPacket(resolution, precinctNumber, layerNumber) {
  36936. var precinctCodeblocks = [];
  36937. // Section B.10.8 Order of info in packet
  36938. var subbands = resolution.subbands;
  36939. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  36940. for (var i = 0, ii = subbands.length; i < ii; i++) {
  36941. var subband = subbands[i];
  36942. var codeblocks = subband.codeblocks;
  36943. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  36944. var codeblock = codeblocks[j];
  36945. if (codeblock.precinctNumber !== precinctNumber) {
  36946. continue;
  36947. }
  36948. precinctCodeblocks.push(codeblock);
  36949. }
  36950. }
  36951. return {
  36952. layerNumber: layerNumber,
  36953. codeblocks: precinctCodeblocks
  36954. };
  36955. }
  36956. function LayerResolutionComponentPositionIterator(context) {
  36957. var siz = context.SIZ;
  36958. var tileIndex = context.currentTile.index;
  36959. var tile = context.tiles[tileIndex];
  36960. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36961. var componentsCount = siz.Csiz;
  36962. var maxDecompositionLevelsCount = 0;
  36963. for (var q = 0; q < componentsCount; q++) {
  36964. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  36965. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  36966. }
  36967. var l = 0, r = 0, i = 0, k = 0;
  36968. this.nextPacket = function JpxImage_nextPacket() {
  36969. // Section B.12.1.1 Layer-resolution-component-position
  36970. for (; l < layersCount; l++) {
  36971. for (; r <= maxDecompositionLevelsCount; r++) {
  36972. for (; i < componentsCount; i++) {
  36973. var component = tile.components[i];
  36974. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  36975. continue;
  36976. }
  36977. var resolution = component.resolutions[r];
  36978. var numprecincts = resolution.precinctParameters.numprecincts;
  36979. for (; k < numprecincts;) {
  36980. var packet = createPacket(resolution, k, l);
  36981. k++;
  36982. return packet;
  36983. }
  36984. k = 0;
  36985. }
  36986. i = 0;
  36987. }
  36988. r = 0;
  36989. }
  36990. throw new Error('JPX Error: Out of packets');
  36991. };
  36992. }
  36993. function ResolutionLayerComponentPositionIterator(context) {
  36994. var siz = context.SIZ;
  36995. var tileIndex = context.currentTile.index;
  36996. var tile = context.tiles[tileIndex];
  36997. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36998. var componentsCount = siz.Csiz;
  36999. var maxDecompositionLevelsCount = 0;
  37000. for (var q = 0; q < componentsCount; q++) {
  37001. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  37002. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  37003. }
  37004. var r = 0, l = 0, i = 0, k = 0;
  37005. this.nextPacket = function JpxImage_nextPacket() {
  37006. // Section B.12.1.2 Resolution-layer-component-position
  37007. for (; r <= maxDecompositionLevelsCount; r++) {
  37008. for (; l < layersCount; l++) {
  37009. for (; i < componentsCount; i++) {
  37010. var component = tile.components[i];
  37011. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  37012. continue;
  37013. }
  37014. var resolution = component.resolutions[r];
  37015. var numprecincts = resolution.precinctParameters.numprecincts;
  37016. for (; k < numprecincts;) {
  37017. var packet = createPacket(resolution, k, l);
  37018. k++;
  37019. return packet;
  37020. }
  37021. k = 0;
  37022. }
  37023. i = 0;
  37024. }
  37025. l = 0;
  37026. }
  37027. throw new Error('JPX Error: Out of packets');
  37028. };
  37029. }
  37030. function buildPackets(context) {
  37031. var siz = context.SIZ;
  37032. var tileIndex = context.currentTile.index;
  37033. var tile = context.tiles[tileIndex];
  37034. var componentsCount = siz.Csiz;
  37035. // Creating resolutions and sub-bands for each component
  37036. for (var c = 0; c < componentsCount; c++) {
  37037. var component = tile.components[c];
  37038. var decompositionLevelsCount =
  37039. component.codingStyleParameters.decompositionLevelsCount;
  37040. // Section B.5 Resolution levels and sub-bands
  37041. var resolutions = [];
  37042. var subbands = [];
  37043. for (var r = 0; r <= decompositionLevelsCount; r++) {
  37044. var blocksDimensions = getBlocksDimensions(context, component, r);
  37045. var resolution = {};
  37046. var scale = 1 << (decompositionLevelsCount - r);
  37047. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  37048. resolution.try0 = Math.ceil(component.tcy0 / scale);
  37049. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  37050. resolution.try1 = Math.ceil(component.tcy1 / scale);
  37051. buildPrecincts(context, resolution, blocksDimensions);
  37052. resolutions.push(resolution);
  37053. var subband;
  37054. if (r === 0) {
  37055. // one sub-band (LL) with last decomposition
  37056. subband = {};
  37057. subband.type = 'LL';
  37058. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  37059. subband.tby0 = Math.ceil(component.tcy0 / scale);
  37060. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  37061. subband.tby1 = Math.ceil(component.tcy1 / scale);
  37062. subband.resolution = resolution;
  37063. buildCodeblocks(context, subband, blocksDimensions);
  37064. subbands.push(subband);
  37065. resolution.subbands = [subband];
  37066. } else {
  37067. var bscale = 1 << (decompositionLevelsCount - r + 1);
  37068. var resolutionSubbands = [];
  37069. // three sub-bands (HL, LH and HH) with rest of decompositions
  37070. subband = {};
  37071. subband.type = 'HL';
  37072. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  37073. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  37074. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  37075. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  37076. subband.resolution = resolution;
  37077. buildCodeblocks(context, subband, blocksDimensions);
  37078. subbands.push(subband);
  37079. resolutionSubbands.push(subband);
  37080. subband = {};
  37081. subband.type = 'LH';
  37082. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  37083. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  37084. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  37085. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  37086. subband.resolution = resolution;
  37087. buildCodeblocks(context, subband, blocksDimensions);
  37088. subbands.push(subband);
  37089. resolutionSubbands.push(subband);
  37090. subband = {};
  37091. subband.type = 'HH';
  37092. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  37093. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  37094. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  37095. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  37096. subband.resolution = resolution;
  37097. buildCodeblocks(context, subband, blocksDimensions);
  37098. subbands.push(subband);
  37099. resolutionSubbands.push(subband);
  37100. resolution.subbands = resolutionSubbands;
  37101. }
  37102. }
  37103. component.resolutions = resolutions;
  37104. component.subbands = subbands;
  37105. }
  37106. // Generate the packets sequence
  37107. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  37108. switch (progressionOrder) {
  37109. case 0:
  37110. tile.packetsIterator =
  37111. new LayerResolutionComponentPositionIterator(context);
  37112. break;
  37113. case 1:
  37114. tile.packetsIterator =
  37115. new ResolutionLayerComponentPositionIterator(context);
  37116. break;
  37117. default:
  37118. throw new Error('JPX Error: Unsupported progression order ' +
  37119. progressionOrder);
  37120. }
  37121. }
  37122. function parseTilePackets(context, data, offset, dataLength) {
  37123. var position = 0;
  37124. var buffer, bufferSize = 0, skipNextBit = false;
  37125. function readBits(count) {
  37126. while (bufferSize < count) {
  37127. var b = data[offset + position];
  37128. position++;
  37129. if (skipNextBit) {
  37130. buffer = (buffer << 7) | b;
  37131. bufferSize += 7;
  37132. skipNextBit = false;
  37133. } else {
  37134. buffer = (buffer << 8) | b;
  37135. bufferSize += 8;
  37136. }
  37137. if (b === 0xFF) {
  37138. skipNextBit = true;
  37139. }
  37140. }
  37141. bufferSize -= count;
  37142. return (buffer >>> bufferSize) & ((1 << count) - 1);
  37143. }
  37144. function alignToByte() {
  37145. bufferSize = 0;
  37146. if (skipNextBit) {
  37147. position++;
  37148. skipNextBit = false;
  37149. }
  37150. }
  37151. function readCodingpasses() {
  37152. if (readBits(1) === 0) {
  37153. return 1;
  37154. }
  37155. if (readBits(1) === 0) {
  37156. return 2;
  37157. }
  37158. var value = readBits(2);
  37159. if (value < 3) {
  37160. return value + 3;
  37161. }
  37162. value = readBits(5);
  37163. if (value < 31) {
  37164. return value + 6;
  37165. }
  37166. value = readBits(7);
  37167. return value + 37;
  37168. }
  37169. var tileIndex = context.currentTile.index;
  37170. var tile = context.tiles[tileIndex];
  37171. var packetsIterator = tile.packetsIterator;
  37172. while (position < dataLength) {
  37173. var packet = packetsIterator.nextPacket();
  37174. if (!readBits(1)) {
  37175. alignToByte();
  37176. continue;
  37177. }
  37178. var layerNumber = packet.layerNumber;
  37179. var queue = [], codeblock;
  37180. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  37181. codeblock = packet.codeblocks[i];
  37182. var precinct = codeblock.precinct;
  37183. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  37184. var codeblockRow = codeblock.cby - precinct.cbyMin;
  37185. var codeblockIncluded = false;
  37186. var firstTimeInclusion = false;
  37187. var valueReady;
  37188. if ('included' in codeblock) {
  37189. codeblockIncluded = !!readBits(1);
  37190. } else {
  37191. // reading inclusion tree
  37192. precinct = codeblock.precinct;
  37193. var inclusionTree, zeroBitPlanesTree;
  37194. if ('inclusionTree' in precinct) {
  37195. inclusionTree = precinct.inclusionTree;
  37196. } else {
  37197. // building inclusion and zero bit-planes trees
  37198. var width = precinct.cbxMax - precinct.cbxMin + 1;
  37199. var height = precinct.cbyMax - precinct.cbyMin + 1;
  37200. inclusionTree = new InclusionTree(width, height, layerNumber);
  37201. zeroBitPlanesTree = new TagTree(width, height);
  37202. precinct.inclusionTree = inclusionTree;
  37203. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  37204. }
  37205. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  37206. while (true) {
  37207. if (readBits(1)) {
  37208. valueReady = !inclusionTree.nextLevel();
  37209. if (valueReady) {
  37210. codeblock.included = true;
  37211. codeblockIncluded = firstTimeInclusion = true;
  37212. break;
  37213. }
  37214. } else {
  37215. inclusionTree.incrementValue(layerNumber);
  37216. break;
  37217. }
  37218. }
  37219. }
  37220. }
  37221. if (!codeblockIncluded) {
  37222. continue;
  37223. }
  37224. if (firstTimeInclusion) {
  37225. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  37226. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  37227. while (true) {
  37228. if (readBits(1)) {
  37229. valueReady = !zeroBitPlanesTree.nextLevel();
  37230. if (valueReady) {
  37231. break;
  37232. }
  37233. } else {
  37234. zeroBitPlanesTree.incrementValue();
  37235. }
  37236. }
  37237. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  37238. }
  37239. var codingpasses = readCodingpasses();
  37240. while (readBits(1)) {
  37241. codeblock.Lblock++;
  37242. }
  37243. var codingpassesLog2 = log2(codingpasses);
  37244. // rounding down log2
  37245. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  37246. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  37247. var codedDataLength = readBits(bits);
  37248. queue.push({
  37249. codeblock: codeblock,
  37250. codingpasses: codingpasses,
  37251. dataLength: codedDataLength
  37252. });
  37253. }
  37254. alignToByte();
  37255. while (queue.length > 0) {
  37256. var packetItem = queue.shift();
  37257. codeblock = packetItem.codeblock;
  37258. if (!('data' in codeblock)) {
  37259. codeblock.data = [];
  37260. }
  37261. codeblock.data.push({
  37262. data: data,
  37263. start: offset + position,
  37264. end: offset + position + packetItem.dataLength,
  37265. codingpasses: packetItem.codingpasses
  37266. });
  37267. position += packetItem.dataLength;
  37268. }
  37269. }
  37270. return position;
  37271. }
  37272. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  37273. delta, mb, reversible, segmentationSymbolUsed) {
  37274. var x0 = subband.tbx0;
  37275. var y0 = subband.tby0;
  37276. var width = subband.tbx1 - subband.tbx0;
  37277. var codeblocks = subband.codeblocks;
  37278. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  37279. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  37280. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  37281. var codeblock = codeblocks[i];
  37282. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  37283. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  37284. if (blockWidth === 0 || blockHeight === 0) {
  37285. continue;
  37286. }
  37287. if (!('data' in codeblock)) {
  37288. continue;
  37289. }
  37290. var bitModel, currentCodingpassType;
  37291. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  37292. codeblock.zeroBitPlanes, mb);
  37293. currentCodingpassType = 2; // first bit plane starts from cleanup
  37294. // collect data
  37295. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  37296. var j, jj, dataItem;
  37297. for (j = 0, jj = data.length; j < jj; j++) {
  37298. dataItem = data[j];
  37299. totalLength += dataItem.end - dataItem.start;
  37300. codingpasses += dataItem.codingpasses;
  37301. }
  37302. var encodedData = new Uint8Array(totalLength);
  37303. var position = 0;
  37304. for (j = 0, jj = data.length; j < jj; j++) {
  37305. dataItem = data[j];
  37306. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  37307. encodedData.set(chunk, position);
  37308. position += chunk.length;
  37309. }
  37310. // decoding the item
  37311. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  37312. bitModel.setDecoder(decoder);
  37313. for (j = 0; j < codingpasses; j++) {
  37314. switch (currentCodingpassType) {
  37315. case 0:
  37316. bitModel.runSignificancePropogationPass();
  37317. break;
  37318. case 1:
  37319. bitModel.runMagnitudeRefinementPass();
  37320. break;
  37321. case 2:
  37322. bitModel.runCleanupPass();
  37323. if (segmentationSymbolUsed) {
  37324. bitModel.checkSegmentationSymbol();
  37325. }
  37326. break;
  37327. }
  37328. currentCodingpassType = (currentCodingpassType + 1) % 3;
  37329. }
  37330. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  37331. var sign = bitModel.coefficentsSign;
  37332. var magnitude = bitModel.coefficentsMagnitude;
  37333. var bitsDecoded = bitModel.bitsDecoded;
  37334. var magnitudeCorrection = reversible ? 0 : 0.5;
  37335. var k, n, nb;
  37336. position = 0;
  37337. // Do the interleaving of Section F.3.3 here, so we do not need
  37338. // to copy later. LL level is not interleaved, just copied.
  37339. var interleave = (subband.type !== 'LL');
  37340. for (j = 0; j < blockHeight; j++) {
  37341. var row = (offset / width) | 0; // row in the non-interleaved subband
  37342. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  37343. for (k = 0; k < blockWidth; k++) {
  37344. n = magnitude[position];
  37345. if (n !== 0) {
  37346. n = (n + magnitudeCorrection) * delta;
  37347. if (sign[position] !== 0) {
  37348. n = -n;
  37349. }
  37350. nb = bitsDecoded[position];
  37351. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  37352. if (reversible && (nb >= mb)) {
  37353. coefficients[pos] = n;
  37354. } else {
  37355. coefficients[pos] = n * (1 << (mb - nb));
  37356. }
  37357. }
  37358. offset++;
  37359. position++;
  37360. }
  37361. offset += width - blockWidth;
  37362. }
  37363. }
  37364. }
  37365. function transformTile(context, tile, c) {
  37366. var component = tile.components[c];
  37367. var codingStyleParameters = component.codingStyleParameters;
  37368. var quantizationParameters = component.quantizationParameters;
  37369. var decompositionLevelsCount =
  37370. codingStyleParameters.decompositionLevelsCount;
  37371. var spqcds = quantizationParameters.SPqcds;
  37372. var scalarExpounded = quantizationParameters.scalarExpounded;
  37373. var guardBits = quantizationParameters.guardBits;
  37374. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  37375. var precision = context.components[c].precision;
  37376. var reversible = codingStyleParameters.reversibleTransformation;
  37377. var transform = (reversible ? new ReversibleTransform() :
  37378. new IrreversibleTransform());
  37379. var subbandCoefficients = [];
  37380. var b = 0;
  37381. for (var i = 0; i <= decompositionLevelsCount; i++) {
  37382. var resolution = component.resolutions[i];
  37383. var width = resolution.trx1 - resolution.trx0;
  37384. var height = resolution.try1 - resolution.try0;
  37385. // Allocate space for the whole sublevel.
  37386. var coefficients = new Float32Array(width * height);
  37387. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  37388. var mu, epsilon;
  37389. if (!scalarExpounded) {
  37390. // formula E-5
  37391. mu = spqcds[0].mu;
  37392. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  37393. } else {
  37394. mu = spqcds[b].mu;
  37395. epsilon = spqcds[b].epsilon;
  37396. b++;
  37397. }
  37398. var subband = resolution.subbands[j];
  37399. var gainLog2 = SubbandsGainLog2[subband.type];
  37400. // calulate quantization coefficient (Section E.1.1.1)
  37401. var delta = (reversible ? 1 :
  37402. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  37403. var mb = (guardBits + epsilon - 1);
  37404. // In the first resolution level, copyCoefficients will fill the
  37405. // whole array with coefficients. In the succeding passes,
  37406. // copyCoefficients will consecutively fill in the values that belong
  37407. // to the interleaved positions of the HL, LH, and HH coefficients.
  37408. // The LL coefficients will then be interleaved in Transform.iterate().
  37409. copyCoefficients(coefficients, width, height, subband, delta, mb,
  37410. reversible, segmentationSymbolUsed);
  37411. }
  37412. subbandCoefficients.push({
  37413. width: width,
  37414. height: height,
  37415. items: coefficients
  37416. });
  37417. }
  37418. var result = transform.calculate(subbandCoefficients,
  37419. component.tcx0, component.tcy0);
  37420. return {
  37421. left: component.tcx0,
  37422. top: component.tcy0,
  37423. width: result.width,
  37424. height: result.height,
  37425. items: result.items
  37426. };
  37427. }
  37428. function transformComponents(context) {
  37429. var siz = context.SIZ;
  37430. var components = context.components;
  37431. var componentsCount = siz.Csiz;
  37432. var resultImages = [];
  37433. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  37434. var tile = context.tiles[i];
  37435. var transformedTiles = [];
  37436. var c;
  37437. for (c = 0; c < componentsCount; c++) {
  37438. transformedTiles[c] = transformTile(context, tile, c);
  37439. }
  37440. var tile0 = transformedTiles[0];
  37441. var out = new Uint8Array(tile0.items.length * componentsCount);
  37442. var result = {
  37443. left: tile0.left,
  37444. top: tile0.top,
  37445. width: tile0.width,
  37446. height: tile0.height,
  37447. items: out
  37448. };
  37449. // Section G.2.2 Inverse multi component transform
  37450. var shift, offset, max, min, maxK;
  37451. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  37452. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  37453. var fourComponents = componentsCount === 4;
  37454. var y0items = transformedTiles[0].items;
  37455. var y1items = transformedTiles[1].items;
  37456. var y2items = transformedTiles[2].items;
  37457. var y3items = fourComponents ? transformedTiles[3].items : null;
  37458. // HACK: The multiple component transform formulas below assume that
  37459. // all components have the same precision. With this in mind, we
  37460. // compute shift and offset only once.
  37461. shift = components[0].precision - 8;
  37462. offset = (128 << shift) + 0.5;
  37463. max = 255 * (1 << shift);
  37464. maxK = max * 0.5;
  37465. min = -maxK;
  37466. var component0 = tile.components[0];
  37467. var alpha01 = componentsCount - 3;
  37468. jj = y0items.length;
  37469. if (!component0.codingStyleParameters.reversibleTransformation) {
  37470. // inverse irreversible multiple component transform
  37471. for (j = 0; j < jj; j++, pos += alpha01) {
  37472. y0 = y0items[j] + offset;
  37473. y1 = y1items[j];
  37474. y2 = y2items[j];
  37475. r = y0 + 1.402 * y2;
  37476. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  37477. b = y0 + 1.772 * y1;
  37478. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37479. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37480. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37481. }
  37482. } else {
  37483. // inverse reversible multiple component transform
  37484. for (j = 0; j < jj; j++, pos += alpha01) {
  37485. y0 = y0items[j] + offset;
  37486. y1 = y1items[j];
  37487. y2 = y2items[j];
  37488. g = y0 - ((y2 + y1) >> 2);
  37489. r = g + y2;
  37490. b = g + y1;
  37491. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37492. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37493. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37494. }
  37495. }
  37496. if (fourComponents) {
  37497. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  37498. k = y3items[j];
  37499. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  37500. }
  37501. }
  37502. } else { // no multi-component transform
  37503. for (c = 0; c < componentsCount; c++) {
  37504. var items = transformedTiles[c].items;
  37505. shift = components[c].precision - 8;
  37506. offset = (128 << shift) + 0.5;
  37507. max = (127.5 * (1 << shift));
  37508. min = -max;
  37509. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  37510. val = items[j];
  37511. out[pos] = val <= min ? 0 :
  37512. val >= max ? 255 : (val + offset) >> shift;
  37513. pos += componentsCount;
  37514. }
  37515. }
  37516. }
  37517. resultImages.push(result);
  37518. }
  37519. return resultImages;
  37520. }
  37521. function initializeTile(context, tileIndex) {
  37522. var siz = context.SIZ;
  37523. var componentsCount = siz.Csiz;
  37524. var tile = context.tiles[tileIndex];
  37525. for (var c = 0; c < componentsCount; c++) {
  37526. var component = tile.components[c];
  37527. var qcdOrQcc = (c in context.currentTile.QCC ?
  37528. context.currentTile.QCC[c] : context.currentTile.QCD);
  37529. component.quantizationParameters = qcdOrQcc;
  37530. var codOrCoc = (c in context.currentTile.COC ?
  37531. context.currentTile.COC[c] : context.currentTile.COD);
  37532. component.codingStyleParameters = codOrCoc;
  37533. }
  37534. tile.codingStyleDefaultParameters = context.currentTile.COD;
  37535. }
  37536. // Section B.10.2 Tag trees
  37537. var TagTree = (function TagTreeClosure() {
  37538. function TagTree(width, height) {
  37539. var levelsLength = log2(Math.max(width, height)) + 1;
  37540. this.levels = [];
  37541. for (var i = 0; i < levelsLength; i++) {
  37542. var level = {
  37543. width: width,
  37544. height: height,
  37545. items: []
  37546. };
  37547. this.levels.push(level);
  37548. width = Math.ceil(width / 2);
  37549. height = Math.ceil(height / 2);
  37550. }
  37551. }
  37552. TagTree.prototype = {
  37553. reset: function TagTree_reset(i, j) {
  37554. var currentLevel = 0, value = 0, level;
  37555. while (currentLevel < this.levels.length) {
  37556. level = this.levels[currentLevel];
  37557. var index = i + j * level.width;
  37558. if (index in level.items) {
  37559. value = level.items[index];
  37560. break;
  37561. }
  37562. level.index = index;
  37563. i >>= 1;
  37564. j >>= 1;
  37565. currentLevel++;
  37566. }
  37567. currentLevel--;
  37568. level = this.levels[currentLevel];
  37569. level.items[level.index] = value;
  37570. this.currentLevel = currentLevel;
  37571. delete this.value;
  37572. },
  37573. incrementValue: function TagTree_incrementValue() {
  37574. var level = this.levels[this.currentLevel];
  37575. level.items[level.index]++;
  37576. },
  37577. nextLevel: function TagTree_nextLevel() {
  37578. var currentLevel = this.currentLevel;
  37579. var level = this.levels[currentLevel];
  37580. var value = level.items[level.index];
  37581. currentLevel--;
  37582. if (currentLevel < 0) {
  37583. this.value = value;
  37584. return false;
  37585. }
  37586. this.currentLevel = currentLevel;
  37587. level = this.levels[currentLevel];
  37588. level.items[level.index] = value;
  37589. return true;
  37590. }
  37591. };
  37592. return TagTree;
  37593. })();
  37594. var InclusionTree = (function InclusionTreeClosure() {
  37595. function InclusionTree(width, height, defaultValue) {
  37596. var levelsLength = log2(Math.max(width, height)) + 1;
  37597. this.levels = [];
  37598. for (var i = 0; i < levelsLength; i++) {
  37599. var items = new Uint8Array(width * height);
  37600. for (var j = 0, jj = items.length; j < jj; j++) {
  37601. items[j] = defaultValue;
  37602. }
  37603. var level = {
  37604. width: width,
  37605. height: height,
  37606. items: items
  37607. };
  37608. this.levels.push(level);
  37609. width = Math.ceil(width / 2);
  37610. height = Math.ceil(height / 2);
  37611. }
  37612. }
  37613. InclusionTree.prototype = {
  37614. reset: function InclusionTree_reset(i, j, stopValue) {
  37615. var currentLevel = 0;
  37616. while (currentLevel < this.levels.length) {
  37617. var level = this.levels[currentLevel];
  37618. var index = i + j * level.width;
  37619. level.index = index;
  37620. var value = level.items[index];
  37621. if (value === 0xFF) {
  37622. break;
  37623. }
  37624. if (value > stopValue) {
  37625. this.currentLevel = currentLevel;
  37626. // already know about this one, propagating the value to top levels
  37627. this.propagateValues();
  37628. return false;
  37629. }
  37630. i >>= 1;
  37631. j >>= 1;
  37632. currentLevel++;
  37633. }
  37634. this.currentLevel = currentLevel - 1;
  37635. return true;
  37636. },
  37637. incrementValue: function InclusionTree_incrementValue(stopValue) {
  37638. var level = this.levels[this.currentLevel];
  37639. level.items[level.index] = stopValue + 1;
  37640. this.propagateValues();
  37641. },
  37642. propagateValues: function InclusionTree_propagateValues() {
  37643. var levelIndex = this.currentLevel;
  37644. var level = this.levels[levelIndex];
  37645. var currentValue = level.items[level.index];
  37646. while (--levelIndex >= 0) {
  37647. level = this.levels[levelIndex];
  37648. level.items[level.index] = currentValue;
  37649. }
  37650. },
  37651. nextLevel: function InclusionTree_nextLevel() {
  37652. var currentLevel = this.currentLevel;
  37653. var level = this.levels[currentLevel];
  37654. var value = level.items[level.index];
  37655. level.items[level.index] = 0xFF;
  37656. currentLevel--;
  37657. if (currentLevel < 0) {
  37658. return false;
  37659. }
  37660. this.currentLevel = currentLevel;
  37661. level = this.levels[currentLevel];
  37662. level.items[level.index] = value;
  37663. return true;
  37664. }
  37665. };
  37666. return InclusionTree;
  37667. })();
  37668. // Section D. Coefficient bit modeling
  37669. var BitModel = (function BitModelClosure() {
  37670. var UNIFORM_CONTEXT = 17;
  37671. var RUNLENGTH_CONTEXT = 18;
  37672. // Table D-1
  37673. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  37674. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  37675. var LLAndLHContextsLabel = new Uint8Array([
  37676. 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,
  37677. 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,
  37678. 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
  37679. ]);
  37680. var HLContextLabel = new Uint8Array([
  37681. 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,
  37682. 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,
  37683. 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
  37684. ]);
  37685. var HHContextLabel = new Uint8Array([
  37686. 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,
  37687. 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,
  37688. 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
  37689. ]);
  37690. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  37691. this.width = width;
  37692. this.height = height;
  37693. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  37694. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  37695. var coefficientCount = width * height;
  37696. // coefficients outside the encoding region treated as insignificant
  37697. // add border state cells for significanceState
  37698. this.neighborsSignificance = new Uint8Array(coefficientCount);
  37699. this.coefficentsSign = new Uint8Array(coefficientCount);
  37700. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  37701. mb > 6 ? new Uint16Array(coefficientCount) :
  37702. new Uint8Array(coefficientCount);
  37703. this.processingFlags = new Uint8Array(coefficientCount);
  37704. var bitsDecoded = new Uint8Array(coefficientCount);
  37705. if (zeroBitPlanes !== 0) {
  37706. for (var i = 0; i < coefficientCount; i++) {
  37707. bitsDecoded[i] = zeroBitPlanes;
  37708. }
  37709. }
  37710. this.bitsDecoded = bitsDecoded;
  37711. this.reset();
  37712. }
  37713. BitModel.prototype = {
  37714. setDecoder: function BitModel_setDecoder(decoder) {
  37715. this.decoder = decoder;
  37716. },
  37717. reset: function BitModel_reset() {
  37718. // We have 17 contexts that are accessed via context labels,
  37719. // plus the uniform and runlength context.
  37720. this.contexts = new Int8Array(19);
  37721. // Contexts are packed into 1 byte:
  37722. // highest 7 bits carry the index, lowest bit carries mps
  37723. this.contexts[0] = (4 << 1) | 0;
  37724. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  37725. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  37726. },
  37727. setNeighborsSignificance:
  37728. function BitModel_setNeighborsSignificance(row, column, index) {
  37729. var neighborsSignificance = this.neighborsSignificance;
  37730. var width = this.width, height = this.height;
  37731. var left = (column > 0);
  37732. var right = (column + 1 < width);
  37733. var i;
  37734. if (row > 0) {
  37735. i = index - width;
  37736. if (left) {
  37737. neighborsSignificance[i - 1] += 0x10;
  37738. }
  37739. if (right) {
  37740. neighborsSignificance[i + 1] += 0x10;
  37741. }
  37742. neighborsSignificance[i] += 0x04;
  37743. }
  37744. if (row + 1 < height) {
  37745. i = index + width;
  37746. if (left) {
  37747. neighborsSignificance[i - 1] += 0x10;
  37748. }
  37749. if (right) {
  37750. neighborsSignificance[i + 1] += 0x10;
  37751. }
  37752. neighborsSignificance[i] += 0x04;
  37753. }
  37754. if (left) {
  37755. neighborsSignificance[index - 1] += 0x01;
  37756. }
  37757. if (right) {
  37758. neighborsSignificance[index + 1] += 0x01;
  37759. }
  37760. neighborsSignificance[index] |= 0x80;
  37761. },
  37762. runSignificancePropogationPass:
  37763. function BitModel_runSignificancePropogationPass() {
  37764. var decoder = this.decoder;
  37765. var width = this.width, height = this.height;
  37766. var coefficentsMagnitude = this.coefficentsMagnitude;
  37767. var coefficentsSign = this.coefficentsSign;
  37768. var neighborsSignificance = this.neighborsSignificance;
  37769. var processingFlags = this.processingFlags;
  37770. var contexts = this.contexts;
  37771. var labels = this.contextLabelTable;
  37772. var bitsDecoded = this.bitsDecoded;
  37773. var processedInverseMask = ~1;
  37774. var processedMask = 1;
  37775. var firstMagnitudeBitMask = 2;
  37776. for (var i0 = 0; i0 < height; i0 += 4) {
  37777. for (var j = 0; j < width; j++) {
  37778. var index = i0 * width + j;
  37779. for (var i1 = 0; i1 < 4; i1++, index += width) {
  37780. var i = i0 + i1;
  37781. if (i >= height) {
  37782. break;
  37783. }
  37784. // clear processed flag first
  37785. processingFlags[index] &= processedInverseMask;
  37786. if (coefficentsMagnitude[index] ||
  37787. !neighborsSignificance[index]) {
  37788. continue;
  37789. }
  37790. var contextLabel = labels[neighborsSignificance[index]];
  37791. var decision = decoder.readBit(contexts, contextLabel);
  37792. if (decision) {
  37793. var sign = this.decodeSignBit(i, j, index);
  37794. coefficentsSign[index] = sign;
  37795. coefficentsMagnitude[index] = 1;
  37796. this.setNeighborsSignificance(i, j, index);
  37797. processingFlags[index] |= firstMagnitudeBitMask;
  37798. }
  37799. bitsDecoded[index]++;
  37800. processingFlags[index] |= processedMask;
  37801. }
  37802. }
  37803. }
  37804. },
  37805. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  37806. var width = this.width, height = this.height;
  37807. var coefficentsMagnitude = this.coefficentsMagnitude;
  37808. var coefficentsSign = this.coefficentsSign;
  37809. var contribution, sign0, sign1, significance1;
  37810. var contextLabel, decoded;
  37811. // calculate horizontal contribution
  37812. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  37813. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  37814. sign1 = coefficentsSign[index + 1];
  37815. if (significance1) {
  37816. sign0 = coefficentsSign[index - 1];
  37817. contribution = 1 - sign1 - sign0;
  37818. } else {
  37819. contribution = 1 - sign1 - sign1;
  37820. }
  37821. } else if (significance1) {
  37822. sign0 = coefficentsSign[index - 1];
  37823. contribution = 1 - sign0 - sign0;
  37824. } else {
  37825. contribution = 0;
  37826. }
  37827. var horizontalContribution = 3 * contribution;
  37828. // calculate vertical contribution and combine with the horizontal
  37829. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  37830. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  37831. sign1 = coefficentsSign[index + width];
  37832. if (significance1) {
  37833. sign0 = coefficentsSign[index - width];
  37834. contribution = 1 - sign1 - sign0 + horizontalContribution;
  37835. } else {
  37836. contribution = 1 - sign1 - sign1 + horizontalContribution;
  37837. }
  37838. } else if (significance1) {
  37839. sign0 = coefficentsSign[index - width];
  37840. contribution = 1 - sign0 - sign0 + horizontalContribution;
  37841. } else {
  37842. contribution = horizontalContribution;
  37843. }
  37844. if (contribution >= 0) {
  37845. contextLabel = 9 + contribution;
  37846. decoded = this.decoder.readBit(this.contexts, contextLabel);
  37847. } else {
  37848. contextLabel = 9 - contribution;
  37849. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  37850. }
  37851. return decoded;
  37852. },
  37853. runMagnitudeRefinementPass:
  37854. function BitModel_runMagnitudeRefinementPass() {
  37855. var decoder = this.decoder;
  37856. var width = this.width, height = this.height;
  37857. var coefficentsMagnitude = this.coefficentsMagnitude;
  37858. var neighborsSignificance = this.neighborsSignificance;
  37859. var contexts = this.contexts;
  37860. var bitsDecoded = this.bitsDecoded;
  37861. var processingFlags = this.processingFlags;
  37862. var processedMask = 1;
  37863. var firstMagnitudeBitMask = 2;
  37864. var length = width * height;
  37865. var width4 = width * 4;
  37866. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  37867. indexNext = Math.min(length, index0 + width4);
  37868. for (var j = 0; j < width; j++) {
  37869. for (var index = index0 + j; index < indexNext; index += width) {
  37870. // significant but not those that have just become
  37871. if (!coefficentsMagnitude[index] ||
  37872. (processingFlags[index] & processedMask) !== 0) {
  37873. continue;
  37874. }
  37875. var contextLabel = 16;
  37876. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  37877. processingFlags[index] ^= firstMagnitudeBitMask;
  37878. // first refinement
  37879. var significance = neighborsSignificance[index] & 127;
  37880. contextLabel = significance === 0 ? 15 : 14;
  37881. }
  37882. var bit = decoder.readBit(contexts, contextLabel);
  37883. coefficentsMagnitude[index] =
  37884. (coefficentsMagnitude[index] << 1) | bit;
  37885. bitsDecoded[index]++;
  37886. processingFlags[index] |= processedMask;
  37887. }
  37888. }
  37889. }
  37890. },
  37891. runCleanupPass: function BitModel_runCleanupPass() {
  37892. var decoder = this.decoder;
  37893. var width = this.width, height = this.height;
  37894. var neighborsSignificance = this.neighborsSignificance;
  37895. var coefficentsMagnitude = this.coefficentsMagnitude;
  37896. var coefficentsSign = this.coefficentsSign;
  37897. var contexts = this.contexts;
  37898. var labels = this.contextLabelTable;
  37899. var bitsDecoded = this.bitsDecoded;
  37900. var processingFlags = this.processingFlags;
  37901. var processedMask = 1;
  37902. var firstMagnitudeBitMask = 2;
  37903. var oneRowDown = width;
  37904. var twoRowsDown = width * 2;
  37905. var threeRowsDown = width * 3;
  37906. var iNext;
  37907. for (var i0 = 0; i0 < height; i0 = iNext) {
  37908. iNext = Math.min(i0 + 4, height);
  37909. var indexBase = i0 * width;
  37910. var checkAllEmpty = i0 + 3 < height;
  37911. for (var j = 0; j < width; j++) {
  37912. var index0 = indexBase + j;
  37913. // using the property: labels[neighborsSignificance[index]] === 0
  37914. // when neighborsSignificance[index] === 0
  37915. var allEmpty = (checkAllEmpty &&
  37916. processingFlags[index0] === 0 &&
  37917. processingFlags[index0 + oneRowDown] === 0 &&
  37918. processingFlags[index0 + twoRowsDown] === 0 &&
  37919. processingFlags[index0 + threeRowsDown] === 0 &&
  37920. neighborsSignificance[index0] === 0 &&
  37921. neighborsSignificance[index0 + oneRowDown] === 0 &&
  37922. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  37923. neighborsSignificance[index0 + threeRowsDown] === 0);
  37924. var i1 = 0, index = index0;
  37925. var i = i0, sign;
  37926. if (allEmpty) {
  37927. var hasSignificantCoefficent =
  37928. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  37929. if (!hasSignificantCoefficent) {
  37930. bitsDecoded[index0]++;
  37931. bitsDecoded[index0 + oneRowDown]++;
  37932. bitsDecoded[index0 + twoRowsDown]++;
  37933. bitsDecoded[index0 + threeRowsDown]++;
  37934. continue; // next column
  37935. }
  37936. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37937. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37938. if (i1 !== 0) {
  37939. i = i0 + i1;
  37940. index += i1 * width;
  37941. }
  37942. sign = this.decodeSignBit(i, j, index);
  37943. coefficentsSign[index] = sign;
  37944. coefficentsMagnitude[index] = 1;
  37945. this.setNeighborsSignificance(i, j, index);
  37946. processingFlags[index] |= firstMagnitudeBitMask;
  37947. index = index0;
  37948. for (var i2 = i0; i2 <= i; i2++, index += width) {
  37949. bitsDecoded[index]++;
  37950. }
  37951. i1++;
  37952. }
  37953. for (i = i0 + i1; i < iNext; i++, index += width) {
  37954. if (coefficentsMagnitude[index] ||
  37955. (processingFlags[index] & processedMask) !== 0) {
  37956. continue;
  37957. }
  37958. var contextLabel = labels[neighborsSignificance[index]];
  37959. var decision = decoder.readBit(contexts, contextLabel);
  37960. if (decision === 1) {
  37961. sign = this.decodeSignBit(i, j, index);
  37962. coefficentsSign[index] = sign;
  37963. coefficentsMagnitude[index] = 1;
  37964. this.setNeighborsSignificance(i, j, index);
  37965. processingFlags[index] |= firstMagnitudeBitMask;
  37966. }
  37967. bitsDecoded[index]++;
  37968. }
  37969. }
  37970. }
  37971. },
  37972. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  37973. var decoder = this.decoder;
  37974. var contexts = this.contexts;
  37975. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  37976. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  37977. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37978. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37979. if (symbol !== 0xA) {
  37980. throw new Error('JPX Error: Invalid segmentation symbol');
  37981. }
  37982. }
  37983. };
  37984. return BitModel;
  37985. })();
  37986. // Section F, Discrete wavelet transformation
  37987. var Transform = (function TransformClosure() {
  37988. function Transform() {}
  37989. Transform.prototype.calculate =
  37990. function transformCalculate(subbands, u0, v0) {
  37991. var ll = subbands[0];
  37992. for (var i = 1, ii = subbands.length; i < ii; i++) {
  37993. ll = this.iterate(ll, subbands[i], u0, v0);
  37994. }
  37995. return ll;
  37996. };
  37997. Transform.prototype.extend = function extend(buffer, offset, size) {
  37998. // Section F.3.7 extending... using max extension of 4
  37999. var i1 = offset - 1, j1 = offset + 1;
  38000. var i2 = offset + size - 2, j2 = offset + size;
  38001. buffer[i1--] = buffer[j1++];
  38002. buffer[j2++] = buffer[i2--];
  38003. buffer[i1--] = buffer[j1++];
  38004. buffer[j2++] = buffer[i2--];
  38005. buffer[i1--] = buffer[j1++];
  38006. buffer[j2++] = buffer[i2--];
  38007. buffer[i1] = buffer[j1];
  38008. buffer[j2] = buffer[i2];
  38009. };
  38010. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  38011. u0, v0) {
  38012. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  38013. var width = hl_lh_hh.width;
  38014. var height = hl_lh_hh.height;
  38015. var items = hl_lh_hh.items;
  38016. var i, j, k, l, u, v;
  38017. // Interleave LL according to Section F.3.3
  38018. for (k = 0, i = 0; i < llHeight; i++) {
  38019. l = i * 2 * width;
  38020. for (j = 0; j < llWidth; j++, k++, l += 2) {
  38021. items[l] = llItems[k];
  38022. }
  38023. }
  38024. // The LL band is not needed anymore.
  38025. llItems = ll.items = null;
  38026. var bufferPadding = 4;
  38027. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  38028. // Section F.3.4 HOR_SR
  38029. if (width === 1) {
  38030. // if width = 1, when u0 even keep items as is, when odd divide by 2
  38031. if ((u0 & 1) !== 0) {
  38032. for (v = 0, k = 0; v < height; v++, k += width) {
  38033. items[k] *= 0.5;
  38034. }
  38035. }
  38036. } else {
  38037. for (v = 0, k = 0; v < height; v++, k += width) {
  38038. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  38039. this.extend(rowBuffer, bufferPadding, width);
  38040. this.filter(rowBuffer, bufferPadding, width);
  38041. items.set(
  38042. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  38043. k);
  38044. }
  38045. }
  38046. // Accesses to the items array can take long, because it may not fit into
  38047. // CPU cache and has to be fetched from main memory. Since subsequent
  38048. // accesses to the items array are not local when reading columns, we
  38049. // have a cache miss every time. To reduce cache misses, get up to
  38050. // 'numBuffers' items at a time and store them into the individual
  38051. // buffers. The colBuffers should be small enough to fit into CPU cache.
  38052. var numBuffers = 16;
  38053. var colBuffers = [];
  38054. for (i = 0; i < numBuffers; i++) {
  38055. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  38056. }
  38057. var b, currentBuffer = 0;
  38058. ll = bufferPadding + height;
  38059. // Section F.3.5 VER_SR
  38060. if (height === 1) {
  38061. // if height = 1, when v0 even keep items as is, when odd divide by 2
  38062. if ((v0 & 1) !== 0) {
  38063. for (u = 0; u < width; u++) {
  38064. items[u] *= 0.5;
  38065. }
  38066. }
  38067. } else {
  38068. for (u = 0; u < width; u++) {
  38069. // if we ran out of buffers, copy several image columns at once
  38070. if (currentBuffer === 0) {
  38071. numBuffers = Math.min(width - u, numBuffers);
  38072. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  38073. for (b = 0; b < numBuffers; b++) {
  38074. colBuffers[b][l] = items[k + b];
  38075. }
  38076. }
  38077. currentBuffer = numBuffers;
  38078. }
  38079. currentBuffer--;
  38080. var buffer = colBuffers[currentBuffer];
  38081. this.extend(buffer, bufferPadding, height);
  38082. this.filter(buffer, bufferPadding, height);
  38083. // If this is last buffer in this group of buffers, flush all buffers.
  38084. if (currentBuffer === 0) {
  38085. k = u - numBuffers + 1;
  38086. for (l = bufferPadding; l < ll; k += width, l++) {
  38087. for (b = 0; b < numBuffers; b++) {
  38088. items[k + b] = colBuffers[b][l];
  38089. }
  38090. }
  38091. }
  38092. }
  38093. }
  38094. return {
  38095. width: width,
  38096. height: height,
  38097. items: items
  38098. };
  38099. };
  38100. return Transform;
  38101. })();
  38102. // Section 3.8.2 Irreversible 9-7 filter
  38103. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  38104. function IrreversibleTransform() {
  38105. Transform.call(this);
  38106. }
  38107. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  38108. IrreversibleTransform.prototype.filter =
  38109. function irreversibleTransformFilter(x, offset, length) {
  38110. var len = length >> 1;
  38111. offset = offset | 0;
  38112. var j, n, current, next;
  38113. var alpha = -1.586134342059924;
  38114. var beta = -0.052980118572961;
  38115. var gamma = 0.882911075530934;
  38116. var delta = 0.443506852043971;
  38117. var K = 1.230174104914001;
  38118. var K_ = 1 / K;
  38119. // step 1 is combined with step 3
  38120. // step 2
  38121. j = offset - 3;
  38122. for (n = len + 4; n--; j += 2) {
  38123. x[j] *= K_;
  38124. }
  38125. // step 1 & 3
  38126. j = offset - 2;
  38127. current = delta * x[j -1];
  38128. for (n = len + 3; n--; j += 2) {
  38129. next = delta * x[j + 1];
  38130. x[j] = K * x[j] - current - next;
  38131. if (n--) {
  38132. j += 2;
  38133. current = delta * x[j + 1];
  38134. x[j] = K * x[j] - current - next;
  38135. } else {
  38136. break;
  38137. }
  38138. }
  38139. // step 4
  38140. j = offset - 1;
  38141. current = gamma * x[j - 1];
  38142. for (n = len + 2; n--; j += 2) {
  38143. next = gamma * x[j + 1];
  38144. x[j] -= current + next;
  38145. if (n--) {
  38146. j += 2;
  38147. current = gamma * x[j + 1];
  38148. x[j] -= current + next;
  38149. } else {
  38150. break;
  38151. }
  38152. }
  38153. // step 5
  38154. j = offset;
  38155. current = beta * x[j - 1];
  38156. for (n = len + 1; n--; j += 2) {
  38157. next = beta * x[j + 1];
  38158. x[j] -= current + next;
  38159. if (n--) {
  38160. j += 2;
  38161. current = beta * x[j + 1];
  38162. x[j] -= current + next;
  38163. } else {
  38164. break;
  38165. }
  38166. }
  38167. // step 6
  38168. if (len !== 0) {
  38169. j = offset + 1;
  38170. current = alpha * x[j - 1];
  38171. for (n = len; n--; j += 2) {
  38172. next = alpha * x[j + 1];
  38173. x[j] -= current + next;
  38174. if (n--) {
  38175. j += 2;
  38176. current = alpha * x[j + 1];
  38177. x[j] -= current + next;
  38178. } else {
  38179. break;
  38180. }
  38181. }
  38182. }
  38183. };
  38184. return IrreversibleTransform;
  38185. })();
  38186. // Section 3.8.1 Reversible 5-3 filter
  38187. var ReversibleTransform = (function ReversibleTransformClosure() {
  38188. function ReversibleTransform() {
  38189. Transform.call(this);
  38190. }
  38191. ReversibleTransform.prototype = Object.create(Transform.prototype);
  38192. ReversibleTransform.prototype.filter =
  38193. function reversibleTransformFilter(x, offset, length) {
  38194. var len = length >> 1;
  38195. offset = offset | 0;
  38196. var j, n;
  38197. for (j = offset, n = len + 1; n--; j += 2) {
  38198. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  38199. }
  38200. for (j = offset + 1, n = len; n--; j += 2) {
  38201. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  38202. }
  38203. };
  38204. return ReversibleTransform;
  38205. })();
  38206. return JpxImage;
  38207. })();
  38208. var Jbig2Image = (function Jbig2ImageClosure() {
  38209. // Utility data structures
  38210. function ContextCache() {}
  38211. ContextCache.prototype = {
  38212. getContexts: function(id) {
  38213. if (id in this) {
  38214. return this[id];
  38215. }
  38216. return (this[id] = new Int8Array(1 << 16));
  38217. }
  38218. };
  38219. function DecodingContext(data, start, end) {
  38220. this.data = data;
  38221. this.start = start;
  38222. this.end = end;
  38223. }
  38224. DecodingContext.prototype = {
  38225. get decoder() {
  38226. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  38227. return shadow(this, 'decoder', decoder);
  38228. },
  38229. get contextCache() {
  38230. var cache = new ContextCache();
  38231. return shadow(this, 'contextCache', cache);
  38232. }
  38233. };
  38234. // Annex A. Arithmetic Integer Decoding Procedure
  38235. // A.2 Procedure for decoding values
  38236. function decodeInteger(contextCache, procedure, decoder) {
  38237. var contexts = contextCache.getContexts(procedure);
  38238. var prev = 1;
  38239. function readBits(length) {
  38240. var v = 0;
  38241. for (var i = 0; i < length; i++) {
  38242. var bit = decoder.readBit(contexts, prev);
  38243. prev = (prev < 256 ? (prev << 1) | bit :
  38244. (((prev << 1) | bit) & 511) | 256);
  38245. v = (v << 1) | bit;
  38246. }
  38247. return v >>> 0;
  38248. }
  38249. var sign = readBits(1);
  38250. var value = readBits(1) ?
  38251. (readBits(1) ?
  38252. (readBits(1) ?
  38253. (readBits(1) ?
  38254. (readBits(1) ?
  38255. (readBits(32) + 4436) :
  38256. readBits(12) + 340) :
  38257. readBits(8) + 84) :
  38258. readBits(6) + 20) :
  38259. readBits(4) + 4) :
  38260. readBits(2);
  38261. return (sign === 0 ? value : (value > 0 ? -value : null));
  38262. }
  38263. // A.3 The IAID decoding procedure
  38264. function decodeIAID(contextCache, decoder, codeLength) {
  38265. var contexts = contextCache.getContexts('IAID');
  38266. var prev = 1;
  38267. for (var i = 0; i < codeLength; i++) {
  38268. var bit = decoder.readBit(contexts, prev);
  38269. prev = (prev << 1) | bit;
  38270. }
  38271. if (codeLength < 31) {
  38272. return prev & ((1 << codeLength) - 1);
  38273. }
  38274. return prev & 0x7FFFFFFF;
  38275. }
  38276. // 7.3 Segment types
  38277. var SegmentTypes = [
  38278. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  38279. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  38280. null, null, null, null, null, 'patternDictionary', null, null, null,
  38281. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  38282. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  38283. null, null, null, null, null, 'IntermediateGenericRegion', null,
  38284. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  38285. 'IntermediateGenericRefinementRegion', null,
  38286. 'ImmediateGenericRefinementRegion',
  38287. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  38288. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  38289. 'Tables', null, null, null, null, null, null, null, null,
  38290. 'Extension'
  38291. ];
  38292. var CodingTemplates = [
  38293. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38294. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  38295. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38296. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  38297. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  38298. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38299. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38300. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  38301. {x: -1, y: 0}],
  38302. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  38303. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  38304. ];
  38305. var RefinementTemplates = [
  38306. {
  38307. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38308. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  38309. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  38310. },
  38311. {
  38312. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38313. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  38314. {x: 0, y: 1}, {x: 1, y: 1}]
  38315. }
  38316. ];
  38317. // See 6.2.5.7 Decoding the bitmap.
  38318. var ReusedContexts = [
  38319. 0x9B25, // 10011 0110010 0101
  38320. 0x0795, // 0011 110010 101
  38321. 0x00E5, // 001 11001 01
  38322. 0x0195 // 011001 0101
  38323. ];
  38324. var RefinementReusedContexts = [
  38325. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  38326. 0x0008 // '0000' + '001000'
  38327. ];
  38328. function decodeBitmapTemplate0(width, height, decodingContext) {
  38329. var decoder = decodingContext.decoder;
  38330. var contexts = decodingContext.contextCache.getContexts('GB');
  38331. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  38332. // ...ooooo....
  38333. // ..ooooooo... Context template for current pixel (X)
  38334. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  38335. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  38336. for (i = 0; i < height; i++) {
  38337. row = bitmap[i] = new Uint8Array(width);
  38338. row1 = (i < 1) ? row : bitmap[i - 1];
  38339. row2 = (i < 2) ? row : bitmap[i - 2];
  38340. // At the beginning of each row:
  38341. // Fill contextLabel with pixels that are above/right of (X)
  38342. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  38343. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  38344. (row1[3] << 4);
  38345. for (j = 0; j < width; j++) {
  38346. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  38347. // At each pixel: Clear contextLabel pixels that are shifted
  38348. // out of the context, then add new ones.
  38349. // If j + n is out of range at the right image border, then
  38350. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  38351. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  38352. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  38353. }
  38354. }
  38355. return bitmap;
  38356. }
  38357. // 6.2 Generic Region Decoding Procedure
  38358. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  38359. decodingContext) {
  38360. if (mmr) {
  38361. error('JBIG2 error: MMR encoding is not supported');
  38362. }
  38363. // Use optimized version for the most common case
  38364. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  38365. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  38366. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  38367. return decodeBitmapTemplate0(width, height, decodingContext);
  38368. }
  38369. var useskip = !!skip;
  38370. var template = CodingTemplates[templateIndex].concat(at);
  38371. // Sorting is non-standard, and it is not required. But sorting increases
  38372. // the number of template bits that can be reused from the previous
  38373. // contextLabel in the main loop.
  38374. template.sort(function (a, b) {
  38375. return (a.y - b.y) || (a.x - b.x);
  38376. });
  38377. var templateLength = template.length;
  38378. var templateX = new Int8Array(templateLength);
  38379. var templateY = new Int8Array(templateLength);
  38380. var changingTemplateEntries = [];
  38381. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  38382. var c, k;
  38383. for (k = 0; k < templateLength; k++) {
  38384. templateX[k] = template[k].x;
  38385. templateY[k] = template[k].y;
  38386. minX = Math.min(minX, template[k].x);
  38387. maxX = Math.max(maxX, template[k].x);
  38388. minY = Math.min(minY, template[k].y);
  38389. // Check if the template pixel appears in two consecutive context labels,
  38390. // so it can be reused. Otherwise, we add it to the list of changing
  38391. // template entries.
  38392. if (k < templateLength - 1 &&
  38393. template[k].y === template[k + 1].y &&
  38394. template[k].x === template[k + 1].x - 1) {
  38395. reuseMask |= 1 << (templateLength - 1 - k);
  38396. } else {
  38397. changingTemplateEntries.push(k);
  38398. }
  38399. }
  38400. var changingEntriesLength = changingTemplateEntries.length;
  38401. var changingTemplateX = new Int8Array(changingEntriesLength);
  38402. var changingTemplateY = new Int8Array(changingEntriesLength);
  38403. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  38404. for (c = 0; c < changingEntriesLength; c++) {
  38405. k = changingTemplateEntries[c];
  38406. changingTemplateX[c] = template[k].x;
  38407. changingTemplateY[c] = template[k].y;
  38408. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  38409. }
  38410. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  38411. var sbb_left = -minX;
  38412. var sbb_top = -minY;
  38413. var sbb_right = width - maxX;
  38414. var pseudoPixelContext = ReusedContexts[templateIndex];
  38415. var row = new Uint8Array(width);
  38416. var bitmap = [];
  38417. var decoder = decodingContext.decoder;
  38418. var contexts = decodingContext.contextCache.getContexts('GB');
  38419. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  38420. for (var i = 0; i < height; i++) {
  38421. if (prediction) {
  38422. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38423. ltp ^= sltp;
  38424. if (ltp) {
  38425. bitmap.push(row); // duplicate previous row
  38426. continue;
  38427. }
  38428. }
  38429. row = new Uint8Array(row);
  38430. bitmap.push(row);
  38431. for (j = 0; j < width; j++) {
  38432. if (useskip && skip[i][j]) {
  38433. row[j] = 0;
  38434. continue;
  38435. }
  38436. // Are we in the middle of a scanline, so we can reuse contextLabel
  38437. // bits?
  38438. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  38439. // If yes, we can just shift the bits that are reusable and only
  38440. // fetch the remaining ones.
  38441. contextLabel = (contextLabel << 1) & reuseMask;
  38442. for (k = 0; k < changingEntriesLength; k++) {
  38443. i0 = i + changingTemplateY[k];
  38444. j0 = j + changingTemplateX[k];
  38445. bit = bitmap[i0][j0];
  38446. if (bit) {
  38447. bit = changingTemplateBit[k];
  38448. contextLabel |= bit;
  38449. }
  38450. }
  38451. } else {
  38452. // compute the contextLabel from scratch
  38453. contextLabel = 0;
  38454. shift = templateLength - 1;
  38455. for (k = 0; k < templateLength; k++, shift--) {
  38456. j0 = j + templateX[k];
  38457. if (j0 >= 0 && j0 < width) {
  38458. i0 = i + templateY[k];
  38459. if (i0 >= 0) {
  38460. bit = bitmap[i0][j0];
  38461. if (bit) {
  38462. contextLabel |= bit << shift;
  38463. }
  38464. }
  38465. }
  38466. }
  38467. }
  38468. var pixel = decoder.readBit(contexts, contextLabel);
  38469. row[j] = pixel;
  38470. }
  38471. }
  38472. return bitmap;
  38473. }
  38474. // 6.3.2 Generic Refinement Region Decoding Procedure
  38475. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  38476. offsetX, offsetY, prediction, at,
  38477. decodingContext) {
  38478. var codingTemplate = RefinementTemplates[templateIndex].coding;
  38479. if (templateIndex === 0) {
  38480. codingTemplate = codingTemplate.concat([at[0]]);
  38481. }
  38482. var codingTemplateLength = codingTemplate.length;
  38483. var codingTemplateX = new Int32Array(codingTemplateLength);
  38484. var codingTemplateY = new Int32Array(codingTemplateLength);
  38485. var k;
  38486. for (k = 0; k < codingTemplateLength; k++) {
  38487. codingTemplateX[k] = codingTemplate[k].x;
  38488. codingTemplateY[k] = codingTemplate[k].y;
  38489. }
  38490. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  38491. if (templateIndex === 0) {
  38492. referenceTemplate = referenceTemplate.concat([at[1]]);
  38493. }
  38494. var referenceTemplateLength = referenceTemplate.length;
  38495. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  38496. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  38497. for (k = 0; k < referenceTemplateLength; k++) {
  38498. referenceTemplateX[k] = referenceTemplate[k].x;
  38499. referenceTemplateY[k] = referenceTemplate[k].y;
  38500. }
  38501. var referenceWidth = referenceBitmap[0].length;
  38502. var referenceHeight = referenceBitmap.length;
  38503. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  38504. var bitmap = [];
  38505. var decoder = decodingContext.decoder;
  38506. var contexts = decodingContext.contextCache.getContexts('GR');
  38507. var ltp = 0;
  38508. for (var i = 0; i < height; i++) {
  38509. if (prediction) {
  38510. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38511. ltp ^= sltp;
  38512. if (ltp) {
  38513. error('JBIG2 error: prediction is not supported');
  38514. }
  38515. }
  38516. var row = new Uint8Array(width);
  38517. bitmap.push(row);
  38518. for (var j = 0; j < width; j++) {
  38519. var i0, j0;
  38520. var contextLabel = 0;
  38521. for (k = 0; k < codingTemplateLength; k++) {
  38522. i0 = i + codingTemplateY[k];
  38523. j0 = j + codingTemplateX[k];
  38524. if (i0 < 0 || j0 < 0 || j0 >= width) {
  38525. contextLabel <<= 1; // out of bound pixel
  38526. } else {
  38527. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  38528. }
  38529. }
  38530. for (k = 0; k < referenceTemplateLength; k++) {
  38531. i0 = i + referenceTemplateY[k] + offsetY;
  38532. j0 = j + referenceTemplateX[k] + offsetX;
  38533. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  38534. j0 >= referenceWidth) {
  38535. contextLabel <<= 1; // out of bound pixel
  38536. } else {
  38537. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  38538. }
  38539. }
  38540. var pixel = decoder.readBit(contexts, contextLabel);
  38541. row[j] = pixel;
  38542. }
  38543. }
  38544. return bitmap;
  38545. }
  38546. // 6.5.5 Decoding the symbol dictionary
  38547. function decodeSymbolDictionary(huffman, refinement, symbols,
  38548. numberOfNewSymbols, numberOfExportedSymbols,
  38549. huffmanTables, templateIndex, at,
  38550. refinementTemplateIndex, refinementAt,
  38551. decodingContext) {
  38552. if (huffman) {
  38553. error('JBIG2 error: huffman is not supported');
  38554. }
  38555. var newSymbols = [];
  38556. var currentHeight = 0;
  38557. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  38558. var decoder = decodingContext.decoder;
  38559. var contextCache = decodingContext.contextCache;
  38560. while (newSymbols.length < numberOfNewSymbols) {
  38561. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  38562. currentHeight += deltaHeight;
  38563. var currentWidth = 0;
  38564. var totalWidth = 0;
  38565. while (true) {
  38566. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  38567. if (deltaWidth === null) {
  38568. break; // OOB
  38569. }
  38570. currentWidth += deltaWidth;
  38571. totalWidth += currentWidth;
  38572. var bitmap;
  38573. if (refinement) {
  38574. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  38575. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  38576. if (numberOfInstances > 1) {
  38577. bitmap = decodeTextRegion(huffman, refinement,
  38578. currentWidth, currentHeight, 0,
  38579. numberOfInstances, 1, //strip size
  38580. symbols.concat(newSymbols),
  38581. symbolCodeLength,
  38582. 0, //transposed
  38583. 0, //ds offset
  38584. 1, //top left 7.4.3.1.1
  38585. 0, //OR operator
  38586. huffmanTables,
  38587. refinementTemplateIndex, refinementAt,
  38588. decodingContext);
  38589. } else {
  38590. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38591. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38592. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38593. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  38594. newSymbols[symbolId - symbols.length]);
  38595. bitmap = decodeRefinement(currentWidth, currentHeight,
  38596. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  38597. decodingContext);
  38598. }
  38599. } else {
  38600. // 6.5.8.1 Direct-coded symbol bitmap
  38601. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  38602. templateIndex, false, null, at, decodingContext);
  38603. }
  38604. newSymbols.push(bitmap);
  38605. }
  38606. }
  38607. // 6.5.10 Exported symbols
  38608. var exportedSymbols = [];
  38609. var flags = [], currentFlag = false;
  38610. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  38611. while (flags.length < totalSymbolsLength) {
  38612. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  38613. while (runLength--) {
  38614. flags.push(currentFlag);
  38615. }
  38616. currentFlag = !currentFlag;
  38617. }
  38618. for (var i = 0, ii = symbols.length; i < ii; i++) {
  38619. if (flags[i]) {
  38620. exportedSymbols.push(symbols[i]);
  38621. }
  38622. }
  38623. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  38624. if (flags[i]) {
  38625. exportedSymbols.push(newSymbols[j]);
  38626. }
  38627. }
  38628. return exportedSymbols;
  38629. }
  38630. function decodeTextRegion(huffman, refinement, width, height,
  38631. defaultPixelValue, numberOfSymbolInstances,
  38632. stripSize, inputSymbols, symbolCodeLength,
  38633. transposed, dsOffset, referenceCorner,
  38634. combinationOperator, huffmanTables,
  38635. refinementTemplateIndex, refinementAt,
  38636. decodingContext) {
  38637. if (huffman) {
  38638. error('JBIG2 error: huffman is not supported');
  38639. }
  38640. // Prepare bitmap
  38641. var bitmap = [];
  38642. var i, row;
  38643. for (i = 0; i < height; i++) {
  38644. row = new Uint8Array(width);
  38645. if (defaultPixelValue) {
  38646. for (var j = 0; j < width; j++) {
  38647. row[j] = defaultPixelValue;
  38648. }
  38649. }
  38650. bitmap.push(row);
  38651. }
  38652. var decoder = decodingContext.decoder;
  38653. var contextCache = decodingContext.contextCache;
  38654. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38655. var firstS = 0;
  38656. i = 0;
  38657. while (i < numberOfSymbolInstances) {
  38658. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38659. stripT += deltaT;
  38660. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  38661. firstS += deltaFirstS;
  38662. var currentS = firstS;
  38663. do {
  38664. var currentT = (stripSize === 1 ? 0 :
  38665. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  38666. var t = stripSize * stripT + currentT;
  38667. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38668. var applyRefinement = (refinement &&
  38669. decodeInteger(contextCache, 'IARI', decoder));
  38670. var symbolBitmap = inputSymbols[symbolId];
  38671. var symbolWidth = symbolBitmap[0].length;
  38672. var symbolHeight = symbolBitmap.length;
  38673. if (applyRefinement) {
  38674. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  38675. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  38676. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38677. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38678. symbolWidth += rdw;
  38679. symbolHeight += rdh;
  38680. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  38681. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  38682. (rdh >> 1) + rdy, false, refinementAt,
  38683. decodingContext);
  38684. }
  38685. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  38686. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  38687. var s2, t2, symbolRow;
  38688. if (transposed) {
  38689. // Place Symbol Bitmap from T1,S1
  38690. for (s2 = 0; s2 < symbolHeight; s2++) {
  38691. row = bitmap[offsetS + s2];
  38692. if (!row) {
  38693. continue;
  38694. }
  38695. symbolRow = symbolBitmap[s2];
  38696. // To ignore Parts of Symbol bitmap which goes
  38697. // outside bitmap region
  38698. var maxWidth = Math.min(width - offsetT, symbolWidth);
  38699. switch (combinationOperator) {
  38700. case 0: // OR
  38701. for (t2 = 0; t2 < maxWidth; t2++) {
  38702. row[offsetT + t2] |= symbolRow[t2];
  38703. }
  38704. break;
  38705. case 2: // XOR
  38706. for (t2 = 0; t2 < maxWidth; t2++) {
  38707. row[offsetT + t2] ^= symbolRow[t2];
  38708. }
  38709. break;
  38710. default:
  38711. error('JBIG2 error: operator ' + combinationOperator +
  38712. ' is not supported');
  38713. }
  38714. }
  38715. currentS += symbolHeight - 1;
  38716. } else {
  38717. for (t2 = 0; t2 < symbolHeight; t2++) {
  38718. row = bitmap[offsetT + t2];
  38719. if (!row) {
  38720. continue;
  38721. }
  38722. symbolRow = symbolBitmap[t2];
  38723. switch (combinationOperator) {
  38724. case 0: // OR
  38725. for (s2 = 0; s2 < symbolWidth; s2++) {
  38726. row[offsetS + s2] |= symbolRow[s2];
  38727. }
  38728. break;
  38729. case 2: // XOR
  38730. for (s2 = 0; s2 < symbolWidth; s2++) {
  38731. row[offsetS + s2] ^= symbolRow[s2];
  38732. }
  38733. break;
  38734. default:
  38735. error('JBIG2 error: operator ' + combinationOperator +
  38736. ' is not supported');
  38737. }
  38738. }
  38739. currentS += symbolWidth - 1;
  38740. }
  38741. i++;
  38742. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  38743. if (deltaS === null) {
  38744. break; // OOB
  38745. }
  38746. currentS += deltaS + dsOffset;
  38747. } while (true);
  38748. }
  38749. return bitmap;
  38750. }
  38751. function readSegmentHeader(data, start) {
  38752. var segmentHeader = {};
  38753. segmentHeader.number = readUint32(data, start);
  38754. var flags = data[start + 4];
  38755. var segmentType = flags & 0x3F;
  38756. if (!SegmentTypes[segmentType]) {
  38757. error('JBIG2 error: invalid segment type: ' + segmentType);
  38758. }
  38759. segmentHeader.type = segmentType;
  38760. segmentHeader.typeName = SegmentTypes[segmentType];
  38761. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  38762. var pageAssociationFieldSize = !!(flags & 0x40);
  38763. var referredFlags = data[start + 5];
  38764. var referredToCount = (referredFlags >> 5) & 7;
  38765. var retainBits = [referredFlags & 31];
  38766. var position = start + 6;
  38767. if (referredFlags === 7) {
  38768. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  38769. position += 3;
  38770. var bytes = (referredToCount + 7) >> 3;
  38771. retainBits[0] = data[position++];
  38772. while (--bytes > 0) {
  38773. retainBits.push(data[position++]);
  38774. }
  38775. } else if (referredFlags === 5 || referredFlags === 6) {
  38776. error('JBIG2 error: invalid referred-to flags');
  38777. }
  38778. segmentHeader.retainBits = retainBits;
  38779. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  38780. (segmentHeader.number <= 65536 ? 2 : 4));
  38781. var referredTo = [];
  38782. var i, ii;
  38783. for (i = 0; i < referredToCount; i++) {
  38784. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  38785. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  38786. readUint32(data, position)));
  38787. referredTo.push(number);
  38788. position += referredToSegmentNumberSize;
  38789. }
  38790. segmentHeader.referredTo = referredTo;
  38791. if (!pageAssociationFieldSize) {
  38792. segmentHeader.pageAssociation = data[position++];
  38793. } else {
  38794. segmentHeader.pageAssociation = readUint32(data, position);
  38795. position += 4;
  38796. }
  38797. segmentHeader.length = readUint32(data, position);
  38798. position += 4;
  38799. if (segmentHeader.length === 0xFFFFFFFF) {
  38800. // 7.2.7 Segment data length, unknown segment length
  38801. if (segmentType === 38) { // ImmediateGenericRegion
  38802. var genericRegionInfo = readRegionSegmentInformation(data, position);
  38803. var genericRegionSegmentFlags = data[position +
  38804. RegionSegmentInformationFieldLength];
  38805. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  38806. // searching for the segment end
  38807. var searchPatternLength = 6;
  38808. var searchPattern = new Uint8Array(searchPatternLength);
  38809. if (!genericRegionMmr) {
  38810. searchPattern[0] = 0xFF;
  38811. searchPattern[1] = 0xAC;
  38812. }
  38813. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  38814. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  38815. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  38816. searchPattern[5] = genericRegionInfo.height & 0xFF;
  38817. for (i = position, ii = data.length; i < ii; i++) {
  38818. var j = 0;
  38819. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  38820. j++;
  38821. }
  38822. if (j === searchPatternLength) {
  38823. segmentHeader.length = i + searchPatternLength;
  38824. break;
  38825. }
  38826. }
  38827. if (segmentHeader.length === 0xFFFFFFFF) {
  38828. error('JBIG2 error: segment end was not found');
  38829. }
  38830. } else {
  38831. error('JBIG2 error: invalid unknown segment length');
  38832. }
  38833. }
  38834. segmentHeader.headerEnd = position;
  38835. return segmentHeader;
  38836. }
  38837. function readSegments(header, data, start, end) {
  38838. var segments = [];
  38839. var position = start;
  38840. while (position < end) {
  38841. var segmentHeader = readSegmentHeader(data, position);
  38842. position = segmentHeader.headerEnd;
  38843. var segment = {
  38844. header: segmentHeader,
  38845. data: data
  38846. };
  38847. if (!header.randomAccess) {
  38848. segment.start = position;
  38849. position += segmentHeader.length;
  38850. segment.end = position;
  38851. }
  38852. segments.push(segment);
  38853. if (segmentHeader.type === 51) {
  38854. break; // end of file is found
  38855. }
  38856. }
  38857. if (header.randomAccess) {
  38858. for (var i = 0, ii = segments.length; i < ii; i++) {
  38859. segments[i].start = position;
  38860. position += segments[i].header.length;
  38861. segments[i].end = position;
  38862. }
  38863. }
  38864. return segments;
  38865. }
  38866. // 7.4.1 Region segment information field
  38867. function readRegionSegmentInformation(data, start) {
  38868. return {
  38869. width: readUint32(data, start),
  38870. height: readUint32(data, start + 4),
  38871. x: readUint32(data, start + 8),
  38872. y: readUint32(data, start + 12),
  38873. combinationOperator: data[start + 16] & 7
  38874. };
  38875. }
  38876. var RegionSegmentInformationFieldLength = 17;
  38877. function processSegment(segment, visitor) {
  38878. var header = segment.header;
  38879. var data = segment.data, position = segment.start, end = segment.end;
  38880. var args, at, i, atLength;
  38881. switch (header.type) {
  38882. case 0: // SymbolDictionary
  38883. // 7.4.2 Symbol dictionary segment syntax
  38884. var dictionary = {};
  38885. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  38886. dictionary.huffman = !!(dictionaryFlags & 1);
  38887. dictionary.refinement = !!(dictionaryFlags & 2);
  38888. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  38889. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  38890. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  38891. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  38892. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  38893. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  38894. dictionary.template = (dictionaryFlags >> 10) & 3;
  38895. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  38896. position += 2;
  38897. if (!dictionary.huffman) {
  38898. atLength = dictionary.template === 0 ? 4 : 1;
  38899. at = [];
  38900. for (i = 0; i < atLength; i++) {
  38901. at.push({
  38902. x: readInt8(data, position),
  38903. y: readInt8(data, position + 1)
  38904. });
  38905. position += 2;
  38906. }
  38907. dictionary.at = at;
  38908. }
  38909. if (dictionary.refinement && !dictionary.refinementTemplate) {
  38910. at = [];
  38911. for (i = 0; i < 2; i++) {
  38912. at.push({
  38913. x: readInt8(data, position),
  38914. y: readInt8(data, position + 1)
  38915. });
  38916. position += 2;
  38917. }
  38918. dictionary.refinementAt = at;
  38919. }
  38920. dictionary.numberOfExportedSymbols = readUint32(data, position);
  38921. position += 4;
  38922. dictionary.numberOfNewSymbols = readUint32(data, position);
  38923. position += 4;
  38924. args = [dictionary, header.number, header.referredTo,
  38925. data, position, end];
  38926. break;
  38927. case 6: // ImmediateTextRegion
  38928. case 7: // ImmediateLosslessTextRegion
  38929. var textRegion = {};
  38930. textRegion.info = readRegionSegmentInformation(data, position);
  38931. position += RegionSegmentInformationFieldLength;
  38932. var textRegionSegmentFlags = readUint16(data, position);
  38933. position += 2;
  38934. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  38935. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  38936. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  38937. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  38938. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  38939. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  38940. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  38941. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  38942. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  38943. if (textRegion.huffman) {
  38944. var textRegionHuffmanFlags = readUint16(data, position);
  38945. position += 2;
  38946. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  38947. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  38948. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  38949. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  38950. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  38951. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  38952. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  38953. textRegion.huffmanRefinementSizeSelector =
  38954. !!(textRegionHuffmanFlags & 14);
  38955. }
  38956. if (textRegion.refinement && !textRegion.refinementTemplate) {
  38957. at = [];
  38958. for (i = 0; i < 2; i++) {
  38959. at.push({
  38960. x: readInt8(data, position),
  38961. y: readInt8(data, position + 1)
  38962. });
  38963. position += 2;
  38964. }
  38965. textRegion.refinementAt = at;
  38966. }
  38967. textRegion.numberOfSymbolInstances = readUint32(data, position);
  38968. position += 4;
  38969. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  38970. if (textRegion.huffman) {
  38971. error('JBIG2 error: huffman is not supported');
  38972. }
  38973. args = [textRegion, header.referredTo, data, position, end];
  38974. break;
  38975. case 38: // ImmediateGenericRegion
  38976. case 39: // ImmediateLosslessGenericRegion
  38977. var genericRegion = {};
  38978. genericRegion.info = readRegionSegmentInformation(data, position);
  38979. position += RegionSegmentInformationFieldLength;
  38980. var genericRegionSegmentFlags = data[position++];
  38981. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  38982. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  38983. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  38984. if (!genericRegion.mmr) {
  38985. atLength = genericRegion.template === 0 ? 4 : 1;
  38986. at = [];
  38987. for (i = 0; i < atLength; i++) {
  38988. at.push({
  38989. x: readInt8(data, position),
  38990. y: readInt8(data, position + 1)
  38991. });
  38992. position += 2;
  38993. }
  38994. genericRegion.at = at;
  38995. }
  38996. args = [genericRegion, data, position, end];
  38997. break;
  38998. case 48: // PageInformation
  38999. var pageInfo = {
  39000. width: readUint32(data, position),
  39001. height: readUint32(data, position + 4),
  39002. resolutionX: readUint32(data, position + 8),
  39003. resolutionY: readUint32(data, position + 12)
  39004. };
  39005. if (pageInfo.height === 0xFFFFFFFF) {
  39006. delete pageInfo.height;
  39007. }
  39008. var pageSegmentFlags = data[position + 16];
  39009. var pageStripingInformatiom = readUint16(data, position + 17);
  39010. pageInfo.lossless = !!(pageSegmentFlags & 1);
  39011. pageInfo.refinement = !!(pageSegmentFlags & 2);
  39012. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  39013. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  39014. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  39015. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  39016. args = [pageInfo];
  39017. break;
  39018. case 49: // EndOfPage
  39019. break;
  39020. case 50: // EndOfStripe
  39021. break;
  39022. case 51: // EndOfFile
  39023. break;
  39024. case 62: // 7.4.15 defines 2 extension types which
  39025. // are comments and can be ignored.
  39026. break;
  39027. default:
  39028. error('JBIG2 error: segment type ' + header.typeName + '(' +
  39029. header.type + ') is not implemented');
  39030. }
  39031. var callbackName = 'on' + header.typeName;
  39032. if (callbackName in visitor) {
  39033. visitor[callbackName].apply(visitor, args);
  39034. }
  39035. }
  39036. function processSegments(segments, visitor) {
  39037. for (var i = 0, ii = segments.length; i < ii; i++) {
  39038. processSegment(segments[i], visitor);
  39039. }
  39040. }
  39041. function parseJbig2(data, start, end) {
  39042. var position = start;
  39043. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  39044. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  39045. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  39046. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  39047. error('JBIG2 error: invalid header');
  39048. }
  39049. var header = {};
  39050. position += 8;
  39051. var flags = data[position++];
  39052. header.randomAccess = !(flags & 1);
  39053. if (!(flags & 2)) {
  39054. header.numberOfPages = readUint32(data, position);
  39055. position += 4;
  39056. }
  39057. var segments = readSegments(header, data, position, end);
  39058. error('Not implemented');
  39059. // processSegments(segments, new SimpleSegmentVisitor());
  39060. }
  39061. function parseJbig2Chunks(chunks) {
  39062. var visitor = new SimpleSegmentVisitor();
  39063. for (var i = 0, ii = chunks.length; i < ii; i++) {
  39064. var chunk = chunks[i];
  39065. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  39066. processSegments(segments, visitor);
  39067. }
  39068. return visitor.buffer;
  39069. }
  39070. function SimpleSegmentVisitor() {}
  39071. SimpleSegmentVisitor.prototype = {
  39072. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  39073. this.currentPageInfo = info;
  39074. var rowSize = (info.width + 7) >> 3;
  39075. var buffer = new Uint8Array(rowSize * info.height);
  39076. // The contents of ArrayBuffers are initialized to 0.
  39077. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  39078. if (info.defaultPixelValue) {
  39079. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39080. buffer[i] = 0xFF;
  39081. }
  39082. }
  39083. this.buffer = buffer;
  39084. },
  39085. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  39086. var pageInfo = this.currentPageInfo;
  39087. var width = regionInfo.width, height = regionInfo.height;
  39088. var rowSize = (pageInfo.width + 7) >> 3;
  39089. var combinationOperator = pageInfo.combinationOperatorOverride ?
  39090. regionInfo.combinationOperator : pageInfo.combinationOperator;
  39091. var buffer = this.buffer;
  39092. var mask0 = 128 >> (regionInfo.x & 7);
  39093. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  39094. var i, j, mask, offset;
  39095. switch (combinationOperator) {
  39096. case 0: // OR
  39097. for (i = 0; i < height; i++) {
  39098. mask = mask0;
  39099. offset = offset0;
  39100. for (j = 0; j < width; j++) {
  39101. if (bitmap[i][j]) {
  39102. buffer[offset] |= mask;
  39103. }
  39104. mask >>= 1;
  39105. if (!mask) {
  39106. mask = 128;
  39107. offset++;
  39108. }
  39109. }
  39110. offset0 += rowSize;
  39111. }
  39112. break;
  39113. case 2: // XOR
  39114. for (i = 0; i < height; i++) {
  39115. mask = mask0;
  39116. offset = offset0;
  39117. for (j = 0; j < width; j++) {
  39118. if (bitmap[i][j]) {
  39119. buffer[offset] ^= mask;
  39120. }
  39121. mask >>= 1;
  39122. if (!mask) {
  39123. mask = 128;
  39124. offset++;
  39125. }
  39126. }
  39127. offset0 += rowSize;
  39128. }
  39129. break;
  39130. default:
  39131. error('JBIG2 error: operator ' + combinationOperator +
  39132. ' is not supported');
  39133. }
  39134. },
  39135. onImmediateGenericRegion:
  39136. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  39137. start, end) {
  39138. var regionInfo = region.info;
  39139. var decodingContext = new DecodingContext(data, start, end);
  39140. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  39141. region.template, region.prediction, null,
  39142. region.at, decodingContext);
  39143. this.drawBitmap(regionInfo, bitmap);
  39144. },
  39145. onImmediateLosslessGenericRegion:
  39146. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  39147. this.onImmediateGenericRegion.apply(this, arguments);
  39148. },
  39149. onSymbolDictionary:
  39150. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  39151. currentSegment,
  39152. referredSegments,
  39153. data, start, end) {
  39154. var huffmanTables;
  39155. if (dictionary.huffman) {
  39156. error('JBIG2 error: huffman is not supported');
  39157. }
  39158. // Combines exported symbols from all referred segments
  39159. var symbols = this.symbols;
  39160. if (!symbols) {
  39161. this.symbols = symbols = {};
  39162. }
  39163. var inputSymbols = [];
  39164. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39165. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39166. }
  39167. var decodingContext = new DecodingContext(data, start, end);
  39168. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  39169. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  39170. dictionary.numberOfExportedSymbols, huffmanTables,
  39171. dictionary.template, dictionary.at,
  39172. dictionary.refinementTemplate, dictionary.refinementAt,
  39173. decodingContext);
  39174. },
  39175. onImmediateTextRegion:
  39176. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  39177. referredSegments,
  39178. data, start, end) {
  39179. var regionInfo = region.info;
  39180. var huffmanTables;
  39181. // Combines exported symbols from all referred segments
  39182. var symbols = this.symbols;
  39183. var inputSymbols = [];
  39184. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39185. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39186. }
  39187. var symbolCodeLength = log2(inputSymbols.length);
  39188. var decodingContext = new DecodingContext(data, start, end);
  39189. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  39190. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  39191. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  39192. symbolCodeLength, region.transposed, region.dsOffset,
  39193. region.referenceCorner, region.combinationOperator, huffmanTables,
  39194. region.refinementTemplate, region.refinementAt, decodingContext);
  39195. this.drawBitmap(regionInfo, bitmap);
  39196. },
  39197. onImmediateLosslessTextRegion:
  39198. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  39199. this.onImmediateTextRegion.apply(this, arguments);
  39200. }
  39201. };
  39202. function Jbig2Image() {}
  39203. Jbig2Image.prototype = {
  39204. parseChunks: function Jbig2Image_parseChunks(chunks) {
  39205. return parseJbig2Chunks(chunks);
  39206. }
  39207. };
  39208. return Jbig2Image;
  39209. })();
  39210. var bidi = PDFJS.bidi = (function bidiClosure() {
  39211. // Character types for symbols from 0000 to 00FF.
  39212. var baseTypes = [
  39213. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  39214. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39215. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  39216. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  39217. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  39218. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39219. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  39220. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39221. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39222. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  39223. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39224. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39225. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  39226. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  39227. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39228. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39229. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39230. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39231. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  39232. ];
  39233. // Character types for symbols from 0600 to 06FF
  39234. var arabicTypes = [
  39235. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39236. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  39237. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39238. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39240. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39241. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39242. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39243. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  39244. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39245. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39247. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39248. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39249. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39250. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39251. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39252. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39253. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39254. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  39255. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39256. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  39257. ];
  39258. function isOdd(i) {
  39259. return (i & 1) !== 0;
  39260. }
  39261. function isEven(i) {
  39262. return (i & 1) === 0;
  39263. }
  39264. function findUnequal(arr, start, value) {
  39265. for (var j = start, jj = arr.length; j < jj; ++j) {
  39266. if (arr[j] !== value) {
  39267. return j;
  39268. }
  39269. }
  39270. return j;
  39271. }
  39272. function setValues(arr, start, end, value) {
  39273. for (var j = start; j < end; ++j) {
  39274. arr[j] = value;
  39275. }
  39276. }
  39277. function reverseValues(arr, start, end) {
  39278. for (var i = start, j = end - 1; i < j; ++i, --j) {
  39279. var temp = arr[i];
  39280. arr[i] = arr[j];
  39281. arr[j] = temp;
  39282. }
  39283. }
  39284. function createBidiText(str, isLTR, vertical) {
  39285. return {
  39286. str: str,
  39287. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  39288. };
  39289. }
  39290. // These are used in bidi(), which is called frequently. We re-use them on
  39291. // each call to avoid unnecessary allocations.
  39292. var chars = [];
  39293. var types = [];
  39294. function bidi(str, startLevel, vertical) {
  39295. var isLTR = true;
  39296. var strLength = str.length;
  39297. if (strLength === 0 || vertical) {
  39298. return createBidiText(str, isLTR, vertical);
  39299. }
  39300. // Get types and fill arrays
  39301. chars.length = strLength;
  39302. types.length = strLength;
  39303. var numBidi = 0;
  39304. var i, ii;
  39305. for (i = 0; i < strLength; ++i) {
  39306. chars[i] = str.charAt(i);
  39307. var charCode = str.charCodeAt(i);
  39308. var charType = 'L';
  39309. if (charCode <= 0x00ff) {
  39310. charType = baseTypes[charCode];
  39311. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  39312. charType = 'R';
  39313. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  39314. charType = arabicTypes[charCode & 0xff];
  39315. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  39316. charType = 'AL';
  39317. }
  39318. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  39319. numBidi++;
  39320. }
  39321. types[i] = charType;
  39322. }
  39323. // Detect the bidi method
  39324. // - If there are no rtl characters then no bidi needed
  39325. // - If less than 30% chars are rtl then string is primarily ltr
  39326. // - If more than 30% chars are rtl then string is primarily rtl
  39327. if (numBidi === 0) {
  39328. isLTR = true;
  39329. return createBidiText(str, isLTR);
  39330. }
  39331. if (startLevel === -1) {
  39332. if ((strLength / numBidi) < 0.3) {
  39333. isLTR = true;
  39334. startLevel = 0;
  39335. } else {
  39336. isLTR = false;
  39337. startLevel = 1;
  39338. }
  39339. }
  39340. var levels = [];
  39341. for (i = 0; i < strLength; ++i) {
  39342. levels[i] = startLevel;
  39343. }
  39344. /*
  39345. X1-X10: skip most of this, since we are NOT doing the embeddings.
  39346. */
  39347. var e = (isOdd(startLevel) ? 'R' : 'L');
  39348. var sor = e;
  39349. var eor = sor;
  39350. /*
  39351. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  39352. type of the NSM to the type of the previous character. If the NSM is at the
  39353. start of the level run, it will get the type of sor.
  39354. */
  39355. var lastType = sor;
  39356. for (i = 0; i < strLength; ++i) {
  39357. if (types[i] === 'NSM') {
  39358. types[i] = lastType;
  39359. } else {
  39360. lastType = types[i];
  39361. }
  39362. }
  39363. /*
  39364. W2. Search backwards from each instance of a European number until the
  39365. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  39366. the type of the European number to Arabic number.
  39367. */
  39368. lastType = sor;
  39369. var t;
  39370. for (i = 0; i < strLength; ++i) {
  39371. t = types[i];
  39372. if (t === 'EN') {
  39373. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  39374. } else if (t === 'R' || t === 'L' || t === 'AL') {
  39375. lastType = t;
  39376. }
  39377. }
  39378. /*
  39379. W3. Change all ALs to R.
  39380. */
  39381. for (i = 0; i < strLength; ++i) {
  39382. t = types[i];
  39383. if (t === 'AL') {
  39384. types[i] = 'R';
  39385. }
  39386. }
  39387. /*
  39388. W4. A single European separator between two European numbers changes to a
  39389. European number. A single common separator between two numbers of the same
  39390. type changes to that type:
  39391. */
  39392. for (i = 1; i < strLength - 1; ++i) {
  39393. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  39394. types[i] = 'EN';
  39395. }
  39396. if (types[i] === 'CS' &&
  39397. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  39398. types[i + 1] === types[i - 1]) {
  39399. types[i] = types[i - 1];
  39400. }
  39401. }
  39402. /*
  39403. W5. A sequence of European terminators adjacent to European numbers changes
  39404. to all European numbers:
  39405. */
  39406. for (i = 0; i < strLength; ++i) {
  39407. if (types[i] === 'EN') {
  39408. // do before
  39409. var j;
  39410. for (j = i - 1; j >= 0; --j) {
  39411. if (types[j] !== 'ET') {
  39412. break;
  39413. }
  39414. types[j] = 'EN';
  39415. }
  39416. // do after
  39417. for (j = i + 1; j < strLength; --j) {
  39418. if (types[j] !== 'ET') {
  39419. break;
  39420. }
  39421. types[j] = 'EN';
  39422. }
  39423. }
  39424. }
  39425. /*
  39426. W6. Otherwise, separators and terminators change to Other Neutral:
  39427. */
  39428. for (i = 0; i < strLength; ++i) {
  39429. t = types[i];
  39430. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  39431. types[i] = 'ON';
  39432. }
  39433. }
  39434. /*
  39435. W7. Search backwards from each instance of a European number until the
  39436. first strong type (R, L, or sor) is found. If an L is found, then change
  39437. the type of the European number to L.
  39438. */
  39439. lastType = sor;
  39440. for (i = 0; i < strLength; ++i) {
  39441. t = types[i];
  39442. if (t === 'EN') {
  39443. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  39444. } else if (t === 'R' || t === 'L') {
  39445. lastType = t;
  39446. }
  39447. }
  39448. /*
  39449. N1. A sequence of neutrals takes the direction of the surrounding strong
  39450. text if the text on both sides has the same direction. European and Arabic
  39451. numbers are treated as though they were R. Start-of-level-run (sor) and
  39452. end-of-level-run (eor) are used at level run boundaries.
  39453. */
  39454. for (i = 0; i < strLength; ++i) {
  39455. if (types[i] === 'ON') {
  39456. var end = findUnequal(types, i + 1, 'ON');
  39457. var before = sor;
  39458. if (i > 0) {
  39459. before = types[i - 1];
  39460. }
  39461. var after = eor;
  39462. if (end + 1 < strLength) {
  39463. after = types[end + 1];
  39464. }
  39465. if (before !== 'L') {
  39466. before = 'R';
  39467. }
  39468. if (after !== 'L') {
  39469. after = 'R';
  39470. }
  39471. if (before === after) {
  39472. setValues(types, i, end, before);
  39473. }
  39474. i = end - 1; // reset to end (-1 so next iteration is ok)
  39475. }
  39476. }
  39477. /*
  39478. N2. Any remaining neutrals take the embedding direction.
  39479. */
  39480. for (i = 0; i < strLength; ++i) {
  39481. if (types[i] === 'ON') {
  39482. types[i] = e;
  39483. }
  39484. }
  39485. /*
  39486. I1. For all characters with an even (left-to-right) embedding direction,
  39487. those of type R go up one level and those of type AN or EN go up two
  39488. levels.
  39489. I2. For all characters with an odd (right-to-left) embedding direction,
  39490. those of type L, EN or AN go up one level.
  39491. */
  39492. for (i = 0; i < strLength; ++i) {
  39493. t = types[i];
  39494. if (isEven(levels[i])) {
  39495. if (t === 'R') {
  39496. levels[i] += 1;
  39497. } else if (t === 'AN' || t === 'EN') {
  39498. levels[i] += 2;
  39499. }
  39500. } else { // isOdd
  39501. if (t === 'L' || t === 'AN' || t === 'EN') {
  39502. levels[i] += 1;
  39503. }
  39504. }
  39505. }
  39506. /*
  39507. L1. On each line, reset the embedding level of the following characters to
  39508. the paragraph embedding level:
  39509. segment separators,
  39510. paragraph separators,
  39511. any sequence of whitespace characters preceding a segment separator or
  39512. paragraph separator, and any sequence of white space characters at the end
  39513. of the line.
  39514. */
  39515. // don't bother as text is only single line
  39516. /*
  39517. L2. From the highest level found in the text to the lowest odd level on
  39518. each line, reverse any contiguous sequence of characters that are at that
  39519. level or higher.
  39520. */
  39521. // find highest level & lowest odd level
  39522. var highestLevel = -1;
  39523. var lowestOddLevel = 99;
  39524. var level;
  39525. for (i = 0, ii = levels.length; i < ii; ++i) {
  39526. level = levels[i];
  39527. if (highestLevel < level) {
  39528. highestLevel = level;
  39529. }
  39530. if (lowestOddLevel > level && isOdd(level)) {
  39531. lowestOddLevel = level;
  39532. }
  39533. }
  39534. // now reverse between those limits
  39535. for (level = highestLevel; level >= lowestOddLevel; --level) {
  39536. // find segments to reverse
  39537. var start = -1;
  39538. for (i = 0, ii = levels.length; i < ii; ++i) {
  39539. if (levels[i] < level) {
  39540. if (start >= 0) {
  39541. reverseValues(chars, start, i);
  39542. start = -1;
  39543. }
  39544. } else if (start < 0) {
  39545. start = i;
  39546. }
  39547. }
  39548. if (start >= 0) {
  39549. reverseValues(chars, start, levels.length);
  39550. }
  39551. }
  39552. /*
  39553. L3. Combining marks applied to a right-to-left base character will at this
  39554. point precede their base character. If the rendering engine expects them to
  39555. follow the base characters in the final display process, then the ordering
  39556. of the marks and the base character must be reversed.
  39557. */
  39558. // don't bother for now
  39559. /*
  39560. L4. A character that possesses the mirrored property as specified by
  39561. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  39562. directionality of that character is R.
  39563. */
  39564. // don't mirror as characters are already mirrored in the pdf
  39565. // Finally, return string
  39566. var result = '';
  39567. for (i = 0, ii = chars.length; i < ii; ++i) {
  39568. var ch = chars[i];
  39569. if (ch !== '<' && ch !== '>') {
  39570. result += ch;
  39571. }
  39572. }
  39573. return createBidiText(result, isLTR);
  39574. }
  39575. return bidi;
  39576. })();
  39577. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  39578. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  39579. /* Copyright 2014 Opera Software ASA
  39580. *
  39581. * Licensed under the Apache License, Version 2.0 (the "License");
  39582. * you may not use this file except in compliance with the License.
  39583. * You may obtain a copy of the License at
  39584. *
  39585. * http://www.apache.org/licenses/LICENSE-2.0
  39586. *
  39587. * Unless required by applicable law or agreed to in writing, software
  39588. * distributed under the License is distributed on an "AS IS" BASIS,
  39589. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39590. * See the License for the specific language governing permissions and
  39591. * limitations under the License.
  39592. *
  39593. *
  39594. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  39595. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  39596. */
  39597. /* globals Uint32ArrayView */
  39598. 'use strict';
  39599. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  39600. // Workaround for missing math precison in JS.
  39601. var MASK_HIGH = 0xffff0000;
  39602. var MASK_LOW = 0xffff;
  39603. function MurmurHash3_64 (seed) {
  39604. var SEED = 0xc3d2e1f0;
  39605. this.h1 = seed ? seed & 0xffffffff : SEED;
  39606. this.h2 = seed ? seed & 0xffffffff : SEED;
  39607. }
  39608. var alwaysUseUint32ArrayView = false;
  39609. // old webkits have issues with non-aligned arrays
  39610. try {
  39611. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  39612. } catch (e) {
  39613. alwaysUseUint32ArrayView = true;
  39614. }
  39615. MurmurHash3_64.prototype = {
  39616. update: function MurmurHash3_64_update(input) {
  39617. var useUint32ArrayView = alwaysUseUint32ArrayView;
  39618. var i;
  39619. if (typeof input === 'string') {
  39620. var data = new Uint8Array(input.length * 2);
  39621. var length = 0;
  39622. for (i = 0; i < input.length; i++) {
  39623. var code = input.charCodeAt(i);
  39624. if (code <= 0xff) {
  39625. data[length++] = code;
  39626. }
  39627. else {
  39628. data[length++] = code >>> 8;
  39629. data[length++] = code & 0xff;
  39630. }
  39631. }
  39632. } else if (input instanceof Uint8Array) {
  39633. data = input;
  39634. length = data.length;
  39635. } else if (typeof input === 'object' && ('length' in input)) {
  39636. // processing regular arrays as well, e.g. for IE9
  39637. data = input;
  39638. length = data.length;
  39639. useUint32ArrayView = true;
  39640. } else {
  39641. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  39642. 'Input must be a string or array.');
  39643. }
  39644. var blockCounts = length >> 2;
  39645. var tailLength = length - blockCounts * 4;
  39646. // we don't care about endianness here
  39647. var dataUint32 = useUint32ArrayView ?
  39648. new Uint32ArrayView(data, blockCounts) :
  39649. new Uint32Array(data.buffer, 0, blockCounts);
  39650. var k1 = 0;
  39651. var k2 = 0;
  39652. var h1 = this.h1;
  39653. var h2 = this.h2;
  39654. var C1 = 0xcc9e2d51;
  39655. var C2 = 0x1b873593;
  39656. var C1_LOW = C1 & MASK_LOW;
  39657. var C2_LOW = C2 & MASK_LOW;
  39658. for (i = 0; i < blockCounts; i++) {
  39659. if (i & 1) {
  39660. k1 = dataUint32[i];
  39661. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39662. k1 = k1 << 15 | k1 >>> 17;
  39663. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39664. h1 ^= k1;
  39665. h1 = h1 << 13 | h1 >>> 19;
  39666. h1 = h1 * 5 + 0xe6546b64;
  39667. } else {
  39668. k2 = dataUint32[i];
  39669. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  39670. k2 = k2 << 15 | k2 >>> 17;
  39671. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  39672. h2 ^= k2;
  39673. h2 = h2 << 13 | h2 >>> 19;
  39674. h2 = h2 * 5 + 0xe6546b64;
  39675. }
  39676. }
  39677. k1 = 0;
  39678. switch (tailLength) {
  39679. case 3:
  39680. k1 ^= data[blockCounts * 4 + 2] << 16;
  39681. /* falls through */
  39682. case 2:
  39683. k1 ^= data[blockCounts * 4 + 1] << 8;
  39684. /* falls through */
  39685. case 1:
  39686. k1 ^= data[blockCounts * 4];
  39687. /* falls through */
  39688. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39689. k1 = k1 << 15 | k1 >>> 17;
  39690. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39691. if (blockCounts & 1) {
  39692. h1 ^= k1;
  39693. } else {
  39694. h2 ^= k1;
  39695. }
  39696. }
  39697. this.h1 = h1;
  39698. this.h2 = h2;
  39699. return this;
  39700. },
  39701. hexdigest: function MurmurHash3_64_hexdigest () {
  39702. var h1 = this.h1;
  39703. var h2 = this.h2;
  39704. h1 ^= h2 >>> 1;
  39705. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  39706. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  39707. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  39708. h1 ^= h2 >>> 1;
  39709. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  39710. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  39711. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  39712. h1 ^= h2 >>> 1;
  39713. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  39714. var hex = (arr[i] >>> 0).toString(16);
  39715. while (hex.length < 8) {
  39716. hex = '0' + hex;
  39717. }
  39718. str += hex;
  39719. }
  39720. return str;
  39721. }
  39722. };
  39723. return MurmurHash3_64;
  39724. })();
  39725. }).call((typeof window === 'undefined') ? this : window);
  39726. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  39727. // workerSrc is not set -- using last script url to define default location
  39728. PDFJS.workerSrc = (function () {
  39729. 'use strict';
  39730. var scriptTagContainer = document.body ||
  39731. document.getElementsByTagName('head')[0];
  39732. var pdfjsSrc = scriptTagContainer.lastChild.src;
  39733. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  39734. })();
  39735. }